use of io.arlas.server.core.model.response.CollectionReferenceDescriptionProperty in project ARLAS-server by gisaia.
the class XmlUtils method parsePropertiesXml.
public static void parsePropertiesXml(Map<String, CollectionReferenceDescriptionProperty> properties, XMLStreamWriter writer, Stack<String> namespace, String uri, Object source, String prefix, ArrayList<Pattern> excludeFields) throws XMLStreamException, ArlasException {
if (properties != null) {
for (String key : properties.keySet()) {
CollectionReferenceDescriptionProperty property = properties.get(key);
namespace.push(key);
String path = String.join(".", new ArrayList<>(namespace));
boolean excludePath = excludeFields.stream().anyMatch(pattern -> pattern.matcher(path).matches());
if (!excludePath && property.indexed) {
if (property.type == FieldType.OBJECT) {
parsePropertiesXml(property.properties, writer, namespace, uri, source, prefix, excludeFields);
} else {
Object valueObject = MapExplorer.getObjectFromPath(String.join(".", new ArrayList<>(namespace)), source);
if (valueObject != null && property.type != FieldType.DATE && property.type != FieldType.GEO_POINT && property.type != FieldType.GEO_SHAPE) {
String value = valueObject.toString();
writeElement(writer, String.join(".", new ArrayList<>(namespace)), value, uri, prefix);
} else if (valueObject != null && property.type == FieldType.DATE) {
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX");
f.setTimeZone(TimeZone.getTimeZone("UTC"));
if (property.format == null) {
property.format = CollectionReference.DEFAULT_TIMESTAMP_FORMAT;
}
Long timestamp = TimestampTypeMapper.getTimestamp(valueObject, property.format);
writeElement(writer, String.join(".", new ArrayList<>(namespace)), f.format(new Date(timestamp)), uri, prefix);
}
}
}
namespace.pop();
}
} else {
writeElement(writer, String.join(".", new ArrayList<>(namespace)), null, uri, prefix);
}
}
use of io.arlas.server.core.model.response.CollectionReferenceDescriptionProperty in project ARLAS-server by gisaia.
the class CollectionReferenceManager method getType.
public FieldType getType(CollectionReference collectionReference, String field, boolean throwException) throws ArlasException {
FieldType fieldType = cacheManager.getFieldType(collectionReference.collectionName, field);
if (fieldType == null) {
String[] props = field.split("\\.");
CollectionReferenceDescriptionProperty esField = collectionReferenceService.describeCollection(collectionReference).properties.get(props[0]);
if (esField == null) {
return getUnknownType(field, collectionReference.collectionName, throwException);
}
for (int i = 1; i < props.length; i++) {
esField = esField.properties.get(props[i]);
if (esField == null) {
return getUnknownType(field, collectionReference.collectionName, throwException);
}
}
if (esField != null) {
fieldType = esField.type;
cacheManager.putFieldType(collectionReference.collectionName, field, fieldType);
} else {
return getUnknownType(field, collectionReference.collectionName, throwException);
}
}
return fieldType;
}
use of io.arlas.server.core.model.response.CollectionReferenceDescriptionProperty in project ARLAS-server by gisaia.
the class CollectionReferenceService method getFromSource.
private Map<String, CollectionReferenceDescriptionProperty> getFromSource(CollectionReference collectionReference, Map source, Stack<String> namespace, ArrayList<Pattern> excludeFields, Optional<Set<String>> columnFilterPredicates, boolean parentIsIndexed) {
Map<String, CollectionReferenceDescriptionProperty> ret = new HashMap<>();
for (Object key : source.keySet()) {
namespace.push(key.toString());
String path = String.join(".", namespace);
boolean excludePath = excludeFields.stream().anyMatch(pattern -> pattern.matcher(path).matches());
if (!excludePath) {
if (source.get(key) instanceof Map) {
Map property = (Map) source.get(key);
CollectionReferenceDescriptionProperty collectionProperty = new CollectionReferenceDescriptionProperty();
if (property.containsKey("type")) {
collectionProperty.type = FieldType.getType(property.get("type"));
} else {
collectionProperty.type = FieldType.OBJECT;
}
if (FilterMatcherUtil.matchesOrWithin(columnFilterPredicates, path, collectionProperty.type == FieldType.OBJECT)) {
// check whether the field is declared in the mapping but not index
if (property.containsKey("enabled")) {
collectionProperty.indexed = (boolean) property.get("enabled") && parentIsIndexed;
} else if (property.containsKey("index")) {
collectionProperty.indexed = (boolean) property.get("index") && parentIsIndexed;
} else {
collectionProperty.indexed = parentIsIndexed;
}
if (property.containsKey("format")) {
String format = property.get("format").toString();
if (format == null && collectionProperty.type.equals(FieldType.DATE)) {
format = CollectionReference.DEFAULT_TIMESTAMP_FORMAT;
}
collectionProperty.format = format;
}
if (property.containsKey("properties") && property.get("properties") instanceof Map) {
collectionProperty.properties = getFromSource(collectionReference, (Map) property.get("properties"), namespace, excludeFields, columnFilterPredicates, collectionProperty.indexed);
}
if (collectionReference.params.taggableFields != null) {
collectionProperty.taggable = Arrays.asList(collectionReference.params.taggableFields.split(",")).stream().map(s -> s.trim()).collect(Collectors.toList()).contains(path);
}
ret.put(key.toString(), collectionProperty);
}
}
}
namespace.pop();
}
return ret;
}
use of io.arlas.server.core.model.response.CollectionReferenceDescriptionProperty in project ARLAS-server by gisaia.
the class CollectionReferenceService method getType.
public FieldType getType(CollectionReference collectionReference, String field, boolean throwException) throws ArlasException {
FieldType fieldType = cacheManager.getFieldType(collectionReference.collectionName, field);
if (fieldType == null) {
String[] props = field.split("\\.");
CollectionReferenceDescriptionProperty esField = describeCollection(collectionReference).properties.get(props[0]);
if (esField == null) {
return getUnknownType(field, collectionReference.collectionName, throwException);
}
for (int i = 1; i < props.length; i++) {
esField = esField.properties.get(props[i]);
if (esField == null) {
return getUnknownType(field, collectionReference.collectionName, throwException);
}
}
if (esField != null) {
fieldType = esField.type;
cacheManager.putFieldType(collectionReference.collectionName, field, fieldType);
} else {
return getUnknownType(field, collectionReference.collectionName, throwException);
}
}
return fieldType;
}
use of io.arlas.server.core.model.response.CollectionReferenceDescriptionProperty 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