Search in sources :

Example 1 with WFSRequestType

use of io.arlas.server.ogc.wfs.utils.WFSRequestType in project ARLAS-server by gisaia.

the class WFSRESTService method doKVP.

@Timed
@Path("{collection}")
@GET
@Produces(MediaType.APPLICATION_XML)
@ApiOperation(value = "WFS", produces = MediaType.APPLICATION_XML, notes = "WFS")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class) })
public Response doKVP(@ApiParam(name = "collection", value = "collection", allowMultiple = false, required = true) @PathParam(value = "collection") String collection, // --------------------------------------------------------
@ApiParam(name = "version", value = "version", allowMultiple = false, required = true) @QueryParam(value = "version") String version, @ApiParam(name = "service", value = "service", allowMultiple = false, required = true) @QueryParam(value = "service") String service, @ApiParam(name = "request", value = "request", allowMultiple = false, required = true) @QueryParam(value = "request") String request, @ApiParam(name = "storedquery_id", value = "storedquery_id", allowMultiple = false, required = false) @QueryParam(value = "storedquery_id") String storedquery_id, @ApiParam(name = "id", value = "id", allowMultiple = false, required = false) @QueryParam(value = "id") String id, @ApiParam(name = "typenames", value = "typenames", allowMultiple = false, required = false) @QueryParam(value = "typenames") String typenames, @ApiParam(name = "startindex", value = "startindex", allowMultiple = false, required = false) @QueryParam(value = "startindex") Integer startindex, @ApiParam(name = "count", value = "count", allowMultiple = false, required = false) @QueryParam(value = "count") Integer count, @ApiParam(name = "valuereference", value = "valuereference", allowMultiple = false, required = false) @QueryParam(value = "valuereference") String valuereference, @ApiParam(name = "filter", value = "filter", allowMultiple = false, required = false) @QueryParam(value = "filter") String filter, @ApiParam(name = "resourceid", value = "resourceid", allowMultiple = false, required = false) @QueryParam(value = "resourceid") String resourceid, @ApiParam(name = "srsname", value = "srsname", allowMultiple = false, required = false) @QueryParam(value = "srsname") String srsname, @ApiParam(name = "bbox", value = "bbox", allowMultiple = false, required = false) @QueryParam(value = "bbox") String bbox, @ApiParam(name = "language", value = "language", allowMultiple = false, required = false) @QueryParam(value = "language") String language, // header filters
@ApiParam(hidden = true) @HeaderParam(value = "Partition-Filter") String partitionFilter, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter) throws IOException, ArlasException {
    Version requestVersion = VersionUtils.getVersion(version, Service.WFS);
    RequestUtils.checkRequestTypeByName(request, WFSConstant.SUPPORTED_WFS_REQUESTYPE, Service.WFS);
    WFSRequestType requestType = WFSRequestType.valueOf(request);
    WFSCheckParam.checkQuerySyntax(service, bbox, resourceid, filter, requestType, requestVersion);
    startindex = Optional.ofNullable(startindex).orElse(0);
    count = Optional.ofNullable(count).orElse(ogcConfiguration.queryMaxFeature.intValue());
    CollectionReference collectionReference = collectionReferenceService.getCollectionReference(collection);
    if (collectionReference == null) {
        throw new OGCException(OGCExceptionCode.NOT_FOUND, "Collection not found " + collection, Service.WFS);
    }
    ColumnFilterUtil.assertCollectionsAllowed(columnFilter, Arrays.asList(collectionReference));
    CollectionReferenceDescription collectionReferenceDescription = wfsToolService.getCollectionReferenceDescription(collectionReference);
    String collectionName = collectionReferenceDescription.collectionName;
    String serviceUrl = serverBaseUrl + "ogc/wfs/" + collectionName + "/?";
    QName featureQname = new QName(serviceUrl, collectionName, wfsConfiguration.featureNamespace);
    WFSCheckParam.checkTypeNames(collectionName, typenames);
    String[] excludes = null;
    if (collectionReference.params.excludeWfsFields != null) {
        excludes = collectionReference.params.excludeWfsFields.split(",");
    }
    switch(requestType) {
        case GetCapabilities:
            GetCapabilitiesHandler getCapabilitiesHandler = wfsHandler.getCapabilitiesHandler;
            getCapabilitiesHandler.setFeatureTypeListType(collectionReference, serviceUrl);
            getCapabilitiesHandler.setOperationsUrl(serviceUrl);
            if (wfsHandler.inspireConfiguration.enabled) {
                getCapabilitiesHandler.addINSPIRECompliantElements(collectionReference, serviceUrl, language);
            }
            JAXBElement<ExtendedWFSCapabilitiesType> getCapabilitiesResponse = ExtendedWFSCapabilitiesType.createWFSCapabilities(getCapabilitiesHandler.getCapabilitiesType);
            return Response.ok(getCapabilitiesResponse).type(MediaType.APPLICATION_XML).build();
        case DescribeFeatureType:
            StreamingOutput describeFeatureTypeResponse = wfsHandler.describeFeatureTypeHandler.getDescribeFeatureTypeResponse(collectionReferenceDescription, serviceUrl, columnFilter);
            return Response.ok(describeFeatureTypeResponse).type(MediaType.APPLICATION_XML).build();
        case ListStoredQueries:
            wfsHandler.listStoredQueriesHandler.setFeatureType(featureQname);
            JAXBElement<ListStoredQueriesResponseType> listStoredQueriesResponse = wfsHandler.listStoredQueriesHandler.getListStoredQueriesResponse();
            return Response.ok(listStoredQueriesResponse).type(MediaType.APPLICATION_XML).build();
        case DescribeStoredQueries:
            DescribeStoredQueriesResponseType describeStoredQueriesType = wfsHandler.wfsFactory.createDescribeStoredQueriesResponseType();
            wfsHandler.storedQueryManager.listStoredQueries().forEach(storedQuery -> {
                storedQuery.setFeatureType(featureQname);
                describeStoredQueriesType.getStoredQueryDescription().add(storedQuery.getStoredQueryDescription());
            });
            JAXBElement<DescribeStoredQueriesResponseType> describeStoredQueriesResponse = wfsHandler.wfsFactory.createDescribeStoredQueriesResponse(describeStoredQueriesType);
            return Response.ok(describeStoredQueriesResponse).type(MediaType.APPLICATION_XML).build();
        case GetFeature:
            WFSCheckParam.checkSrsName(srsname);
            StreamingOutput getFeatureResponse = null;
            if (storedquery_id != null) {
                Map<String, Object> response = wfsToolService.getFeature(id, bbox, filter, resourceid, storedquery_id, partitionFilter, collectionReference, excludes, columnFilter);
                getFeatureResponse = wfsHandler.getFeatureHandler.getFeatureByIdResponse(response, collectionReferenceDescription, serviceUrl);
            } else {
                List<Map<String, Object>> featureList = wfsToolService.getFeatures(id, bbox, filter, resourceid, partitionFilter, collectionReference, excludes, startindex, count, columnFilter);
                getFeatureResponse = wfsHandler.getFeatureHandler.getFeatureResponse(wfsHandler.ogcConfiguration, collectionReferenceDescription, startindex, count, featureList, serviceUrl);
            }
            return Response.ok(getFeatureResponse).type(MediaType.APPLICATION_XML).build();
        case GetPropertyValue:
            String include = OGCCheckParam.formatValueReference(valuereference, collectionReferenceDescription);
            ColumnFilterUtil.assertFieldAvailable(columnFilter, collectionReference, include);
            ValueCollectionType valueCollectionType = wfsToolService.getPropertyValue(id, bbox, filter, resourceid, storedquery_id, partitionFilter, collectionReference, include, excludes, startindex, count, columnFilter);
            return Response.ok(wfsHandler.wfsFactory.createValueCollection(valueCollectionType)).type(MediaType.APPLICATION_XML).build();
        default:
            throw new OGCException(OGCExceptionCode.INTERNAL_SERVER_ERROR, "Internal error: Unhandled request '" + request + "'.", Service.WFS);
    }
}
Also used : GetCapabilitiesHandler(io.arlas.server.ogc.wfs.operation.getcapabilities.GetCapabilitiesHandler) ExtendedWFSCapabilitiesType(io.arlas.server.ogc.wfs.utils.ExtendedWFSCapabilitiesType) CollectionReferenceDescription(io.arlas.server.core.model.response.CollectionReferenceDescription) QName(javax.xml.namespace.QName) WFSRequestType(io.arlas.server.ogc.wfs.utils.WFSRequestType) StreamingOutput(javax.ws.rs.core.StreamingOutput) CollectionReference(io.arlas.server.core.model.CollectionReference) Version(io.arlas.server.ogc.common.utils.Version) Map(java.util.Map) OGCException(io.arlas.server.ogc.common.exceptions.OGC.OGCException) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)1 CollectionReference (io.arlas.server.core.model.CollectionReference)1 CollectionReferenceDescription (io.arlas.server.core.model.response.CollectionReferenceDescription)1 OGCException (io.arlas.server.ogc.common.exceptions.OGC.OGCException)1 Version (io.arlas.server.ogc.common.utils.Version)1 GetCapabilitiesHandler (io.arlas.server.ogc.wfs.operation.getcapabilities.GetCapabilitiesHandler)1 ExtendedWFSCapabilitiesType (io.arlas.server.ogc.wfs.utils.ExtendedWFSCapabilitiesType)1 WFSRequestType (io.arlas.server.ogc.wfs.utils.WFSRequestType)1 Map (java.util.Map)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 QName (javax.xml.namespace.QName)1