use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class DocumentFacade method getDocument.
public Document getDocument(String collectionId, String documentId) {
Collection collection = collectionDao.getCollectionById(collectionId);
permissionsChecker.checkRole(collection, Role.READ);
Document document = documentDao.getDocumentById(documentId);
DataDocument data = dataDao.getData(collection.getId(), documentId);
document.setData(data);
return document;
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class DocumentFacade method createDocument.
public Document createDocument(String collectionId, Document document) {
Collection collection = collectionDao.getCollectionById(collectionId);
permissionsChecker.checkRole(collection, Role.WRITE);
DataDocument data = DocumentUtils.checkDocumentKeysValidity(document.getData());
Document storedDocument = createDocument(collection, document);
DataDocument storedData = dataDao.createData(collection.getId(), storedDocument.getId(), data);
storedDocument.setData(storedData);
updateCollectionMetadata(collection, data.keySet(), Collections.emptySet(), 1);
return storedDocument;
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class DocumentFacade method patchDocumentData.
public Document patchDocumentData(String collectionId, String documentId, DataDocument data) {
Collection collection = collectionDao.getCollectionById(collectionId);
permissionsChecker.checkRole(collection, Role.WRITE);
DataDocument oldData = dataDao.getData(collectionId, documentId);
Set<String> attributesToAdd = new HashSet<>(data.keySet());
attributesToAdd.removeAll(oldData.keySet());
updateCollectionMetadata(collection, attributesToAdd, Collections.emptySet(), 0);
// TODO archive the old document
DataDocument patchedData = dataDao.patchData(collection.getId(), documentId, data);
Document updatedDocument = updateDocument(collection, documentId);
updatedDocument.setData(patchedData);
return updatedDocument;
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class ImportFacade method addDocumentsToDb.
private void addDocumentsToDb(String collectionId, List<Document> documents) {
List<Document> storedDocuments = documentDao.createDocuments(documents);
List<DataDocument> dataDocuments = new LinkedList<>();
for (int i = 0; i < documents.size(); i++) {
DataDocument dataDocument = documents.get(i).getData();
dataDocument.setId(storedDocuments.get(i).getId());
dataDocuments.add(dataDocument);
}
dataDao.createData(collectionId, dataDocuments);
}
use of io.lumeer.engine.api.data.DataDocument 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