Search in sources :

Example 1 with OGCException

use of io.arlas.server.ogc.common.exceptions.OGC.OGCException 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 OGCException

use of io.arlas.server.ogc.common.exceptions.OGC.OGCException in project ARLAS-server by gisaia.

the class FilterToElastic method writeLiteral.

/**
 * Writes out a non null, non geometry literal. The base class properly handles
 * null, numeric and booleans (true|false), and turns everything else into a string.
 * Subclasses are expected to override this shall they need a different treatment
 * (e.g. for dates)
 *
 * @param literal
 */
protected void writeLiteral(Object literal) {
    boolean isDate = false;
    if (((String) field).split(":").length > 1) {
        String[] pathElements = ((String) field).split(":")[1].split(ArlasServerConfiguration.FLATTEN_CHAR);
        isDate = isPathDate(pathElements, collectionReference.properties);
    } else if (((String) field).split(":").length == 1) {
        String[] pathElements = ((String) field).split(ArlasServerConfiguration.FLATTEN_CHAR);
        isDate = isPathDate(pathElements, collectionReference.properties);
    }
    field = literal;
    if (isDate && !Date.class.isAssignableFrom(literal.getClass())) {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX");
        f.setTimeZone(TimeZone.getTimeZone("UTC"));
        try {
            // hack for the ets test suite wich test with bad date
            // bad 1970-01-01T00:13:33.4Z
            // bad 1970-01-01T00:13:33.43Z
            // good 1970-01-01T00:13:33.430Z
            String lastElement = ((String) literal).split("\\.")[1];
            String firstElement = ((String) literal).split("\\.")[0];
            String millisPart = lastElement.trim();
            if (millisPart.length() == 1) {
                literal = firstElement.concat(".").concat(millisPart).concat("00").concat("Z");
            } else if (lastElement.trim().length() == 2) {
                literal = firstElement.concat(".").concat(millisPart).concat("0").concat("Z");
            }
            // TODO change the test
            field = dateFormatter.print((f.parse((String) literal)).getTime());
        } catch (ParseException e) {
            List<OGCExceptionMessage> wfsExceptionMessages = new ArrayList<>();
            wfsExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.OPERATION_PROCESSING_FAILED, "Invalid Filter", "filter"));
            wfsExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.INVALID_PARAMETER_VALUE, "Unable to format " + field + "  in " + collectionReference.collectionName + ".", "filter"));
            ogcException = new OGCException(wfsExceptionMessages, Service.WFS);
            throw new RuntimeException();
        }
    }
    if (Date.class.isAssignableFrom(literal.getClass())) {
        field = dateFormatter.print(((Date) literal).getTime());
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) OGCExceptionMessage(io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) OGCException(io.arlas.server.ogc.common.exceptions.OGC.OGCException)

Example 3 with OGCException

use of io.arlas.server.ogc.common.exceptions.OGC.OGCException in project ARLAS-server by gisaia.

the class FilterToElastic method throwInvalidFesFilterException.

private void throwInvalidFesFilterException(String message) {
    List<OGCExceptionMessage> ogcExceptionMessages = new ArrayList<>();
    ogcExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.MISSING_ATTRIBUTE_FOR_OPERATOR, message, "filter"));
    ogcException = new OGCException(ogcExceptionMessages, service);
    throw new RuntimeException();
}
Also used : OGCExceptionMessage(io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage) OGCException(io.arlas.server.ogc.common.exceptions.OGC.OGCException)

Example 4 with OGCException

use of io.arlas.server.ogc.common.exceptions.OGC.OGCException in project ARLAS-server by gisaia.

the class FilterToElastic method throwDateException.

private void throwDateException() {
    List<OGCExceptionMessage> ogcExceptionMessages = new ArrayList<>();
    ogcExceptionMessages.add(new OGCExceptionMessage(INSPIREExceptionCode.INVALID_PARAMETER_VALUE, "Invalid date format. It should be YYYY-MM-DD", "filter"));
    ogcException = new OGCException(ogcExceptionMessages, service);
    throw new RuntimeException();
}
Also used : OGCExceptionMessage(io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage) OGCException(io.arlas.server.ogc.common.exceptions.OGC.OGCException)

Example 5 with OGCException

use of io.arlas.server.ogc.common.exceptions.OGC.OGCException in project ARLAS-server by gisaia.

the class FilterToElastic method throwInvalidFieldException.

private void throwInvalidFieldException() {
    List<OGCExceptionMessage> ogcExceptionMessages = new ArrayList<>();
    ogcExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.OPERATION_PROCESSING_FAILED, "Invalid Filter", "filter"));
    String exceptionText;
    if (service == Service.WFS) {
        exceptionText = "Unable to find " + field + "  in " + collectionReference.collectionName + ".";
    } else {
        exceptionText = "Unable to find the queried metadata : '" + key + "'";
    }
    ogcExceptionMessages.add(new OGCExceptionMessage(OGCExceptionCode.INVALID_PARAMETER_VALUE, exceptionText, "filter"));
    ogcException = new OGCException(ogcExceptionMessages, service);
    throw new RuntimeException();
}
Also used : OGCExceptionMessage(io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage) OGCException(io.arlas.server.ogc.common.exceptions.OGC.OGCException)

Aggregations

OGCException (io.arlas.server.ogc.common.exceptions.OGC.OGCException)15 OGCExceptionMessage (io.arlas.server.ogc.common.exceptions.OGC.OGCExceptionMessage)6 Timed (com.codahale.metrics.annotation.Timed)2 CollectionReference (io.arlas.server.core.model.CollectionReference)2 Version (io.arlas.server.ogc.common.utils.Version)2 MDMetadataType (org.isotc211._2005.gmd.MDMetadataType)2 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)2 OpenSearchDescription (com.a9.opensearch.OpenSearchDescription)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArlasException (io.arlas.server.core.exceptions.ArlasException)1 CollectionReferences (io.arlas.server.core.model.CollectionReferences)1 CollectionReferenceDescription (io.arlas.server.core.model.response.CollectionReferenceDescription)1 BoundingBox (io.arlas.server.core.utils.BoundingBox)1 GetCapabilitiesHandler (io.arlas.server.ogc.csw.operation.getcapabilities.GetCapabilitiesHandler)1 GetRecordByIdResponse (io.arlas.server.ogc.csw.operation.getrecordbyid.GetRecordByIdResponse)1 GetRecordsByIdHandler (io.arlas.server.ogc.csw.operation.getrecordbyid.GetRecordsByIdHandler)1 GetRecordsHandler (io.arlas.server.ogc.csw.operation.getrecords.GetRecordsHandler)1 OpenSearchHandler (io.arlas.server.ogc.csw.operation.opensearch.OpenSearchHandler)1 CSWRequestType (io.arlas.server.ogc.csw.utils.CSWRequestType)1 GetCapabilitiesHandler (io.arlas.server.ogc.wfs.operation.getcapabilities.GetCapabilitiesHandler)1