Search in sources :

Example 6 with CollectionReference

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

the class CSWService method createMetaCollection.

private CollectionReference createMetaCollection(String index, OGCConfiguration ogcConfiguration, InspireConfiguration inspireConfiguration) {
    CollectionReference collectionReference = new CollectionReference();
    collectionReference.collectionName = getMetacollectionName();
    MetaCollectionReferenceParameters collectionReferenceParameters = new MetaCollectionReferenceParameters();
    collectionReferenceParameters.indexName = index;
    collectionReferenceParameters.idPath = META_COLLECTION_ID_PATH;
    collectionReferenceParameters.geometryPath = META_COLLECTION_GEOMETRY_PATH;
    collectionReferenceParameters.centroidPath = META_COLLECTION_CENTROID_PATH;
    collectionReferenceParameters.timestampPath = META_COLLECTION_TIMESTAMP_PATH;
    collectionReferenceParameters.inspireConfigurationParameters = new OgcInspireConfigurationParameters();
    collectionReferenceParameters.inspireConfigurationParameters.reponsibleParty = ogcConfiguration.serviceProviderName;
    collectionReferenceParameters.inspireConfigurationParameters.reponsiblePartyRole = ogcConfiguration.serviceProviderRole;
    collectionReferenceParameters.inspireConfigurationParameters.setConformityParameter();
    collectionReferenceParameters.inspireConfigurationParameters.publicAccessLimitations = inspireConfiguration.publicAccessLimitations;
    collectionReferenceParameters.inspireConfigurationParameters.accessAndUseConditions = inspireConfiguration.accessAndUseConditions;
    collectionReference.params = collectionReferenceParameters;
    return collectionReference;
}
Also used : OgcInspireConfigurationParameters(io.arlas.server.core.model.OgcInspireConfigurationParameters) MetaCollectionReferenceParameters(io.arlas.server.core.model.MetaCollectionReferenceParameters) CollectionReference(io.arlas.server.core.model.CollectionReference)

Example 7 with CollectionReference

use of io.arlas.server.core.model.CollectionReference 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 8 with CollectionReference

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

the class ElasticTool method getCollectionReferenceFromES.

public static CollectionReference getCollectionReferenceFromES(ElasticClient client, String index, ObjectReader reader, String ref) throws ArlasException {
    CollectionReference collection = new CollectionReference(ref);
    // Exclude old include_fields for support old collection
    String[] includes = Strings.EMPTY_ARRAY;
    String[] excludes = new String[] { "include_fields" };
    String source = client.getHit(index, ref, includes, excludes);
    if (source != null) {
        try {
            collection.params = reader.readValue(source);
        } catch (IOException e) {
            throw new InternalServerErrorException("Can not fetch collection " + ref, e);
        }
    } else {
        throw new NotFoundException("Collection " + ref + " not found.");
    }
    return collection;
}
Also used : InternalServerErrorException(io.arlas.server.core.exceptions.InternalServerErrorException) NotFoundException(io.arlas.server.core.exceptions.NotFoundException) IOException(java.io.IOException) CollectionReference(io.arlas.server.core.model.CollectionReference)

Example 9 with CollectionReference

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

the class CollectionReferenceService method getFromSource.

private Map<String, CollectionReferenceDescriptionProperty> getFromSource(CollectionReference collectionReference, Map source, Stack<String> namespace, ArrayList<Pattern> excludeFields, Optional<Set<String>> columnFilterPredicates, boolean parentIsIndexed) {
    Map<String, CollectionReferenceDescriptionProperty> ret = new HashMap<>();
    for (Object key : source.keySet()) {
        namespace.push(key.toString());
        String path = String.join(".", namespace);
        boolean excludePath = excludeFields.stream().anyMatch(pattern -> pattern.matcher(path).matches());
        if (!excludePath) {
            if (source.get(key) instanceof Map) {
                Map property = (Map) source.get(key);
                CollectionReferenceDescriptionProperty collectionProperty = new CollectionReferenceDescriptionProperty();
                if (property.containsKey("type")) {
                    collectionProperty.type = FieldType.getType(property.get("type"));
                } else {
                    collectionProperty.type = FieldType.OBJECT;
                }
                if (FilterMatcherUtil.matchesOrWithin(columnFilterPredicates, path, collectionProperty.type == FieldType.OBJECT)) {
                    // check whether the field is declared in the mapping but not index
                    if (property.containsKey("enabled")) {
                        collectionProperty.indexed = (boolean) property.get("enabled") && parentIsIndexed;
                    } else if (property.containsKey("index")) {
                        collectionProperty.indexed = (boolean) property.get("index") && parentIsIndexed;
                    } else {
                        collectionProperty.indexed = parentIsIndexed;
                    }
                    if (property.containsKey("format")) {
                        String format = property.get("format").toString();
                        if (format == null && collectionProperty.type.equals(FieldType.DATE)) {
                            format = CollectionReference.DEFAULT_TIMESTAMP_FORMAT;
                        }
                        collectionProperty.format = format;
                    }
                    if (property.containsKey("properties") && property.get("properties") instanceof Map) {
                        collectionProperty.properties = getFromSource(collectionReference, (Map) property.get("properties"), namespace, excludeFields, columnFilterPredicates, collectionProperty.indexed);
                    }
                    if (collectionReference.params.taggableFields != null) {
                        collectionProperty.taggable = Arrays.asList(collectionReference.params.taggableFields.split(",")).stream().map(s -> s.trim()).collect(Collectors.toList()).contains(path);
                    }
                    ret.put(key.toString(), collectionProperty);
                }
            }
        }
        namespace.pop();
    }
    return ret;
}
Also used : CollectionReference(io.arlas.server.core.model.CollectionReference) FieldType(io.arlas.server.core.model.response.FieldType) java.util(java.util) Logger(org.slf4j.Logger) CollectionReferenceParameters(io.arlas.server.core.model.CollectionReferenceParameters) NotFoundException(io.arlas.server.core.exceptions.NotFoundException) CacheManager(io.arlas.server.core.managers.CacheManager) LoggerFactory(org.slf4j.LoggerFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) ArlasException(io.arlas.server.core.exceptions.ArlasException) Stream(java.util.stream.Stream) io.arlas.server.core.utils(io.arlas.server.core.utils) CollectionReferenceDescriptionProperty(io.arlas.server.core.model.response.CollectionReferenceDescriptionProperty) Pattern(java.util.regex.Pattern) CollectionReferenceDescription(io.arlas.server.core.model.response.CollectionReferenceDescription) CollectionReferenceDescriptionProperty(io.arlas.server.core.model.response.CollectionReferenceDescriptionProperty)

Example 10 with CollectionReference

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

Aggregations

CollectionReference (io.arlas.server.core.model.CollectionReference)40 Timed (com.codahale.metrics.annotation.Timed)23 ApiOperation (io.swagger.annotations.ApiOperation)21 ApiResponses (io.swagger.annotations.ApiResponses)21 ArlasException (io.arlas.server.core.exceptions.ArlasException)14 MixedRequest (io.arlas.server.core.model.request.MixedRequest)13 Search (io.arlas.server.core.model.request.Search)7 Collectors (java.util.stream.Collectors)7 FeatureCollection (org.geojson.FeatureCollection)7 NotFoundException (io.arlas.server.core.exceptions.NotFoundException)6 CollectionReferenceService (io.arlas.server.core.services.CollectionReferenceService)6 ExploreService (io.arlas.server.core.services.ExploreService)6 IOException (java.io.IOException)6 java.util (java.util)5 Response (javax.ws.rs.core.Response)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 CollectionReferenceParameters (io.arlas.server.core.model.CollectionReferenceParameters)4 AggregationResponse (io.arlas.server.core.model.response.AggregationResponse)4 CollectionReferenceDescription (io.arlas.server.core.model.response.CollectionReferenceDescription)4 io.arlas.server.core.utils (io.arlas.server.core.utils)4