Search in sources :

Example 1 with ArlasException

use of io.arlas.server.core.exceptions.ArlasException 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 2 with ArlasException

use of io.arlas.server.core.exceptions.ArlasException 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 3 with ArlasException

use of io.arlas.server.core.exceptions.ArlasException in project ARLAS-server by gisaia.

the class StacRESTService method getDateFilter.

protected String getDateFilter(String datetime, CollectionReference collectionReference) throws ArlasException {
    if (StringUtil.isNullOrEmpty(datetime)) {
        // no date filter
        return null;
    }
    if (collectionReference.params.timestampPath == null) {
        throw new ArlasException("No default timestamp path defined for the collection");
    }
    String dateField = collectionReference.params.timestampPath;
    String format = collectionReference.params.customParams.get(CollectionReference.TIMESTAMP_FORMAT);
    Object dateFormatted;
    if (datetime.startsWith("/")) {
        datetime = ".." + datetime;
    }
    if (datetime.endsWith("/")) {
        datetime = datetime + "..";
    }
    if (datetime.endsWith(".Z")) {
        throw new InvalidParameterException("Datetime value is not RFC 3339 compatible (missing fractional seconds: " + datetime);
    }
    String[] parts = datetime.split("/");
    if (parts.length == 1) {
        try {
            Long millisecondValue = Long.valueOf(OffsetDateTime.parse(datetime).toInstant().toEpochMilli());
            dateFormatted = formatDate(millisecondValue, format);
        } catch (DateTimeParseException e) {
            throw new InvalidParameterException("Datetime value is not RFC 3339 compatible: " + datetime);
        }
        return StringUtil.concat(dateField, ":", OperatorEnum.eq.name(), ":", String.valueOf(dateFormatted));
    } else if (parts.length == 2) {
        if (parts[0].equals("..")) {
            return StringUtil.concat(dateField, ":", OperatorEnum.lte.name(), ":", getTimestamp(parts[1]));
        } else if (parts[1].equals("..")) {
            return StringUtil.concat(dateField, ":", OperatorEnum.gte.name(), ":", getTimestamp(parts[0]));
        } else {
            if (Long.valueOf(OffsetDateTime.parse(parts[0]).toInstant().toEpochMilli()) > Long.valueOf(OffsetDateTime.parse(parts[1]).toInstant().toEpochMilli())) {
                throw new InvalidParameterException("Interval dates cannot be the same: " + datetime);
            }
            return StringUtil.concat(dateField, ":", OperatorEnum.range.name(), ":[", getTimestamp(parts[0]), "<", getTimestamp(parts[1]), "]");
        }
    } else {
        throw new ArlasException("Invalid datetime format for value " + datetime);
    }
}
Also used : ArlasException(io.arlas.server.core.exceptions.ArlasException) InvalidParameterException(io.arlas.server.core.exceptions.InvalidParameterException) DateTimeParseException(java.time.format.DateTimeParseException) GeoJsonObject(org.geojson.GeoJsonObject)

Example 4 with ArlasException

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

Example 5 with ArlasException

use of io.arlas.server.core.exceptions.ArlasException in project ARLAS-server by gisaia.

the class GeoUtilTest method testSplitPolygon.

@Test
public void testSplitPolygon() throws ArlasException {
    /**
     * east > 180 & west is canonical*
     */
    Geometry geo = (Polygon) GeoUtil.readWKT("POLYGON((210 -10,210 10,150 10,150 -10,210 -10))");
    List<Polygon> geometries = GeoUtil.splitPolygon((Polygon) geo)._1();
    assertTrue(geometries.size() == 2);
    List<String> geometriesString = geometries.stream().map(geometry -> geometry.toString()).collect(Collectors.toList());
    assertThat(geometriesString, CoreMatchers.hasItems("POLYGON ((180 10, 180 -10, 150 -10, 150 10, 180 10))", "POLYGON ((-180 -10, -180 10, -150 10, -150 -10, -180 -10))"));
    /**
     * west < -180 & east is canonical*
     */
    geo = GeoUtil.readWKT("POLYGON((-320 -10,-320 10,-40 10,-40 -10,-320 -10))");
    geometries = GeoUtil.splitPolygon((Polygon) geo)._1();
    assertTrue(geometries.size() == 2);
    geometriesString = geometries.stream().map(geometry -> geometry.toString()).collect(Collectors.toList());
    assertThat(geometriesString, CoreMatchers.hasItems("POLYGON ((180 10, 180 -10, 40 -10, 40 10, 180 10))", "POLYGON ((-180 -10, -180 10, -40 10, -40 -10, -180 -10))"));
    /**
     * west and east are canonical
     */
    geo = GeoUtil.readWKT("POLYGON((-80 -10,-80 10,-40 10,-40 -10,-80 -10))");
    geometries = GeoUtil.splitPolygon((Polygon) geo)._1();
    assertTrue(geometries.size() == 1);
    geometriesString = geometries.stream().map(geometry -> geometry.toString()).collect(Collectors.toList());
    assertThat(geometriesString, CoreMatchers.hasItems("POLYGON ((-80 -10, -80 10, -40 10, -40 -10, -80 -10))"));
    /**
     * west and east are < -180
     */
    geo = GeoUtil.readWKT("POLYGON((-360 -10,-360 10,-200 10,-200 -10,-360 -10))");
    geometries = GeoUtil.splitPolygon((Polygon) geo)._1();
    assertTrue(geometries.size() == 1);
    geometriesString = geometries.stream().map(geometry -> geometry.toString()).collect(Collectors.toList());
    assertThat(geometriesString, CoreMatchers.hasItems("POLYGON ((0 -10, 0 10, 160 10, 160 -10, 0 -10))"));
    /**
     * west and east are > 180
     */
    geo = GeoUtil.readWKT("POLYGON((200 -10,200 10,360 10,360 -10,200 -10))");
    geometries = GeoUtil.splitPolygon((Polygon) geo)._1();
    assertTrue(geometries.size() == 1);
    geometriesString = geometries.stream().map(geometry -> geometry.toString()).collect(Collectors.toList());
    assertThat(geometriesString, CoreMatchers.hasItems("POLYGON ((-160 -10, -160 10, 0 10, 0 -10, -160 -10))"));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Assert.assertThat(org.junit.Assert.assertThat) CoreMatchers(org.hamcrest.CoreMatchers) List(java.util.List) ArlasException(io.arlas.server.core.exceptions.ArlasException) GeoUtil(io.arlas.server.core.utils.GeoUtil) Polygon(org.locationtech.jts.geom.Polygon) Geometry(org.locationtech.jts.geom.Geometry) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Envelope(org.locationtech.jts.geom.Envelope) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) Polygon(org.locationtech.jts.geom.Polygon) Test(org.junit.Test)

Aggregations

ArlasException (io.arlas.server.core.exceptions.ArlasException)29 CollectionReference (io.arlas.server.core.model.CollectionReference)15 IOException (java.io.IOException)11 Collectors (java.util.stream.Collectors)8 InvalidParameterException (io.arlas.server.core.exceptions.InvalidParameterException)7 ExploreService (io.arlas.server.core.services.ExploreService)7 Timed (com.codahale.metrics.annotation.Timed)6 CollectionReferenceService (io.arlas.server.core.services.CollectionReferenceService)6 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 List (java.util.List)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 CollectionReferenceParameters (io.arlas.server.core.model.CollectionReferenceParameters)5 IntParam (io.dropwizard.jersey.params.IntParam)5 java.util (java.util)5 Optional (java.util.Optional)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 DublinCoreElementName (io.arlas.server.core.model.DublinCoreElementName)4 Inspire (io.arlas.server.core.model.Inspire)4 UnknownHostException (java.net.UnknownHostException)4