Search in sources :

Example 1 with SLDGenerator

use of gov.usgs.cida.coastalhazards.sld.SLDGenerator in project coastal-hazards by USGS-CIDA.

the class SLDResource method getSLDInfo.

/**
 * JSON representation of the contents of the SLD, this is primarily for
 * building a UI legend ;qs=0 is to make this a lower priority than the xml
 * document, must say accepts=application/json to get this document
 *
 * @param id item ID
 * @param ribbon Not used currently, but represents which ribbon to
 * represent
 * @return JSON document with SLD info
 */
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON + ";qs=0")
public Response getSLDInfo(@PathParam("id") String id, @QueryParam("ribbon") Integer ribbon, @QueryParam("selectedItem") String selectedId) {
    PerformanceProfiler.startTimer("SLDResource.getSLDInfo - " + id);
    Response response;
    try (ItemManager manager = new ItemManager()) {
        if (selectedId == null || selectedId.length() == 0) {
            selectedId = id;
        }
        PerformanceProfiler.startTimer("SLDResource.getSLD_ItemManager.load - " + id);
        Item item = manager.load(id);
        PerformanceProfiler.stopDebug("SLDResource.getSLD_ItemManager.load - " + id);
        if (item == null) {
            response = Response.status(Response.Status.NOT_FOUND).build();
        } else {
            PerformanceProfiler.startTimer("SLDResource.getSLDInfo_getGenerator - " + id);
            SLDGenerator generator = SLDGenerator.getGenerator(item, selectedId, ribbon);
            PerformanceProfiler.stopDebug("SLDResource.getSLDInfo_getGenerator - " + id);
            if (generator == null) {
                response = Response.status(Response.Status.NOT_FOUND).build();
            } else {
                PerformanceProfiler.startTimer("SLDResource.getSLDInfo_generateSLDInfo - " + id);
                response = generator.generateSLDInfo();
                PerformanceProfiler.stopDebug("SLDResource.getSLDInfo_generateSLDInfo - " + id);
            }
        }
    } catch (Exception e) {
        response = Response.status(500).build();
    }
    PerformanceProfiler.stopDebug("SLDResource.getSLDInfo - " + id);
    return response;
}
Also used : Response(javax.ws.rs.core.Response) Item(gov.usgs.cida.coastalhazards.model.Item) SLDGenerator(gov.usgs.cida.coastalhazards.sld.SLDGenerator) ItemManager(gov.usgs.cida.coastalhazards.jpa.ItemManager) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with SLDGenerator

use of gov.usgs.cida.coastalhazards.sld.SLDGenerator in project coastal-hazards by USGS-CIDA.

the class SLDResource method getSLD.

/**
 * XML representation of the SLD document related to a specific item ;qs=1
 * is required to make this the default response when no accepts header is
 * given
 *
 * @param id item ID
 * @param ribbon which ribbon to represent (not required)
 * @return response with SLD XML representation
 */
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_XML + ";qs=1")
public Response getSLD(@PathParam("id") String id, @QueryParam("ribbon") Integer ribbon, @QueryParam("selectedItem") String selectedId) {
    PerformanceProfiler.startTimer("SLDResource.getSLD - " + id);
    Response response = null;
    try (ItemManager manager = new ItemManager()) {
        if (selectedId == null || selectedId.length() == 0) {
            selectedId = id;
        }
        PerformanceProfiler.startTimer("SLDResource.getSLD_ItemManager.load - " + id);
        Item item = manager.load(id);
        PerformanceProfiler.stopDebug("SLDResource.getSLD_ItemManager.load - " + id);
        if (item == null) {
            response = Response.status(Response.Status.NOT_FOUND).build();
        } else {
            PerformanceProfiler.startTimer("SLDResource.getSLD_getGenerator - " + id);
            SLDGenerator generator = SLDGenerator.getGenerator(item, selectedId, ribbon);
            PerformanceProfiler.stopDebug("SLDResource.getSLD_getGenerator - " + id);
            if (generator != null) {
                PerformanceProfiler.startTimer("SLDResource.getSLD_generateSLD - " + id);
                response = generator.generateSLD();
                PerformanceProfiler.stopDebug("SLDResource.getSLD_generateSLD - " + id);
            }
        }
    } catch (Exception e) {
        response = Response.status(500).build();
    }
    PerformanceProfiler.stopDebug("SLDResource.getSLD - " + id);
    return response;
}
Also used : Response(javax.ws.rs.core.Response) Item(gov.usgs.cida.coastalhazards.model.Item) SLDGenerator(gov.usgs.cida.coastalhazards.sld.SLDGenerator) ItemManager(gov.usgs.cida.coastalhazards.jpa.ItemManager) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ItemManager (gov.usgs.cida.coastalhazards.jpa.ItemManager)2 Item (gov.usgs.cida.coastalhazards.model.Item)2 SLDGenerator (gov.usgs.cida.coastalhazards.sld.SLDGenerator)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2