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