Search in sources :

Example 1 with DataDomainManager

use of gov.usgs.cida.coastalhazards.jpa.DataDomainManager in project coastal-hazards by USGS-CIDA.

the class DataDomainResource method getDataDomain.

@GET
@Path("/item/{id}")
public Response getDataDomain(@PathParam("id") String id, @Context Request request) {
    Response response = null;
    try (ItemManager itemManager = new ItemManager();
        DataDomainManager domainManager = new DataDomainManager()) {
        Item item = itemManager.load(id);
        if (item == null || item.getType() != Item.Type.historical) {
            throw new NotFoundException("Only historical is supported at this time");
        }
        DataDomain domain = domainManager.getDomainForItem(item);
        Response checkModified = HTTPCachingUtil.checkModified(request, domain);
        if (checkModified != null) {
            response = checkModified;
        } else {
            Gson serializer = GsonUtil.getDefault();
            String domainJson = serializer.toJson(domain);
            response = Response.ok(domainJson, MediaType.APPLICATION_JSON_TYPE).lastModified(domain.getLastModified()).build();
        }
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) Item(gov.usgs.cida.coastalhazards.model.Item) DataDomain(gov.usgs.cida.coastalhazards.model.util.DataDomain) ItemManager(gov.usgs.cida.coastalhazards.jpa.ItemManager) DataDomainManager(gov.usgs.cida.coastalhazards.jpa.DataDomainManager) NotFoundException(javax.ws.rs.NotFoundException) Gson(com.google.gson.Gson) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

Gson (com.google.gson.Gson)1 DataDomainManager (gov.usgs.cida.coastalhazards.jpa.DataDomainManager)1 ItemManager (gov.usgs.cida.coastalhazards.jpa.ItemManager)1 Item (gov.usgs.cida.coastalhazards.model.Item)1 DataDomain (gov.usgs.cida.coastalhazards.model.util.DataDomain)1 GET (javax.ws.rs.GET)1 NotFoundException (javax.ws.rs.NotFoundException)1 Path (javax.ws.rs.Path)1 Response (javax.ws.rs.core.Response)1