Search in sources :

Example 1 with Version

use of io.arlas.server.ogc.common.utils.Version 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)

Example 2 with Version

use of io.arlas.server.ogc.common.utils.Version in project ARLAS-server by gisaia.

the class CSWCheckParam method checkQuerySyntax.

public static void checkQuerySyntax(CSWRequestType requestType, String elementName, String elementSetName, String acceptVersions, String version, String service, String outputSchema, String typeNames, String bbox, String resourceid, String query, String id, String constraintLanguage) throws OGCException {
    if (service == null) {
        throw new OGCException(OGCExceptionCode.MISSING_PARAMETER_VALUE, "Missing service", "service", Service.CSW);
    }
    if (requestType.equals(CSWRequestType.GetRecordById)) {
        if (id == null) {
            throw new OGCException(OGCExceptionCode.MISSING_PARAMETER_VALUE, "Missing id", "id", Service.CSW);
        }
    }
    if (bbox != null && resourceid != null) {
        throw new OGCException(OGCExceptionCode.OPERATION_NOT_SUPPORTED, "BBOX and RECORDIDS can't be used together", "bbox,recordIds", Service.CSW);
    } else if (resourceid != null && query != null) {
        throw new OGCException(OGCExceptionCode.OPERATION_NOT_SUPPORTED, "RECORDIDS and Q can't be used together", "bbox,q", Service.CSW);
    }
    if (outputSchema != null) {
        boolean isValidOutputSchema = Arrays.asList(CSWConstant.SUPPORTED_CSW_OUTPUT_SCHEMA).contains(outputSchema);
        if (!isValidOutputSchema)
            throw new OGCException(OGCExceptionCode.INVALID_PARAMETER_VALUE, "Invalid outputSchema", "outputSchema", Service.CSW);
    }
    if (typeNames != null) {
        ArrayList<Pattern> accepTypeName = new ArrayList<>();
        Arrays.asList(CSWConstant.SUPPORTED_TYPE_NAME_PATTERN).forEach(field -> {
            accepTypeName.add(Pattern.compile("^" + field + "$"));
        });
        for (String field : Arrays.asList(typeNames.split(","))) {
            boolean validType = accepTypeName.stream().anyMatch(pattern -> pattern.matcher(field).matches());
            if (!validType)
                throw new OGCException(OGCExceptionCode.INVALID_PARAMETER_VALUE, "Invalid typeNames", "typeNames", Service.CSW);
        }
    }
    if (bbox != null) {
        if (bbox.split(",").length == 5) {
            if (bbox.split(",")[4] != "urn:ogc:def:crs:EPSG::4326") {
                throw new OGCException(OGCExceptionCode.INVALID_PARAMETER_VALUE, "Invalid BBOX", "BBOX", Service.CSW);
            }
        }
    }
    ElementSetName elementSetNameEnum;
    if (elementSetName != null) {
        try {
            elementSetNameEnum = ElementSetName.valueOf(elementSetName);
        } catch (IllegalArgumentException e) {
            String msg = "Invalid elementSetName value, allowed values : " + ElementSetName.brief.name() + ", " + ElementSetName.summary.name() + "or " + ElementSetName.full.name();
            throw new OGCException(OGCExceptionCode.INVALID_PARAMETER_VALUE, "Invalid elementSetName", "elementSetName", Service.CSW);
        }
    }
    if (elementName != null && elementSetName != null) {
        throw new OGCException(OGCExceptionCode.NO_APPLICABLE_CODE_400, "elementName and elementSetName can't be used together", "elementName,elementSetName", Service.CSW);
    }
    Version requestVersion = null;
    if (acceptVersions != null) {
        List<String> versions = Arrays.asList(acceptVersions.split(","));
        for (String v : versions) {
            requestVersion = VersionUtils.getVersion(v, Service.CSW);
            VersionUtils.checkVersion(requestVersion, CSWConstant.SUPPORTED_CSW_VERSION, Service.CSW);
        }
    } else {
        requestVersion = VersionUtils.getVersion(version, Service.CSW);
        VersionUtils.checkVersion(requestVersion, CSWConstant.SUPPORTED_CSW_VERSION, Service.CSW);
    }
    if (constraintLanguage != null && !constraintLanguage.equals("") && !Arrays.asList(CSWConstant.SUPPORTED_CSW_CONSTRAINTLANGUAGE).contains(constraintLanguage)) {
        throw new OGCException(OGCExceptionCode.INVALID_PARAMETER_VALUE, "Invalid constraintLanguage. Supported constraint languages are : 'Filter'. ", "outputSchema", Service.CSW);
    }
}
Also used : Pattern(java.util.regex.Pattern) Version(io.arlas.server.ogc.common.utils.Version) ArrayList(java.util.ArrayList) OGCException(io.arlas.server.ogc.common.exceptions.OGC.OGCException)

Aggregations

OGCException (io.arlas.server.ogc.common.exceptions.OGC.OGCException)2 Version (io.arlas.server.ogc.common.utils.Version)2 Timed (com.codahale.metrics.annotation.Timed)1 CollectionReference (io.arlas.server.core.model.CollectionReference)1 CollectionReferenceDescription (io.arlas.server.core.model.response.CollectionReferenceDescription)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 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 QName (javax.xml.namespace.QName)1