Search in sources :

Example 1 with InvalidDocumentKeyException

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;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) InvalidDocumentKeyException(io.lumeer.engine.api.exception.InvalidDocumentKeyException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

DataDocument (io.lumeer.engine.api.data.DataDocument)1 InvalidDocumentKeyException (io.lumeer.engine.api.exception.InvalidDocumentKeyException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1