Search in sources :

Example 1 with CollectionReference

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

the class StacCollectionsRESTService method getFeature.

@Timed
@Path("/collections/{collectionId}/items/{featureId}")
@GET
@Produces({ "application/geo+json", MediaType.APPLICATION_JSON })
@ApiOperation(value = "Fetch a single feature", notes = "Fetch the feature with id `featureId` in the feature collection with id `collectionId`.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Fetch the feature with id `featureId` in the feature collection with id `collectionId`.", response = Item.class, responseContainer = "Item"), @ApiResponse(code = 404, message = "The requested URI was not found.", response = Error.class), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class) })
public Response getFeature(@Context UriInfo uriInfo, @ApiParam(name = "collectionId", value = "Local identifier of a collection", required = true) @PathParam(value = "collectionId") String collectionId, @ApiParam(name = "featureId", value = "Local identifier of a feature", required = true) @PathParam(value = "featureId") String featureId, @ApiParam(hidden = true) @HeaderParam(value = "partition-filter") String partitionFilter, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter) throws ArlasException {
    CollectionReference collectionReference = collectionReferenceService.getCollectionReference(collectionId);
    StacFeatureCollection features = getStacFeatureCollection(collectionReference, partitionFilter, columnFilter, null, java.util.Collections.singletonList(getIdFilter(featureId, collectionReference)), uriInfo, "GET", true);
    if (features.getFeatures().size() == 1) {
        Item response = getItem(features.getFeatures().get(0), collectionReference, uriInfo);
        return cache(Response.ok(response), 0);
    } else {
        throw new NotFoundException("Item not found");
    }
}
Also used : NotFoundException(io.arlas.server.core.exceptions.NotFoundException) CollectionReference(io.arlas.server.core.model.CollectionReference) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with CollectionReference

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

the class StacRESTService method getCollection.

protected Collection getCollection(CollectionReference collectionReference, UriInfo uriInfo) throws ArlasException {
    // https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md#link-object
    List<StacLink> cLinks = new ArrayList<>();
    cLinks.add(getRootLink(uriInfo));
    // TODO
    cLinks.add(getRawLink("TODO", "licence"));
    cLinks.add(getLink(uriInfo, "collections/" + collectionReference.collectionName, "self", MediaType.APPLICATION_JSON));
    cLinks.add(getLink(uriInfo, "collections/" + collectionReference.collectionName + "/items", "items", "application/geo+json"));
    // https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md#collection-fields
    return new Collection().id(collectionReference.collectionName).stacVersion(configuration.stacVersion).stacExtensions(// TODO optional
    new ArrayList<>()).title(collectionReference.params.dublinCoreElementName.title).description(collectionReference.params.dublinCoreElementName.description).keywords(collectionReference.params.inspire.keywords.stream().map(k -> k.value).collect(Collectors.toList())).license(// TODO *required*
    "proprietary").extent(new Extent().spatial(getSpatialExtent(collectionReference)).temporal(getTemporalExtent(collectionReference))).links(cLinks);
}
Also used : java.util(java.util) Link(io.arlas.server.core.model.Link) MixedRequest(io.arlas.server.core.model.request.MixedRequest) Path(javax.ws.rs.Path) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Feature(org.geojson.Feature) ComputationRequest(io.arlas.server.core.model.request.ComputationRequest) Collection(io.arlas.server.stac.model.Collection) MediaType(javax.ws.rs.core.MediaType) ArlasException(io.arlas.server.core.exceptions.ArlasException) ExploreService(io.arlas.server.core.services.ExploreService) FeatureCollection(org.geojson.FeatureCollection) InvalidParameterException(io.arlas.server.core.exceptions.InvalidParameterException) IntParam(io.dropwizard.jersey.params.IntParam) io.arlas.server.core.utils(io.arlas.server.core.utils) UriBuilder(javax.ws.rs.core.UriBuilder) Api(io.swagger.annotations.Api) ZoneOffset(java.time.ZoneOffset) Search(io.arlas.server.core.model.request.Search) Polygon(org.geojson.Polygon) CollectionReference(io.arlas.server.core.model.CollectionReference) CollectionReferenceService(io.arlas.server.core.services.CollectionReferenceService) GeoJsonObject(org.geojson.GeoJsonObject) ITU(com.ethlo.time.ITU) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Instant(java.time.Instant) ComputationEnum(io.arlas.server.core.model.enumerations.ComputationEnum) io.arlas.server.stac.model(io.arlas.server.stac.model) Collectors(java.util.stream.Collectors) MD(io.arlas.server.core.model.response.MD) TimestampTypeMapper.formatDate(io.arlas.server.core.utils.TimestampTypeMapper.formatDate) DateTimeParseException(java.time.format.DateTimeParseException) OffsetDateTime(java.time.OffsetDateTime) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) ParseException(org.locationtech.jts.io.ParseException) STACConfiguration(io.arlas.server.core.app.STACConfiguration) Geometry(org.locationtech.jts.geom.Geometry) UriInfo(javax.ws.rs.core.UriInfo) OperatorEnum(io.arlas.server.core.model.enumerations.OperatorEnum) Collection(io.arlas.server.stac.model.Collection) FeatureCollection(org.geojson.FeatureCollection)

Example 3 with CollectionReference

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

the class StacRESTService method getStacFeatureCollection.

protected StacFeatureCollection getStacFeatureCollection(CollectionReference collectionReference, String partitionFilter, Optional<String> columnFilter, SearchBody body, List<String> filter, UriInfo uriInfo, String method, boolean isOgc) throws ArlasException {
    Search search = new Search();
    search.filter = ParamsParser.getFilter(collectionReference, filter, null, null);
    if (body != null) {
        search.page = ParamsParser.getPage(new IntParam(body.getLimit().toString()), new IntParam(body.getFrom().toString()), getCleanSortBy(collectionReference.params.idPath, body.getSortBy()), body.getAfter(), body.getBefore());
    }
    exploreService.setValidGeoFilters(collectionReference, search);
    ColumnFilterUtil.assertRequestAllowed(columnFilter, collectionReference, search);
    Search searchHeader = new Search();
    searchHeader.filter = ParamsParser.getFilter(partitionFilter);
    MixedRequest request = new MixedRequest();
    request.basicRequest = search;
    request.headerRequest = searchHeader;
    request.columnFilter = ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collectionReference);
    ;
    HashMap<String, Object> context = new HashMap<>();
    FeatureCollection features = exploreService.getFeatures(request, collectionReference, false, uriInfo, method, context);
    // TODO what do we put in there?
    List<StacLink> links = new ArrayList<>();
    links.add(getRootLink(uriInfo));
    if (context.get("self") == null) {
        links.add(getSelfLink(uriInfo));
    } else {
        Arrays.asList("self", "next", "previous").forEach(rel -> {
            if (context.containsKey(rel)) {
                if (method.equals("POST")) {
                    links.add(getRawLink(((Link) context.get(rel)).href, rel, getSearchBody(body, (Search) ((Link) context.get(rel)).body)));
                } else {
                    links.add(getRawLink(((Link) context.get(rel)).href, rel));
                }
            }
        });
    }
    List<Item> items = features.getFeatures().stream().map(feat -> getItem(feat, collectionReference, uriInfo)).collect(Collectors.toList());
    StacFeatureCollection response = new StacFeatureCollection();
    response.setFeatures(items);
    response.setLinks(links);
    if (isOgc) {
        response.setNumberMatched(((Long) context.get("matched")).intValue());
        response.setNumberReturned(items.size());
        response.setTimeStamp(ITU.formatUtc(OffsetDateTime.now()));
    } else {
        Map<String, Object> ctx = new HashMap<>();
        ctx.put("returned", Long.valueOf(items.size()));
        ctx.put("limit", body.getLimit());
        ctx.put("matched", (Long) context.get("matched"));
        response.setContext(ctx);
    }
    return response;
}
Also used : java.util(java.util) Link(io.arlas.server.core.model.Link) MixedRequest(io.arlas.server.core.model.request.MixedRequest) Path(javax.ws.rs.Path) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Feature(org.geojson.Feature) ComputationRequest(io.arlas.server.core.model.request.ComputationRequest) Collection(io.arlas.server.stac.model.Collection) MediaType(javax.ws.rs.core.MediaType) ArlasException(io.arlas.server.core.exceptions.ArlasException) ExploreService(io.arlas.server.core.services.ExploreService) FeatureCollection(org.geojson.FeatureCollection) InvalidParameterException(io.arlas.server.core.exceptions.InvalidParameterException) IntParam(io.dropwizard.jersey.params.IntParam) io.arlas.server.core.utils(io.arlas.server.core.utils) UriBuilder(javax.ws.rs.core.UriBuilder) Api(io.swagger.annotations.Api) ZoneOffset(java.time.ZoneOffset) Search(io.arlas.server.core.model.request.Search) Polygon(org.geojson.Polygon) CollectionReference(io.arlas.server.core.model.CollectionReference) CollectionReferenceService(io.arlas.server.core.services.CollectionReferenceService) GeoJsonObject(org.geojson.GeoJsonObject) ITU(com.ethlo.time.ITU) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Instant(java.time.Instant) ComputationEnum(io.arlas.server.core.model.enumerations.ComputationEnum) io.arlas.server.stac.model(io.arlas.server.stac.model) Collectors(java.util.stream.Collectors) MD(io.arlas.server.core.model.response.MD) TimestampTypeMapper.formatDate(io.arlas.server.core.utils.TimestampTypeMapper.formatDate) DateTimeParseException(java.time.format.DateTimeParseException) OffsetDateTime(java.time.OffsetDateTime) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) ParseException(org.locationtech.jts.io.ParseException) STACConfiguration(io.arlas.server.core.app.STACConfiguration) Geometry(org.locationtech.jts.geom.Geometry) UriInfo(javax.ws.rs.core.UriInfo) OperatorEnum(io.arlas.server.core.model.enumerations.OperatorEnum) MixedRequest(io.arlas.server.core.model.request.MixedRequest) IntParam(io.dropwizard.jersey.params.IntParam) FeatureCollection(org.geojson.FeatureCollection) Search(io.arlas.server.core.model.request.Search) GeoJsonObject(org.geojson.GeoJsonObject) Link(io.arlas.server.core.model.Link)

Example 4 with CollectionReference

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

the class CSWRESTService method getCollectionReferencesForGetRecords.

private CollectionReferences getCollectionReferencesForGetRecords(String[] elements, String[] excludes, int maxRecords, int startPosition, String[] ids, String q, String constraint, BoundingBox boundingBox) throws IOException, ArlasException {
    CollectionReference metacollection = collectionReferenceService.getCollectionReference(getMetacollectionName());
    // First we check if there is only "metacollection" that is returned. If this is the case, it means that the queried param is a config param. Thus all collections should be returned
    CollectionReferences collectionReferences = ogcDao.getCollectionReferences(elements, null, 2, startPosition - 1, ids, q, constraint, boundingBox);
    if (collectionReferences.totalCollectionReferences == 1 && collectionReferences.collectionReferences.size() == 1 && collectionReferences.collectionReferences.get(0).collectionName.equals(getMetacollectionName())) {
        return ogcDao.getAllCollectionReferencesExceptOne(elements, excludes, maxRecords, startPosition - 1, metacollection);
    } else {
        return ogcDao.getCollectionReferencesExceptOne(elements, excludes, maxRecords, startPosition - 1, ids, q, constraint, boundingBox, metacollection);
    }
}
Also used : CollectionReferences(io.arlas.server.core.model.CollectionReferences) CollectionReference(io.arlas.server.core.model.CollectionReference)

Example 5 with CollectionReference

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

the class CSWService method initMetaCollection.

private void initMetaCollection(String index, OGCConfiguration ogcConfiguration, InspireConfiguration inspireConfiguration) throws ArlasException {
    List<CollectionReference> collectionReferences = collectionReferenceService.getAllCollectionReferences(Optional.empty());
    long count = collectionReferences.stream().filter(collectionReference -> collectionReference.collectionName.equals(getMetacollectionName())).count();
    if (count > 0) {
        collectionReferenceService.deleteCollectionReference(getMetacollectionName());
    }
    CollectionReference metacolletion = createMetaCollection(index, ogcConfiguration, inspireConfiguration);
    collectionReferenceService.putCollectionReference(metacolletion);
}
Also used : CollectionReference(io.arlas.server.core.model.CollectionReference) List(java.util.List) ArlasException(io.arlas.server.core.exceptions.ArlasException) InspireConfiguration(io.arlas.server.core.app.InspireConfiguration) CollectionReferenceService(io.arlas.server.core.services.CollectionReferenceService) OGCConfiguration(io.arlas.server.core.app.OGCConfiguration) OgcInspireConfigurationParameters(io.arlas.server.core.model.OgcInspireConfigurationParameters) OGCCollectionReferenceDao(io.arlas.server.ogc.common.dao.OGCCollectionReferenceDao) MetaCollectionReferenceParameters(io.arlas.server.core.model.MetaCollectionReferenceParameters) Optional(java.util.Optional) ArlasServerConfiguration(io.arlas.server.core.app.ArlasServerConfiguration) 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