use of gov.usgs.cida.coastalhazards.model.Layer in project coastal-hazards by USGS-CIDA.
the class LayerResource method createVectorLayer.
@POST
@Path("/")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.TEXT_PLAIN)
@RolesAllowed({ CoastalHazardsTokenBasedSecurityFilter.CCH_ADMIN_ROLE })
public Response createVectorLayer(@Context HttpServletRequest req, InputStream postBody) {
Response response = null;
String newId = IdGenerator.generate();
List<Service> added = null;
try {
log.info("Vector layer upload - about to parseRequest");
byte[] inmemory = IOUtils.toByteArray(postBody);
try (ByteArrayInputStream bais = new ByteArrayInputStream(inmemory)) {
log.info("Vector layer create - about to doCSWInsertFromString");
String metadataId = MetadataUtil.doCSWInsertFromString(MetadataUtil.extractMetadataFromShp(bais));
bais.reset();
log.info("Vector layer create - about to do GeoserverUtil.addVectorLayer with Id: " + newId);
added = GeoserverUtil.addVectorLayer(bais, newId);
log.info("Vector layer create - about to makeCSWServiceForUrl with metadataId: " + metadataId);
added.add(MetadataUtil.makeCSWServiceForUrl(MetadataUtil.getMetadataByIdUrl(metadataId)));
} finally {
// just in case
inmemory = null;
}
} catch (IOException | ParserConfigurationException | SAXException | IllegalArgumentException e) {
log.error("Problem creating services from input", e);
}
if (added != null && !added.isEmpty()) {
WFSService wfs = (WFSService) Service.ogcHelper(Service.ServiceType.proxy_wfs, added);
Bbox bbox = null;
try {
bbox = WFSIntrospector.getBbox(wfs);
} catch (IOException ex) {
log.debug("Error determining bounding box", ex);
}
Layer layer = new Layer();
layer.setId(newId);
layer.setServices(added);
layer.setBbox(bbox);
try (LayerManager manager = new LayerManager()) {
manager.save(layer);
}
response = Response.created(layerURI(layer)).build();
} else {
response = Response.serverError().entity("Unable to create layer").build();
}
return response;
}
use of gov.usgs.cida.coastalhazards.model.Layer in project coastal-hazards by USGS-CIDA.
the class LayerResource method getLayer.
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getLayer(@Context HttpServletRequest req, @PathParam("id") String id) {
Response response = null;
try (LayerManager manager = new LayerManager()) {
Layer layer = manager.load(id);
if (layer == null) {
throw new NotFoundException();
}
response = Response.ok(GsonUtil.getDefault().toJson(layer), MediaType.APPLICATION_JSON).build();
}
return response;
}
Aggregations