Search in sources :

Example 11 with Summary

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

the class ShorelineTest method testGenerateSLDInfo.

/**
 * Test of generateSLDInfo method, of class Shoreline.
 */
@Test
public void testGenerateSLDInfo() {
    Item item = new Item();
    item.setAttr("Date_");
    item.setId("abcde");
    item.setType(Item.Type.historical);
    List<Service> services = new LinkedList<>();
    Service wmsService = new Service();
    wmsService.setEndpoint("http://test");
    wmsService.setServiceParameter("0");
    wmsService.setType(ServiceType.source_wms);
    services.add(wmsService);
    item.setServices(services);
    Summary summary = new Summary();
    Tiny tiny = new Tiny();
    tiny.setText("Shoreline");
    summary.setTiny(tiny);
    item.setSummary(summary);
    SLDGenerator shoreline = new SLDGenerator(item, item.getId(), null, Shorelines.shorelines);
    Response response = shoreline.generateSLDInfo();
    String json = (String) response.getEntity();
    Map<String, Object> sldInfo = new Gson().fromJson(json, HashMap.class);
    List<Object> bins = (List) sldInfo.get("bins");
    Map<String, Object> bin = (Map) bins.get(0);
    Double year0 = ((List<Double>) bin.get("years")).get(0);
    String color = (String) bin.get("color");
    assertEquals(year0, 0.0f, 0.01f);
    assertEquals(color, "#ff0000");
}
Also used : Tiny(gov.usgs.cida.coastalhazards.model.summary.Tiny) Service(gov.usgs.cida.coastalhazards.model.Service) Gson(com.google.gson.Gson) LinkedList(java.util.LinkedList) Response(javax.ws.rs.core.Response) Item(gov.usgs.cida.coastalhazards.model.Item) Summary(gov.usgs.cida.coastalhazards.model.summary.Summary) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 12 with Summary

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

the class ShorelineTest method testGenerateSLDInfoSelected.

/**
 * Test of generateSLDInfo method, of class Shoreline with an overriding
 * selected item.
 */
@Test
public void testGenerateSLDInfoSelected() {
    Item item = new Item();
    Item selectedItem = new Item();
    item.setAttr("Date_");
    item.setId("abcd");
    item.setType(Item.Type.historical);
    selectedItem.setAttr("Date_");
    selectedItem.setId("efg");
    selectedItem.setType(Item.Type.historical);
    selectedItem.setItemType(Item.ItemType.aggregation);
    List<Service> services = new LinkedList<>();
    Service wmsService = new Service();
    wmsService.setEndpoint("http://test");
    wmsService.setServiceParameter("0");
    wmsService.setType(ServiceType.source_wms);
    services.add(wmsService);
    item.setServices(services);
    selectedItem.setServices(services);
    Summary summary = new Summary();
    Tiny tiny = new Tiny();
    tiny.setText("Shoreline");
    summary.setTiny(tiny);
    item.setSummary(summary);
    selectedItem.setSummary(summary);
    SLDGenerator shoreline = new SLDGenerator(item, selectedItem.getId(), null, Shorelines.shorelines);
    Response response = shoreline.generateSLDInfo();
    String json = (String) response.getEntity();
    Map<String, Object> sldInfo = new Gson().fromJson(json, HashMap.class);
    List<Object> bins = (List) sldInfo.get("bins");
    Map<String, Object> bin = (Map) bins.get(0);
    Double year0 = ((List<Double>) bin.get("years")).get(0);
    String color = (String) bin.get("color");
    assertEquals(year0, 0.0f, 0.01f);
    assertEquals(color, "#ff0000");
}
Also used : Tiny(gov.usgs.cida.coastalhazards.model.summary.Tiny) Service(gov.usgs.cida.coastalhazards.model.Service) Gson(com.google.gson.Gson) LinkedList(java.util.LinkedList) Response(javax.ws.rs.core.Response) Item(gov.usgs.cida.coastalhazards.model.Item) Summary(gov.usgs.cida.coastalhazards.model.summary.Summary) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 13 with Summary

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

the class ShorelineTest method testGenerateSLD.

@Test
public void testGenerateSLD() {
    Item item = new Item();
    item.setAttr("DATE_");
    item.setId("abcde");
    item.setType(Item.Type.historical);
    List<Service> services = new LinkedList<>();
    Service wmsService = new Service();
    wmsService.setEndpoint("http://test");
    wmsService.setServiceParameter("0");
    wmsService.setType(ServiceType.source_wms);
    services.add(wmsService);
    item.setServices(services);
    Summary summary = new Summary();
    Tiny tiny = new Tiny();
    tiny.setText("Shoreline");
    summary.setTiny(tiny);
    item.setSummary(summary);
    SLDGenerator shoreline = new SLDGenerator(item, item.getId(), null, Shorelines.shorelines);
    Response response = shoreline.generateSLD();
    Viewable sld = (Viewable) response.getEntity();
}
Also used : Response(javax.ws.rs.core.Response) Item(gov.usgs.cida.coastalhazards.model.Item) Tiny(gov.usgs.cida.coastalhazards.model.summary.Tiny) Viewable(org.glassfish.jersey.server.mvc.Viewable) Service(gov.usgs.cida.coastalhazards.model.Service) Summary(gov.usgs.cida.coastalhazards.model.summary.Summary) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 14 with Summary

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

the class MetadataResource method getMetadataSummaryByAttribtueUsingFD.

@GET
@Path("/summarize/fid/{fid}/attribute/{attr}")
@Produces(MediaType.APPLICATION_JSON)
public Response getMetadataSummaryByAttribtueUsingFD(@PathParam("fid") String fid, @PathParam("attr") String attr) throws URISyntaxException {
    Response response;
    try {
        String jsonSummary = MetadataUtil.getSummaryFromWPS(fid, attr);
        Summary summary = GsonUtil.getDefault().fromJson(jsonSummary, Summary.class);
        response = Response.ok(GsonUtil.getDefault().toJson(summary, Summary.class), MediaType.APPLICATION_JSON_TYPE).build();
    } catch (IOException | ParserConfigurationException | SAXException | JsonSyntaxException ex) {
        Map<String, String> err = new HashMap<>();
        err.put("message", ex.getMessage());
        response = Response.serverError().entity(GsonUtil.getDefault().toJson(err, HashMap.class)).build();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) JsonSyntaxException(com.google.gson.JsonSyntaxException) Summary(gov.usgs.cida.coastalhazards.model.summary.Summary) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashMap(java.util.HashMap) Map(java.util.Map) SAXException(org.xml.sax.SAXException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 15 with Summary

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

the class TemplateResource method copyExistingSummary.

private Summary copyExistingSummary(String copyType, String copyVal, ItemManager itemMan, AliasManager aliasMan) {
    Summary newSummary = null;
    Item summaryItem = null;
    if (copyType.equalsIgnoreCase("item")) {
        summaryItem = itemMan.load(copyVal);
    } else if (copyType.equalsIgnoreCase("alias")) {
        summaryItem = itemMan.load(aliasMan.load(copyVal).getItemId());
    } else {
        log.error("Attempted to copy existing summary from invalid copy type: " + copyType);
    }
    if (summaryItem != null) {
        newSummary = Summary.copyValues(summaryItem.getSummary(), new Summary());
    } else {
        log.error("Item provided to copy summary from (" + copyType + " | " + copyVal + ") could not be loaded.");
    }
    return newSummary;
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) Summary(gov.usgs.cida.coastalhazards.model.summary.Summary)

Aggregations

Summary (gov.usgs.cida.coastalhazards.model.summary.Summary)16 Item (gov.usgs.cida.coastalhazards.model.Item)12 LinkedList (java.util.LinkedList)9 Response (javax.ws.rs.core.Response)9 Service (gov.usgs.cida.coastalhazards.model.Service)7 Tiny (gov.usgs.cida.coastalhazards.model.summary.Tiny)7 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 Gson (com.google.gson.Gson)5 Map (java.util.Map)5 IOException (java.io.IOException)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 SAXException (org.xml.sax.SAXException)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 Layer (gov.usgs.cida.coastalhazards.model.Layer)3 List (java.util.List)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Viewable (org.glassfish.jersey.server.mvc.Viewable)3