Search in sources :

Example 6 with Service

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

the class TemplateResource method instantiateStormTemplate.

@GET
@Path("/storm")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ CoastalHazardsTokenBasedSecurityFilter.CCH_ADMIN_ROLE })
public Response instantiateStormTemplate(@Context HttpServletRequest request, @QueryParam("layerId") String layerId, @QueryParam("activeStorm") String active, @QueryParam("alias") String alias, @QueryParam("copyType") String copyType, @QueryParam("copyVal") String copyVal, @QueryParam("trackId") String trackId) {
    Response response;
    if (layerId != null && active != null) {
        Gson gson = GsonUtil.getDefault();
        String childJson = null;
        childJson = gson.toJson(StormUtil.createStormChildMap(layerId, Boolean.parseBoolean(active), trackId));
        if (childJson != null && childJson.length() > 0) {
            try (ItemManager itemMan = new ItemManager();
                LayerManager layerMan = new LayerManager();
                AliasManager aliasMan = new AliasManager()) {
                Layer layer = layerMan.load(layerId);
                if (layer != null) {
                    Summary summary = null;
                    if (copyType.equalsIgnoreCase("item") || copyType.equalsIgnoreCase("alias")) {
                        summary = copyExistingSummary(copyType, copyVal, itemMan, aliasMan);
                    } else {
                        summary = StormUtil.buildStormTemplateSummary(layer);
                    }
                    if (summary != null) {
                        List<Service> services = layer.getServices();
                        List<Service> serviceCopies = new LinkedList<>();
                        for (Service service : services) {
                            serviceCopies.add(Service.copyValues(service, new Service()));
                        }
                        Item baseTemplate = baseTemplateItem(Boolean.parseBoolean(active), layer.getBbox(), serviceCopies, summary);
                        String templateId = itemMan.persist(baseTemplate);
                        if (templateId != null && templateId.length() > 0) {
                            response = instantiateTemplate(request, templateId, childJson);
                            if (response.getStatus() == HttpStatus.SC_OK) {
                                Map<String, Object> ok = new HashMap<String, Object>() {

                                    private static final long serialVersionUID = 2398472L;

                                    {
                                        put("id", templateId);
                                    }
                                };
                                if (alias != null && alias.length() > 0) {
                                    Alias fullAlias = aliasMan.load(alias);
                                    if (fullAlias != null) {
                                        fullAlias.setItemId(templateId);
                                        aliasMan.update(fullAlias);
                                    } else {
                                        fullAlias = new Alias();
                                        fullAlias.setId(alias);
                                        fullAlias.setItemId(templateId);
                                        aliasMan.save(fullAlias);
                                    }
                                }
                                response = Response.ok(GsonUtil.getDefault().toJson(ok, HashMap.class), MediaType.APPLICATION_JSON_TYPE).build();
                            }
                        } else {
                            response = Response.status(500).build();
                        }
                    } else {
                        response = Response.status(400).build();
                    }
                } else {
                    response = Response.status(400).build();
                }
            } catch (Exception e) {
                log.error(e.toString());
                response = Response.status(500).build();
            }
        } else {
            response = Response.status(400).build();
        }
    } else {
        response = Response.status(400).build();
    }
    return response;
}
Also used : ItemManager(gov.usgs.cida.coastalhazards.jpa.ItemManager) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Gson(com.google.gson.Gson) WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) OGCService(gov.usgs.cida.coastalhazards.util.ogc.OGCService) Service(gov.usgs.cida.coastalhazards.model.Service) Layer(gov.usgs.cida.coastalhazards.model.Layer) LinkedList(java.util.LinkedList) URISyntaxException(java.net.URISyntaxException) BadRequestException(javax.ws.rs.BadRequestException) SAXException(org.xml.sax.SAXException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Response(javax.ws.rs.core.Response) AliasManager(gov.usgs.cida.coastalhazards.jpa.AliasManager) Item(gov.usgs.cida.coastalhazards.model.Item) Alias(gov.usgs.cida.coastalhazards.model.Alias) Summary(gov.usgs.cida.coastalhazards.model.summary.Summary) JsonObject(com.google.gson.JsonObject) LayerManager(gov.usgs.cida.coastalhazards.jpa.LayerManager) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with Service

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

the class DownloadUtility method getWfsService.

/**
 * Replaces item.getWfsService() after services were added to list
 *
 * @param item
 * @return source wfsService representing the canonical dataset
 */
private static WFSService getWfsService(Item item) {
    WFSService sourceWfs = null;
    List<Service> services = item.getServices();
    for (Service service : services) {
        if (service.getType() == ServiceType.proxy_wfs) {
            sourceWfs = new WFSService(service);
        }
    }
    return sourceWfs;
}
Also used : WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) Service(gov.usgs.cida.coastalhazards.model.Service) ExecutorService(java.util.concurrent.ExecutorService)

Example 8 with Service

use of gov.usgs.cida.coastalhazards.model.Service 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 Service

use of gov.usgs.cida.coastalhazards.model.Service 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 Service

use of gov.usgs.cida.coastalhazards.model.Service 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

Service (gov.usgs.cida.coastalhazards.model.Service)17 Item (gov.usgs.cida.coastalhazards.model.Item)8 LinkedList (java.util.LinkedList)8 Response (javax.ws.rs.core.Response)8 Summary (gov.usgs.cida.coastalhazards.model.summary.Summary)7 Tiny (gov.usgs.cida.coastalhazards.model.summary.Tiny)6 Test (org.junit.Test)6 WFSService (gov.usgs.cida.coastalhazards.util.ogc.WFSService)5 Gson (com.google.gson.Gson)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 LayerManager (gov.usgs.cida.coastalhazards.jpa.LayerManager)3 Bbox (gov.usgs.cida.coastalhazards.model.Bbox)3 Layer (gov.usgs.cida.coastalhazards.model.Layer)3 List (java.util.List)3 Map (java.util.Map)3 RolesAllowed (javax.annotation.security.RolesAllowed)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Viewable (org.glassfish.jersey.server.mvc.Viewable)3