use of io.arlas.server.core.exceptions.InternalServerErrorException in project ARLAS-server by gisaia.
the class ElasticTool method getCollectionReferenceFromES.
public static CollectionReference getCollectionReferenceFromES(ElasticClient client, String index, ObjectReader reader, String ref) throws ArlasException {
CollectionReference collection = new CollectionReference(ref);
// Exclude old include_fields for support old collection
String[] includes = Strings.EMPTY_ARRAY;
String[] excludes = new String[] { "include_fields" };
String source = client.getHit(index, ref, includes, excludes);
if (source != null) {
try {
collection.params = reader.readValue(source);
} catch (IOException e) {
throw new InternalServerErrorException("Can not fetch collection " + ref, e);
}
} else {
throw new NotFoundException("Collection " + ref + " not found.");
}
return collection;
}
use of io.arlas.server.core.exceptions.InternalServerErrorException in project ARLAS-server by gisaia.
the class ElasticCollectionReferenceService method getAllCollectionReferences.
@Override
public List<CollectionReference> getAllCollectionReferences(Optional<String> columnFilter) throws ArlasException {
List<CollectionReference> collections = new ArrayList<>();
try {
QueryBuilder qb = QueryBuilders.matchAllQuery();
SearchRequest request = new SearchRequest(arlasIndex);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
// Exclude old include_fields for support old collection
searchSourceBuilder.fetchSource(null, "include_fields").sort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC).query(qb).size(// max of 100 hits will be returned for each scroll
100);
request.source(searchSourceBuilder);
request.scroll(new TimeValue(60000));
SearchResponse scrollResp = client.search(request);
Set<String> allowedCollections = ColumnFilterUtil.getAllowedCollections(columnFilter);
do {
for (SearchHit hit : scrollResp.getHits().getHits()) {
String source = hit.getSourceAsString();
try {
for (String c : allowedCollections) {
if ((c.endsWith("*") && hit.getId().startsWith(c.substring(0, c.indexOf("*")))) || hit.getId().equals(c)) {
collections.add(new CollectionReference(hit.getId(), reader.readValue(source)));
break;
}
}
} catch (IOException e) {
throw new InternalServerErrorException("Can not fetch collection", e);
}
}
SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollResp.getScrollId());
scrollRequest.scroll(new TimeValue(60000));
scrollResp = client.searchScroll(scrollRequest);
} while (// Zero hits mark the end of the scroll and the while loop.
scrollResp.getHits().getHits().length != 0);
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
clearScrollRequest.addScrollId(scrollResp.getScrollId());
client.clearScroll(clearScrollRequest);
} catch (IndexNotFoundException e) {
throw new InternalServerErrorException("Unreachable collections", e);
}
return collections.stream().filter(c -> {
try {
return !getMapping(c.params.indexName).isEmpty();
} catch (ArlasException e) {
return false;
}
}).collect(Collectors.toList());
}
use of io.arlas.server.core.exceptions.InternalServerErrorException in project ARLAS-server by gisaia.
the class XmlUtils method writeElement.
private static void writeElement(XMLStreamWriter xmlStream, String nameToDisplay, String value, String uri, String prefix) throws XMLStreamException, ArlasException {
nameToDisplay = replacePointPath(nameToDisplay);
if (!StringUtils.isBlank(nameToDisplay)) {
/**
* check if the name to display respects the w3c recommendation*
*/
String startChar = nameToDisplay.substring(0, 1);
Matcher sm = ELEMENT_NAME_START_CHAR_PATTERN.matcher(startChar);
Matcher m = ELEMENT_NAME_CHAR_PATTERN.matcher(nameToDisplay);
if (!sm.matches() || !m.matches()) {
/**
* This error is thrown after response.ok() has been sent. Therefore it's written in the XML itself*
*/
xmlStream.writeCharacters("\n \n");
xmlStream.writeCharacters("ERROR WHILE WRITING XML. Element name : '" + nameToDisplay + "' is invalid");
xmlStream.flush();
xmlStream.close();
throw new InternalServerErrorException("Element name : '" + nameToDisplay + "' is invalid");
}
}
xmlStream.writeStartElement(prefix, nameToDisplay, uri);
xmlStream.writeCharacters(value);
xmlStream.writeEndElement();
}
use of io.arlas.server.core.exceptions.InternalServerErrorException 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