Commit 3ceebb75 authored by Michael Ritter's avatar Michael Ritter
Browse files

Add search options for collection state

parent 7c1fa961
......@@ -30,8 +30,10 @@
// $Id$
package edu.umiacs.ace.monitor.access;
import com.google.common.collect.ImmutableList;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.monitor.support.PageBean;
import edu.umiacs.ace.monitor.support.CStateBean;
import edu.umiacs.ace.util.EntityManagerServlet;
import edu.umiacs.util.Strings;
import org.apache.log4j.Logger;
......@@ -55,6 +57,7 @@ public class StatusServlet extends EntityManagerServlet {
private static final Logger LOG = Logger.getLogger(StatusServlet.class);
private static final String PAGE_COLLECTIONS = "collections";
private static final String PAGE_STATES = "states";
private static final String PAGE_COUNT = "count";
private static final String PAGE_NUMBER = "page";
......@@ -72,6 +75,7 @@ public class StatusServlet extends EntityManagerServlet {
// Search Params
private static final String PARAM_GROUP = "group";
private static final String PARAM_STATE = "state";
private static final String PARAM_COLLECTION_LIKE = "collection";
private static final String PARAM_AUDIT_DATE = "audit";
......@@ -99,6 +103,7 @@ public class StatusServlet extends EntityManagerServlet {
int count = (int) getParameter(request, PARAM_COUNT, DEFAULT_COUNT);
String group = getParameter(request, PARAM_GROUP, null);
String collection = getParameter(request, PARAM_COLLECTION_LIKE, null);
String state = getParameter(request, PARAM_STATE, null);
// String date = getParameter(request, PARAM_GROUP, null);
PageBean pb = new PageBean((int) page, count, "Status");
......@@ -116,7 +121,7 @@ public class StatusServlet extends EntityManagerServlet {
List<String> queries = new ArrayList<>();
if (!Strings.isEmpty(group)) {
queries.add("c.group = :group");
queries.add("c.group LIKE :group");
pb.addParam(PARAM_GROUP, group);
}
......@@ -125,6 +130,12 @@ public class StatusServlet extends EntityManagerServlet {
pb.addParam(PARAM_COLLECTION_LIKE, collection);
}
// Enforce that the state is not empty, or larger than 1 character
if (!Strings.isEmpty(state) && state.length() == 1) {
queries.add("c.state = :state");
pb.addParam(PARAM_STATE, state);
}
queryString.append("SELECT c FROM Collection c");
countString.append("SELECT COUNT(c.id) FROM Collection c");
......@@ -136,7 +147,7 @@ public class StatusServlet extends EntityManagerServlet {
while (it.hasNext()) {
String query = it.next();
params.append(" ")
.append(query);
.append(query);
if (it.hasNext()) {
params.append(" AND");
}
......@@ -156,8 +167,8 @@ public class StatusServlet extends EntityManagerServlet {
Query countQuery = em.createQuery(countString.toString());
if (!Strings.isEmpty(group)) {
query.setParameter(PARAM_GROUP, group);
countQuery.setParameter(PARAM_GROUP, group);
query.setParameter(PARAM_GROUP, "%" + group + "%");
countQuery.setParameter(PARAM_GROUP, "%" + group + "%");
}
if (!Strings.isEmpty(collection)) {
......@@ -165,6 +176,11 @@ public class StatusServlet extends EntityManagerServlet {
countQuery.setParameter(PARAM_COLLECTION_LIKE, "%" + collection + "%");
}
if (!Strings.isEmpty(state) && state.length() == 1) {
query.setParameter(PARAM_STATE, state.charAt(0));
countQuery.setParameter(PARAM_STATE, state.charAt(0));
}
items = query.getResultList();
// We only need to execute this query if we have parameters
......@@ -208,6 +224,7 @@ public class StatusServlet extends EntityManagerServlet {
}
request.setAttribute(PAGE_COLLECTIONS, collections);
request.setAttribute(PAGE_STATES, ImmutableList.copyOf(CStateBean.values()));
request.setAttribute(PAGE_COUNT, count);
request.setAttribute(PAGE_NUMBER, pb);
if (hasJson(request)) {
......
package edu.umiacs.ace.monitor.support;
/**
* A Bean to hold each collection status as well as its definition
*
* Created by shake on 4/5/16.
*/
public enum CStateBean {
NO_FILTER(""),
ACTIVE("A"),
ERROR("E"),
NEVER_SCANNED("N");
private final String state;
CStateBean(String state) {
this.state = state;
}
public String getState() {
return state;
}
}
......@@ -3,6 +3,9 @@ package edu.umiacs.ace.util;
import edu.umiacs.ace.monitor.core.Collection;
/**
* Encapsulate metadata about a Runnable to keep track of information regarding
* the type of task being run
*
* Created by shake on 9/11/15.
*/
public class Submittable<V extends Runnable> implements Comparable<Submittable> {
......
......@@ -167,6 +167,14 @@
margin-right: 5px;
}
.form-select {
border: 1px solid #ccc;
width: 100%;
padding: 3px 8px;
margin-left: -3px;
margin-right: 5px;
}
.btn {
padding: 2px;
width: 75px;
......@@ -198,6 +206,14 @@
<span class="input-group-addon">Collection</span>
<input type="text" class="form-input" id="coll-filter" name="collection" placeholder="Search Collection"/>
</div>
<div class="input">
<span class="input-group-addon">State</span>
<select name="state" id="state-filter" class="form-select">
<c:forEach var="state" items="${states}">
<option value="${state.state}">${state.name()}</option>
</c:forEach>
</select>
</div>
<button type="submit" class="btn" value="Submit"><span>Submit</span></button>
</form>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment