Search in sources :

Example 11 with ItemManager

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();
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) HashMap(java.util.HashMap) ItemManager(gov.usgs.cida.coastalhazards.jpa.ItemManager) Viewable(org.glassfish.jersey.server.mvc.Viewable) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with ItemManager

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();
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) HashMap(java.util.HashMap) ItemManager(gov.usgs.cida.coastalhazards.jpa.ItemManager) Viewable(org.glassfish.jersey.server.mvc.Viewable) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with ItemManager

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();
        }
    }
}
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 14 with ItemManager

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();
        }
    }
}
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 15 with ItemManager

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;
}
Also used : SessionItem(gov.usgs.cida.coastalhazards.model.SessionItem) Item(gov.usgs.cida.coastalhazards.model.Item) SessionItem(gov.usgs.cida.coastalhazards.model.SessionItem) HashMap(java.util.HashMap) ItemManager(gov.usgs.cida.coastalhazards.jpa.ItemManager) WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Aggregations

ItemManager (gov.usgs.cida.coastalhazards.jpa.ItemManager)31 Item (gov.usgs.cida.coastalhazards.model.Item)26 Path (javax.ws.rs.Path)24 GET (javax.ws.rs.GET)22 Produces (javax.ws.rs.Produces)21 Response (javax.ws.rs.core.Response)21 HashMap (java.util.HashMap)11 NotFoundException (javax.ws.rs.NotFoundException)9 StatusManager (gov.usgs.cida.coastalhazards.jpa.StatusManager)8 Status (gov.usgs.cida.coastalhazards.model.util.Status)8 JsonSyntaxException (com.google.gson.JsonSyntaxException)7 BadRequestException (gov.usgs.cida.coastalhazards.exception.BadRequestException)7 Viewable (org.glassfish.jersey.server.mvc.Viewable)7 Gson (com.google.gson.Gson)6 JsonObject (com.google.gson.JsonObject)5 AliasManager (gov.usgs.cida.coastalhazards.jpa.AliasManager)5 Alias (gov.usgs.cida.coastalhazards.model.Alias)5 RolesAllowed (javax.annotation.security.RolesAllowed)5 ThumbnailManager (gov.usgs.cida.coastalhazards.jpa.ThumbnailManager)4 IOException (java.io.IOException)4