Commit 8022b48a authored by Michael Ritter's avatar Michael Ritter
Browse files

Endpoint for querying collections

parent 16fb0803
...@@ -5,15 +5,21 @@ import edu.umiacs.ace.util.PersistUtil; ...@@ -5,15 +5,21 @@ import edu.umiacs.ace.util.PersistUtil;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.Query; import javax.persistence.Query;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Get a listing of groups/collections in ACE
*
* Created by shake on 10/22/14. * Created by shake on 10/22/14.
*/ */
@Path("/") @Path("/")
...@@ -75,4 +81,31 @@ public class ListController { ...@@ -75,4 +81,31 @@ public class ListController {
return groupless; return groupless;
} }
/**
* New API method to get all collections with query parameters
*
* @return
*/
@GET
@Path("collections")
@Produces(MediaType.APPLICATION_JSON)
public List<Collection> getCollections(@QueryParam("group") String group,
@QueryParam("active") Boolean active,
@QueryParam("corrupt") Boolean corrupt) {
EntityManager entityManager = PersistUtil.getEntityManager();
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Collection> cq = cb.createQuery(Collection.class);
Root<Collection> coll = cq.from(Collection.class);
cq.select(coll);
if (active != null && active) {
cq.where(cb.equal(coll.get("state"), 'A'));
}
if (corrupt != null && corrupt) {
cq.where(cb.equal(coll.get("state"), 'E'));
}
return entityManager.createQuery(cq).getResultList();
}
} }
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