Search in sources :

Example 6 with Summary

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

the class TemplateResource method makeSummary.

private Summary makeSummary(Layer layer, String attr) throws JsonSyntaxException {
    OGCService cswService = Service.ogcHelper(Service.ServiceType.csw, layer.getServices());
    log.debug("cswService {}", cswService);
    String cswEndpoint = cswService.getEndpoint();
    log.debug("cswEndpoint {}", cswEndpoint);
    String summaryJson = null;
    try {
        summaryJson = MetadataUtil.getSummaryFromWPS(cswEndpoint, attr);
        log.debug("summaryJsonMetadataUtil {}", summaryJson);
    } catch (IOException | ParserConfigurationException | SAXException | URISyntaxException ex) {
        log.error("Problem getting summary from item", ex);
    }
    Gson gson = GsonUtil.getDefault();
    log.debug(String.valueOf(gson));
    Summary summary = gson.fromJson(summaryJson, Summary.class);
    log.debug(String.valueOf(summary));
    return summary;
}
Also used : OGCService(gov.usgs.cida.coastalhazards.util.ogc.OGCService) Gson(com.google.gson.Gson) Summary(gov.usgs.cida.coastalhazards.model.summary.Summary) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) URISyntaxException(java.net.URISyntaxException) SAXException(org.xml.sax.SAXException)

Example 7 with Summary

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

the class TemplateResource method makeItemsFromLayer.

private List<Item> makeItemsFromLayer(Item template, String layerId, LayerManager layerMan) throws IOException {
    List<Item> items = new LinkedList<>();
    Layer layer = layerMan.load(layerId);
    WFSService wfs = (WFSService) Service.ogcHelper(Service.ServiceType.proxy_wfs, layer.getServices());
    List<String> attrs = WFSIntrospector.getAttrs(wfs);
    for (String attr : attrs) {
        if (Attributes.contains(attr)) {
            Summary summary = makeSummary(layer, attr);
            Item item = templateItem(template, attr, layer, summary);
            items.add(item);
        }
    }
    return items;
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) Summary(gov.usgs.cida.coastalhazards.model.summary.Summary) Layer(gov.usgs.cida.coastalhazards.model.Layer) LinkedList(java.util.LinkedList)

Example 8 with Summary

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

the class PcoiTest method testGenerateSLD.

@Test
public void testGenerateSLD() {
    Item item = new Item();
    item.setAttr("PCOL1");
    item.setId("abcde");
    item.setType(Item.Type.storms);
    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("Pcoi");
    summary.setTiny(tiny);
    item.setSummary(summary);
    SLDGenerator pcoi = new SLDGenerator(item, item.getId(), null, Pcoi.pcoi);
    Response response = pcoi.generateSLD();
    // TODO?
    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 9 with Summary

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

the class PcoiTest method testGenerateSLDInfo.

/**
 * Test of generateSLDInfo method, of class Pcoi.
 */
@Test
public void testGenerateSLDInfo() {
    Item item = new Item();
    item.setAttr("PCOL1");
    item.setId("abcde");
    item.setType(Item.Type.storms);
    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("Pcoi");
    summary.setTiny(tiny);
    item.setSummary(summary);
    SLDGenerator pcoi = new SLDGenerator(item, item.getId(), null, Pcoi.pcoi);
    Response response = pcoi.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 lowerBound = (Double) bin.get("lowerBound");
    String color = (String) bin.get("color");
    assertEquals(lowerBound, 0.0f, 0.01f);
    assertEquals(color, "#FFFFFE");
}
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 10 with Summary

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

the class RasterTest method testGenerateSLD.

@Test
public void testGenerateSLD() {
    Item item = new Item();
    // for rasters, this will stay the same. We may need a way to manage the type for a raster(ramp, intervals) etc as that is the volatile piece of data.
    item.setAttr("GRAY_INDEX");
    // may want h
    item.setId("EHr6oLT5");
    item.setType(Item.Type.vulnerability);
    List<Service> services = new LinkedList<>();
    Service wmsService = new Service();
    wmsService.setEndpoint("http://test");
    wmsService.setServiceParameter("0");
    wmsService.setType(Service.ServiceType.source_wms);
    services.add(wmsService);
    item.setServices(services);
    Summary summary = new Summary();
    Tiny tiny = new Tiny();
    tiny.setText("Coastal response to Sea Level");
    summary.setTiny(tiny);
    item.setSummary(summary);
    SLDGenerator raster = new SLDGenerator(item, item.getId(), null, RasterAE.rasterConfig);
    Response response = raster.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)

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