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);
}
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;
}
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);
}
}
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);
}
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))"));
}
Aggregations