use of io.arlas.server.core.model.response.CollectionReferenceDescription 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);
}
}
use of io.arlas.server.core.model.response.CollectionReferenceDescription 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;
}
use of io.arlas.server.core.model.response.CollectionReferenceDescription in project ARLAS-server by gisaia.
the class DescribeCollectionRESTService method describe.
@Timed
@Path("{collection}/_describe")
@GET
@Produces(UTF8JSON)
@Consumes(UTF8JSON)
@ApiOperation(value = "Describe", produces = UTF8JSON, notes = "Describe the structure and the content of the given collection. ", consumes = UTF8JSON, response = CollectionReferenceDescription.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation", response = CollectionReferenceDescription.class, responseContainer = "CollectionReferenceDescription"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class), @ApiResponse(code = 400, message = "Bad request.", response = Error.class) })
public Response describe(// --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter, // --------------------------------------------------------
@ApiParam(name = "pretty", value = "Pretty print", defaultValue = "false") @QueryParam(value = "pretty") Boolean pretty, // --------------------------------------------------------
@ApiParam(value = "max-age-cache") @QueryParam(value = "max-age-cache") Integer maxagecache) throws ArlasException {
CollectionReference collectionReference = exploreService.getCollectionReferenceService().getCollectionReference(collection);
if (collectionReference == null) {
throw new NotFoundException(collection);
}
ColumnFilterUtil.assertCollectionsAllowed(columnFilter, Collections.singletonList(collectionReference));
CollectionReferenceDescription collectionReferenceDescription = exploreService.describeCollection(collectionReference, columnFilter);
return cache(Response.ok(collectionReferenceDescription), maxagecache);
}
use of io.arlas.server.core.model.response.CollectionReferenceDescription in project ARLAS-server by gisaia.
the class CollectionReferenceService method describeAllCollections.
public List<CollectionReferenceDescription> describeAllCollections(List<CollectionReference> collectionReferenceList, Optional<String> columnFilter) throws ArlasException {
// Can't use lambdas because of the need to throw the exception of describeCollection()
List<CollectionReferenceDescription> res = new ArrayList<>();
for (CollectionReference collection : collectionReferenceList) {
if (!ColumnFilterUtil.cleanColumnFilter(columnFilter).isPresent() || ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collection).isPresent()) {
try {
CollectionReferenceDescription describe = describeCollection(collection, columnFilter);
res.add(describe);
} catch (ArlasException e) {
}
}
}
return res;
}
use of io.arlas.server.core.model.response.CollectionReferenceDescription in project ARLAS-server by gisaia.
the class CollectionReferenceService method describeCollection.
public CollectionReferenceDescription describeCollection(CollectionReference collectionReference, Optional<String> columnFilter) throws ArlasException {
ArrayList<Pattern> excludeFields = new ArrayList<>();
if (collectionReference.params.excludeFields != null) {
Arrays.asList(collectionReference.params.excludeFields.split(",")).forEach(field -> excludeFields.add(Pattern.compile("^" + field.replace(".", "\\.").replace("*", ".*") + "$")));
}
CollectionReferenceDescription collectionReferenceDescription = new CollectionReferenceDescription();
collectionReferenceDescription.params = collectionReference.params;
collectionReferenceDescription.collectionName = collectionReference.collectionName;
Map<String, LinkedHashMap> mappings = getMapping(collectionReferenceDescription.params.indexName);
Iterator<String> indices = mappings.keySet().iterator();
Map<String, CollectionReferenceDescriptionProperty> properties = new HashMap<>();
Optional<Set<String>> columnFilterPredicates = ColumnFilterUtil.getColumnFilterPredicates(columnFilter, collectionReference);
while (indices.hasNext()) {
String index = indices.next();
LinkedHashMap fields = mappings.get(index);
properties = union(properties, getFromSource(collectionReference, fields, new Stack<>(), excludeFields, columnFilterPredicates, true));
}
collectionReferenceDescription.properties = properties;
if (properties.isEmpty()) {
throw new ArlasException("This collection can not be described. Check if index or template ".concat(collectionReferenceDescription.params.indexName).concat(" exist in Elasticsearch"));
}
return collectionReferenceDescription;
}
Aggregations