Search in sources :

Example 6 with Layer

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;
}
Also used : WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) Service(gov.usgs.cida.coastalhazards.model.Service) IOException(java.io.IOException) Layer(gov.usgs.cida.coastalhazards.model.Layer) SAXException(org.xml.sax.SAXException) Response(javax.ws.rs.core.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) Bbox(gov.usgs.cida.coastalhazards.model.Bbox) WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) LayerManager(gov.usgs.cida.coastalhazards.jpa.LayerManager) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 7 with Layer

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;
}
Also used : Response(javax.ws.rs.core.Response) NotFoundException(javax.ws.rs.NotFoundException) Layer(gov.usgs.cida.coastalhazards.model.Layer) LayerManager(gov.usgs.cida.coastalhazards.jpa.LayerManager) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Layer (gov.usgs.cida.coastalhazards.model.Layer)7 LayerManager (gov.usgs.cida.coastalhazards.jpa.LayerManager)4 WFSService (gov.usgs.cida.coastalhazards.util.ogc.WFSService)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Item (gov.usgs.cida.coastalhazards.model.Item)3 Service (gov.usgs.cida.coastalhazards.model.Service)3 Summary (gov.usgs.cida.coastalhazards.model.summary.Summary)3 IOException (java.io.IOException)3 LinkedList (java.util.LinkedList)3 RolesAllowed (javax.annotation.security.RolesAllowed)3 Response (javax.ws.rs.core.Response)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 SAXException (org.xml.sax.SAXException)3 JsonObject (com.google.gson.JsonObject)2 Bbox (gov.usgs.cida.coastalhazards.model.Bbox)2 BadRequestException (javax.ws.rs.BadRequestException)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2