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