Search in sources :

Example 11 with QueryStem

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

the class PusherAdapterIT method viewCollectionsLostOrGainedTest.

@Test
public void viewCollectionsLostOrGainedTest() {
    String aCollection = createCollection("A", EMPTY_ROLES, EMPTY_ROLES).getId();
    String bCollection = createCollection("B", EMPTY_ROLES, EMPTY_ROLES).getId();
    String cCollection = createCollection("C", EMPTY_ROLES, EMPTY_ROLES).getId();
    View view = createView("V1", new Query(Arrays.asList(new QueryStem(aCollection), new QueryStem(bCollection), new QueryStem(cCollection))), 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(3);
    assertThat(events).extracting("name").containsOnly("Collection:update");
    assertThat(events).extracting("data").extracting("object").extracting("id").containsOnly(aCollection, bCollection, cCollection);
    // check gained by group roles
    events = pusherAdapter.checkViewPermissionsChange(organization, project, otherUser, view, viewWithGroup);
    assertThat(events).hasSize(3);
    assertThat(events).extracting("name").containsOnly("Collection:update");
    assertThat(events).extracting("data").extracting("object").extracting("id").containsOnly(aCollection, bCollection, cCollection);
    // check lost by user roles
    events = pusherAdapter.checkViewPermissionsChange(organization, project, otherUser, viewWithUser, view);
    assertThat(events).hasSize(4);
    assertThat(events).extracting("name").containsOnly("View:remove", "Collection:remove");
    assertThat(events).extracting("data").extracting("id").containsOnly(view.getId(), aCollection, bCollection, cCollection);
    // check lost by group roles
    events = pusherAdapter.checkViewPermissionsChange(organization, project, otherUser, viewWithGroup, view);
    assertThat(events).hasSize(4);
    assertThat(events).extracting("name").containsOnly("View:remove", "Collection:remove");
    assertThat(events).extracting("data").extracting("id").containsOnly(view.getId(), aCollection, bCollection, cCollection);
}
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 12 with QueryStem

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

the class CopyFacadeIT method testTemplateImportLocal.

@Test
@SuppressWarnings("unchecked")
public void testTemplateImportLocal() {
    assertThatThrownBy(() -> templateFacade.installTemplate(project, organization.getId(), TEMPLATE, Language.EN)).isInstanceOf(NoResourcePermissionException.class);
    setProjectUserRoles(Set.of(new Role(RoleType.Read), new Role(RoleType.CollectionContribute), new Role(RoleType.ViewContribute), new Role(RoleType.LinkContribute), new Role(RoleType.TechConfig)));
    templateFacade.installTemplate(project, organization.getId(), TEMPLATE, Language.EN);
    var collections = collectionFacade.getCollections();
    assertThat(collections).hasSize(4);
    var objectivesCollection = collections.stream().filter(collection -> collection.getName().equals("Objectives")).findFirst().orElse(null);
    assertThat(objectivesCollection).isNotNull();
    assertThat(objectivesCollection.getIcon()).isEqualTo("fas fa-crosshairs");
    assertThat(objectivesCollection.getColor()).isEqualTo("#cc0000");
    assertThat(objectivesCollection.getAttributes()).hasSize(3);
    assertThat(objectivesCollection.getDefaultAttributeId()).isEqualTo("a1");
    var a3 = getAttribute(objectivesCollection.getAttributes(), "a3");
    assertThat(a3).isNotNull();
    assertThat(a3.getName()).isEqualTo("Progress");
    assertThat(a3.getConstraint().getType()).isEqualTo(ConstraintType.Percentage);
    assertThat(a3.getConstraint().getConfig()).isInstanceOf(org.bson.Document.class);
    assertThat(((org.bson.Document) a3.getConstraint().getConfig()).getLong("decimals")).isEqualTo(0L);
    assertThat(a3.getFunction()).isNotNull();
    var linkTypes = linkTypeFacade.getLinkTypes();
    assertThat(linkTypes).hasSize(3);
    var objectiveKeyResultsLinkType = linkTypes.stream().filter(linkType -> linkType.getName().equals("Objectives Key Results")).findFirst().orElse(null);
    assertThat(objectiveKeyResultsLinkType).isNotNull();
    assertThat(a3.getFunction().getJs().indexOf("getLinkedDocuments(thisDocument, '" + objectiveKeyResultsLinkType.getId() + "')")).isGreaterThanOrEqualTo(0);
    var employeesCollection = collections.stream().filter(collection -> collection.getName().equals("Employees")).findFirst().orElse(null);
    assertThat(employeesCollection).isNotNull();
    var allEmployees = searchFacade.searchDocuments(new Query(new QueryStem(employeesCollection.getId())), true);
    // verify documents hierarchy
    var natosha = allEmployees.stream().filter(doc -> doc.getData().getString("a1").equals("Natosha")).findFirst().orElse(null);
    assertThat(natosha).isNotNull();
    var parent1 = natosha.getMetaData().getString(Document.META_PARENT_ID);
    assertThat(parent1).isNotNull();
    var jasmin = allEmployees.stream().filter(doc -> doc.getData().getId().equals(parent1)).findFirst().orElse(null);
    assertThat(jasmin).isNotNull();
    assertThat(jasmin.getData()).contains(Map.entry("a1", "Jasmin"));
    var parent2 = jasmin.getMetaData().getString(Document.META_PARENT_ID);
    assertThat(parent2).isNotNull();
    var marta = allEmployees.stream().filter(doc -> doc.getData().getId().equals(parent2)).findFirst().orElse(null);
    assertThat(marta).isNotNull();
    assertThat(marta.getData()).contains(Map.entry("a1", "Marta"));
    var parent3 = marta.getMetaData().getString(Document.META_PARENT_ID);
    assertThat(parent3).isNotNull();
    var macie = allEmployees.stream().filter(doc -> doc.getData().getId().equals(parent3)).findFirst().orElse(null);
    assertThat(macie).isNotNull();
    assertThat(macie.getData()).contains(Map.entry("a1", "Macie"));
    var keyResultsCollection = collections.stream().filter(collection -> collection.getName().equals("Key Results")).findFirst().orElse(null);
    var initiativesCollection = collections.stream().filter(collection -> collection.getName().equals("Initiatives")).findFirst().orElse(null);
    assertThat(keyResultsCollection).isNotNull();
    assertThat(initiativesCollection).isNotNull();
    assertThat(objectiveKeyResultsLinkType.getCollectionIds()).containsExactly(objectivesCollection.getId(), keyResultsCollection.getId());
    var allKeyResults = searchFacade.searchDocuments(new Query(new QueryStem(keyResultsCollection.getId())), true);
    var allInitiatives = searchFacade.searchDocuments(new Query(new QueryStem(initiativesCollection.getId())), true);
    var conversionDoc = allKeyResults.stream().filter(doc -> doc.getData().getString("a1").equals("15% conversion")).findFirst().orElse(null);
    var abTestingDoc = allInitiatives.stream().filter(doc -> doc.getData().getString("a1").equals("A/B testing the CTA")).findFirst().orElse(null);
    assertThat(conversionDoc).isNotNull();
    assertThat(abTestingDoc).isNotNull();
    var keyResultsInitiativesLinkType = linkTypes.stream().filter(linkType -> linkType.getName().equals("Key Results Initiatives")).findFirst().orElse(null);
    assertThat(keyResultsInitiativesLinkType).isNotNull();
    var links = searchFacade.searchLinkInstances(new Query(new QueryStem(null, keyResultsCollection.getId(), List.of(keyResultsInitiativesLinkType.getId()), Set.of(conversionDoc.getId()), Collections.emptyList(), Collections.emptyList())), true);
    assertThat(links).isNotNull();
    var allDocuments = searchFacade.searchDocuments(new Query(), true);
    assertThat(allDocuments).hasSize(78);
    var views = viewFacade.getViews();
    assertThat(views).hasSize(6);
    var okrInitiatives = views.stream().filter(view -> view.getName().equals("OKR Initiatives")).findFirst().orElse(null);
    assertThat(okrInitiatives).isNotNull();
    org.bson.Document config = (org.bson.Document) okrInitiatives.getConfig();
    assertThat(config.containsKey("table")).isTrue();
    var table = (org.bson.Document) config.get("table");
    assertThat(table.containsKey("parts"));
    var parts = (List<org.bson.Document>) table.get("parts");
    var collectionConfig = parts.stream().filter(doc -> doc.containsKey("collectionId") && doc.getString("collectionId").equals(keyResultsCollection.getId())).findFirst().orElse(null);
    assertThat(collectionConfig).isNotNull();
    var columns = (List<org.bson.Document>) collectionConfig.get("columns");
    assertThat(columns).isNotNull();
    var hiddenPart = columns.stream().filter(doc -> doc.containsKey("type") && doc.getString("type").equals("hidden")).findFirst().orElse(null);
    assertThat(hiddenPart).isNotNull();
    assertThat(hiddenPart.containsKey("attributeIds")).isTrue();
    assertThat((List<String>) hiddenPart.get("attributeIds")).containsExactly("a3", "a4", "a5", "a2");
    assertThat(okrInitiatives.getQuery().getStems()).hasSize(1);
    assertThat(okrInitiatives.getQuery().getStems().get(0).getCollectionId()).isEqualTo(keyResultsCollection.getId());
}
Also used : Role(io.lumeer.api.model.Role) Query(io.lumeer.api.model.Query) List(java.util.List) Document(io.lumeer.api.model.Document) QueryStem(io.lumeer.api.model.QueryStem) Test(org.junit.Test)

Example 13 with QueryStem

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

the class LinkInstanceServiceIT method testGetLinkInstancesByDocumentIds.

@Test
public void testGetLinkInstancesByDocumentIds() {
    String id1 = createLinkInstance(linkTypeId1, documentIdsColl1.get(0), documentIdsColl2.get(0)).getId();
    String id2 = createLinkInstance(linkTypeId1, documentIdsColl1.get(0), documentIdsColl2.get(2)).getId();
    String id3 = createLinkInstance(linkTypeId1, documentIdsColl1.get(1), documentIdsColl2.get(1)).getId();
    String id4 = createLinkInstance(linkTypeId2, documentIdsColl1.get(0), documentIdsColl2.get(0)).getId();
    QueryStem stem = new QueryStem(null, collection1Id, Collections.singletonList(linkTypeId1), Collections.singleton(documentIdsColl1.get(0)), null, null);
    Query query = new Query(stem);
    Entity entity1 = Entity.json(query);
    Response response = client.target(searchUrl).path("linkInstances").request(MediaType.APPLICATION_JSON).buildPost(entity1).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<LinkInstance> linkInstances = response.readEntity(new GenericType<List<LinkInstance>>() {
    });
    assertThat(linkInstances).extracting("id").containsOnly(id1, id2);
    QueryStem stem2 = new QueryStem(null, collection2Id, Collections.singletonList(linkTypeId1), Collections.singleton(documentIdsColl2.get(1)), null, null);
    Query query2 = new Query(stem2);
    Entity entity2 = Entity.json(query2);
    response = client.target(searchUrl).path("linkInstances").request(MediaType.APPLICATION_JSON).buildPost(entity2).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    linkInstances = response.readEntity(new GenericType<List<LinkInstance>>() {
    });
    assertThat(linkInstances).extracting("id").containsOnly(id3);
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) GenericType(javax.ws.rs.core.GenericType) Query(io.lumeer.api.model.Query) ArrayList(java.util.ArrayList) List(java.util.List) LinkInstance(io.lumeer.api.model.LinkInstance) QueryStem(io.lumeer.api.model.QueryStem) Test(org.junit.Test)

Example 14 with QueryStem

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

the class LinkInstanceServiceIT method testGetLinkInstancesByLinkTypeIds.

@Test
public void testGetLinkInstancesByLinkTypeIds() {
    String id1 = createLinkInstance(linkTypeId1, documentIdsColl1.get(0), documentIdsColl2.get(0)).getId();
    String id2 = createLinkInstance(linkTypeId1, documentIdsColl1.get(0), documentIdsColl2.get(2)).getId();
    String id3 = createLinkInstance(linkTypeId1, documentIdsColl1.get(1), documentIdsColl2.get(1)).getId();
    String id4 = createLinkInstance(linkTypeId2, documentIdsColl1.get(0), documentIdsColl2.get(0)).getId();
    QueryStem stem = new QueryStem(null, collection1Id, Collections.singletonList(linkTypeId1), null, null, null);
    Query query = new Query(stem);
    Entity entity1 = Entity.json(query);
    Response response = client.target(searchUrl).path("linkInstances").request(MediaType.APPLICATION_JSON).buildPost(entity1).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<LinkInstance> linkInstances = response.readEntity(new GenericType<List<LinkInstance>>() {
    });
    assertThat(linkInstances).extracting("id").containsOnly(id1, id2, id3);
    QueryStem stem2 = new QueryStem(null, collection1Id, Collections.singletonList(linkTypeId2), null, null, null);
    Query query2 = new Query(stem2);
    Entity entity2 = Entity.json(query2);
    response = client.target(searchUrl).path("linkInstances").request(MediaType.APPLICATION_JSON).buildPost(entity2).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    linkInstances = response.readEntity(new GenericType<List<LinkInstance>>() {
    });
    assertThat(linkInstances).extracting("id").containsOnly(id4);
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) GenericType(javax.ws.rs.core.GenericType) Query(io.lumeer.api.model.Query) ArrayList(java.util.ArrayList) List(java.util.List) LinkInstance(io.lumeer.api.model.LinkInstance) QueryStem(io.lumeer.api.model.QueryStem) Test(org.junit.Test)

Example 15 with QueryStem

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

the class LinkTypeServiceIT method configureLinkTypes.

@Before
public void configureLinkTypes() {
    User user = new User(USER);
    final User createdUser = userDao.createUser(user);
    Organization organization = new Organization();
    organization.setCode(ORGANIZATION_CODE);
    organization.setPermissions(new Permissions());
    Organization storedOrganization = organizationDao.createOrganization(organization);
    projectDao.setOrganization(storedOrganization);
    Permissions organizationPermissions = new Permissions();
    Permission userPermission = Permission.buildWithRoles(createdUser.getId(), Set.of(new Role(RoleType.Read)));
    organizationPermissions.updateUserPermissions(userPermission);
    storedOrganization.setPermissions(organizationPermissions);
    organizationDao.updateOrganization(storedOrganization.getId(), storedOrganization);
    Project project = new Project();
    project.setPermissions(new Permissions());
    project.setCode(PROJECT_CODE);
    Project storedProject = projectDao.createProject(project);
    Permissions projectPermissions = new Permissions();
    Permission userProjectPermission = Permission.buildWithRoles(createdUser.getId(), Set.of(new Role(RoleType.Read), new Role(RoleType.LinkContribute)));
    projectPermissions.updateUserPermissions(userProjectPermission);
    storedProject.setPermissions(projectPermissions);
    storedProject = projectDao.updateProject(storedProject.getId(), storedProject);
    collectionDao.setProject(storedProject);
    linkTypeDao.setProject(storedProject);
    viewDao.setProject(storedProject);
    collectionIds.clear();
    Permissions userPermissions = new Permissions();
    userPermissions.updateUserPermissions(new Permission(createdUser.getId(), Project.ROLES));
    for (String name : COLLECTION_NAMES) {
        Collection collection = new Collection(name, name, COLLECTION_ICON, COLLECTION_COLOR, userPermissions);
        collectionIds.add(collectionDao.createCollection(collection).getId());
    }
    Collection collection = new Collection("noPerm", "noPerm", COLLECTION_ICON, COLLECTION_COLOR, new Permissions());
    collectionIdNoPerm = collectionDao.createCollection(collection).getId();
    LinkType linkType = prepareLinkType();
    linkType.setCollectionIds(Arrays.asList(collectionIdNoPerm, collectionIds.get(1)));
    linkTypeIdFromView = linkTypeDao.createLinkType(linkType).getId();
    QueryStem stem = new QueryStem(null, collectionIdNoPerm, Collections.singletonList(linkTypeIdFromView), Collections.emptySet(), Collections.emptyList(), Collections.emptyList());
    Query query = new Query(stem);
    View view = new View("code", "name", "", "", "", null, userPermissions, query, Collections.emptyList(), Perspective.Kanban, "", null, createdUser.getId(), Collections.emptyList());
    viewDao.createView(view);
    linkTypesUrl = projectPath(storedOrganization, storedProject) + "link-types";
}
Also used : Role(io.lumeer.api.model.Role) 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) Permissions(io.lumeer.api.model.Permissions) Permission(io.lumeer.api.model.Permission) Collection(io.lumeer.api.model.Collection) LinkType(io.lumeer.api.model.LinkType) View(io.lumeer.api.model.View) 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