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();
}
}
}
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();
}
}
}
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;
}
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;
}
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;
}
Aggregations