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;
}
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;
}
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();
}
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");
}
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();
}
Aggregations