Search in sources :

Example 56 with Item

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

the class DownloadResource method checkItemAvailability.

@HEAD
@Path("/item/{id}")
public Response checkItemAvailability(@PathParam("id") String id) throws IOException {
    Response response;
    Item item;
    try (ItemManager itemManager = new ItemManager()) {
        item = itemManager.load(id);
    }
    if (item == null) {
        response = Response.status(NOT_FOUND).build();
    } else {
        Download download;
        try (DownloadManager downloadManager = new DownloadManager()) {
            download = downloadManager.load(id);
        }
        if (download != null) {
            LOG.debug("Download manager found a download for item id {}", id);
            String persistenceURI = download.getPersistanceURI();
            // If it is null or blank, the download has been accepted
            if (download.isProblem()) {
                LOG.debug("Download manager found a problem with download for item id {}", id);
                response = Response.status(INTERNAL_SERVER_ERROR).build();
            } else if (StringUtils.isBlank(persistenceURI)) {
                LOG.debug("Download manager found a download with no path id {}, Item is probably still being created", id);
                response = Response.status(ACCEPTED).build();
            } else {
                // If it is has content, check whether the file exists on the server
                // If it does not, that means this is a desynchronized entry in the datbase
                // and it should be deleted and reinitialized. Otherwise, this is
                // is good to go and send an OK response
                boolean existsOnFileSystem;
                try (DownloadManager downloadManager = new DownloadManager()) {
                    existsOnFileSystem = downloadManager.downloadFileExistsOnFilesystem(download);
                }
                if (!existsOnFileSystem) {
                    LOG.debug("Download manager found a download path that doesn't exist for id {}. Will delete and re-stage", id);
                    try (DownloadService svc = new DownloadService()) {
                        svc.delete(id);
                    }
                    LOG.debug("Download path for item {} was deleted in the database. Will not attempt to re-stage", id);
                    DownloadUtility.stageAsyncItemDownload(id);
                    response = Response.status(ACCEPTED).build();
                } else {
                    LOG.debug("Download manager found the download for item {}", id);
                    response = Response.status(OK).build();
                }
            }
        } else {
            LOG.debug("Download manager could not find download for item {}. A download will be staged for this item.", id);
            DownloadUtility.stageAsyncItemDownload(id);
            response = Response.status(ACCEPTED).build();
        }
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) Item(gov.usgs.cida.coastalhazards.model.Item) ItemManager(gov.usgs.cida.coastalhazards.jpa.ItemManager) Download(gov.usgs.cida.coastalhazards.model.util.Download) DownloadManager(gov.usgs.cida.coastalhazards.jpa.DownloadManager) DownloadService(gov.usgs.cida.coastalhazards.service.data.DownloadService) Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD)

Example 57 with Item

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

the class PrintRouter method useInfoPrintViewJsp.

@GET
@Produces(MediaType.TEXT_HTML)
@Path("/item/{id}")
public Response useInfoPrintViewJsp(@PathParam("id") String id) {
    Map<String, Object> map = new HashMap<>();
    try (ItemManager mgr = new ItemManager()) {
        Item item = mgr.load(id);
        if (item == null) {
            return Response.status(Response.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 58 with Item

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

the class PrintRouter method useAliasInfoPrintViewJsp.

@GET
@Produces(MediaType.TEXT_HTML)
@Path("/alias/{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 59 with Item

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

the class SLDGenerator method getGenerator.

public static SLDGenerator getGenerator(Item item, String selectedId, Integer ribbon) {
    SLDGenerator generator = null;
    Item.Type itemDotType = item.getType();
    Item.ItemType itemType = item.getItemType();
    if (itemType == Item.ItemType.data) {
        String itemAttribute = item.getAttr();
        Map<String, SLDConfig> typeLookup = generatorMap.get(itemDotType);
        SLDConfig conf = typeLookup.get(StringUtils.upperCase(itemAttribute));
        if (null != conf) {
            generator = new SLDGenerator(item, selectedId, ribbon, conf);
        }
    } else if (itemType == Item.ItemType.aggregation || itemType == Item.ItemType.template) {
        SortedSet<String> aggAttributes = ItemUtil.gatherAttributes(item);
        Map<String, SLDConfig> typeLookup = generatorMap.get(itemDotType);
        // TODO enforce all attributes map to same SLD type
        SLDConfig conf = typeLookup.get(StringUtils.upperCase(aggAttributes.first()));
        generator = new SLDGenerator(item, selectedId, ribbon, conf);
    } else {
        throw new BadRequestException();
    }
    if (null == generator) {
        throw new IllegalArgumentException("Type not found");
    }
    return generator;
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) BadRequestException(gov.usgs.cida.coastalhazards.exception.BadRequestException) SortedSet(java.util.SortedSet) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 60 with Item

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

the class TutorialRouter method showActionCenterTutorial.

/**
 * Sends the client to the item info page with a header to notify the client
 * to start a tour
 *
 * @param id
 * @return
 */
@GET
@Produces(MediaType.TEXT_HTML)
@Path("/item/{itemId}")
public Response showActionCenterTutorial(@PathParam("itemId") String id) {
    Response response;
    Map<String, Object> map;
    Item item;
    try (ItemManager mgr = new ItemManager()) {
        item = mgr.load(id);
    }
    if (item == null) {
        response = Response.status(Response.Status.NOT_FOUND).build();
    } else {
        map = new HashMap<>();
        map.put("item", item);
        map.put("tutorial", "true");
        response = Response.ok(new Viewable("/WEB-INF/jsp/ui/back/index.jsp", map)).build();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) Item(gov.usgs.cida.coastalhazards.model.Item) 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)

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