Search in sources :

Example 1 with QueryStem

use of io.lumeer.api.model.QueryStem 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 QueryStem

use of io.lumeer.api.model.QueryStem 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 QueryStem

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

the class SearchFacadeIT method testChildDocuments.

@Test
public void testChildDocuments() {
    final Document a0 = createDocument(collectionIds.get(0), "a0");
    final Document b1 = createDocument(collectionIds.get(0), "b1", a0.getId());
    final Document b2 = createDocument(collectionIds.get(0), "b2", a0.getId());
    createDocument(collectionIds.get(0), "c1", b1.getId());
    final Document c2 = createDocument(collectionIds.get(0), "c2", b1.getId());
    createDocument(collectionIds.get(0), "c3", b1.getId());
    createDocument(collectionIds.get(0), "d1", b2.getId());
    createDocument(collectionIds.get(0), "d2", b2.getId());
    createDocument(collectionIds.get(0), "d3", b2.getId());
    createDocument(collectionIds.get(0), "e1", c2.getId());
    createDocument(collectionIds.get(0), "e2", c2.getId());
    Query query = new Query(new QueryStem(null, collectionIds.get(0), Collections.emptyList(), Collections.singleton(a0.getId()), Collections.emptyList(), Collections.emptyList()));
    List<Document> documents = searchFacade.searchDocuments(query, true);
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(documents.stream().filter(d -> d.getMetaData() == null || d.getMetaData().get(Document.META_PARENT_ID) == null).count()).isEqualTo(1);
    assertions.assertThat(documents).hasSize(11);
    assertions.assertThat(documents.stream().map(d -> d.getData().getString(DOCUMENT_KEY)).collect(Collectors.toSet())).containsExactlyInAnyOrder("a0", "b1", "b2", "c1", "c2", "c3", "d1", "d2", "d3", "e1", "e2");
    assertions.assertAll();
    query = new Query(new QueryStem(null, collectionIds.get(0), Collections.emptyList(), Collections.singleton(b2.getId()), Collections.emptyList(), Collections.emptyList()));
    documents = searchFacade.searchDocuments(query, true);
    assertions = new SoftAssertions();
    assertions.assertThat(documents).hasSize(4);
    assertions.assertThat(documents.stream().map(d -> d.getData().getString(DOCUMENT_KEY)).collect(Collectors.toSet())).containsExactlyInAnyOrder("b2", "d1", "d2", "d3");
    assertions.assertAll();
    query = new Query(new QueryStem(null, collectionIds.get(0), Collections.emptyList(), Collections.singleton(b1.getId()), Collections.emptyList(), Collections.emptyList()));
    documents = searchFacade.searchDocuments(query, true);
    assertions = new SoftAssertions();
    assertions.assertThat(documents).hasSize(6);
    assertions.assertThat(documents.stream().map(d -> d.getData().getString(DOCUMENT_KEY)).collect(Collectors.toSet())).containsExactlyInAnyOrder("b1", "c1", "c2", "c3", "e1", "e2");
    assertions.assertAll();
}
Also used : Arrays(java.util.Arrays) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) LinkTypeDao(io.lumeer.storage.api.dao.LinkTypeDao) WorkspaceKeeper(io.lumeer.core.WorkspaceKeeper) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) QueryStem(io.lumeer.api.model.QueryStem) Map(java.util.Map) ConstraintManager(io.lumeer.core.constraint.ConstraintManager) Permission(io.lumeer.api.model.Permission) RoleType(io.lumeer.api.model.RoleType) DataDocument(io.lumeer.engine.api.data.DataDocument) ConditionValueType(io.lumeer.api.model.ConditionValueType) Document(io.lumeer.api.model.Document) Set(java.util.Set) PermissionsChecker(io.lumeer.core.auth.PermissionsChecker) Constraint(io.lumeer.api.model.Constraint) Collectors(java.util.stream.Collectors) LinkInstance(io.lumeer.api.model.LinkInstance) LinkType(io.lumeer.api.model.LinkType) DefaultConfigurationProducer(io.lumeer.core.facade.configuration.DefaultConfigurationProducer) List(java.util.List) Attribute(io.lumeer.api.model.Attribute) ConstraintType(io.lumeer.api.model.ConstraintType) CollectionAttributeFilter(io.lumeer.api.model.CollectionAttributeFilter) UserDao(io.lumeer.storage.api.dao.UserDao) SoftAssertions(org.assertj.core.api.SoftAssertions) RunWith(org.junit.runner.RunWith) CollectionPurpose(io.lumeer.api.model.CollectionPurpose) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) Language(io.lumeer.api.model.Language) Role(io.lumeer.api.model.Role) DataDao(io.lumeer.storage.api.dao.DataDao) Query(io.lumeer.api.model.Query) Organization(io.lumeer.api.model.Organization) Before(org.junit.Before) ConditionType(io.lumeer.api.model.ConditionType) DocumentDao(io.lumeer.storage.api.dao.DocumentDao) Permissions(io.lumeer.api.model.Permissions) Test(org.junit.Test) CollectionPurposeType(io.lumeer.api.model.CollectionPurposeType) Project(io.lumeer.api.model.Project) LinkInstanceDao(io.lumeer.storage.api.dao.LinkInstanceDao) IntegrationTestBase(io.lumeer.engine.IntegrationTestBase) LinkDataDao(io.lumeer.storage.api.dao.LinkDataDao) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Query(io.lumeer.api.model.Query) SoftAssertions(org.assertj.core.api.SoftAssertions) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) QueryStem(io.lumeer.api.model.QueryStem) Test(org.junit.Test)

Example 4 with QueryStem

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

the class SearchFacadeIT method testSearchDocumentsByFiltersAndFulltexts.

@Test
public void testSearchDocumentsByFiltersAndFulltexts() {
    createDocument(collectionIds.get(0), "word");
    String id2 = createDocument(collectionIds.get(0), "lmr").getId();
    String id3 = createDocument(collectionIds.get(0), "wlmrd").getId();
    String id4 = createDocument(collectionIds.get(0), "lalamr").getId();
    createDocument(collectionIds.get(1), "something fulltext");
    String id6 = createDocument(collectionIds.get(1), "lmr").getId();
    String id7 = createDocument(collectionIds.get(1), "other lmr").getId();
    String id8 = createDocument(collectionIds.get(2), "full wordmr").getId();
    Query query = new Query(Collections.emptyList(), new HashSet<>(Collections.singletonList("mr")), null, null);
    List<Document> documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id2, id3, id4, id6, id7, id8);
    List<CollectionAttributeFilter> filters = Collections.singletonList(CollectionAttributeFilter.createFromValues(collectionIds.get(0), DOCUMENT_KEY, ConditionType.EQUALS, "lmr"));
    QueryStem stem = new QueryStem(null, collectionIds.get(0), Collections.emptyList(), Collections.emptySet(), filters, Collections.emptyList());
    query = new Query(Collections.singletonList(stem), new HashSet<>(Collections.singletonList("mr")), null, null);
    documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id2);
    filters = Arrays.asList(CollectionAttributeFilter.createFromValues(collectionIds.get(0), DOCUMENT_KEY, ConditionType.EQUALS, "lmr"), CollectionAttributeFilter.createFromValues(collectionIds.get(1), DOCUMENT_KEY, ConditionType.EQUALS, "other lmr"));
    List<QueryStem> stems = Arrays.asList(new QueryStem(null, collectionIds.get(0), Collections.emptyList(), Collections.emptySet(), filters, Collections.emptyList()), new QueryStem(null, collectionIds.get(1), Collections.emptyList(), Collections.emptySet(), filters, Collections.emptyList()));
    query = new Query(stems, new HashSet<>(Collections.singletonList("mr")), null, null);
    documents = searchFacade.searchDocuments(query, true);
    assertThat(documents).extracting(Document::getId).containsOnly(id2, id7);
}
Also used : Query(io.lumeer.api.model.Query) CollectionAttributeFilter(io.lumeer.api.model.CollectionAttributeFilter) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) QueryStem(io.lumeer.api.model.QueryStem) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with QueryStem

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

the class ViewFacadeIT method configureProject.

@Before
public void configureProject() {
    User user = new User(USER);
    this.user = userDao.createUser(user);
    Organization organization = new Organization();
    organization.setCode(ORGANIZATION_CODE);
    organization.setPermissions(new Permissions());
    Organization storedOrganization = organizationDao.createOrganization(organization);
    projectDao.setOrganization(storedOrganization);
    groupDao.setOrganization(storedOrganization);
    group = groupDao.createGroup(new Group(GROUP, Collections.singletonList(user.getId())));
    user.setOrganizations(Collections.singleton(storedOrganization.getId()));
    this.user = userDao.updateUser(user.getId(), user);
    Permissions organizationPermissions = new Permissions();
    Permission userPermission = Permission.buildWithRoles(this.user.getId(), Set.of(new Role(RoleType.Read)));
    organizationPermissions.updateUserPermissions(userPermission);
    storedOrganization.setPermissions(organizationPermissions);
    this.organization = organizationDao.updateOrganization(storedOrganization.getId(), storedOrganization);
    this.userPermission = Permission.buildWithRoles(this.user.getId(), Set.of(new Role(RoleType.Read)));
    this.groupPermission = Permission.buildWithRoles(this.group.getId(), Set.of(new Role(RoleType.Read)));
    Project project = new Project();
    project.setCode(PROJECT_CODE);
    project.setPermissions(new Permissions());
    Project storedProject = projectDao.createProject(project);
    workspaceKeeper.setWorkspaceIds(storedOrganization.getId(), storedProject.getId());
    Permissions projectPermissions = new Permissions();
    Permission userProjectPermission = Permission.buildWithRoles(this.user.getId(), Set.of(new Role(RoleType.Read), new Role(RoleType.ViewContribute), new Role(RoleType.CollectionContribute)));
    projectPermissions.updateUserPermissions(userProjectPermission);
    storedProject.setPermissions(projectPermissions);
    this.project = projectDao.updateProject(storedProject.getId(), storedProject);
    viewDao.setProject(this.project);
    Collection collection = collectionFacade.createCollection(new Collection("abc", "abc random", ICON, COLOR, projectPermissions));
    collectionFacade.updateUserPermissions(collection.getId(), Set.of(Permission.buildWithRoles(this.user.getId(), Collections.singleton(new Role(RoleType.Read)))));
    query = new Query(new QueryStem(collection.getId()));
    PermissionCheckerUtil.allowGroups();
    permissionsChecker.getPermissionAdapter().invalidateUserCache();
}
Also used : Role(io.lumeer.api.model.Role) Group(io.lumeer.api.model.Group) Project(io.lumeer.api.model.Project) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) Organization(io.lumeer.api.model.Organization) Query(io.lumeer.api.model.Query) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) Permissions(io.lumeer.api.model.Permissions) Permission(io.lumeer.api.model.Permission) Collection(io.lumeer.api.model.Collection) QueryStem(io.lumeer.api.model.QueryStem) Before(org.junit.Before)

Aggregations

Query (io.lumeer.api.model.Query)22 QueryStem (io.lumeer.api.model.QueryStem)22 Test (org.junit.Test)14 Collection (io.lumeer.api.model.Collection)8 Document (io.lumeer.api.model.Document)8 Role (io.lumeer.api.model.Role)8 DataDocument (io.lumeer.engine.api.data.DataDocument)8 Permission (io.lumeer.api.model.Permission)7 Permissions (io.lumeer.api.model.Permissions)7 Project (io.lumeer.api.model.Project)6 View (io.lumeer.api.model.View)6 ArrayList (java.util.ArrayList)6 CollectionAttributeFilter (io.lumeer.api.model.CollectionAttributeFilter)5 LinkInstance (io.lumeer.api.model.LinkInstance)5 LinkType (io.lumeer.api.model.LinkType)5 Organization (io.lumeer.api.model.Organization)5 User (io.lumeer.api.model.User)5 AuthenticatedUser (io.lumeer.core.auth.AuthenticatedUser)5 Before (org.junit.Before)5 LumeerAssertions.assertPermissions (io.lumeer.test.util.LumeerAssertions.assertPermissions)4