use of io.lumeer.engine.api.exception.InvalidDocumentKeyException in project engine by Lumeer.
the class DocumentUtils method checkDocumentKeysValidity.
public static DataDocument checkDocumentKeysValidity(DataDocument dataDocument) throws InvalidDocumentKeyException {
DataDocument ndd = new DataDocument();
for (Map.Entry<String, Object> entry : dataDocument.entrySet()) {
String attributeName = entry.getKey().trim();
if (!isAttributeNameValid(attributeName)) {
throw new InvalidDocumentKeyException(attributeName);
}
Object value = entry.getValue();
if (isDataDocument(value)) {
ndd.put(attributeName, checkDocumentKeysValidity((DataDocument) value));
} else if (isList(value)) {
List l = (List) entry.getValue();
if (!l.isEmpty() && isDataDocument(l.get(0))) {
ArrayList<DataDocument> docs = new ArrayList<>();
ndd.put(attributeName, docs);
for (Object o : l) {
docs.add(checkDocumentKeysValidity((DataDocument) o));
}
} else {
ndd.put(attributeName, l);
}
} else {
ndd.put(attributeName, value);
}
}
return ndd;
}
Aggregations