use of io.lumeer.engine.api.event.ImportCollectionContent in project engine by Lumeer.
the class DocumentFacade method updateDocumentsMetaData.
public List<Document> updateDocumentsMetaData(final String collectionId, final List<Document> documents) {
final List<Document> updatedDocuments = new ArrayList<>();
Collection collection = null;
for (Document document : documents) {
var tuple = checkEditDocument(document.getId());
collection = tuple.getFirst();
document.setUpdatedBy(getCurrentUserId());
document.setUpdateDate(ZonedDateTime.now());
final Document updatedDocument = documentDao.updateDocument(document.getId(), document);
updatedDocument.setData(constraintManager.decodeDataTypes(collection, document.getData()));
updatedDocuments.add(updatedDocument);
}
if (importCollectionContentEvent != null && collection != null) {
importCollectionContentEvent.fire(new ImportCollectionContent(collection));
}
return updatedDocuments;
}
use of io.lumeer.engine.api.event.ImportCollectionContent in project engine by Lumeer.
the class DocumentFacade method createDocuments.
public List<Document> createDocuments(final String collectionId, final List<Document> documents, final boolean sendNotification) {
final Collection collection = checkCreateDocuments(collectionId);
final Map<String, Integer> usages = new HashMap<>();
final Map<String, DataDocument> documentsData = new HashMap<>();
permissionsChecker.checkDocumentLimits(documents);
// encode the original data and remember them by their original template id
documents.forEach(document -> {
DataDocument data = constraintManager.encodeDataTypes(collection, document.getData());
documentsData.put((String) document.createIfAbsentMetaData().computeIfAbsent(Document.META_TEMPLATE_ID, key -> UUID.randomUUID().toString()), data);
});
final List<Document> storedDocuments = createDocuments(collection, documents);
// map the original data to the newly created documents
storedDocuments.forEach(storedDocument -> {
final DataDocument data = documentsData.get(storedDocument.getMetaData().getString(Document.META_TEMPLATE_ID));
data.setId(storedDocument.getId());
storedDocument.setData(data);
});
// store the documents data
final List<DataDocument> storedData = dataDao.createData(collection.getId(), storedDocuments.stream().map(Document::getData).collect(Collectors.toList()));
// map the stored data to the document ids
final Map<String, DataDocument> storedDocumentsData = new HashMap<>();
storedData.forEach(dd -> storedDocumentsData.put(dd.getId(), dd));
// put the stored data to the stored documents, decode data types and count attributes usage
storedDocuments.forEach(storedDocument -> {
final DataDocument singleStoredData = storedDocumentsData.get(storedDocument.getId());
storedDocument.setData(singleStoredData);
singleStoredData.keySet().forEach(key -> usages.put(key, usages.computeIfAbsent(key, k -> 0) + 1));
storedDocument.setData(constraintManager.decodeDataTypes(collection, storedDocument.getData()));
});
collectionAdapter.updateCollectionMetadata(collection, usages);
if (sendNotification && importCollectionContentEvent != null) {
importCollectionContentEvent.fire(new ImportCollectionContent(collection));
}
return storedDocuments;
}
Aggregations