Search in sources :

Example 46 with Collection

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));
    }
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) Collection(io.lumeer.api.model.Collection) LinkType(io.lumeer.api.model.LinkType)

Example 47 with Collection

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));
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Collection(io.lumeer.api.model.Collection)

Example 48 with Collection

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);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Collection(io.lumeer.api.model.Collection)

Example 49 with Collection

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);
}
Also used : DocumentDao(io.lumeer.storage.api.dao.DocumentDao) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) LocalDateTime(java.time.LocalDateTime) Set(java.util.Set) SearchQuery(io.lumeer.storage.api.query.SearchQuery) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) DocumentUtils(io.lumeer.core.util.DocumentUtils) HashSet(java.util.HashSet) Inject(javax.inject.Inject) LinkInstanceDao(io.lumeer.storage.api.dao.LinkInstanceDao) List(java.util.List) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) Role(io.lumeer.api.model.Role) DataDao(io.lumeer.storage.api.dao.DataDao) JsonAttribute(io.lumeer.api.dto.JsonAttribute) RequestScoped(javax.enterprise.context.RequestScoped) Map(java.util.Map) Attribute(io.lumeer.api.model.Attribute) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Pagination(io.lumeer.api.model.Pagination) LinkedHashSet(java.util.LinkedHashSet) JsonAttribute(io.lumeer.api.dto.JsonAttribute) Attribute(io.lumeer.api.model.Attribute) JsonAttribute(io.lumeer.api.dto.JsonAttribute)

Example 50 with 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;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Collection(io.lumeer.api.model.Collection) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Collection (io.lumeer.api.model.Collection)77 Test (org.junit.Test)47 JsonCollection (io.lumeer.api.dto.JsonCollection)34 DataDocument (io.lumeer.engine.api.data.DataDocument)17 MorphiaCollection (io.lumeer.storage.mongodb.model.MorphiaCollection)17 SearchQuery (io.lumeer.storage.api.query.SearchQuery)14 SoftAssertions (org.assertj.core.api.SoftAssertions)12 Document (io.lumeer.api.model.Document)8 ImportedCollection (io.lumeer.api.model.ImportedCollection)8 SuggestionQuery (io.lumeer.storage.api.query.SuggestionQuery)8 Response (javax.ws.rs.core.Response)8 JsonAttribute (io.lumeer.api.dto.JsonAttribute)7 Attribute (io.lumeer.api.model.Attribute)7 HashSet (java.util.HashSet)6 JsonQuery (io.lumeer.api.dto.JsonQuery)5 LocalDateTime (java.time.LocalDateTime)4 List (java.util.List)4 JsonDocument (io.lumeer.api.dto.JsonDocument)3 LinkType (io.lumeer.api.model.LinkType)3 CollectionDao (io.lumeer.storage.api.dao.CollectionDao)3