Search in sources :

Example 36 with Item

use of gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.

the class InfoRouter method useAliasInfoPrintViewJsp.

@GET
@Produces(MediaType.TEXT_HTML)
@Path("/alias/print/{aliasId}")
public Response useAliasInfoPrintViewJsp(@PathParam("aliasId") String aliasId) {
    Map<String, Object> map = new HashMap<>();
    try (ItemManager mgr = new ItemManager();
        AliasManager amgr = new AliasManager()) {
        Alias alias = amgr.load(aliasId);
        if (alias != null) {
            Item item = mgr.load(alias.getItemId());
            if (item == null) {
                return Response.status(Response.Status.NOT_FOUND).build();
            }
            map.put("item", item);
            map.put("alias", alias);
            return Response.ok(new Viewable("/WEB-INF/jsp/ui/back/index-print.jsp", map)).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    }
}
Also used : AliasManager(gov.usgs.cida.coastalhazards.jpa.AliasManager) Item(gov.usgs.cida.coastalhazards.model.Item) HashMap(java.util.HashMap) ItemManager(gov.usgs.cida.coastalhazards.jpa.ItemManager) Alias(gov.usgs.cida.coastalhazards.model.Alias) Viewable(org.glassfish.jersey.server.mvc.Viewable) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 37 with Item

use of gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.

the class InfoRouter method useAliasInfoJsp.

@GET
@Produces(MediaType.TEXT_HTML)
@Path("/alias/{aliasId}")
public Response useAliasInfoJsp(@PathParam("aliasId") String aliasId) {
    Map<String, Object> map = new HashMap<>();
    try (ItemManager mgr = new ItemManager();
        AliasManager amgr = new AliasManager()) {
        Alias alias = amgr.load(aliasId);
        if (alias != null) {
            Item item = mgr.load(alias.getItemId());
            if (item == null) {
                return Response.status(Response.Status.NOT_FOUND).build();
            }
            map.put("item", item);
            map.put("alias", alias);
            return Response.ok(new Viewable("/WEB-INF/jsp/ui/back/index.jsp", map)).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    }
}
Also used : AliasManager(gov.usgs.cida.coastalhazards.jpa.AliasManager) Item(gov.usgs.cida.coastalhazards.model.Item) HashMap(java.util.HashMap) ItemManager(gov.usgs.cida.coastalhazards.jpa.ItemManager) Alias(gov.usgs.cida.coastalhazards.model.Alias) Viewable(org.glassfish.jersey.server.mvc.Viewable) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 38 with Item

use of gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.

the class ItemManager method mergeItem.

private synchronized String mergeItem(Item item) {
    String id;
    try (DataDomainManager dm = new DataDomainManager()) {
        if (anyCycles(item)) {
            throw new CycleIntroductionException();
        }
        List<Item> children = item.getChildren();
        List<Item> replaceList = new LinkedList<>();
        if (children != null) {
            for (Item child : children) {
                replaceList.add(load(child.getId()));
            }
            item.setChildren(replaceList);
        }
        em.merge(item);
        id = item.getId();
        // Clear the upstream data domains if this item has a domain
        if (dm.load(id) != null) {
            List<Item> domainsToDelete = findVisibleAncestors(item);
            for (Item toDelete : domainsToDelete) {
                dm.deleteDomainForItem(toDelete);
            }
        }
    } catch (Exception e) {
        log.error("Failed to save item: " + item.getId() + " | Error: " + e.getMessage());
        id = null;
    }
    return id;
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) CycleIntroductionException(gov.usgs.cida.coastalhazards.exception.CycleIntroductionException) LinkedList(java.util.LinkedList) BadRequestException(gov.usgs.cida.coastalhazards.exception.BadRequestException) CycleIntroductionException(gov.usgs.cida.coastalhazards.exception.CycleIntroductionException) PersistenceException(javax.persistence.PersistenceException)

Example 39 with Item

use of gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.

the class ItemManager method loadRootItems.

public List<Item> loadRootItems() {
    List<Item> items = new ArrayList<>();
    Query query = em.createNativeQuery("SELECT id FROM item WHERE item.id NOT IN(SELECT DISTINCT agg.item_id FROM aggregation_children as agg)");
    List resultList = query.getResultList();
    for (Object row : resultList) {
        if (row instanceof String) {
            String id = (String) row;
            Item loaded = load(id);
            items.add(loaded);
        } else {
            throw new IllegalStateException("Row not a String");
        }
    }
    return items;
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 40 with Item

use of gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.

the class ItemManager method updateAncestors.

private List<Item> updateAncestors(Item item) {
    List<Item> ancestors = findAncestors(item);
    try (DownloadService downloadService = new DownloadService()) {
        List<String> itemIds = new LinkedList<>();
        for (Item ancestor : ancestors) {
            itemIds.add(ancestor.getId());
            ancestor.setLastModified(new Date());
            ancestor.setBbox(calculateBbox(ancestor));
        }
        downloadService.deleteAll(itemIds);
    }
    return ancestors;
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) DownloadService(gov.usgs.cida.coastalhazards.service.data.DownloadService) LinkedList(java.util.LinkedList) Date(java.util.Date)

Aggregations

Item (gov.usgs.cida.coastalhazards.model.Item)60 ItemManager (gov.usgs.cida.coastalhazards.jpa.ItemManager)26 Response (javax.ws.rs.core.Response)24 Path (javax.ws.rs.Path)22 LinkedList (java.util.LinkedList)21 GET (javax.ws.rs.GET)20 Produces (javax.ws.rs.Produces)20 HashMap (java.util.HashMap)16 BadRequestException (gov.usgs.cida.coastalhazards.exception.BadRequestException)12 Summary (gov.usgs.cida.coastalhazards.model.summary.Summary)12 JsonObject (com.google.gson.JsonObject)10 ArrayList (java.util.ArrayList)10 Viewable (org.glassfish.jersey.server.mvc.Viewable)10 Gson (com.google.gson.Gson)9 Service (gov.usgs.cida.coastalhazards.model.Service)8 NotFoundException (javax.ws.rs.NotFoundException)8 Test (org.junit.Test)8 JsonElement (com.google.gson.JsonElement)7 StatusManager (gov.usgs.cida.coastalhazards.jpa.StatusManager)7 Status (gov.usgs.cida.coastalhazards.model.util.Status)7