use of gov.usgs.cida.coastalhazards.jpa.ItemManager in project coastal-hazards by USGS-CIDA.
the class InfoRouter method useInfoJsp.
@GET
@Produces(MediaType.TEXT_HTML)
@Path("/item/{id}")
public Response useInfoJsp(@PathParam("id") String id) {
Map<String, Object> map = new HashMap<>();
Item item;
try (ItemManager mgr = new ItemManager()) {
item = mgr.load(id);
}
if (item == null) {
return Response.status(Status.NOT_FOUND).build();
}
map.put("item", item);
return Response.ok(new Viewable("/WEB-INF/jsp/ui/back/index.jsp", map)).build();
}
use of gov.usgs.cida.coastalhazards.jpa.ItemManager in project coastal-hazards by USGS-CIDA.
the class InfoRouter method useInfoPrintViewJsp.
@GET
@Produces(MediaType.TEXT_HTML)
@Path("/item/print/{id}")
public Response useInfoPrintViewJsp(@PathParam("id") String id) {
Map<String, Object> map = new HashMap<>();
Item item;
try (ItemManager mgr = new ItemManager()) {
item = mgr.load(id);
}
if (item == null) {
return Response.status(Status.NOT_FOUND).build();
}
map.put("item", item);
return Response.ok(new Viewable("/WEB-INF/jsp/ui/back/index-print.jsp", map)).build();
}
use of gov.usgs.cida.coastalhazards.jpa.ItemManager 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.jpa.ItemManager 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.jpa.ItemManager in project coastal-hazards by USGS-CIDA.
the class DownloadUtility method stageSessionDownload.
/**
* TODO stage all the items with some smarts about naming and such
*
* @param stageThis
* @param stagingDir
* @return
* @throws java.io.IOException
*/
public static boolean stageSessionDownload(Session stageThis, File stagingDir) throws IOException, ConcurrentModificationException {
boolean success = false;
lock(stagingDir);
List<String> missing = new LinkedList<>();
try {
Map<WFSService, SingleDownload> downloadMap = new HashMap<>(stageThis.getItems().size());
for (SessionItem sessionItem : stageThis.getItems()) {
Item item;
try (ItemManager itemManager = new ItemManager()) {
item = itemManager.load(sessionItem.getItemId());
}
populateDownloadMap(downloadMap, item);
}
List<String> namesUsed = new ArrayList<>(downloadMap.size());
for (SingleDownload stagedDownload : downloadMap.values()) {
while (namesUsed.contains(stagedDownload.getName())) {
stagedDownload.incrementName();
}
namesUsed.add(stagedDownload.getName());
// TODO try/catch this to isolate/retry problem downloads?
boolean stage = stagedDownload.stage(stagingDir, missing);
success = success || stage;
}
} finally {
writeMissingFile(stagingDir, missing);
writeReadmeFile(stagingDir);
unlock(stagingDir);
}
return success;
}
Aggregations