use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class CollectionFacade method deleteCollection.
public void deleteCollection(String collectionId) {
Collection collection = collectionDao.getCollectionById(collectionId);
permissionsChecker.checkRole(collection, Role.MANAGE);
collectionDao.deleteCollection(collectionId);
documentDao.deleteDocuments(collectionId);
dataDao.deleteDataRepository(collectionId);
SearchQuery queryLinkTypes = createQueryForLinkTypes(collectionId);
List<LinkType> linkTypes = linkTypeDao.getLinkTypes(queryLinkTypes);
if (!linkTypes.isEmpty()) {
linkTypeDao.deleteLinkTypes(queryLinkTypes);
linkInstanceDao.deleteLinkInstances(createQueryForLinkInstances(linkTypes));
}
}
use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class DocumentFacade method deleteDocument.
public void deleteDocument(String collectionId, String documentId) {
Collection collection = collectionDao.getCollectionById(collectionId);
permissionsChecker.checkRole(collection, Role.WRITE);
DataDocument data = dataDao.getData(collectionId, documentId);
updateCollectionMetadata(collection, Collections.emptySet(), data.keySet(), -1);
documentDao.deleteDocument(documentId);
dataDao.deleteData(collection.getId(), documentId);
linkInstanceDao.deleteLinkInstances(createQueryForLinkInstances(documentId));
}
use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class DocumentFacade method getDocuments.
public List<Document> getDocuments(String collectionId, Pagination pagination) {
Collection collection = collectionDao.getCollectionById(collectionId);
permissionsChecker.checkRole(collection, Role.READ);
Map<String, DataDocument> dataDocuments = getDataDocuments(collection.getId(), pagination);
return getDocuments(dataDocuments);
}
use of io.lumeer.api.model.Collection in project engine by Lumeer.
the class DocumentFacade method updateCollectionMetadata.
private void updateCollectionMetadata(Collection collection, Set<String> attributesToInc, Set<String> attributesToDec, int documentCountDiff) {
Map<String, Attribute> oldAttributes = collection.getAttributes().stream().collect(Collectors.toMap(Attribute::getFullName, Function.identity()));
oldAttributes.keySet().forEach(attributeName -> {
if (attributesToInc.contains(attributeName)) {
Attribute attribute = oldAttributes.get(attributeName);
attribute.setUsageCount(attribute.getUsageCount() + 1);
attributesToInc.remove(attributeName);
} else if (attributesToDec.contains(attributeName)) {
Attribute attribute = oldAttributes.get(attributeName);
attribute.setUsageCount(Math.max(attribute.getUsageCount() - 1, 0));
}
});
Set<Attribute> newAttributes = attributesToInc.stream().map(attributeName -> new JsonAttribute(extractAttributeName(attributeName), attributeName, Collections.emptySet(), 1)).collect(Collectors.toSet());
newAttributes.addAll(oldAttributes.values());
collection.setAttributes(newAttributes);
collection.setLastTimeUsed(LocalDateTime.now());
collection.setDocumentsCount(collection.getDocumentsCount() + documentCountDiff);
collectionDao.updateCollection(collection.getId(), collection);
}
use of io.lumeer.api.model.Collection 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;
}
Aggregations