Author: [log in to unmask]
Date: Thu Aug 27 18:43:05 2015
New Revision: 3429
Log:
Updates to run web app.
Added:
java/trunk/run-webapp/src/main/java/org/hps/runweb/
java/trunk/run-webapp/src/main/java/org/hps/runweb/DatabaseUtilities.java
java/trunk/run-webapp/src/main/java/org/hps/runweb/EpicsDataServlet.java
java/trunk/run-webapp/src/main/java/org/hps/runweb/RunSummaryServlet.java
java/trunk/run-webapp/src/main/java/org/hps/runweb/RunsServlet.java
java/trunk/run-webapp/src/main/java/org/hps/runweb/ScalerDataServlet.java
Removed:
java/trunk/run-webapp/src/main/java/org/hps/run/
Modified:
java/trunk/run-webapp/pom.xml
java/trunk/run-webapp/src/main/webapp/WEB-INF/web.xml
java/trunk/run-webapp/src/main/webapp/css/style.css
java/trunk/run-webapp/src/main/webapp/runEpics.jsp
java/trunk/run-webapp/src/main/webapp/runSummary.jsp
java/trunk/run-webapp/src/main/webapp/runTable.jsp
Modified: java/trunk/run-webapp/pom.xml
=============================================================================
--- java/trunk/run-webapp/pom.xml (original)
+++ java/trunk/run-webapp/pom.xml Thu Aug 27 18:43:05 2015
@@ -35,6 +35,7 @@
</dependency>
</dependencies>
<build>
+ <defaultGoal>war:war tomcat7:redeploy</defaultGoal>
<finalName>hps-run-webapp</finalName>
<plugins>
<plugin>
Added: java/trunk/run-webapp/src/main/java/org/hps/runweb/DatabaseUtilities.java
=============================================================================
--- java/trunk/run-webapp/src/main/java/org/hps/runweb/DatabaseUtilities.java (added)
+++ java/trunk/run-webapp/src/main/java/org/hps/runweb/DatabaseUtilities.java Thu Aug 27 18:43:05 2015
@@ -0,0 +1,23 @@
+package org.hps.runweb;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+public final class DatabaseUtilities {
+
+ private static String DATASOURCE_CONTEXT = "java:comp/env/jdbc/hps_run_db_dev";
+
+ public static DataSource getDataSource() {
+ DataSource dataSource = null;
+ try {
+ dataSource = (DataSource) new InitialContext().lookup(DATASOURCE_CONTEXT);
+ } catch (final NamingException e) {
+ throw new RuntimeException("Error creating data source.");
+ }
+ if (dataSource == null) {
+ throw new IllegalStateException("Data source not found");
+ }
+ return dataSource;
+ }
+}
Added: java/trunk/run-webapp/src/main/java/org/hps/runweb/EpicsDataServlet.java
=============================================================================
--- java/trunk/run-webapp/src/main/java/org/hps/runweb/EpicsDataServlet.java (added)
+++ java/trunk/run-webapp/src/main/java/org/hps/runweb/EpicsDataServlet.java Thu Aug 27 18:43:05 2015
@@ -0,0 +1,82 @@
+package org.hps.runweb;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.sql.DataSource;
+
+import org.hps.record.epics.EpicsData;
+import org.hps.rundb.EpicsDataDao;
+import org.hps.rundb.EpicsType;
+import org.hps.rundb.EpicsVariable;
+import org.hps.rundb.EpicsVariableDao;
+import org.hps.rundb.RunDatabaseDaoFactory;
+
+/**
+ * Setup session state for JSP that shows a run's EPICS data.
+ *
+ * @author Jeremy McCormick, SLAC
+ */
+@SuppressWarnings("serial")
+public class EpicsDataServlet extends HttpServlet {
+
+ private final DataSource dataSource;
+
+ public EpicsDataServlet() {
+ this.dataSource = DatabaseUtilities.getDataSource();
+ }
+
+ @Override
+ public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException,
+ IOException {
+ if (!request.getParameterMap().containsKey("run")) {
+ throw new RuntimeException("Missing required run parameter.");
+ }
+ final Integer run = Integer.parseInt(request.getParameterValues("run")[0]);
+ EpicsDataDao epicsDataDao = null;
+ Connection connection = null;
+ List<EpicsData> epicsDataList = null;
+
+ EpicsType epicsType = EpicsType.EPICS_1S;
+ if (request.getParameterMap().containsKey("epicsBankType")) {
+ epicsType = EpicsType.valueOf(request.getParameter("epicsBankType"));
+ }
+
+ List<EpicsVariable> epicsVariables = null;
+
+ try {
+ connection = dataSource.getConnection();
+
+ final RunDatabaseDaoFactory dbFactory = new RunDatabaseDaoFactory(connection);
+
+ epicsDataDao = dbFactory.createEpicsDataDao();
+ epicsDataList = epicsDataDao.getEpicsData(epicsType, run);
+
+ final EpicsVariableDao epicsVariableDao = dbFactory.createEpicsVariableDao();
+ epicsVariables = epicsVariableDao.getEpicsVariables(epicsType);
+
+ } catch (final SQLException e) {
+ throw new IllegalStateException("Failed to setup data source connection.", e);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (final SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ request.setAttribute("EpicsDataList", epicsDataList);
+ request.setAttribute("EpicsType", epicsType);
+ request.setAttribute("EpicsVariables", epicsVariables);
+ final RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/runEpics.jsp");
+ dispatcher.forward(request, response);
+ }
+}
Added: java/trunk/run-webapp/src/main/java/org/hps/runweb/RunSummaryServlet.java
=============================================================================
--- java/trunk/run-webapp/src/main/java/org/hps/runweb/RunSummaryServlet.java (added)
+++ java/trunk/run-webapp/src/main/java/org/hps/runweb/RunSummaryServlet.java Thu Aug 27 18:43:05 2015
@@ -0,0 +1,82 @@
+package org.hps.runweb;
+
+import java.io.IOException;
+import java.sql.Connection;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.sql.DataSource;
+
+import org.hps.rundb.RunManager;
+import org.hps.rundb.RunSummary;
+
+/**
+ * Setup state for JSP that shows run summary.
+ *
+ * @author Jeremy McCormick, SLAC
+ */
+@SuppressWarnings("serial")
+public class RunSummaryServlet extends HttpServlet {
+
+ /**
+ * JSP target page.
+ */
+ private static final String JSP_TARGET = "/runSummary.jsp";
+
+ /**
+ * Attribute in the request which will have the run summary object.
+ */
+ private static final String RUN_SUMMARY_ATTRIBUTE = "RunSummary";
+
+ /**
+ * The data source with the database connection.
+ */
+ private final DataSource dataSource;
+
+ /**
+ * Create a new runs servlet.
+ * <p>
+ * This will initialize the data source with the db connection.
+ */
+ public RunSummaryServlet() {
+ this.dataSource = DatabaseUtilities.getDataSource();
+ }
+
+ /**
+ * Setup servlet state by loading the run summaries and then forward to the JSP page for display.
+ */
+ @Override
+ public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException,
+ IOException {
+ if (!request.getParameterMap().containsKey("run")) {
+ throw new RuntimeException("Missing required run parameter.");
+ }
+ final Integer run = Integer.parseInt(request.getParameterValues("run")[0]);
+ final RunSummary runSummary = this.getRunSummary(run);
+ request.setAttribute(RUN_SUMMARY_ATTRIBUTE, runSummary);
+ final RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher(JSP_TARGET);
+ dispatcher.forward(request, response);
+ }
+
+ /**
+ * Get a run summary for the given run number.
+ *
+ * @param run the run number
+ * @return the run summary
+ */
+ private RunSummary getRunSummary(final Integer run) {
+ final RunManager runManager = new RunManager();
+ RunSummary runSummary = null;
+ try (Connection connection = this.dataSource.getConnection()) {
+ runManager.setConnection(connection);
+ runManager.setRun(run);
+ runSummary = runManager.getRunSummary();
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
+ }
+ return runSummary;
+ }
+}
Added: java/trunk/run-webapp/src/main/java/org/hps/runweb/RunsServlet.java
=============================================================================
--- java/trunk/run-webapp/src/main/java/org/hps/runweb/RunsServlet.java (added)
+++ java/trunk/run-webapp/src/main/java/org/hps/runweb/RunsServlet.java Thu Aug 27 18:43:05 2015
@@ -0,0 +1,92 @@
+package org.hps.runweb;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.sql.DataSource;
+
+import org.hps.rundb.RunDatabaseDaoFactory;
+import org.hps.rundb.RunSummary;
+import org.hps.rundb.RunSummaryDao;
+
+/**
+ * Loads the list of {@link org.hps.rundb.RunSummary} objects to setup state for the <code>runTable.jsp</code> page.
+ *
+ * @author Jeremy McCormick, SLAC
+ */
+@SuppressWarnings("serial")
+public final class RunsServlet extends HttpServlet {
+
+ /**
+ * The JSP page to which the servlet will forward the request.
+ */
+ private static final String JSP_TARGET = "/runTable.jsp";
+
+ /**
+ * Attribute for list of run summaries that will set on the request object.
+ */
+ private static final String RUN_SUMMARIES_ATTRIBUTE = "RunSummaries";
+
+ /**
+ * The data source with the database connection.
+ */
+ private final DataSource dataSource;
+
+ /**
+ * Create a new runs servlet.
+ * <p>
+ * This will initialize the data source with the db connection.
+ */
+ public RunsServlet() {
+ this.dataSource = DatabaseUtilities.getDataSource();
+ }
+
+ /**
+ * Setup servlet state by loading the run summaries and then forward to the JSP page for display.
+ */
+ @Override
+ public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException,
+ IOException {
+
+ final List<RunSummary> runSummaries = this.getRunSummaries();
+ request.setAttribute(RUN_SUMMARIES_ATTRIBUTE, runSummaries);
+ final RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher(JSP_TARGET);
+ dispatcher.forward(request, response);
+ }
+
+ /**
+ * Read the full list of run summaries from the db.
+ *
+ * @return the list of run summaries
+ */
+ private List<RunSummary> getRunSummaries() {
+ List<RunSummary> runSummaries = new ArrayList<RunSummary>();
+ Connection connection = null;
+ try {
+ connection = this.dataSource.getConnection();
+ final RunSummaryDao runSummaryDao = new RunDatabaseDaoFactory(connection).createRunSummaryDao();
+
+ // This does a shallow read of all run summaries but does not load their complex state.
+ runSummaries = runSummaryDao.getRunSummaries();
+ } catch (final SQLException e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return runSummaries;
+ }
+}
Added: java/trunk/run-webapp/src/main/java/org/hps/runweb/ScalerDataServlet.java
=============================================================================
--- java/trunk/run-webapp/src/main/java/org/hps/runweb/ScalerDataServlet.java (added)
+++ java/trunk/run-webapp/src/main/java/org/hps/runweb/ScalerDataServlet.java Thu Aug 27 18:43:05 2015
@@ -0,0 +1,72 @@
+package org.hps.runweb;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.util.List;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.sql.DataSource;
+
+import org.hps.record.scalers.ScalerData;
+import org.hps.rundb.RunDatabaseDaoFactory;
+import org.hps.rundb.ScalerDataDao;
+
+/**
+ * Setup session state for JSP that shows a run's scaler data.
+ *
+ * @author Jeremy McCormick, SLAC
+ */
+@SuppressWarnings("serial")
+public class ScalerDataServlet extends HttpServlet {
+
+ /**
+ * JSP target page.
+ */
+ private static final String JSP_TARGET = "/runScalers.jsp";
+
+ /**
+ * Attribute in the request which will have the run summary object.
+ */
+ private static final String SCALAR_DATA_ATTRIBUTE = "ScalerDataList";
+
+ /**
+ * The data source with the database connection.
+ */
+ private final DataSource dataSource;
+
+ /**
+ * Create a new runs servlet.
+ * <p>
+ * This will initialize the data source with the db connection.
+ */
+ public ScalerDataServlet() {
+ this.dataSource = DatabaseUtilities.getDataSource();
+ }
+
+ /**
+ * Setup servlet state by loading the run summaries and then forward to the JSP page for display.
+ */
+ @Override
+ public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException,
+ IOException {
+ if (!request.getParameterMap().containsKey("run")) {
+ throw new RuntimeException("Missing required run parameter.");
+ }
+ final Integer run = Integer.parseInt(request.getParameterValues("run")[0]);
+ List<ScalerData> scalerDataList = null;
+ try (Connection connection = this.dataSource.getConnection()) {
+ final ScalerDataDao scalarDataDao = new RunDatabaseDaoFactory(connection).createScalerDataDao();
+ scalerDataList = scalarDataDao.getScalerData(run);
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
+ }
+ request.setAttribute(SCALAR_DATA_ATTRIBUTE, scalerDataList);
+ final RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher(JSP_TARGET);
+ dispatcher.forward(request, response);
+ }
+
+}
Modified: java/trunk/run-webapp/src/main/webapp/WEB-INF/web.xml
=============================================================================
--- java/trunk/run-webapp/src/main/webapp/WEB-INF/web.xml (original)
+++ java/trunk/run-webapp/src/main/webapp/WEB-INF/web.xml Thu Aug 27 18:43:05 2015
@@ -22,7 +22,7 @@
<servlet>
<servlet-name>RunsServlet</servlet-name>
- <servlet-class>org.hps.run.web.RunsServlet</servlet-class>
+ <servlet-class>org.hps.runweb.RunsServlet</servlet-class>
</servlet>
<servlet-mapping>
@@ -34,7 +34,7 @@
<servlet>
<servlet-name>RunSummaryServlet</servlet-name>
- <servlet-class>org.hps.run.web.RunSummaryServlet</servlet-class>
+ <servlet-class>org.hps.runweb.RunSummaryServlet</servlet-class>
</servlet>
<servlet-mapping>
@@ -46,7 +46,7 @@
<servlet>
<servlet-name>EpicsDataServlet</servlet-name>
- <servlet-class>org.hps.run.web.EpicsDataServlet</servlet-class>
+ <servlet-class>org.hps.runweb.EpicsDataServlet</servlet-class>
</servlet>
<servlet-mapping>
@@ -58,12 +58,18 @@
<servlet>
<servlet-name>ScalerDataServlet</servlet-name>
- <servlet-class>org.hps.run.web.ScalerDataServlet</servlet-class>
+ <servlet-class>org.hps.runweb.ScalerDataServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ScalerDataServlet</servlet-name>
<url-pattern>/scalers</url-pattern>
</servlet-mapping>
-
+
+<!--
+ <welcome-file-list>
+ <welcome-file>path.jsp</welcome-file>
+ </welcome-file-list>
+ -->
+
</web-app>
Modified: java/trunk/run-webapp/src/main/webapp/css/style.css
=============================================================================
--- java/trunk/run-webapp/src/main/webapp/css/style.css (original)
+++ java/trunk/run-webapp/src/main/webapp/css/style.css Thu Aug 27 18:43:05 2015
@@ -4,4 +4,5 @@
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-bottom: 1px solid
rgba(255, 255, 255, 0.3);
-}
+}
+
Modified: java/trunk/run-webapp/src/main/webapp/runEpics.jsp
=============================================================================
--- java/trunk/run-webapp/src/main/webapp/runEpics.jsp (original)
+++ java/trunk/run-webapp/src/main/webapp/runEpics.jsp Thu Aug 27 18:43:05 2015
@@ -1,4 +1,4 @@
-<%@ page contentType="text/html" import="java.util.*,java.text.SimpleDateFormat,org.hps.record.epics.*"%>
+<%@ page contentType="text/html" import="java.util.*,java.text.SimpleDateFormat,org.hps.record.epics.*,org.hps.rundb.*" %>
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="css/style.css" />
@@ -21,24 +21,12 @@
<body>
<%
- // Get the run number.
- int run = Integer.parseInt(request.getParameterValues("run")[0]);
-
- // Get the EPICS variable names.
- String epicsBankType = (String) request.getAttribute("EpicsBankType");
- List<String> variableNames = null;
- if (epicsBankType.equals("2s")) {
- variableNames = new ArrayList<String>(Epics2sVariables.getVariables().keySet());
- } else if (epicsBankType.equals("20s")) {
- variableNames = new ArrayList<String>(Epics20sVariables.getVariables().keySet());
- } else {
- throw new RuntimeException("bad EpicsBankType attribute: " + request.getAttribute("EpicsBankType"));
- }
-
- // Get the list of EPICS data for this run.
+ int run = Integer.parseInt(request.getParameterValues("run")[0]);
+ List<EpicsVariable> epicsVariables = (List<EpicsVariable>) request.getAttribute("EpicsVariables");
+ EpicsType epicsType = (EpicsType) request.getAttribute("EpicsType");
List<EpicsData> epicsDataList = (List<EpicsData>) request.getAttribute("EpicsDataList");
%>
- <h1>HPS Run <%= run %> - EPICS <%= epicsBankType %> Data</h1>
+ <h1>HPS Run <%= run %> - EPICS <%= epicsType.getTypeCode() %>s Data</h1>
<hr />
<!--
@@ -62,9 +50,9 @@
<th>Sequence</th>
<th>Timestamp</th>
<%
- for (String variableName : variableNames) {
+ for (EpicsVariable epicsVariable : epicsVariables) {
%>
- <th><%= variableName %></th>
+ <th><%= epicsVariable.getVariableName() %></th>
<%
}
%>
@@ -73,22 +61,18 @@
<tbody>
<%
for (EpicsData epicsData : epicsDataList) {
- if (epicsData.hasKey(variableNames.get(0))) {
%>
<tr>
<td><%=epicsData.getEpicsHeader().getSequence()%></td>
<td><%=epicsData.getEpicsHeader().getTimestamp()%></td>
<%
- for (String variableName : variableNames) {
+ for (EpicsVariable epicsVariable : epicsVariables) {
%>
- <td><%=epicsData.getValue(variableName)%></td>
+ <td><%=epicsData.getValue(epicsVariable.getVariableName())%></td>
<%
}
%>
</tr>
- <%
- }
- %>
<%
}
%>
Modified: java/trunk/run-webapp/src/main/webapp/runSummary.jsp
=============================================================================
--- java/trunk/run-webapp/src/main/webapp/runSummary.jsp (original)
+++ java/trunk/run-webapp/src/main/webapp/runSummary.jsp Thu Aug 27 18:43:05 2015
@@ -1,4 +1,4 @@
-<%@ page contentType="text/html" import="java.util.*,org.hps.record.run.RunSummary,java.text.SimpleDateFormat"%>
+<%@ page contentType="text/html" import="java.util.*,org.hps.rundb.*,java.text.SimpleDateFormat"%>
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="css/style.css" />
@@ -7,24 +7,24 @@
<hr />
<%
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
- dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ dateFormat.setTimeZone(TimeZone.getTimeZone("America/New_York"));
RunSummary runSummary = (RunSummary) request.getAttribute("RunSummary");
%>
- <p>run: <%= runSummary.getRun() %></p>
- <p>start: <%= dateFormat.format(runSummary.getStartDate()) %></p>
- <p>end: <%= dateFormat.format(runSummary.getEndDate()) %></p>
- <p>events: <%= runSummary.getTotalEvents() %></p>
- <p>files: <%= runSummary.getTotalFiles() %></p>
- <p>end okay: <%= runSummary.getEndOkay() %></p>
- <p>run okay: <%= runSummary.getRunOkay() %></p>
- <p>updated: <%= dateFormat.format(runSummary.getUpdated()) %></p>
- <p>created: <%= dateFormat.format(runSummary.getCreated()) %></p>
+ <p><b>run:</b> <%= runSummary.getRun() %></p>
+ <p><b>start:</b> <%= dateFormat.format(runSummary.getStartDate()) %></p>
+ <p><b>end:</b> <%= dateFormat.format(runSummary.getEndDate()) %></p>
+ <p><b>events:</b> <%= runSummary.getTotalEvents() %></p>
+ <p><b>files:</b> <%= runSummary.getTotalFiles() %></p>
+ <p><b>end okay:</b> <%= runSummary.getEndOkay() %></p>
+ <p><b>run okay:</b> <%= runSummary.getRunOkay() %></p>
+ <p><b>updated:</b> <%= dateFormat.format(runSummary.getUpdated()) %></p>
+ <p><b>created:</b> <%= dateFormat.format(runSummary.getCreated()) %></p>
<hr/>
<p>
- <a href="epics?run=<%= runSummary.getRun() %>&epicsBankType=2s">EPICS 2s Data</a>
+ <a href="epics?run=<%= runSummary.getRun() %>&epicsBankType=<%= EpicsType.EPICS_1S %>">EPICS 1s Data</a>
</p>
<p>
- <a href="epics?run=<%= runSummary.getRun() %>&epicsBankType=20s">EPICS 20s Data</a>
+ <a href="epics?run=<%= runSummary.getRun() %>&epicsBankType=<%= EpicsType.EPICS_10S %>">EPICS 10s Data</a>
</p>
<p>
<a href="scalers?run=<%= runSummary.getRun() %>">Scaler Data</a>
Modified: java/trunk/run-webapp/src/main/webapp/runTable.jsp
=============================================================================
--- java/trunk/run-webapp/src/main/webapp/runTable.jsp (original)
+++ java/trunk/run-webapp/src/main/webapp/runTable.jsp Thu Aug 27 18:43:05 2015
@@ -1,4 +1,4 @@
-<%@ page contentType="text/html" import="java.util.*,org.hps.record.run.RunSummary,java.text.SimpleDateFormat"%>
+<%@ page contentType="text/html" import="java.util.*,org.hps.rundb.RunSummary,java.text.SimpleDateFormat"%>
<!DOCTYPE html>
<html>
@@ -28,8 +28,8 @@
<thead>
<tr>
<th>Run</th>
- <th>Start Time UTC</th>
- <th>End Time UTC</th>
+ <th>Start Date</th>
+ <th>End Date</th>
<th>Events</th>
<th>Files</th>
<th>End Okay</th>
|