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;
}
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);
}
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();
}
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);
}
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();
}
Aggregations