diff --git a/iTrust/WebRoot/WEB-INF/web.xml b/iTrust/WebRoot/WEB-INF/web.xml index aa258d6cab4e7c258a1c7429be34407b3ad79c4a..7966ebc7be34ad02d8e3c21af015fadebdd5c4ec 100644 --- a/iTrust/WebRoot/WEB-INF/web.xml +++ b/iTrust/WebRoot/WEB-INF/web.xml @@ -246,10 +246,12 @@ </web-resource-name> <!-- Define the context-relative URL(s) to be protected --> <url-pattern>/auth/admin/*</url-pattern> + <url-pattern>/auth/tester/*</url-pattern> </web-resource-collection> <auth-constraint> <!-- Anyone with one of the listed roles may access this area --> <role-name>admin</role-name> + <role-name>tester</role-name> </auth-constraint> </security-constraint> diff --git a/iTrust/WebRoot/auth/admin/menu.jsp b/iTrust/WebRoot/auth/admin/menu.jsp index cdfeab9ebcff917fee0794622deacf7328308849..4c6caef6330958468d1c90e3e3165ca74c4b509d 100644 --- a/iTrust/WebRoot/auth/admin/menu.jsp +++ b/iTrust/WebRoot/auth/admin/menu.jsp @@ -56,6 +56,7 @@ <li><a href="/iTrust/auth/admin/sessionTimeout.jsp">Change Global Session Timeout </a></li> <li><a href="/iTrust/auth/surveyResults.jsp">Satisfaction Survey Results</a></li> <li><a href="/iTrust/auth/admin/activatePatient.jsp">Activate Patient</a></li> + <li><a href="/iTrust/auth/admin/viewTransactionLogs.jsp">View Transaction Logs</a></li> <li><a href="/iTrust/auth/admin/sendAppointmentReminders.jsp">Send Appointment Reminders</a></li> </ul> </div> diff --git a/iTrust/WebRoot/auth/admin/viewTransactionLogs.jsp b/iTrust/WebRoot/auth/admin/viewTransactionLogs.jsp new file mode 100644 index 0000000000000000000000000000000000000000..ca0dbb2110a1f6f76cca84fcd6332647cd1ad684 --- /dev/null +++ b/iTrust/WebRoot/auth/admin/viewTransactionLogs.jsp @@ -0,0 +1,412 @@ +<%@taglib uri="/WEB-INF/tags.tld" prefix="itrust"%> +<%@page errorPage="/auth/exceptionHandler.jsp"%> + +<%@page import="java.util.List"%> +<%@page import="java.util.ArrayList"%> +<%@page import="java.util.Iterator"%> +<%@page import="java.util.Date"%> +<%@page import="java.text.DateFormat"%> +<%@page import="java.text.SimpleDateFormat"%> +<%@page import="java.sql.Timestamp"%> +<%@page import="java.util.HashMap"%> +<%@page import="java.util.TreeMap"%> +<%@page import="java.lang.String"%> +<%@page import="edu.ncsu.csc.itrust.exception.FormValidationException"%> +<%@page import="edu.ncsu.csc.itrust.enums.TransactionType"%> +<%@page import="edu.ncsu.csc.itrust.dao.DAOFactory"%> +<%@page import="edu.ncsu.csc.itrust.beans.TransactionBean"%> +<%@page import="edu.ncsu.csc.itrust.beans.TransactionWithRoleBean"%> +<%@page import="org.apache.commons.lang.StringEscapeUtils"%> +<%@page import="edu.ncsu.csc.itrust.enums.TransactionType"%> +<%@page import="edu.ncsu.csc.itrust.enums.Role"%> + + +<%@include file="/global.jsp" %> + +<% +pageTitle = "iTrust - View Transaction Logs"; +String view = request.getParameter("viewSelect"); +%> + +<%@include file="/header.jsp" %> +<% + //get form data + String startDate = request.getParameter("startDate"); + String endDate = request.getParameter("endDate"); + String mainRole = request.getParameter("mainRole"); + String secondRole = request.getParameter("secondRole"); + String transactionType = request.getParameter("transactionType"); + String convertedDate = request.getParameter("convertedDate"); + SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy"); + String formatted = df.format(new Date()); + + if (startDate == null) + startDate = "01/01/2000"; + if (endDate == null) + endDate = formatted; +%> +<br /> +<form action="viewTransactionLogs.jsp" method="post" id="formMain"> +<input type="hidden" name="viewSelect" value=""/> +<table class="fTable" align="center" id="transactionLogsTable"> + <tr> + <th colspan="4">View Transaction Logs</th> + </tr> + <tr class="subHeader"> + <td>Start Date:</td> + <td> + <input name="startDate" value="<%= StringEscapeUtils.escapeHtml("" + (startDate)) %>" size="10"> + <input type=button value="Select Date" onclick="displayDatePicker('startDate');"> + </td> + <td>End Date:</td> + <td> + <input name="endDate" value="<%= StringEscapeUtils.escapeHtml("" + (endDate)) %>" size="10"> + <input type=button value="Select Date" onclick="displayDatePicker('endDate');"> + </td> + </tr> + <tr class="subHeader"> + <td>Main Role:</td> + <td> + <select name="mainRole" style="font-size:10" > + <option value="All"> All</option> + <% + for(Role type : Role.values()){ + %><option value="<%= StringEscapeUtils.escapeHtml("" + (type.getUserRolesString()))%>"><%=type.getUserRolesString()%></option><% + } + %> + </select> + </td> + <td>Secondary Role:</td> + <td> + <select name="secondRole" style="font-size:10" > + <option value="All"> All</option> + <% + for(Role type : Role.values()){ + %><option value="<%= StringEscapeUtils.escapeHtml("" + (type.getUserRolesString()))%>"><%=type.getUserRolesString()%></option><% + } + %> + <option value="N/A"> N/A</option> + </select> + </td> + </tr> + <tr class="subHeader"> + <td colspan="2" style="text-align: left;">Transaction Type:</td> + <td> + <select name="transactionType" style="font-size:10" > + <option value="All"> All</option> + <% + for(TransactionType type : TransactionType.values()){ + %><option value="<%= StringEscapeUtils.escapeHtml("" + (type.name()))%>"><%=type.name()%> + </option><% + } + %> + </select> + </td> + <td></td> + </tr> + <tr> + <td colspan="1" style="text-align: center;"><input type="submit" id="viewReport" value="View Report" onclick="document.forms[0].elements['viewSelect'].value = 'view report clicked';return true;"></td> + <td colspan="1" style="text-align: center;"><input type="submit" id="viewGraph" value="Summarize" onclick="document.forms[0].elements['viewSelect'].value = 'summarize clicked';return true;"></td> + <td> </td> + <td colspan="1" style="text-align: center;"><button><a href="viewTransactionLogs.jsp?reset=true" style="text-decoration:none; padding: 0.4em;color:black;">Reset</a></button></td> + + </tr> +</table> +</form> +<br /> +<% + +String resetCheck = null; +if(request.getParameter("reset")!= null){ + resetCheck = request.getParameter("reset"); +} + +if (view != null && view.equals("view report clicked") && resetCheck != "true") { %> + <table border=1 align="center"> + <% + List<TransactionWithRoleBean> list = DAOFactory.getProductionInstance().getTransactionDAO().getAllTransactionsWithRoles(); + SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); + Date convertedSimpleDate = null; + Date startSimpleDate = null; + Date endSimpleDate = null; + + if(startDate != ""){ + startSimpleDate = sdf.parse(startDate); + } + else{ + startSimpleDate = sdf.parse("01/01/2000"); + } + if(endDate != ""){ + endSimpleDate = sdf.parse(endDate); + } + else{ + endSimpleDate = sdf.parse(formatted); + } + + boolean dateFormatError = false; + String regex = "^(1[0-2]|0[1-9])/(3[01]|[12][0-9]|0[1-9])/[0-9]{4}$"; + boolean result = (startDate.matches(regex)||startDate.equals("")) && (endDate.matches(regex)||endDate.equals("")); + if(!result) { + dateFormatError = true; + %> + <span class="iTrustError">ERROR: Date must by in the format: MM/dd/yyyy</span> + <% + } + else if(endSimpleDate.before(startSimpleDate)){ + dateFormatError = true; + %> + <span class="iTrustError">ERROR: End Date cannot be before Start Date</span> + <% + } + + int countEntries = 0; + if(!dateFormatError){ + %> + <tr> + <th>Main Role</th> + <th>Secondary Role</th> + <th>Type</th> + <th>Extra Info</th> + <th>Time Logged</th> + </tr> + <% + for (TransactionWithRoleBean t : list) { + + convertedSimpleDate = sdf.parse(StringEscapeUtils.escapeHtml("" + (t.getConvertedDate()))); + + if(StringEscapeUtils.escapeHtml("" + (t.getMainRole())).equals(StringEscapeUtils.escapeHtml(mainRole)) + || StringEscapeUtils.escapeHtml(mainRole).equals("All")){ + if(StringEscapeUtils.escapeHtml("" + (t.getSecondaryRole())).equals(StringEscapeUtils.escapeHtml(secondRole)) + || StringEscapeUtils.escapeHtml(secondRole).equals("All")){ + if(StringEscapeUtils.escapeHtml("" + (t.getTransactionType().name())).equals(StringEscapeUtils.escapeHtml (transactionType)) || StringEscapeUtils.escapeHtml(transactionType).equals("All")){ + if((convertedSimpleDate.before(endSimpleDate) || convertedSimpleDate.equals(endSimpleDate)) && (convertedSimpleDate.after(startSimpleDate) || convertedSimpleDate.equals(startSimpleDate))){ + countEntries++; + %> + <tr id="resultRow"> + <td id="mainTD"><%= StringEscapeUtils.escapeHtml("" + (t.getMainRole())) %></td> + <td id="secondTD"><%= StringEscapeUtils.escapeHtml("" + (t.getSecondaryRole())) %></td> + <td id="typeTD"><%= StringEscapeUtils.escapeHtml("" + (t.getTransactionType().name())) %></td> + <td id="infoTD"><%= StringEscapeUtils.escapeHtml("" + (t.getAddedInfo())) %></td> + <td id="timeTD"><%= StringEscapeUtils.escapeHtml("" + (t.getTimeLogged())) %></td> + </tr> + <% + } + } + } + } + } + + if(countEntries == 0){ + %> + <tr id="resultRow"> + <td style="color:red;" id="noResults" colspan="5">There are no results for the criteria specified</td> + </tr> + <% + } + } + %> + </table> + +<% } %> + +<% +if (view != null && view.equals("summarize clicked") && resetCheck != "true") { + List<TransactionWithRoleBean> list = DAOFactory.getProductionInstance().getTransactionDAO().getAllTransactionsWithRoles(); + List<TransactionWithRoleBean> filteredList = new ArrayList(); + SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); + Date convertedSimpleDate = null; + Date startSimpleDate = null; + Date endSimpleDate = null; + if(startDate != ""){ + startSimpleDate = sdf.parse(startDate); + } + else{ + startSimpleDate = sdf.parse("01/01/2000"); + } + if(endDate != ""){ + endSimpleDate = sdf.parse(endDate); + } + else{ + endSimpleDate = sdf.parse(formatted); + } + + boolean dateFormatError = false; + String regex = "^(1[0-2]|0[1-9])/(3[01]|[12][0-9]|0[1-9])/[0-9]{4}$"; + boolean result = (startDate.matches(regex)||startDate.equals("")) && (endDate.matches(regex)||endDate.equals("")); + if(!result) { + dateFormatError = true; + %> + <span class="iTrustError">ERROR: Date must by in the format: MM/dd/yyyy</span> + <% + } + else if(endSimpleDate.before(startSimpleDate)){ + dateFormatError = true; + %> + <span class="iTrustError">ERROR: End Date cannot be before Start Date</span> + <% + } + %> + <h2 align="center" >Summary of Transactions</h2> + <% + + for (TransactionWithRoleBean t : list) { + + convertedSimpleDate = sdf.parse(StringEscapeUtils.escapeHtml("" + (t.getConvertedDate()))); + + if(StringEscapeUtils.escapeHtml("" + (t.getMainRole())).equals(StringEscapeUtils.escapeHtml(mainRole)) + || StringEscapeUtils.escapeHtml(mainRole).equals("All")){ + if(StringEscapeUtils.escapeHtml("" + (t.getSecondaryRole())).equals(StringEscapeUtils.escapeHtml(secondRole)) + || StringEscapeUtils.escapeHtml(secondRole).equals("All")){ + if(StringEscapeUtils.escapeHtml("" + (t.getTransactionType().name())).equals(StringEscapeUtils.escapeHtml (transactionType)) || StringEscapeUtils.escapeHtml(transactionType).equals("All")){ + if((convertedSimpleDate.before(endSimpleDate) || convertedSimpleDate.equals(endSimpleDate)) && (convertedSimpleDate.after(startSimpleDate) || convertedSimpleDate.equals(startSimpleDate))){ + filteredList.add(t); + } + } + } + } + } + + if (filteredList.isEmpty()) { + %> + <h4 align="center" style="color:red;" id="noResults">There are no results for the criteria specified</h4> + <% + } + else { + HashMap<String, Integer> mainRoleMap = new HashMap<String, Integer>(); + HashMap<String, Integer> secondaryRoleMap = new HashMap<String, Integer>(); + HashMap<String, Integer> transactionMonthMap = new HashMap<String, Integer>(); + HashMap<String, Integer> transactionTypeMap = new HashMap<String, Integer>(); + + for (TransactionWithRoleBean tb : filteredList) { + String key = tb.getMainRole(); + String key2 = tb.getSecondaryRole(); + String key3 = tb.getTimeLogged().toString(); + key3 = key3.substring(0, 7); + String key4 = tb.getTransactionType().getDescription(); + + if (mainRoleMap.get(key) == null) { + mainRoleMap.put(key, 1); + } else { + mainRoleMap.put(key, mainRoleMap.get(key) + 1); + } + + if (secondaryRoleMap.get(key2) == null) { + secondaryRoleMap.put(key2, 1); + } else { + secondaryRoleMap.put(key2, secondaryRoleMap.get(key2) + 1); + } + + if (transactionMonthMap.get(key3) == null){ + transactionMonthMap.put(key3, 1); + } else { + transactionMonthMap.put(key3, transactionMonthMap.get(key3) + 1); + } + + if (transactionTypeMap.get(key4) == null) { + transactionTypeMap.put(key4, 1); + } else { + transactionTypeMap.put(key4, transactionTypeMap.get(key4) + 1); + } + } + + TreeMap<String, Integer> sortedMonthMap = new TreeMap<>(); + sortedMonthMap.putAll(transactionMonthMap); + + %> + <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> + <script type="text/javascript"> + + google.charts.load('current', {'packages':['corechart']}); + + google.charts.setOnLoadCallback(drawGraphs); + + function drawGraphs() { + + var data = new google.visualization.DataTable(); + data.addColumn('string', 'MainRole'); + data.addColumn('number', 'Count'); + + var data2 = new google.visualization.DataTable(); + data2.addColumn('string', 'SecondaryRole'); + data2.addColumn('number', 'Count'); + + var data3 = new google.visualization.DataTable(); + data3.addColumn('string', 'Month'); + data3.addColumn('number', 'Count'); + + var data4 = new google.visualization.DataTable(); + data4.addColumn('string', 'TransactionType'); + data4.addColumn('number', 'Count'); + + <%for (String key : mainRoleMap.keySet()) {%> + data.addRows([['<%=key%>', <%=mainRoleMap.get(key)%>]]); + <%}%> + + <%for (String key : secondaryRoleMap.keySet()) {%> + data2.addRows([['<%=key%>', <%=secondaryRoleMap.get(key)%>]]); + <%}%> + + <%for (String key : sortedMonthMap.keySet()) {%> + data3.addRows([['<%=key%>', <%=sortedMonthMap.get(key)%>]]); + <%}%> + + <%for (String key : transactionTypeMap.keySet()) {%> + data4.addRows([['<%=key%>', <%=transactionTypeMap.get(key)%>]]); + <%}%> + + var options = {'title':'Number of Transactions per Main Role', + 'width':600, + 'height':500, + 'legend' : 'none'}; + + var options2 = {'title':'Number of Transactions per Secondary Role', + 'width':600, + 'height':500, + 'legend' : 'none'}; + + var options3 = {'title':'Number of Transactions per Month', + 'width':600, + 'height':500, + 'legend' : 'none'}; + + var options4 = {'title':'Number of Transactions per Transaction Type', + 'width':600, + 'height':500, + 'legend' : 'none'}; + + var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); + var chart2 = new google.visualization.ColumnChart(document.getElementById('chart_div2')); + var chart3 = new google.visualization.ColumnChart(document.getElementById('chart_div3')); + var chart4 = new google.visualization.ColumnChart(document.getElementById('chart_div4')); + chart.draw(data, options); + chart2.draw(data2, options2); + chart3.draw(data3, options3); + chart4.draw(data4, options4); + } + </script> + <table id="Graph_table" class="fTable"> + <tr> + <td> + <div id="chart_div"></div> + </td> + <td> + <div id="chart_div2"></div> + </td> + </tr> + <tr> + <td> + <div id="chart_div3"></div> + </td> + <td> + <div id="chart_div4"></div> + </td> + </tr> + </table> + <% + } +} +%> + +<br /> + +<%@include file="/footer.jsp" %> \ No newline at end of file diff --git a/iTrust/WebRoot/auth/tester/menu.jsp b/iTrust/WebRoot/auth/tester/menu.jsp index 4333be9eb3ec2de480370398a7715db0fceea7fb..f243696898823a94d27ff87043d55926bbf97efc 100644 --- a/iTrust/WebRoot/auth/tester/menu.jsp +++ b/iTrust/WebRoot/auth/tester/menu.jsp @@ -5,6 +5,7 @@ <div class="panel-body" id="view-menu"> <ul class="nav nav-sidebar"> <li><a href="/iTrust/auth/tester/home.jsp">Operational Profile</a></li> + <li><a href="/iTrust/auth/admin/viewTransactionLogs.jsp">View Transaction Logs</a></li> </ul> </div> </div> \ No newline at end of file diff --git a/iTrust/src/edu/ncsu/csc/itrust/beans/TransactionWithRoleBean.java b/iTrust/src/edu/ncsu/csc/itrust/beans/TransactionWithRoleBean.java new file mode 100644 index 0000000000000000000000000000000000000000..de1ac7d6f0256c7a9b934e1d64532ea3409a2c04 --- /dev/null +++ b/iTrust/src/edu/ncsu/csc/itrust/beans/TransactionWithRoleBean.java @@ -0,0 +1,100 @@ +package edu.ncsu.csc.itrust.beans; + +import java.sql.Timestamp; +import edu.ncsu.csc.itrust.enums.TransactionType; + +/** + * A bean for storing data about a transaction that occurred within iTrust. + * + * A bean's purpose is to store data. Period. Little or no functionality is to + * be added to a bean (with the exception of minor formatting such as + * concatenating phone numbers together). A bean must only have Getters and + * Setters (Eclipse Hint: Use Source > Generate Getters and Setters to create + * these easily) + */ +public class TransactionWithRoleBean { + private String mainRole; + private String secondaryRole; + private long transactionID; + private long loggedInMID; + private long secondaryMID; + private TransactionType transactionType; + private Timestamp timeLogged; + private String addedInfo; + private String convertedDate; + + public TransactionWithRoleBean() { + } + + public String getMainRole() { + return mainRole; + } + + public void setMainRole(String mainRole) { + this.mainRole = mainRole; + } + + public String getSecondaryRole() { + return secondaryRole; + } + + public void setSecondaryRole(String secondaryRole) { + this.secondaryRole = secondaryRole; + } + + public String getAddedInfo() { + return addedInfo; + } + + public void setAddedInfo(String addedInfo) { + this.addedInfo = addedInfo; + } + + public long getLoggedInMID() { + return loggedInMID; + } + + public void setLoggedInMID(long loggedInMID) { + this.loggedInMID = loggedInMID; + } + + public long getSecondaryMID() { + return secondaryMID; + } + + public void setSecondaryMID(long secondaryMID) { + this.secondaryMID = secondaryMID; + } + + public Timestamp getTimeLogged() { + return (Timestamp) timeLogged.clone(); + } + + public void setTimeLogged(Timestamp timeLogged) { + this.timeLogged = (Timestamp) timeLogged.clone(); + } + + public TransactionType getTransactionType() { + return transactionType; + } + + public void setTransactionType(TransactionType tranactionType) { + this.transactionType = tranactionType; + } + + public long getTransactionID() { + return transactionID; + } + + public void setTransactionID(long transactionID) { + this.transactionID = transactionID; + } + + public String getConvertedDate() { + return convertedDate; + } + + public void setConvertedDate(String convertedDate) { + this.convertedDate = convertedDate; + } +} diff --git a/iTrust/src/edu/ncsu/csc/itrust/beans/loaders/TransactionBeanWithRoleLoader.java b/iTrust/src/edu/ncsu/csc/itrust/beans/loaders/TransactionBeanWithRoleLoader.java new file mode 100644 index 0000000000000000000000000000000000000000..00f056f30c393af07cc804af6335438805a072af --- /dev/null +++ b/iTrust/src/edu/ncsu/csc/itrust/beans/loaders/TransactionBeanWithRoleLoader.java @@ -0,0 +1,46 @@ +package edu.ncsu.csc.itrust.beans.loaders; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import edu.ncsu.csc.itrust.beans.TransactionWithRoleBean; +import edu.ncsu.csc.itrust.enums.TransactionType; + +/** + * A loader for TransactionBeans. + * + * Loads in information to/from beans using ResultSets and PreparedStatements. + * Use the superclass to enforce consistency. For details on the paradigm for a + * loader (and what its methods do), see {@link BeanLoader} + */ +public class TransactionBeanWithRoleLoader implements BeanLoader<TransactionWithRoleBean> { + + public List<TransactionWithRoleBean> loadList(ResultSet rs) throws SQLException { + List<TransactionWithRoleBean> list = new ArrayList<TransactionWithRoleBean>(); + while (rs.next()) { + list.add(loadSingle(rs)); + } + return list; + } + + public PreparedStatement loadParameters(PreparedStatement ps, TransactionWithRoleBean bean) throws SQLException { + throw new IllegalStateException("unimplemented!"); + } + + public TransactionWithRoleBean loadSingle(ResultSet rs) throws SQLException { + TransactionWithRoleBean t = new TransactionWithRoleBean(); + t.setMainRole(rs.getString("mainRole")); + t.setSecondaryRole(rs.getString("secondaryRole")); + t.setAddedInfo(rs.getString("addedInfo")); + t.setLoggedInMID(rs.getLong("loggedInMID")); + t.setSecondaryMID(rs.getLong("secondaryMID")); + t.setTimeLogged(rs.getTimestamp("timeLogged")); + t.setTransactionType(TransactionType.parse(rs.getInt("transactionCode"))); + t.setTransactionID(rs.getLong("transactionID")); + t.setConvertedDate(rs.getString("convertedDate")); + return t; + } + +} diff --git a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/ApptDAO.java b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/ApptDAO.java index 7b91089e577109761c010f43d9c6ddbb65f0becf..8f40629f4b6d575c41154a4f05f9a1b0e643e45e 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/ApptDAO.java +++ b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/ApptDAO.java @@ -342,7 +342,7 @@ public class ApptDAO { conn = factory.getConnection(); pstring = conn.prepareStatement( - "SELECT * FROM appointment WHERE " + /*" sched_date.after(?)=TRUE AND sched_date.before(?)=TRUE");*/ + "SELECT * FROM appointment WHERE " + "DATE(sched_date)<=DATE_ADD(CURRENT_DATE, INTERVAL ? DAY) AND " + //sched_date day is before or at (numDays) days from now "sched_date>=CURRENT_DATE"); // sched_date is after today diff --git a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/TransactionDAO.java b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/TransactionDAO.java index 8868c73c018e39e206c05d7e6e245e344844f3ba..05db48dd0a30767adabce33bfce43b50ed73a74f 100644 --- a/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/TransactionDAO.java +++ b/iTrust/src/edu/ncsu/csc/itrust/dao/mysql/TransactionDAO.java @@ -10,8 +10,10 @@ import java.util.List; import edu.ncsu.csc.itrust.DBUtil; import edu.ncsu.csc.itrust.beans.OperationalProfile; import edu.ncsu.csc.itrust.beans.TransactionBean; +import edu.ncsu.csc.itrust.beans.TransactionWithRoleBean; import edu.ncsu.csc.itrust.beans.loaders.OperationalProfileLoader; import edu.ncsu.csc.itrust.beans.loaders.TransactionBeanLoader; +import edu.ncsu.csc.itrust.beans.loaders.TransactionBeanWithRoleLoader; import edu.ncsu.csc.itrust.dao.DAOFactory; import edu.ncsu.csc.itrust.enums.TransactionType; import edu.ncsu.csc.itrust.exception.DBException; @@ -19,25 +21,30 @@ import edu.ncsu.csc.itrust.exception.DBException; /** * Used for the logging mechanism. * - * DAO stands for Database Access Object. All DAOs are intended to be reflections of the database, that is, - * one DAO per table in the database (most of the time). For more complex sets of queries, extra DAOs are - * added. DAOs can assume that all data has been validated and is correct. + * DAO stands for Database Access Object. All DAOs are intended to be + * reflections of the database, that is, one DAO per table in the database (most + * of the time). For more complex sets of queries, extra DAOs are added. DAOs + * can assume that all data has been validated and is correct. * - * DAOs should never have setters or any other parameter to the constructor than a factory. All DAOs should be - * accessed by DAOFactory (@see {@link DAOFactory}) and every DAO should have a factory - for obtaining JDBC + * DAOs should never have setters or any other parameter to the constructor than + * a factory. All DAOs should be accessed by DAOFactory (@see + * {@link DAOFactory}) and every DAO should have a factory - for obtaining JDBC * connections and/or accessing other DAOs. * - * + * * */ public class TransactionDAO { private DAOFactory factory; private TransactionBeanLoader loader = new TransactionBeanLoader(); + private TransactionBeanWithRoleLoader loaderWithRole = new TransactionBeanWithRoleLoader(); private OperationalProfileLoader operationalProfileLoader = new OperationalProfileLoader(); /** * The typical constructor. - * @param factory The {@link DAOFactory} associated with this DAO, which is used for obtaining SQL connections, etc. + * + * @param factory The {@link DAOFactory} associated with this DAO, which is used + * for obtaining SQL connections, etc. */ public TransactionDAO(DAOFactory factory) { this.factory = factory; @@ -61,7 +68,33 @@ public class TransactionDAO { ps.close(); return loadlist; } catch (SQLException e) { - + + throw new DBException(e); + } finally { + DBUtil.closeConnection(conn, ps); + } + } + + /** + * Returns the whole transaction log with roles for main and secondary users + * + * @return + * @throws DBException + */ + public List<TransactionWithRoleBean> getAllTransactionsWithRoles() throws DBException { + Connection conn = null; + PreparedStatement ps = null; + try { + conn = factory.getConnection(); + ps = conn.prepareStatement( + "SELECT u1.Role mainRole, CASE WHEN u2.Role IS NULL THEN 'N/A' ELSE u2.Role END AS secondaryRole,t.transactionID,t.loggedInMID,t.secondaryMID,t.transactionCode,t.timeLogged,t.addedInfo,DATE_FORMAT(timeLogged,'%m/%d/%Y') convertedDate FROM transactionlog t LEFT OUTER JOIN users u1 ON t.loggedinMID = u1.MID LEFT OUTER JOIN users u2 ON t.secondaryMID = u2.MID ORDER BY timeLogged DESC"); + ResultSet rs = ps.executeQuery(); + List<TransactionWithRoleBean> loadlist = loaderWithRole.loadList(rs); + rs.close(); + ps.close(); + return loadlist; + } catch (SQLException e) { + throw new DBException(e); } finally { DBUtil.closeConnection(conn, ps); @@ -69,13 +102,15 @@ public class TransactionDAO { } /** - * Log a transaction, with all of the info. The meaning of secondaryMID and addedInfo changes depending on - * the transaction type. + * Log a transaction, with all of the info. The meaning of secondaryMID and + * addedInfo changes depending on the transaction type. * - * @param type The {@link TransactionType} enum representing the type this transaction is. - * @param loggedInMID The MID of the user who is logged in. + * @param type The {@link TransactionType} enum representing the type + * this transaction is. + * @param loggedInMID The MID of the user who is logged in. * @param secondaryMID Typically, the MID of the user who is being acted upon. - * @param addedInfo A note about a subtransaction, or specifics of this transaction (for posterity). + * @param addedInfo A note about a subtransaction, or specifics of this + * transaction (for posterity). * @throws DBException */ public void logTransaction(TransactionType type, long loggedInMID, long secondaryMID, String addedInfo) @@ -93,7 +128,7 @@ public class TransactionDAO { ps.executeUpdate(); ps.close(); } catch (SQLException e) { - + throw new DBException(e); } finally { DBUtil.closeConnection(conn, ps); @@ -101,63 +136,63 @@ public class TransactionDAO { } /** - * Return a list of all transactions in which an HCP accessed the given patient's record + * Return a list of all transactions in which an HCP accessed the given + * patient's record * * @param patientID The MID of the patient in question. * @return A java.util.List of transactions. * @throws DBException */ - public List<TransactionBean> getAllRecordAccesses(long patientID, long dlhcpID, boolean getByRole) throws DBException { + public List<TransactionBean> getAllRecordAccesses(long patientID, long dlhcpID, boolean getByRole) + throws DBException { Connection conn = null; PreparedStatement ps = null; try { conn = factory.getConnection(); - ps = conn - .prepareStatement("SELECT * FROM transactionlog WHERE secondaryMID=? AND transactionCode " - + "IN(" + TransactionType.patientViewableStr + ") AND loggedInMID!=? ORDER BY timeLogged DESC"); + ps = conn.prepareStatement("SELECT * FROM transactionlog WHERE secondaryMID=? AND transactionCode " + "IN(" + + TransactionType.patientViewableStr + ") AND loggedInMID!=? ORDER BY timeLogged DESC"); ps.setLong(1, patientID); ps.setLong(2, dlhcpID); ResultSet rs = ps.executeQuery(); List<TransactionBean> tbList = loader.loadList(rs); tbList = addAndSortRoles(tbList, patientID, getByRole); - + rs.close(); ps.close(); return tbList; } catch (SQLException e) { - + throw new DBException(e); } finally { DBUtil.closeConnection(conn, ps); } } - + /** - * The Most Thorough Fetch - * @param mid MID of the logged in user + * The Most Thorough Fetch + * + * @param mid MID of the logged in user * @param dlhcpID MID of the user's DLHCP - * @param start Index to start pulling entries from - * @param range Number of entries to retrieve - * @return List of <range> TransactionBeans affecting the user starting from the <start>th entry + * @param start Index to start pulling entries from + * @param range Number of entries to retrieve + * @return List of <range> TransactionBeans affecting the user starting from the + * <start>th entry * @throws DBException */ - public List<TransactionBean> getTransactionsAffecting(long mid, long dlhcpID, java.util.Date start, int range) throws DBException { + public List<TransactionBean> getTransactionsAffecting(long mid, long dlhcpID, java.util.Date start, int range) + throws DBException { Connection conn = null; PreparedStatement ps = null; try { conn = factory.getConnection(); - ps = conn - .prepareStatement("SELECT * FROM transactionlog WHERE ((timeLogged <= ?) " + - "AND (secondaryMID=? AND transactionCode " + - "IN (" + - TransactionType.patientViewableStr+ ")) " + - "OR (loggedInMID=? AND transactionCode=?) ) " + - "AND NOT (loggedInMID=? AND transactionCode IN (" + //exclude if DLHCP as specified in UC43 - TransactionType.dlhcpHiddenStr + ")) " + - "ORDER BY timeLogged DESC LIMIT 0,?"); + ps = conn.prepareStatement("SELECT * FROM transactionlog WHERE ((timeLogged <= ?) " + + "AND (secondaryMID=? AND transactionCode " + "IN (" + TransactionType.patientViewableStr + ")) " + + "OR (loggedInMID=? AND transactionCode=?) ) " + "AND NOT (loggedInMID=? AND transactionCode IN (" + + // exclude if DLHCP as specified in UC43 + TransactionType.dlhcpHiddenStr + ")) " + "ORDER BY timeLogged DESC LIMIT 0,?"); ps.setString(2, mid + ""); ps.setString(3, mid + ""); ps.setInt(4, TransactionType.LOGIN_SUCCESS.getCode()); @@ -170,7 +205,7 @@ public class TransactionDAO { ps.close(); return tbList; } catch (SQLException e) { - + throw new DBException(e); } finally { DBUtil.closeConnection(conn, ps); @@ -178,26 +213,24 @@ public class TransactionDAO { } /** - * Return a list of all transactions in which an HCP accessed the given patient's record, within the dates + * Return a list of all transactions in which an HCP accessed the given + * patient's record, within the dates * * @param patientID The MID of the patient in question. - * @param lower The starting date as a java.util.Date - * @param upper The ending date as a java.util.Date + * @param lower The starting date as a java.util.Date + * @param upper The ending date as a java.util.Date * @return A java.util.List of transactions. * @throws DBException */ - public List<TransactionBean> getRecordAccesses(long patientID, long dlhcpID, java.util.Date lower, java.util.Date upper, boolean getByRole) throws DBException { + public List<TransactionBean> getRecordAccesses(long patientID, long dlhcpID, java.util.Date lower, + java.util.Date upper, boolean getByRole) throws DBException { Connection conn = null; PreparedStatement ps = null; try { conn = factory.getConnection(); - ps = conn - .prepareStatement("SELECT * FROM transactionlog WHERE secondaryMID=? AND transactionCode IN (" - + TransactionType.patientViewableStr - + ") " - + "AND timeLogged >= ? AND timeLogged <= ? " - + "AND loggedInMID!=? " - + "ORDER BY timeLogged DESC"); + ps = conn.prepareStatement("SELECT * FROM transactionlog WHERE secondaryMID=? AND transactionCode IN (" + + TransactionType.patientViewableStr + ") " + "AND timeLogged >= ? AND timeLogged <= ? " + + "AND loggedInMID!=? " + "ORDER BY timeLogged DESC"); ps.setLong(1, patientID); ps.setTimestamp(2, new Timestamp(lower.getTime())); // add 1 day's worth to include the upper @@ -205,13 +238,13 @@ public class TransactionDAO { ps.setLong(4, dlhcpID); ResultSet rs = ps.executeQuery(); List<TransactionBean> tbList = loader.loadList(rs); - + tbList = addAndSortRoles(tbList, patientID, getByRole); rs.close(); ps.close(); return tbList; } catch (SQLException e) { - + throw new DBException(e); } finally { DBUtil.closeConnection(conn, ps); @@ -239,13 +272,13 @@ public class TransactionDAO { ps.close(); return result; } catch (SQLException e) { - + throw new DBException(e); } finally { DBUtil.closeConnection(conn, ps); } } - + /** * * @param tbList @@ -254,84 +287,81 @@ public class TransactionDAO { * @return * @throws DBException */ - private List<TransactionBean> addAndSortRoles(List<TransactionBean> tbList, long patientID, boolean sortByRole) throws DBException { + private List<TransactionBean> addAndSortRoles(List<TransactionBean> tbList, long patientID, boolean sortByRole) + throws DBException { Connection conn = null; PreparedStatement ps = null; - + try { conn = factory.getConnection(); - - for(TransactionBean t : tbList) { - ps = conn - .prepareStatement("SELECT Role FROM users WHERE MID=?"); + + for (TransactionBean t : tbList) { + ps = conn.prepareStatement("SELECT Role FROM users WHERE MID=?"); ps.setLong(1, t.getLoggedInMID()); ResultSet rs = ps.executeQuery(); String role = ""; - if(rs.next()) + if (rs.next()) role = rs.getString("Role"); - if(role.equals("er")) + if (role.equals("er")) role = "Emergency Responder"; - else if(role.equals("uap")) + else if (role.equals("uap")) role = "UAP"; - else if(role.equals("hcp")) { + else if (role.equals("hcp")) { role = "LHCP"; ps.close(); - ps = conn - .prepareStatement("SELECT PatientID FROM declaredhcp WHERE HCPID=?"); + ps = conn.prepareStatement("SELECT PatientID FROM declaredhcp WHERE HCPID=?"); ps.setLong(1, t.getLoggedInMID()); ResultSet rs2 = ps.executeQuery(); - while(rs2.next()) { - if (rs2.getLong("PatientID") == patientID){ + while (rs2.next()) { + if (rs2.getLong("PatientID") == patientID) { role = "DLHCP"; break; } } rs2.close(); - } - else if(role.equals("patient")){ + } else if (role.equals("patient")) { role = "Patient"; ps.close(); - ps = conn - .prepareStatement("SELECT representeeMID FROM representatives WHERE representerMID=?"); + ps = conn.prepareStatement("SELECT representeeMID FROM representatives WHERE representerMID=?"); ps.setLong(1, t.getLoggedInMID()); ResultSet rs2 = ps.executeQuery(); - while(rs2.next()) { - if (rs2.getLong("representeeMID") == patientID){ + while (rs2.next()) { + if (rs2.getLong("representeeMID") == patientID) { role = "Personal Health Representative"; break; } } rs2.close(); } - + t.setRole(role); rs.close(); ps.close(); } - - if(sortByRole){ + + if (sortByRole) { TransactionBean[] array = new TransactionBean[tbList.size()]; array[0] = tbList.get(0); TransactionBean t; - for(int i = 1; i < tbList.size(); i++) { + for (int i = 1; i < tbList.size(); i++) { t = tbList.get(i); String role = t.getRole(); int j = 0; - while(array[j] != null && role.compareToIgnoreCase(array[j].getRole()) >= 0) + while (array[j] != null && role.compareToIgnoreCase(array[j].getRole()) >= 0) j++; - for(int k = i; k > j; k--) { - array[k] = array[k-1]; + for (int k = i; k > j; k--) { + array[k] = array[k - 1]; } array[j] = t; } int size = tbList.size(); - for(int i = 0; i < size; i++) + for (int i = 0; i < size; i++) tbList.set(i, array[i]); } - + return tbList; } catch (SQLException e) { - + throw new DBException(e); } finally { DBUtil.closeConnection(conn, ps); diff --git a/iTrust/test/edu/ncsu/csc/itrust/selenium/AppointmentTest.java b/iTrust/test/edu/ncsu/csc/itrust/selenium/AppointmentTest.java index d591bb9b9e9f5ddbedd85b8ea42e41dc0a0f3701..e2ad19756d3b3863e128be997d6f186a90127f24 100644 --- a/iTrust/test/edu/ncsu/csc/itrust/selenium/AppointmentTest.java +++ b/iTrust/test/edu/ncsu/csc/itrust/selenium/AppointmentTest.java @@ -160,7 +160,7 @@ public class AppointmentTest extends iTrustSeleniumTest{ WebElement element; //go to the View My Appointments link - element = driver.findElement(By.linkText("View My Appointments")); + element = driver.findElement(By.linkText("View/Edit My Appointments")); element.click(); //confirm that appointments are showing diff --git a/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewTransactionLogsTest.java b/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewTransactionLogsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1bc85e407406d4a05f5b72963f2e179a93019124 --- /dev/null +++ b/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewTransactionLogsTest.java @@ -0,0 +1,355 @@ +package edu.ncsu.csc.itrust.selenium; + +import java.util.concurrent.TimeUnit; +import org.junit.*; +import org.openqa.selenium.*; +import org.openqa.selenium.support.ui.Select; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; + +public class ViewTransactionLogsTest extends iTrustSeleniumTest { + private HtmlUnitDriver driver; + private StringBuffer verificationErrors = new StringBuffer(); + + @Before + public void setUp() throws Exception { + super.setUp(); + gen.clearAllTables(); + gen.standardData(); + driver = new HtmlUnitDriver(); + driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); + } + + @Test + public void testAdminLogin() throws Exception { + driver = (HtmlUnitDriver) login("9000000001", "pw"); + driver.setJavascriptEnabled(true); + assertEquals("iTrust - Admin Home", driver.getTitle()); + driver.findElement(By.linkText("View Transaction Logs")).click(); + assertEquals("iTrust - View Transaction Logs", driver.getTitle()); + } + + @Test + public void testTesterLogin() throws Exception { + driver = (HtmlUnitDriver) login("9999999999", "pw"); + driver.setJavascriptEnabled(true); + assertEquals("iTrust - Tester Home", driver.getTitle()); + driver.findElement(By.linkText("View Transaction Logs")).click(); + assertEquals("iTrust - View Transaction Logs", driver.getTitle()); + } + + @Test + public void testAdminRegular() throws Exception { + driver = (HtmlUnitDriver) login("9000000001", "pw"); + driver.setJavascriptEnabled(true); + assertEquals("iTrust - Admin Home", driver.getTitle()); + driver.findElement(By.linkText("View Transaction Logs")).click(); + assertEquals("iTrust - View Transaction Logs", driver.getTitle()); + + //fill form + driver.findElement(By.name("startDate")).clear(); + driver.findElement(By.name("startDate")).sendKeys("05/10/2009"); + driver.findElement(By.name("endDate")).clear(); + driver.findElement(By.name("endDate")).sendKeys("10/10/2021"); + Select select; + select = new Select (driver.findElement(By.name("mainRole"))); + select.selectByValue("All"); + select = new Select (driver.findElement(By.name("secondRole"))); + select.selectByValue("All"); + select = new Select (driver.findElement(By.name("transactionType"))); + select.selectByValue("All"); + + //click button + driver.findElement(By.id("viewReport")).click(); + + //check to see if page shows info past 2009 + assertTrue(driver.getPageSource().contains("EMERGENCY_REPORT_VIEW")); + assertTrue(driver.getPageSource().contains("Patient added to monitoring list")); + assertTrue(driver.getPageSource().contains("2011-06-24 06:54:59.0")); + + //check to see pages does not show info before 2009 + assertFalse(driver.getPageSource().contains("Identified risk factors of chronic diseases")); + assertFalse(driver.getPageSource().contains("2008-06-15 13:15:00.0")); + } + + @Test + public void testTesterRegular() throws Exception { + driver = (HtmlUnitDriver) login("9999999999", "pw"); + driver.setJavascriptEnabled(true); + assertEquals("iTrust - Tester Home", driver.getTitle()); + driver.findElement(By.linkText("View Transaction Logs")).click(); + assertEquals("iTrust - View Transaction Logs", driver.getTitle()); + + //fill form + driver.findElement(By.name("startDate")).clear(); + driver.findElement(By.name("startDate")).sendKeys("05/10/2009"); + driver.findElement(By.name("endDate")).clear(); + driver.findElement(By.name("endDate")).sendKeys("10/10/2021"); + Select select; + select = new Select (driver.findElement(By.name("mainRole"))); + select.selectByValue("All"); + select = new Select (driver.findElement(By.name("secondRole"))); + select.selectByValue("All"); + select = new Select (driver.findElement(By.name("transactionType"))); + select.selectByValue("All"); + + //click button + driver.findElement(By.id("viewReport")).click(); + + //check to see if page shows info past 2009 + assertTrue(driver.getPageSource().contains("EMERGENCY_REPORT_VIEW")); + assertTrue(driver.getPageSource().contains("Patient added to monitoring list")); + assertTrue(driver.getPageSource().contains("2011-06-24 06:54:59.0")); + + //check to see pages does not show info before 2009 + assertFalse(driver.getPageSource().contains("Identified risk factors of chronic diseases")); + assertFalse(driver.getPageSource().contains("2008-06-15 13:15:00.0")); + } + + @Test + public void testAdminSelectMainRole() throws Exception { + driver = (HtmlUnitDriver) login("9000000001", "pw"); + driver.setJavascriptEnabled(true); + assertEquals("iTrust - Admin Home", driver.getTitle()); + driver.findElement(By.linkText("View Transaction Logs")).click(); + assertEquals("iTrust - View Transaction Logs", driver.getTitle()); + + //fill form + driver.findElement(By.name("startDate")).clear(); + driver.findElement(By.name("startDate")).sendKeys("05/10/2000"); + driver.findElement(By.name("endDate")).clear(); + driver.findElement(By.name("endDate")).sendKeys("10/10/2021"); + Select select; + select = new Select (driver.findElement(By.name("mainRole"))); + select.selectByValue("hcp"); + select = new Select (driver.findElement(By.name("secondRole"))); + select.selectByValue("All"); + select = new Select (driver.findElement(By.name("transactionType"))); + select.selectByValue("All"); + + //click view report button + driver.findElement(By.id("viewReport")).click(); + + //check to see if first five rows are only hcp + assertTrue(driver.findElements(By.id("resultRow")).get(0).findElement(By.id("mainTD")).getText().contains("hcp")); + assertTrue(driver.findElements(By.id("resultRow")).get(1).findElement(By.id("mainTD")).getText().contains("hcp")); + assertTrue(driver.findElements(By.id("resultRow")).get(2).findElement(By.id("mainTD")).getText().contains("hcp")); + assertTrue(driver.findElements(By.id("resultRow")).get(3).findElement(By.id("mainTD")).getText().contains("hcp")); + assertTrue(driver.findElements(By.id("resultRow")).get(4).findElement(By.id("mainTD")).getText().contains("hcp")); + + //click summarize button + driver.findElement(By.id("viewGraph")).click(); + + //check to see if graphs are shown + assertTrue(!driver.findElements(By.id("Graph_table")).isEmpty()); + assertTrue(!driver.findElements(By.id("chart_div")).isEmpty()); + assertTrue(!driver.findElements(By.id("chart_div2")).isEmpty()); + assertTrue(!driver.findElements(By.id("chart_div3")).isEmpty()); + assertTrue(!driver.findElements(By.id("chart_div4")).isEmpty()); + } + + @Test + public void testAdminSelectSecondaryRole() throws Exception { + driver = (HtmlUnitDriver) login("9000000001", "pw"); + driver.setJavascriptEnabled(true); + assertEquals("iTrust - Admin Home", driver.getTitle()); + driver.findElement(By.linkText("View Transaction Logs")).click(); + assertEquals("iTrust - View Transaction Logs", driver.getTitle()); + + //fill form + driver.findElement(By.name("startDate")).clear(); + driver.findElement(By.name("startDate")).sendKeys("05/10/2000"); + driver.findElement(By.name("endDate")).clear(); + driver.findElement(By.name("endDate")).sendKeys("10/10/2021"); + Select select; + select = new Select (driver.findElement(By.name("mainRole"))); + select.selectByValue("All"); + select = new Select (driver.findElement(By.name("secondRole"))); + select.selectByValue("patient"); + select = new Select (driver.findElement(By.name("transactionType"))); + select.selectByValue("All"); + + //click view report button + driver.findElement(By.id("viewReport")).click(); + + //check to see if first five rows are only patient + assertTrue(driver.findElements(By.id("resultRow")).get(0).findElement(By.id("secondTD")).getText().contains("patient")); + assertTrue(driver.findElements(By.id("resultRow")).get(1).findElement(By.id("secondTD")).getText().contains("patient")); + assertTrue(driver.findElements(By.id("resultRow")).get(2).findElement(By.id("secondTD")).getText().contains("patient")); + assertTrue(driver.findElements(By.id("resultRow")).get(3).findElement(By.id("secondTD")).getText().contains("patient")); + assertTrue(driver.findElements(By.id("resultRow")).get(4).findElement(By.id("secondTD")).getText().contains("patient")); + + //click summarize button + driver.findElement(By.id("viewGraph")).click(); + + //check to see if graphs are shown + assertTrue(!driver.findElements(By.id("Graph_table")).isEmpty()); + assertTrue(!driver.findElements(By.id("chart_div")).isEmpty()); + assertTrue(!driver.findElements(By.id("chart_div2")).isEmpty()); + assertTrue(!driver.findElements(By.id("chart_div3")).isEmpty()); + assertTrue(!driver.findElements(By.id("chart_div4")).isEmpty()); + } + + @Test + public void testAdminSelectType() throws Exception { + driver = (HtmlUnitDriver) login("9000000001", "pw"); + driver.setJavascriptEnabled(true); + assertEquals("iTrust - Admin Home", driver.getTitle()); + driver.findElement(By.linkText("View Transaction Logs")).click(); + assertEquals("iTrust - View Transaction Logs", driver.getTitle()); + + //fill form + driver.findElement(By.name("startDate")).clear(); + driver.findElement(By.name("startDate")).sendKeys("05/10/2000"); + driver.findElement(By.name("endDate")).clear(); + driver.findElement(By.name("endDate")).sendKeys("10/10/2021"); + Select select; + select = new Select (driver.findElement(By.name("mainRole"))); + select.selectByValue("All"); + select = new Select (driver.findElement(By.name("secondRole"))); + select.selectByValue("All"); + select = new Select (driver.findElement(By.name("transactionType"))); + select.selectByValue("EMERGENCY_REPORT_VIEW"); + + //click view report button + driver.findElement(By.id("viewReport")).click(); + + //check to see if first two rows are only EMERGENCY_REPORT_VIEW + assertTrue(driver.findElements(By.id("resultRow")).get(0).findElement(By.id("typeTD")).getText().contains("EMERGENCY_REPORT_VIEW")); + assertTrue(driver.findElements(By.id("resultRow")).get(1).findElement(By.id("typeTD")).getText().contains("EMERGENCY_REPORT_VIEW")); + + //click summarize button + driver.findElement(By.id("viewGraph")).click(); + + //check to see if graphs are shown + assertTrue(!driver.findElements(By.id("Graph_table")).isEmpty()); + assertTrue(!driver.findElements(By.id("chart_div")).isEmpty()); + assertTrue(!driver.findElements(By.id("chart_div2")).isEmpty()); + assertTrue(!driver.findElements(By.id("chart_div3")).isEmpty()); + assertTrue(!driver.findElements(By.id("chart_div4")).isEmpty()); + } + + @Test + public void testAdminIncorrectDate() throws Exception { + driver = (HtmlUnitDriver) login("9000000001", "pw"); + driver.setJavascriptEnabled(true); + assertEquals("iTrust - Admin Home", driver.getTitle()); + driver.findElement(By.linkText("View Transaction Logs")).click(); + assertEquals("iTrust - View Transaction Logs", driver.getTitle()); + + //fill form + driver.findElement(By.name("startDate")).clear(); + driver.findElement(By.name("startDate")).sendKeys("05/10/20000000"); + driver.findElement(By.name("endDate")).clear(); + driver.findElement(By.name("endDate")).sendKeys("10/10/2021"); + Select select; + select = new Select (driver.findElement(By.name("mainRole"))); + select.selectByValue("All"); + select = new Select (driver.findElement(By.name("secondRole"))); + select.selectByValue("All"); + select = new Select (driver.findElement(By.name("transactionType"))); + select.selectByValue("All"); + + //click view report button + driver.findElement(By.id("viewReport")).click(); + + //check to see if error message appears + assertTrue(driver.getPageSource().contains("ERROR: Date must by in the format: MM/dd/yyyy")); + + //click summarize button + driver.findElement(By.id("viewGraph")).click(); + + //check to see if error message appears + assertTrue(driver.getPageSource().contains("ERROR: Date must by in the format: MM/dd/yyyy")); + + } + + @Test + public void testAdminImpossibleDate() throws Exception { + driver = (HtmlUnitDriver) login("9000000001", "pw"); + driver.setJavascriptEnabled(true); + assertEquals("iTrust - Admin Home", driver.getTitle()); + driver.findElement(By.linkText("View Transaction Logs")).click(); + assertEquals("iTrust - View Transaction Logs", driver.getTitle()); + + //fill form + driver.findElement(By.name("startDate")).clear(); + driver.findElement(By.name("startDate")).sendKeys("05/10/2030"); + driver.findElement(By.name("endDate")).clear(); + driver.findElement(By.name("endDate")).sendKeys("10/10/2021"); + Select select; + select = new Select (driver.findElement(By.name("mainRole"))); + select.selectByValue("All"); + select = new Select (driver.findElement(By.name("secondRole"))); + select.selectByValue("All"); + select = new Select (driver.findElement(By.name("transactionType"))); + select.selectByValue("All"); + + //click button + driver.findElement(By.id("viewReport")).click(); + + //check to see if error message appears + assertTrue(driver.getPageSource().contains("ERROR: End Date cannot be before Start Date")); + + //click summarize button + driver.findElement(By.id("viewGraph")).click(); + + //check to see if error message appears + assertTrue(driver.getPageSource().contains("ERROR: End Date cannot be before Start Date")); + } + + @Test + public void testAdminNoResults() throws Exception { + driver = (HtmlUnitDriver) login("9000000001", "pw"); + driver.setJavascriptEnabled(true); + assertEquals("iTrust - Admin Home", driver.getTitle()); + driver.findElement(By.linkText("View Transaction Logs")).click(); + assertEquals("iTrust - View Transaction Logs", driver.getTitle()); + + //fill form + driver.findElement(By.name("startDate")).clear(); + driver.findElement(By.name("startDate")).sendKeys("05/10/2000"); + driver.findElement(By.name("endDate")).clear(); + driver.findElement(By.name("endDate")).sendKeys("10/10/2021"); + Select select; + select = new Select (driver.findElement(By.name("mainRole"))); + select.selectByValue("pha"); + select = new Select (driver.findElement(By.name("secondRole"))); + select.selectByValue("pha"); + select = new Select (driver.findElement(By.name("transactionType"))); + select.selectByValue("All"); + + //click view report button + driver.findElement(By.id("viewReport")).click(); + + //check to see if error message appears + assertTrue(driver.getPageSource().contains("There are no results for the criteria specified")); + + //fill form again + driver.findElement(By.name("startDate")).clear(); + driver.findElement(By.name("startDate")).sendKeys("05/10/2000"); + driver.findElement(By.name("endDate")).clear(); + driver.findElement(By.name("endDate")).sendKeys("10/10/2021"); + select = new Select (driver.findElement(By.name("mainRole"))); + select.selectByValue("pha"); + select = new Select (driver.findElement(By.name("secondRole"))); + select.selectByValue("pha"); + select = new Select (driver.findElement(By.name("transactionType"))); + select.selectByValue("All"); + + //click summarize button + driver.findElement(By.id("viewGraph")).click(); + + //check to see if error message appears + assertTrue(driver.getPageSource().contains("There are no results for the criteria specified")); + + } + + @After + public void tearDown() throws Exception { + driver.quit(); + String verificationErrorString = verificationErrors.toString(); + if (!"".equals(verificationErrorString)) { + fail(verificationErrorString); + } + } +} \ No newline at end of file diff --git a/iTrust/test/edu/ncsu/csc/itrust/unit/bean/TransactionWithRoleBeanTest.java b/iTrust/test/edu/ncsu/csc/itrust/unit/bean/TransactionWithRoleBeanTest.java new file mode 100644 index 0000000000000000000000000000000000000000..821d70651dffa92e42311928eb53cd3daac0c32a --- /dev/null +++ b/iTrust/test/edu/ncsu/csc/itrust/unit/bean/TransactionWithRoleBeanTest.java @@ -0,0 +1,59 @@ +package edu.ncsu.csc.itrust.unit.bean; + +import junit.framework.TestCase; +import java.sql.Timestamp; +import java.util.Date; +import edu.ncsu.csc.itrust.enums.TransactionType; +import edu.ncsu.csc.itrust.beans.TransactionWithRoleBean; + +public class TransactionWithRoleBeanTest extends TestCase { + + public void testTransactionWithRoleBeanRoles() throws Exception { + TransactionWithRoleBean b = new TransactionWithRoleBean(); + + // test setters + long MID1 = 23; + long MID2 = 7000; + long TID = 5; + b.setMainRole("hcp"); + b.setSecondaryRole("patient"); + b.setLoggedInMID(MID1); + b.setSecondaryMID(MID2); + b.setTransactionID(TID); + + // confirm with getters + assertEquals("hcp", b.getMainRole()); + assertEquals("patient", b.getSecondaryRole()); + assertEquals(MID1, b.getLoggedInMID()); + assertEquals(MID2, b.getSecondaryMID()); + assertEquals(TID, b.getTransactionID()); + } + + public void testTransactionWithRoleBeanTimes() throws Exception { + TransactionWithRoleBean b = new TransactionWithRoleBean(); + + // test setters + Date date= new Date(); + long time = date.getTime(); + Timestamp ts = new Timestamp(time); + b.setTimeLogged(ts); + b.setTransactionType(TransactionType.LOGIN_FAILURE); + b.setConvertedDate("01/01/2000"); + + // confirm with getters + assertEquals(ts, b.getTimeLogged()); + assertEquals(TransactionType.LOGIN_FAILURE, b.getTransactionType()); + assertEquals("01/01/2000", b.getConvertedDate()); + } + + public void testTransactionWithRoleBeanInfo() throws Exception { + TransactionWithRoleBean b = new TransactionWithRoleBean(); + + // test setters + b.setAddedInfo("I'm dying"); + + // confirm with getters + assertEquals("I'm dying", b.getAddedInfo()); + } + +} diff --git a/iTrust/test/edu/ncsu/csc/itrust/unit/dao/transaction/LogTransactionTest.java b/iTrust/test/edu/ncsu/csc/itrust/unit/dao/transaction/LogTransactionTest.java index 9252380d014ee45c23e832a93ecfad68dbf82289..1eee85fb3adf8dbfc7201ff0751c7063c2431bd3 100644 --- a/iTrust/test/edu/ncsu/csc/itrust/unit/dao/transaction/LogTransactionTest.java +++ b/iTrust/test/edu/ncsu/csc/itrust/unit/dao/transaction/LogTransactionTest.java @@ -4,6 +4,7 @@ import java.util.List; import junit.framework.TestCase; import edu.ncsu.csc.itrust.beans.TransactionBean; +import edu.ncsu.csc.itrust.beans.TransactionWithRoleBean; import edu.ncsu.csc.itrust.dao.mysql.TransactionDAO; import edu.ncsu.csc.itrust.enums.TransactionType; import edu.ncsu.csc.itrust.unit.datagenerators.TestDataGenerator; @@ -27,6 +28,14 @@ public class LogTransactionTest extends TestCase { assertEquals(1L, list.get(3).getLoggedInMID()); assertEquals(TransactionType.DEMOGRAPHICS_EDIT, list.get(3).getTransactionType()); } + + public void testGetAllTransactionsWithRoles() throws Exception { + List<TransactionWithRoleBean> list = tranDAO.getAllTransactionsWithRoles(); + assertEquals(8, list.size()); + // that last one inserted should be last because it was backdated + assertEquals(1L, list.get(3).getLoggedInMID()); + assertEquals(TransactionType.DEMOGRAPHICS_EDIT, list.get(3).getTransactionType()); + } public void testLogFull() throws Exception { tranDAO.logTransaction(TransactionType.OFFICE_VISIT_EDIT, 9000000000L, 1L, "added information");