use of io.arlas.server.core.model.CollectionReference in project ARLAS-server by gisaia.
the class GeoSearchRESTService method shapesearchPost.
@Timed
@Path("{collection}/_shapesearch")
@POST
@Produces(ZIPFILE)
@Consumes(UTF8JSON)
@ApiOperation(value = "ShapeSearch", produces = ZIPFILE, notes = Documentation.SHAPESEARCH_OPERATION, consumes = UTF8JSON)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class), @ApiResponse(code = 400, message = "Bad request.", response = Error.class) })
public Response shapesearchPost(// --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, // --------------------------------------------------------
Search search, @ApiParam(hidden = true) @HeaderParam(value = "partition-filter") String partitionFilter, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter, // --------------------------------------------------------
@ApiParam(name = "pretty", value = Documentation.FORM_PRETTY, defaultValue = "false") @QueryParam(value = "pretty") Boolean pretty, // --------------------------------------------------------
@ApiParam(value = "max-age-cache") @QueryParam(value = "max-age-cache") Integer maxagecache) throws NotFoundException, ArlasException {
CollectionReference collectionReference = exploreService.getCollectionReferenceService().getCollectionReference(collection);
if (collectionReference == null) {
throw new NotFoundException(collection);
}
String includes = search.projection != null ? search.projection.includes : null;
String excludes = search.projection != null ? search.projection.excludes : null;
CheckParams.checkReturnedGeometries(collectionReference, includes, excludes, search.returned_geometries);
Search searchHeader = new Search();
searchHeader.filter = ParamsParser.getFilter(partitionFilter);
exploreService.setValidGeoFilters(collectionReference, search);
exploreService.setValidGeoFilters(collectionReference, searchHeader);
ColumnFilterUtil.assertRequestAllowed(columnFilter, collectionReference, search);
search.projection = ParamsParser.enrichIncludes(search.projection, search.returned_geometries);
MixedRequest request = new MixedRequest();
request.basicRequest = search;
request.headerRequest = searchHeader;
request.columnFilter = ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collectionReference);
FeatureCollection fc = exploreService.getFeatures(request, collectionReference, true);
File result = toShapefile(fc);
try {
return Response.ok(result).header("Content-Disposition", "attachment; filename=" + result.getName()).build();
} finally {
try {
FileUtils.forceDeleteOnExit(result);
} catch (IOException e) {
}
}
}
use of io.arlas.server.core.model.CollectionReference in project ARLAS-server by gisaia.
the class SearchRESTService method searchPost.
@Timed
@Path("{collection}/_search")
@POST
@Produces(UTF8JSON)
@Consumes(UTF8JSON)
@ApiOperation(value = "Search", produces = UTF8JSON, notes = Documentation.SEARCH_OPERATION, consumes = UTF8JSON, response = Hits.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation", response = Hits.class, responseContainer = "ArlasHits"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class), @ApiResponse(code = 400, message = "Bad request.", response = Error.class) })
public Response searchPost(@Context UriInfo uriInfo, // --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, // --------------------------------------------------------
Search search, @ApiParam(hidden = true) @HeaderParam(value = "partition-filter") String partitionFilter, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter, // --------------------------------------------------------
@ApiParam(name = "pretty", value = Documentation.FORM_PRETTY, defaultValue = "false") @QueryParam(value = "pretty") Boolean pretty, // --------------------------------------------------------
@ApiParam(value = "max-age-cache") @QueryParam(value = "max-age-cache") Integer maxagecache) throws NotFoundException, ArlasException {
CollectionReference collectionReference = exploreService.getCollectionReferenceService().getCollectionReference(collection);
if (collectionReference == null) {
throw new NotFoundException(collection);
}
String includes = search.projection != null ? search.projection.includes : null;
String excludes = search.projection != null ? search.projection.excludes : null;
Search searchHeader = new Search();
searchHeader.filter = ParamsParser.getFilter(partitionFilter);
exploreService.setValidGeoFilters(collectionReference, search);
exploreService.setValidGeoFilters(collectionReference, searchHeader);
ColumnFilterUtil.assertRequestAllowed(columnFilter, collectionReference, search);
CheckParams.checkReturnedGeometries(collectionReference, includes, excludes, search.returned_geometries);
search.projection = ParamsParser.enrichIncludes(search.projection, search.returned_geometries);
MixedRequest request = new MixedRequest();
request.basicRequest = search;
request.headerRequest = searchHeader;
request.columnFilter = ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collectionReference);
Hits hits = exploreService.search(request, collectionReference, (search.form != null && Boolean.TRUE.equals(search.form.flat)), uriInfo, "POST");
return cache(Response.ok(hits), maxagecache);
}
use of io.arlas.server.core.model.CollectionReference in project ARLAS-server by gisaia.
the class AtomHitsMessageBodyWriter method writeTo.
@Override
public void writeTo(Hits hits, Class aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap multivaluedMap, OutputStream outputStream) throws WebApplicationException {
XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
try {
XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(outputStream);
writer.writeStartDocument();
writer.setPrefix(ATOM.XML_PREFIX, ATOM.XML_NS);
writer.writeStartElement(ATOM.XML_NS, "feed");
writer.writeNamespace(ATOM.XML_PREFIX, ATOM.XML_NS);
writer.writeNamespace(OPENSEARCH.XML_PREFIX, OPENSEARCH.XML_NS);
writer.writeNamespace(GEORSS.XML_PREFIX, GEORSS.XML_NS);
writer.writeNamespace(GML.XML_PREFIX, GML.XML_NS);
writeElement(writer, ATOM.XML_NS, "id", hits.collection);
writeElement(writer, ATOM.XML_NS, "title", hits.collection);
writeElement(writer, ATOM.XML_NS, "updated", dateFormater.format(new Date()));
writeElement(writer, OPENSEARCH.XML_NS, "totalResults", "" + hits.totalnb);
CollectionReference cr;
try {
cr = exploreService.getCollectionReferenceService().getCollectionReference(hits.collection);
} catch (ArlasException e) {
throw new WebApplicationException("Can not access collection metadata", e);
}
CollectionReferenceDescription fields = exploreService.describeCollection(cr, Optional.empty());
if (cr.params.atomFeed != null) {
Feed feed = cr.params.atomFeed;
if (feed.author != null) {
writer.writeStartElement(ATOM.XML_NS, "author");
writeElement(writer, ATOM.XML_NS, "name", feed.author.name);
writeElement(writer, ATOM.XML_NS, "email", feed.author.email);
writeElement(writer, ATOM.XML_NS, "uri", feed.author.uri);
writer.writeEndElement();
}
if (feed.contributor != null) {
writer.writeStartElement(ATOM.XML_NS, "contributor");
writeElement(writer, ATOM.XML_NS, "name", feed.contributor.name);
writeElement(writer, ATOM.XML_NS, "email", feed.contributor.email);
writeElement(writer, ATOM.XML_NS, "uri", feed.contributor.uri);
writer.writeEndElement();
}
if (feed.generator != null) {
writer.writeStartElement(ATOM.XML_NS, "generator");
writeElement(writer, ATOM.XML_NS, "name", feed.generator.name);
writeElement(writer, ATOM.XML_NS, "uri", feed.generator.uri);
writeElement(writer, ATOM.XML_NS, "version", feed.generator.version);
writer.writeEndElement();
}
writeElement(writer, ATOM.XML_NS, "icon", feed.icon);
writeElement(writer, ATOM.XML_NS, "logo", feed.logo);
writeElement(writer, ATOM.XML_NS, "rights", feed.rights);
writeElement(writer, ATOM.XML_NS, "subtitle", feed.subtitle);
}
for (Hit hit : hits.hits) {
writer.writeStartElement(ATOM.XML_NS, "entry");
writeElement(writer, ATOM.XML_NS, "id", hit.md.id);
writeElement(writer, ATOM.XML_NS, "title", hit.md.id);
writeElement(writer, ATOM.XML_NS, "update", dateFormater.format(new Date(hit.md.timestamp)));
writer.writeStartElement(ATOM.XML_NS, "content");
if (hit.isFlat()) {
for (String key : hit.getDataAsMap().keySet()) {
writeElement(writer, ATOM.XML_NS, key, hit.getDataAsMap().get(key).toString());
}
} else {
writeFields(writer, fields.properties, ATOM.XML_NS, new Stack<>(), hit.data);
}
writer.writeEndElement();
writer.writeStartElement(GEORSS.XML_NS, "where");
if (hit.md.geometry != null) {
GeoFormat.geojson2gml(hit.md.geometry, writer, hit.md.id);
} else {
GeoFormat.geojson2gml(hit.md.centroid, writer, hit.md.id);
}
writer.writeEndElement();
writer.writeEndElement();
}
writer.writeEndElement();
writer.flush();
} catch (ArlasException | XMLStreamException e) {
e.printStackTrace();
throw new WebApplicationException(e);
}
}
use of io.arlas.server.core.model.CollectionReference in project ARLAS-server by gisaia.
the class AggregateRESTService method aggregate.
@Timed
@Path("{collection}/_aggregate")
@GET
@Produces(UTF8JSON)
@Consumes(UTF8JSON)
@ApiOperation(value = "Aggregate", produces = UTF8JSON, notes = Documentation.AGGREGATION_OPERATION, consumes = UTF8JSON, response = AggregationResponse.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful operation", response = AggregationResponse.class, responseContainer = "ArlasAggregation"), @ApiResponse(code = 500, message = "Arlas Server Error.", response = Error.class), @ApiResponse(code = 400, message = "Bad request.", response = Error.class) })
public Response aggregate(// --------------------------------------------------------
@ApiParam(name = "collection", value = "collection", required = true) @PathParam(value = "collection") String collection, // --------------------------------------------------------
@ApiParam(name = "agg", value = Documentation.AGGREGATION_PARAM_AGG, required = true) @QueryParam(value = "agg") List<String> agg, // --------------------------------------------------------
@ApiParam(name = "f", value = Documentation.FILTER_PARAM_F, allowMultiple = true) @QueryParam(value = "f") List<String> f, @ApiParam(name = "q", value = Documentation.FILTER_PARAM_Q, allowMultiple = true) @QueryParam(value = "q") List<String> q, @ApiParam(name = "dateformat", value = Documentation.FILTER_DATE_FORMAT) @QueryParam(value = "dateformat") String dateformat, @ApiParam(hidden = true) @HeaderParam(value = "partition-filter") String partitionFilter, @ApiParam(hidden = true) @HeaderParam(value = "Column-Filter") Optional<String> columnFilter, // --------------------------------------------------------
@ApiParam(name = "pretty", value = Documentation.FORM_PRETTY, defaultValue = "false") @QueryParam(value = "pretty") Boolean pretty, @ApiParam(name = "flat", value = Documentation.FORM_FLAT, defaultValue = "false") @QueryParam(value = "flat") Boolean flat, // --------------------------------------------------------
@ApiParam(value = "max-age-cache") @QueryParam(value = "max-age-cache") Integer maxagecache) throws ArlasException {
long startArlasTime = System.nanoTime();
CollectionReference collectionReference = exploreService.getCollectionReferenceService().getCollectionReference(collection);
if (collectionReference == null) {
throw new NotFoundException(collection);
}
AggregationsRequest aggregationsRequest = new AggregationsRequest();
aggregationsRequest.filter = ParamsParser.getFilter(collectionReference, f, q, dateformat);
aggregationsRequest.aggregations = ParamsParser.getAggregations(collectionReference, agg);
exploreService.setValidGeoFilters(collectionReference, aggregationsRequest);
ColumnFilterUtil.assertRequestAllowed(columnFilter, collectionReference, aggregationsRequest);
AggregationsRequest aggregationsRequestHeader = new AggregationsRequest();
aggregationsRequestHeader.filter = ParamsParser.getFilter(partitionFilter);
MixedRequest request = new MixedRequest();
request.basicRequest = aggregationsRequest;
exploreService.setValidGeoFilters(collectionReference, aggregationsRequestHeader);
request.headerRequest = aggregationsRequestHeader;
request.columnFilter = ColumnFilterUtil.getCollectionRelatedColumnFilter(columnFilter, collectionReference);
AggregationResponse aggregationResponse = getArlasAggregation(request, collectionReference, Boolean.TRUE.equals(flat));
aggregationResponse.totalTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startArlasTime);
return cache(Response.ok(aggregationResponse), maxagecache);
}
use of io.arlas.server.core.model.CollectionReference in project ARLAS-server by gisaia.
the class ElasticOGCCollectionReferenceDao method getCollectionReferences.
private CollectionReferences getCollectionReferences(BoolQueryBuilder boolQueryBuilder, String[] includes, String[] excludes, int size, int from) throws ArlasException {
CollectionReferences collectionReferences = new CollectionReferences();
collectionReferences.collectionReferences = new ArrayList<>();
// Exclude old include_fields for support old collection
if (excludes != null) {
String[] copy = Arrays.copyOf(excludes, excludes.length + 1);
copy[excludes.length] = "include_fields";
excludes = copy;
} else {
excludes = new String[] { "include_fields" };
}
try {
SearchRequest request = new SearchRequest(arlasIndex);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(boolQueryBuilder).from(from).size(size).fetchSource(includes, excludes);
request.source(searchSourceBuilder);
SearchResponse response = client.search(request);
collectionReferences.totalCollectionReferences = response.getHits().getTotalHits().value;
for (SearchHit hit : response.getHits().getHits()) {
String source = hit.getSourceAsString();
try {
collectionReferences.collectionReferences.add(new CollectionReference(hit.getId(), mapper.readerFor(CollectionReferenceParameters.class).readValue(source)));
} catch (IOException e) {
throw new InternalServerErrorException("Can not fetch collection", e);
}
}
collectionReferences.nbCollectionReferences = collectionReferences.collectionReferences.size();
} catch (IndexNotFoundException e) {
throw new InternalServerErrorException("Unreachable collections", e);
}
return collectionReferences;
}
Aggregations