Search in sources :

Example 26 with Query

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

the class LumeerBridge method readView.

@SuppressWarnings("unused")
public List<DocumentBridge> readView(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());
        return documents.stream().map(DocumentBridge::new).collect(toList());
    } catch (Exception e) {
        cause = e;
        throw e;
    }
}
Also used : AllowedPermissions(io.lumeer.api.model.AllowedPermissions) 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) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) View(io.lumeer.api.model.View) IOException(java.io.IOException)

Example 27 with Query

use of io.lumeer.api.model.Query 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 28 with Query

use of io.lumeer.api.model.Query 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 29 with Query

use of io.lumeer.api.model.Query 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 30 with Query

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

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