Search in sources :

Example 1 with CollectionReferenceDescription

use of io.arlas.server.core.model.response.CollectionReferenceDescription 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 CollectionReferenceDescription

use of io.arlas.server.core.model.response.CollectionReferenceDescription in project ARLAS-server by gisaia.

the class CollectionReferenceService method getAllIndicesAsCollections.

public List<CollectionReferenceDescription> getAllIndicesAsCollections() throws ArlasException {
    List<CollectionReferenceDescription> collections = new ArrayList<>();
    Map<String, LinkedHashMap> indices = getAllMappingsFromDao(this.arlasIndex);
    for (String indexName : indices.keySet()) {
        CollectionReference collection = new CollectionReference();
        collection.collectionName = indexName;
        collection.params = new CollectionReferenceParameters();
        collection.params.indexName = indexName;
        collections.add(describeCollection(collection));
    }
    return collections;
}
Also used : CollectionReferenceDescription(io.arlas.server.core.model.response.CollectionReferenceDescription) CollectionReferenceParameters(io.arlas.server.core.model.CollectionReferenceParameters) CollectionReference(io.arlas.server.core.model.CollectionReference)

Example 3 with CollectionReferenceDescription

use of io.arlas.server.core.model.response.CollectionReferenceDescription in project ARLAS-server by gisaia.

the class DescribeCollectionRESTService method describe.

@Timed
@Path("{collection}/_describe")
@GET
@Produces(UTF8JSON)
@Consumes(UTF8JSON)
@ApiOperation(value = "Describe", produces = UTF8JSON, notes = "Describe the structure and the content of the given collection. ", consumes = UTF8JSON, response = CollectionReferenceDescription.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation", response = CollectionReferenceDescription.class, responseContainer = "CollectionReferenceDescription"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class), @ApiResponse(code = 400, message = "Bad request.", response = Error.class) })
public Response describe(// --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter, // --------------------------------------------------------
@ApiParam(name = "pretty", value = "Pretty print", defaultValue = "false") @QueryParam(value = "pretty") Boolean pretty, // --------------------------------------------------------
@ApiParam(value = "max-age-cache") @QueryParam(value = "max-age-cache") Integer maxagecache) throws ArlasException {
    CollectionReference collectionReference = exploreService.getCollectionReferenceService().getCollectionReference(collection);
    if (collectionReference == null) {
        throw new NotFoundException(collection);
    }
    ColumnFilterUtil.assertCollectionsAllowed(columnFilter, Collections.singletonList(collectionReference));
    CollectionReferenceDescription collectionReferenceDescription = exploreService.describeCollection(collectionReference, columnFilter);
    return cache(Response.ok(collectionReferenceDescription), maxagecache);
}
Also used : CollectionReferenceDescription(io.arlas.server.core.model.response.CollectionReferenceDescription) CollectionReference(io.arlas.server.core.model.CollectionReference) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with CollectionReferenceDescription

use of io.arlas.server.core.model.response.CollectionReferenceDescription in project ARLAS-server by gisaia.

the class CollectionReferenceService method describeAllCollections.

public List<CollectionReferenceDescription> describeAllCollections(List<CollectionReference> collectionReferenceList, Optional<String> columnFilter) throws ArlasException {
    // Can't use lambdas because of the need to throw the exception of describeCollection()
    List<CollectionReferenceDescription> res = new ArrayList<>();
    for (CollectionReference collection : collectionReferenceList) {
        if (!ColumnFilterUtil.cleanColumnFilter(columnFilter).isPresent() || ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collection).isPresent()) {
            try {
                CollectionReferenceDescription describe = describeCollection(collection, columnFilter);
                res.add(describe);
            } catch (ArlasException e) {
            }
        }
    }
    return res;
}
Also used : ArlasException(io.arlas.server.core.exceptions.ArlasException) CollectionReferenceDescription(io.arlas.server.core.model.response.CollectionReferenceDescription) CollectionReference(io.arlas.server.core.model.CollectionReference)

Example 5 with CollectionReferenceDescription

use of io.arlas.server.core.model.response.CollectionReferenceDescription in project ARLAS-server by gisaia.

the class CollectionReferenceService method describeCollection.

public CollectionReferenceDescription describeCollection(CollectionReference collectionReference, Optional<String> columnFilter) throws ArlasException {
    ArrayList<Pattern> excludeFields = new ArrayList<>();
    if (collectionReference.params.excludeFields != null) {
        Arrays.asList(collectionReference.params.excludeFields.split(",")).forEach(field -> excludeFields.add(Pattern.compile("^" + field.replace(".", "\\.").replace("*", ".*") + "$")));
    }
    CollectionReferenceDescription collectionReferenceDescription = new CollectionReferenceDescription();
    collectionReferenceDescription.params = collectionReference.params;
    collectionReferenceDescription.collectionName = collectionReference.collectionName;
    Map<String, LinkedHashMap> mappings = getMapping(collectionReferenceDescription.params.indexName);
    Iterator<String> indices = mappings.keySet().iterator();
    Map<String, CollectionReferenceDescriptionProperty> properties = new HashMap<>();
    Optional<Set<String>> columnFilterPredicates = ColumnFilterUtil.getColumnFilterPredicates(columnFilter, collectionReference);
    while (indices.hasNext()) {
        String index = indices.next();
        LinkedHashMap fields = mappings.get(index);
        properties = union(properties, getFromSource(collectionReference, fields, new Stack<>(), excludeFields, columnFilterPredicates, true));
    }
    collectionReferenceDescription.properties = properties;
    if (properties.isEmpty()) {
        throw new ArlasException("This collection can not be described. Check if index or template ".concat(collectionReferenceDescription.params.indexName).concat(" exist in Elasticsearch"));
    }
    return collectionReferenceDescription;
}
Also used : ArlasException(io.arlas.server.core.exceptions.ArlasException) Pattern(java.util.regex.Pattern) CollectionReferenceDescription(io.arlas.server.core.model.response.CollectionReferenceDescription) CollectionReferenceDescriptionProperty(io.arlas.server.core.model.response.CollectionReferenceDescriptionProperty)

Aggregations

CollectionReferenceDescription (io.arlas.server.core.model.response.CollectionReferenceDescription)6 CollectionReference (io.arlas.server.core.model.CollectionReference)4 Timed (com.codahale.metrics.annotation.Timed)2 ArlasException (io.arlas.server.core.exceptions.ArlasException)2 ArlasConfigurationException (io.arlas.server.core.exceptions.ArlasConfigurationException)1 CollectionReferenceParameters (io.arlas.server.core.model.CollectionReferenceParameters)1 CollectionReferenceDescriptionProperty (io.arlas.server.core.model.response.CollectionReferenceDescriptionProperty)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 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)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