use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class DocumentFacade method updateDocumentData.
public Document updateDocumentData(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());
Set<String> attributesToDec = new HashSet<>(oldData.keySet());
attributesToDec.removeAll(data.keySet());
updateCollectionMetadata(collection, attributesToAdd, attributesToDec, 0);
// TODO archive the old document
DataDocument updatedData = dataDao.updateData(collection.getId(), documentId, data);
Document updatedDocument = updateDocument(collection, documentId);
updatedDocument.setData(updatedData);
return updatedDocument;
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class ImportFacade method createDocumentFromRow.
private Document createDocumentFromRow(String[] headers, String[] row, int[] counts) {
final DataDocument d = new DataDocument();
for (int i = 0; i < Math.min(headers.length, row.length); i++) {
if (row[i] != null) {
d.append(headers[i], row[i]);
counts[i]++;
}
}
return new JsonDocument(d);
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDbStorage method createOldDocument.
@Override
public void createOldDocument(final String collectionName, final DataDocument dataDocument, final String documentId, final int version) throws UnsuccessfulOperationException {
Document doc = new Document(dataDocument);
doc.put(DOCUMENT_ID, new BasicDBObject(DOCUMENT_ID, new ObjectId(documentId)));
try {
database.getCollection(collectionName).insertOne(doc);
} catch (MongoWriteException e) {
if (e.getError().getCategory().equals(ErrorCategory.DUPLICATE_KEY)) {
throw new UnsuccessfulOperationException(e.getMessage(), e.getCause());
} else {
throw e;
}
}
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDbStorage method replaceDocument.
@Override
public void replaceDocument(final String collectionName, final DataDocument replaceDocument, final DataFilter filter) {
DataDocument toReplace = new DataDocument(replaceDocument);
if (toReplace.containsKey(DOCUMENT_ID)) {
toReplace.remove(DOCUMENT_ID);
}
Document replaceDoc = new Document(toReplace);
database.getCollection(collectionName).replaceOne(filter.<Bson>get(), replaceDoc, new UpdateOptions().upsert(true));
}
use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.
the class MongoDbStorage method aggregate.
@Override
public List<DataDocument> aggregate(final String collectionName, final DataDocument... stages) {
if (stages == null || stages.length == 0) {
return Collections.emptyList();
}
final List<DataDocument> result = new LinkedList<>();
final List<Document> documents = new LinkedList<>();
for (final DataDocument d : stages) {
documents.add(MongoUtils.dataDocumentToDocument(d));
}
AggregateIterable<Document> resultDocuments = database.getCollection(collectionName).aggregate(documents);
resultDocuments.into(new LinkedList<>()).forEach(d -> {
result.add(MongoUtils.convertDocument(d));
});
return result;
}
Aggregations