Search in sources :

Example 1 with Query

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

the class DelayedActionProcessor method processData.

// format due date to string according to attribute constraint format and user language
private Map<String, Object> processData(final DataDocument originalData, final Language language, final User receiverUser) {
    final Map<String, Object> data = new HashMap<>(originalData);
    if (originalData.getDate(DelayedAction.DATA_TASK_DUE_DATE) != null) {
        String format = translationManager.getDefaultDateFormat(language);
        if (StringUtils.isNotEmpty(originalData.getString(DelayedAction.DATA_DUE_DATE_FORMAT))) {
            format = originalData.getString(DelayedAction.DATA_DUE_DATE_FORMAT);
        }
        // we get the date in UTC and need to convert it to user's time zone, however, we send the date for parsing as an instant
        // instant is without a timezone, so we need to get epoch milli, as we were in UTC
        ZonedDateTime dueDate = ZonedDateTime.ofInstant(originalData.getDate(DelayedAction.DATA_TASK_DUE_DATE).toInstant(), ZoneOffset.UTC);
        if (receiverUser != null && StringUtils.isNotEmpty(receiverUser.getTimeZone())) {
            dueDate = dueDate.withZoneSameInstant(TimeZone.getTimeZone(receiverUser.getTimeZone()).toZoneId()).withZoneSameLocal(ZoneOffset.UTC);
        }
        data.put(DelayedAction.DATA_TASK_DUE_DATE, JsFunctionsParser.formatMomentJsDate(// originalData.getDate(DelayedAction.DATA_TASK_DUE_DATE).getTime(),
        dueDate.toInstant().toEpochMilli(), format, language.toString().toLowerCase(), false));
    }
    final String query = new Query(List.of(new QueryStem(originalData.getString(DelayedAction.DATA_COLLECTION_ID))), null, null, null).toQueryString();
    data.put(DelayedAction.DATA_COLLECTION_QUERY, Utils.encodeQueryParam(query));
    final String cursor = new ViewCursor(originalData.getString(DelayedAction.DATA_COLLECTION_ID), null, originalData.getString(DelayedAction.DATA_DOCUMENT_ID), null, originalData.getString(DelayedAction.DATA_TASK_NAME_ATTRIBUTE), true).toQueryString();
    data.put(DelayedAction.DATA_DOCUMENT_CURSOR, Utils.encodeQueryParam(cursor));
    data.remove(DelayedAction.DATA_ORIGINAL_ACTION_IDS);
    data.remove(DelayedAction.DATA_ORIGINAL_ACTION_TYPES);
    return data;
}
Also used : Query(io.lumeer.api.model.Query) HashMap(java.util.HashMap) ZonedDateTime(java.time.ZonedDateTime) QueryStem(io.lumeer.api.model.QueryStem) ViewCursor(io.lumeer.api.model.ViewCursor)

Example 2 with Query

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

the class PusherAdapterIT method viewLinkTypesLostOrGainedTest.

@Test
public void viewLinkTypesLostOrGainedTest() {
    String aCollection = createCollection("A", EMPTY_ROLES, EMPTY_ROLES).getId();
    String bCollection = createCollection("B", READ_ROLES, EMPTY_ROLES).getId();
    String cCollection = createCollection("C", READ_ROLES, EMPTY_ROLES).getId();
    String aLinkType = createLinkType("A", Arrays.asList(aCollection, bCollection), EMPTY_ROLES, EMPTY_ROLES).getId();
    String bLinkType = createLinkType("B", Arrays.asList(bCollection, cCollection), EMPTY_ROLES, READ_ROLES).getId();
    View view = createView("V1", new Query(Arrays.asList(new QueryStem(aCollection, Collections.singletonList(aLinkType)), new QueryStem(bCollection, Collections.singletonList(bLinkType)))), EMPTY_ROLES, EMPTY_ROLES);
    View viewWithUser = updateViewRoles(view.getId(), READ_ROLES, EMPTY_ROLES);
    View viewWithGroup = updateViewRoles(view.getId(), EMPTY_ROLES, READ_ROLES);
    // check gained by user roles
    List<Event> events = pusherAdapter.checkViewPermissionsChange(organization, project, otherUser, view, viewWithUser);
    assertThat(events).hasSize(2);
    assertThat(events).extracting("name").containsOnly("Collection:update", "LinkType:update");
    assertThat(events).extracting("data").extracting("object").extracting("id").containsOnly(aCollection, aLinkType);
    // check gained by group roles
    events = pusherAdapter.checkViewPermissionsChange(organization, project, otherUser, view, viewWithGroup);
    assertThat(events).hasSize(2);
    assertThat(events).extracting("name").containsOnly("Collection:update", "LinkType:update");
    assertThat(events).extracting("data").extracting("object").extracting("id").containsOnly(aCollection, aLinkType);
    // check lost by user roles
    events = pusherAdapter.checkViewPermissionsChange(organization, project, otherUser, viewWithUser, view);
    assertThat(events).hasSize(3);
    assertThat(events).extracting("name").containsOnly("View:remove", "Collection:remove", "LinkType:remove");
    assertThat(events).extracting("data").extracting("id").containsOnly(view.getId(), aCollection, aLinkType);
    // check lost by group roles
    events = pusherAdapter.checkViewPermissionsChange(organization, project, otherUser, viewWithGroup, view);
    assertThat(events).hasSize(3);
    assertThat(events).extracting("name").containsOnly("View:remove", "Collection:remove", "LinkType:remove");
    assertThat(events).extracting("data").extracting("id").containsOnly(view.getId(), aCollection, aLinkType);
}
Also used : Query(io.lumeer.api.model.Query) Event(org.marvec.pusher.data.Event) View(io.lumeer.api.model.View) QueryStem(io.lumeer.api.model.QueryStem) Test(org.junit.Test)

Example 3 with Query

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

the class SearchFacadeIT method testSearchMultiSelectConstraint.

@Test
public void testSearchMultiSelectConstraint() {
    var options = Arrays.asList(new DataDocument("option", "a"), new DataDocument("option", "b"), new DataDocument("option", "c"), new DataDocument("option", "d"));
    Constraint constraint = new Constraint(ConstraintType.Select, new DataDocument("multi", true).append("options", options));
    Attribute attribute = new Attribute(DOCUMENT_KEY, DOCUMENT_KEY, null, constraint, null, null, 3, null);
    String collectionId = createCollection("selectCollection", attribute).getId();
    String id1 = createDocument(collectionId, Arrays.asList("a", "b", "c")).getId();
    String id2 = createDocument(collectionId, Arrays.asList("a", "b")).getId();
    String id3 = createDocument(collectionId, Arrays.asList("a", "c")).getId();
    String id4 = createDocument(collectionId, Arrays.asList("c", "x")).getId();
    String id5 = createDocument(collectionId, Collections.singletonList("d")).getId();
    Query query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.IN, Arrays.asList("a", "b")));
    List<Document> documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id2);
    query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.HAS_SOME, Arrays.asList("a", "c")));
    documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id3, id4);
    query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.HAS_ALL, Arrays.asList("a", "b")));
    documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id2);
    query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.HAS_NONE_OF, Arrays.asList("a", "b")));
    documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id4, id5);
    query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.NOT_EMPTY));
    documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id3, id4, id5);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Query(io.lumeer.api.model.Query) Constraint(io.lumeer.api.model.Constraint) Attribute(io.lumeer.api.model.Attribute) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 4 with Query

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

the class SearchFacadeIT method testUserConstraint.

@Test
public void testUserConstraint() {
    Constraint constraint = new Constraint(ConstraintType.User, new DataDocument("multi", true));
    Attribute attribute = new Attribute(DOCUMENT_KEY, DOCUMENT_KEY, null, constraint, null, null, 3, null);
    String collectionId = createCollection("userCollection", attribute).getId();
    String id1 = createDocument(collectionId, Collections.singletonList(USER)).getId();
    String id2 = createDocument(collectionId, Arrays.asList(USER1, USER2)).getId();
    String id3 = createDocument(collectionId, Arrays.asList(USER, USER1)).getId();
    String id4 = createDocument(collectionId, Collections.singletonList(USER1)).getId();
    Query query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromTypes(collectionId, DOCUMENT_KEY, ConditionType.HAS_SOME, ConditionValueType.CURRENT_USER.getValue()));
    List<Document> documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id3);
    query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.HAS_NONE_OF, USER2));
    documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id3, id4);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Query(io.lumeer.api.model.Query) Constraint(io.lumeer.api.model.Constraint) Attribute(io.lumeer.api.model.Attribute) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 5 with Query

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

the class SearchFacadeIT method testSearchTasksAndContributors.

@Test
public void testSearchTasksAndContributors() {
    Collection taskCollection = createTaskCollectionWithAttributes("taskCollection");
    Attribute stateAttribute = taskCollection.getAttributes().stream().filter(a -> a.getId().equals("a1")).findFirst().get();
    Attribute assigneeAttribute = taskCollection.getAttributes().stream().filter(a -> a.getId().equals("a2")).findFirst().get();
    String id1 = createDocumentWithOtherUser(taskCollection.getId(), Map.of(stateAttribute.getId(), "a", assigneeAttribute.getId(), USER)).getId();
    String id2 = createDocumentWithOtherUser(taskCollection.getId(), Collections.singletonMap(stateAttribute.getId(), "b")).getId();
    String id3 = createDocument(taskCollection.getId(), Collections.singletonMap(stateAttribute.getId(), "c")).getId();
    String id4 = createDocument(taskCollection.getId(), Collections.singletonMap(stateAttribute.getId(), "d")).getId();
    String id5 = createDocumentWithOtherUser(taskCollection.getId(), Map.of(stateAttribute.getId(), Arrays.asList("a", "b"), assigneeAttribute.getId(), USER)).getId();
    String id6 = createDocument(taskCollection.getId(), Collections.singletonMap(stateAttribute.getId(), Arrays.asList("b", "c"))).getId();
    String id7 = createDocumentWithOtherUser(taskCollection.getId(), Collections.singletonMap(stateAttribute.getId(), Arrays.asList("c", "d"))).getId();
    String id8 = createDocument(taskCollection.getId(), Collections.singletonMap(stateAttribute.getId(), Arrays.asList("d", "a"))).getId();
    setCollectionUserRoles(taskCollection, Set.of(new Role(RoleType.Read)));
    Query query = new Query();
    List<Document> documents = searchFacade.searchDocumentsAndLinks(query, true).getFirst();
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id5);
    setCollectionUserRoles(taskCollection, Set.of(new Role(RoleType.Read), new Role(RoleType.DataContribute)));
    documents = searchFacade.searchDocumentsAndLinks(query, true).getFirst();
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id3, id4, id5, id6, id8);
    setCollectionUserRoles(taskCollection, Set.of(new Role(RoleType.Read), new Role(RoleType.DataRead)));
    documents = searchFacade.searchDocumentsAndLinks(query, true).getFirst();
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id3, id4, id5, id6, id7, id8);
    setCollectionUserRoles(taskCollection, Set.of(new Role(RoleType.Read), new Role(RoleType.DataContribute)));
    query = createSimpleQueryWithAttributeFilter(taskCollection.getId(), CollectionAttributeFilter.createFromValues(taskCollection.getId(), stateAttribute.getId(), ConditionType.HAS_SOME, Arrays.asList("a", "b")));
    documents = searchFacade.searchDocumentsAndLinks(query, true).getFirst();
    assertThat(documents).extracting(Document::getId).containsOnly(id1, id5, id6, id8);
}
Also used : Role(io.lumeer.api.model.Role) Query(io.lumeer.api.model.Query) Attribute(io.lumeer.api.model.Attribute) Collection(io.lumeer.api.model.Collection) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

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