Search in sources :

Example 21 with Query

use of io.lumeer.api.model.Query in project engine by Lumeer.

the class LumeerBridge method removeDocumentsInView.

@SuppressWarnings("unused")
public void removeDocumentsInView(final String viewId) {
    try {
        final View view = task.getDaoContextSnapshot().getViewDao().getViewById(viewId);
        final Query query = view.getQuery().getFirstStem(0, Task.MAX_VIEW_DOCUMENTS);
        final Language language = Language.fromString(task.getCurrentLocale());
        final Set<RoleType> roles = PermissionUtils.getUserRolesInResource(task.getDaoContextSnapshot().getOrganization(), task.getDaoContextSnapshot().getProject(), view, task.getInitiator(), task.getGroups());
        final AllowedPermissions permissions = new AllowedPermissions(roles);
        final List<Document> documents = DocumentUtils.getDocuments(task.getDaoContextSnapshot(), query, task.getInitiator(), language, permissions, task.getTimeZone());
        documents.stream().filter(d -> task.getDaoContextSnapshot().increaseDeletionCounter() <= Task.MAX_CREATED_AND_DELETED_DOCUMENTS_AND_LINKS).forEach(d -> operations.add(new DocumentRemovalOperation(d)));
    } catch (Exception e) {
        cause = e;
        throw e;
    }
}
Also used : AllowedPermissions(io.lumeer.api.model.AllowedPermissions) SelectedWorkspace(io.lumeer.api.SelectedWorkspace) Arrays(java.util.Arrays) TaskExecutor(io.lumeer.core.task.TaskExecutor) PrintTextOperation(io.lumeer.core.task.executor.operation.PrintTextOperation) CollectionUtil(io.lumeer.api.util.CollectionUtil) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) FileAttachmentData(io.lumeer.core.task.executor.operation.data.FileAttachmentData) Operation(io.lumeer.core.task.executor.operation.Operation) TextPrintRequest(io.lumeer.core.task.executor.request.TextPrintRequest) StringUtils(org.apache.commons.lang3.StringUtils) UserMessageOperation(io.lumeer.core.task.executor.operation.UserMessageOperation) BigDecimal(java.math.BigDecimal) SmtpConfigurationBuilder(io.lumeer.core.task.executor.request.SmtpConfigurationBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceType(io.lumeer.api.model.ResourceType) Map(java.util.Map) AddLinkFileAttachmentOperation(io.lumeer.core.task.executor.operation.AddLinkFileAttachmentOperation) Collectors.toSet(java.util.stream.Collectors.toSet) ConstraintManager(io.lumeer.core.constraint.ConstraintManager) DocumentOperation(io.lumeer.core.task.executor.operation.DocumentOperation) RoleType(io.lumeer.api.model.RoleType) View(io.lumeer.api.model.View) ViewPermissionsOperation(io.lumeer.core.task.executor.operation.ViewPermissionsOperation) DataDocument(io.lumeer.engine.api.data.DataDocument) Value(org.graalvm.polyglot.Value) DummySequenceOperation(io.lumeer.core.task.executor.operation.DummySequenceOperation) Document(io.lumeer.api.model.Document) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) LinkInstance(io.lumeer.api.model.LinkInstance) StandardCharsets(java.nio.charset.StandardCharsets) LinkType(io.lumeer.api.model.LinkType) Group(io.lumeer.api.model.Group) DefaultConfigurationProducer(io.lumeer.core.facade.configuration.DefaultConfigurationProducer) PrintAttributeOperation(io.lumeer.core.task.executor.operation.PrintAttributeOperation) SendSmtpEmailRequest(io.lumeer.core.task.executor.request.SendSmtpEmailRequest) List(java.util.List) SendEmailOperation(io.lumeer.core.task.executor.operation.SendEmailOperation) EmailSecurityType(io.lumeer.core.util.EmailSecurityType) Optional(java.util.Optional) Attribute(io.lumeer.api.model.Attribute) WithId(io.lumeer.api.model.common.WithId) SendSmtpEmailOperation(io.lumeer.core.task.executor.operation.SendSmtpEmailOperation) ChangesTracker(io.lumeer.core.task.executor.ChangesTracker) LongAdder(java.util.concurrent.atomic.LongAdder) LinkOperation(io.lumeer.core.task.executor.operation.LinkOperation) Engine(com.floreysoft.jmte.Engine) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocumentCreationOperation(io.lumeer.core.task.executor.operation.DocumentCreationOperation) SendEmailRequest(io.lumeer.core.task.executor.request.SendEmailRequest) HashMap(java.util.HashMap) AllowedPermissions(io.lumeer.api.model.AllowedPermissions) ArrayList(java.util.ArrayList) NavigationOperation(io.lumeer.core.task.executor.operation.NavigationOperation) SearchQueryStem(io.lumeer.storage.api.query.SearchQueryStem) HashSet(java.util.HashSet) Language(io.lumeer.api.model.Language) LinkCreationOperation(io.lumeer.core.task.executor.operation.LinkCreationOperation) PrintRequest(io.lumeer.core.task.executor.request.PrintRequest) DocumentRemovalOperation(io.lumeer.core.task.executor.operation.DocumentRemovalOperation) Query(io.lumeer.api.model.Query) ResourceOperation(io.lumeer.core.task.executor.operation.ResourceOperation) ContextualTask(io.lumeer.core.task.ContextualTask) LinkTypeUtil(io.lumeer.api.util.LinkTypeUtil) Task(io.lumeer.core.task.Task) PermissionUtils(io.lumeer.api.util.PermissionUtils) IOException(java.io.IOException) UserMessageRequest(io.lumeer.core.task.executor.request.UserMessageRequest) NavigationRequest(io.lumeer.core.task.executor.request.NavigationRequest) SmtpConfiguration(io.lumeer.core.task.executor.request.SmtpConfiguration) SearchQuery(io.lumeer.storage.api.query.SearchQuery) AddDocumentFileAttachmentOperation(io.lumeer.core.task.executor.operation.AddDocumentFileAttachmentOperation) DocumentUtils(io.lumeer.core.util.DocumentUtils) FileAttachment(io.lumeer.api.model.FileAttachment) Collectors.toList(java.util.stream.Collectors.toList) ResourceVariable(io.lumeer.api.model.ResourceVariable) PdfCreator(io.lumeer.core.pdf.PdfCreator) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Query(io.lumeer.api.model.Query) SearchQuery(io.lumeer.storage.api.query.SearchQuery) Language(io.lumeer.api.model.Language) RoleType(io.lumeer.api.model.RoleType) DocumentRemovalOperation(io.lumeer.core.task.executor.operation.DocumentRemovalOperation) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) View(io.lumeer.api.model.View) IOException(java.io.IOException)

Example 22 with Query

use of io.lumeer.api.model.Query in project engine by Lumeer.

the class DocumentMatcher method filterForCreation.

public Tuple<List<Document>, List<LinkInstance>> filterForCreation() {
    final List<Document> documents = loadDataAndDecode(dao.getDocumentDao().getDocumentsByCollection(thatCollection.getId()));
    final Query query = queryProvider.getMatchQueryForCreation(oldValue, newValue);
    return filterDocuments(query, documents, List.of());
}
Also used : Query(io.lumeer.api.model.Query) SearchQuery(io.lumeer.storage.api.query.SearchQuery) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document)

Example 23 with Query

use of io.lumeer.api.model.Query in project engine by Lumeer.

the class DocumentMatcher method filterForRemoval.

public Tuple<List<Document>, List<LinkInstance>> filterForRemoval() {
    final List<Document> documents = new ArrayList<>();
    documents.add(getOldDocument());
    final List<LinkInstance> links = getAllLinkInstances();
    documents.addAll(getLinkedDocuments(links));
    final Query query = queryProvider.getMatchQueryForRemoval(oldValue, newValue);
    return filterDocuments(query, documents, links);
}
Also used : Query(io.lumeer.api.model.Query) SearchQuery(io.lumeer.storage.api.query.SearchQuery) ArrayList(java.util.ArrayList) LinkInstance(io.lumeer.api.model.LinkInstance) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document)

Example 24 with Query

use of io.lumeer.api.model.Query in project engine by Lumeer.

the class ViewCreator method translateQuery.

private Query translateQuery(final Query query) {
    var newStems = new ArrayList<QueryStem>();
    query.getStems().forEach(stem -> {
        var collectionId = stem.getCollectionId() != null ? templateParser.getDict().getCollectionId(stem.getCollectionId()) : null;
        List<String> linkTypeIds = new ArrayList<>();
        var linkTypeIdsUsed = false;
        if (stem.getLinkTypeIds() != null) {
            linkTypeIdsUsed = true;
            stem.getLinkTypeIds().forEach(linkTypeId -> linkTypeIds.add(templateParser.getDict().getLinkTypeId(linkTypeId)));
        }
        Set<String> documentIds = new HashSet<>();
        var documentIdsUsed = false;
        if (stem.getDocumentIds() != null) {
            documentIdsUsed = true;
            stem.getDocumentIds().forEach(documentId -> documentIds.add(templateParser.getDict().getDocumentId(documentId)));
        }
        List<CollectionAttributeFilter> collectionAttributeFilters = new ArrayList<>();
        var filtersUsed = false;
        if (stem.getFilters() != null) {
            filtersUsed = true;
            stem.getFilters().forEach(filter -> collectionAttributeFilters.add(new CollectionAttributeFilter(templateParser.getDict().getCollectionId(filter.getCollectionId()), filter.getAttributeId(), filter.getCondition(), filter.getConditionValues())));
        }
        List<LinkAttributeFilter> linkAttributeFilters = new ArrayList<>();
        var linkFiltersUsed = false;
        if (stem.getCollectionId() != null) {
            linkFiltersUsed = true;
            stem.getLinkFilters().forEach(filter -> linkAttributeFilters.add(new LinkAttributeFilter(templateParser.getDict().getLinkTypeId(filter.getLinkTypeId()), filter.getAttributeId(), filter.getCondition(), filter.getConditionValues())));
        }
        newStems.add(new QueryStem(null, collectionId, linkTypeIdsUsed ? linkTypeIds : null, documentIdsUsed ? documentIds : null, filtersUsed ? collectionAttributeFilters : null, linkFiltersUsed ? linkAttributeFilters : null));
    });
    return new Query(newStems, query.getFulltexts(), query.getPage(), query.getPageSize());
}
Also used : CollectionAttributeFilter(io.lumeer.api.model.CollectionAttributeFilter) Query(io.lumeer.api.model.Query) LinkAttributeFilter(io.lumeer.api.model.LinkAttributeFilter) ArrayList(java.util.ArrayList) QueryStem(io.lumeer.api.model.QueryStem) HashSet(java.util.HashSet)

Example 25 with Query

use of io.lumeer.api.model.Query in project engine by Lumeer.

the class ZapierFacade method updateDocument.

public List<DataDocument> updateDocument(final String collectionId, final String key, final Map<String, Object> data) {
    final List<DataDocument> results = new ArrayList<>();
    final Collection collection = collectionFacade.getCollection(collectionId);
    List<Document> documents;
    if (key.equals("_id")) {
        if (data != null && data.containsKey("_id")) {
            documents = List.of(documentFacade.getDocument(collectionId, data.get("_id").toString()));
        } else {
            return List.of();
        }
    } else {
        documents = searchFacade.searchDocuments(new Query(new QueryStem(null, collectionId, null, null, Collections.singletonList(CollectionAttributeFilter.createFromValues(collectionId, key, ConditionType.EQUALS, data.get(key))), null)), true);
    }
    documents.forEach(document -> {
        results.add(translateAttributes(collection, addMissingAttributes(documentFacade.patchDocumentData(collectionId, document.getId(), new DataDocument(data)).getData(), collection)));
    });
    return results;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Query(io.lumeer.api.model.Query) ArrayList(java.util.ArrayList) Collection(io.lumeer.api.model.Collection) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) QueryStem(io.lumeer.api.model.QueryStem)

Aggregations

Query (io.lumeer.api.model.Query)43 Document (io.lumeer.api.model.Document)28 Test (org.junit.Test)26 DataDocument (io.lumeer.engine.api.data.DataDocument)24 QueryStem (io.lumeer.api.model.QueryStem)22 Collection (io.lumeer.api.model.Collection)15 Attribute (io.lumeer.api.model.Attribute)14 Constraint (io.lumeer.api.model.Constraint)10 LinkInstance (io.lumeer.api.model.LinkInstance)10 Role (io.lumeer.api.model.Role)10 LinkType (io.lumeer.api.model.LinkType)9 View (io.lumeer.api.model.View)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 Permission (io.lumeer.api.model.Permission)7 Permissions (io.lumeer.api.model.Permissions)7 List (java.util.List)7 Project (io.lumeer.api.model.Project)6 User (io.lumeer.api.model.User)6 CollectionAttributeFilter (io.lumeer.api.model.CollectionAttributeFilter)5