Commit e3e76d59 authored by Michael Ritter's avatar Michael Ritter
Browse files

API Method for getting monitoreditems

parent b54cbf63
package edu.umiacs.ace.rest;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.monitor.core.MonitoredItem;
import edu.umiacs.ace.util.PersistUtil;
import org.apache.log4j.Logger;
import javax.persistence.EntityManager;
import javax.persistence.Query;
......@@ -24,6 +26,7 @@ import java.util.List;
*/
@Path("/")
public class ListController {
private static final Logger LOG = Logger.getLogger(ListController.class);
/**
* Get a list of all the groups registered in ACE
......@@ -70,7 +73,7 @@ public class ListController {
// Get all
Query q = em.createNamedQuery("Collection.listAllCollections");
List<Collection> results = q.getResultList();
List<Collection> groupless = new ArrayList<Collection>();
List<Collection> groupless = new ArrayList<>();
// Filter if the group == null
for (Collection result : results) {
......@@ -108,4 +111,38 @@ public class ListController {
return entityManager.createQuery(cq).getResultList();
}
/**
* API for getting items in a collection. We can offer more query parameters (path, last seen, etc),
* but for now just query based on state
*
* @param id The id of the collection
* @param state The state of the monitored items
* @return a list of monitored items for the collection
*/
@GET
@Path("collections/{id}/items")
@Produces(MediaType.APPLICATION_JSON)
public List<MonitoredItemBean> getCollectionItems(@PathParam("id") Long id,
@QueryParam("state") String state) {
EntityManager entityManager = PersistUtil.getEntityManager();
Collection c = entityManager.find(Collection.class, id);
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<MonitoredItemBean> cq = cb.createQuery(MonitoredItemBean.class);
Root<MonitoredItem> mi = cq.from(MonitoredItem.class);
cq.select(cb.construct(MonitoredItemBean.class,
mi.get("id"), mi.get("path"),
mi.get("state"), mi.get("fileDigest"),
mi.get("size"), mi.get("lastSeen"),
mi.get("stateChange"), mi.get("lastVisited")));
cq.where(cb.equal(mi.get("parentCollection"), c));
if (state != null && !state.isEmpty()) {
cq.where(cb.equal(mi.get("state"), state));
}
return entityManager.createQuery(cq).getResultList();
}
}
package edu.umiacs.ace.rest;
import java.util.Date;
/**
* Bean for displaying certain MonitoredItem properties in our api
*
* Created by shake on 11/14/16.
*/
public class MonitoredItemBean {
private Long id;
private String path;
private String state;
private String fileDigest;
private Long size;
private Date lastSeen;
private Date stateChange;
private Date lastVisited;
public MonitoredItemBean() {
}
public MonitoredItemBean(Long id, String path, char state, String fileDigest, Long size , Date lastSeen, Date stateChange, Date lastVisited) {
this.id = id;
this.path = path;
this.state = String.valueOf(state);
this.fileDigest = fileDigest;
this.size = size;
this.lastSeen = lastSeen;
this.stateChange = stateChange;
this.lastVisited = lastVisited;
}
public Long getId() {
return id;
}
public MonitoredItemBean setId(Long id) {
this.id = id;
return this;
}
public String getPath() {
return path;
}
public MonitoredItemBean setPath(String path) {
this.path = path;
return this;
}
public String getState() {
return state;
}
public MonitoredItemBean setState(String state) {
this.state = state;
return this;
}
public String getFileDigest() {
return fileDigest;
}
public MonitoredItemBean setFileDigest(String fileDigest) {
this.fileDigest = fileDigest;
return this;
}
public Long getSize() {
return size;
}
public MonitoredItemBean setSize(Long size) {
this.size = size;
return this;
}
public Date getLastSeen() {
return lastSeen;
}
public MonitoredItemBean setLastSeen(Date lastSeen) {
this.lastSeen = lastSeen;
return this;
}
public Date getStateChange() {
return stateChange;
}
public MonitoredItemBean setStateChange(Date stateChange) {
this.stateChange = stateChange;
return this;
}
public Date getLastVisited() {
return lastVisited;
}
public MonitoredItemBean setLastVisited(Date lastVisited) {
this.lastVisited = lastVisited;
return this;
}
}
Supports Markdown
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