use of io.lumeer.api.model.CollectionAttributeFilter in project engine by Lumeer.
the class CollectionAttributeFilterCodec method convertFromDocument.
public static CollectionAttributeFilter convertFromDocument(final Document document) {
String collectionId = document.getString(COLLECTION_ID);
AttributeFilter filter = AttributeFilterCodec.convertFromDocument(document);
return new CollectionAttributeFilter(collectionId, filter.getAttributeId(), filter.getCondition(), filter.getConditionValues());
}
use of io.lumeer.api.model.CollectionAttributeFilter 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.CollectionAttributeFilter in project engine by Lumeer.
the class SearchFacade method modifyQueryForTasks.
private Query modifyQueryForTasks(boolean isPublic, final Query query, final List<Collection> collections) {
if (isPublic || !query.isEmpty()) {
return query;
}
final List<QueryStem> stems = collections.stream().map(collection -> {
final String assigneeAttributeId = collection.getPurpose().getAssigneeAttributeId();
final Attribute assigneeAttribute = ResourceUtils.findAttribute(collection.getAttributes(), assigneeAttributeId);
if (assigneeAttribute != null) {
final CollectionAttributeFilter filter = CollectionAttributeFilter.createFromTypes(collection.getId(), assigneeAttribute.getId(), ConditionType.HAS_SOME, ConditionValueType.CURRENT_USER.getValue());
return new QueryStem(null, collection.getId(), Collections.emptyList(), Collections.emptySet(), Collections.singletonList(filter), Collections.emptyList());
}
if (permissionsChecker.hasAnyRole(collection, Set.of(RoleType.DataRead, RoleType.DataContribute))) {
return new QueryStem(null, collection.getId(), Collections.emptyList(), Collections.emptySet(), Collections.emptyList(), Collections.emptyList());
}
return null;
}).filter(Objects::nonNull).collect(Collectors.toList());
return stems.isEmpty() ? null : new Query(stems);
}
use of io.lumeer.api.model.CollectionAttributeFilter in project engine by Lumeer.
the class ViewCreator method translateQuery.
private Query translateQuery(final Query query) {
var newStems = new ArrayList<QueryStem>();
query.getStems().forEach(stem -> {
var collectionId = stem.getCollectionId() != null ? templateParser.getDict().getCollectionId(stem.getCollectionId()) : null;
List<String> linkTypeIds = new ArrayList<>();
var linkTypeIdsUsed = false;
if (stem.getLinkTypeIds() != null) {
linkTypeIdsUsed = true;
stem.getLinkTypeIds().forEach(linkTypeId -> linkTypeIds.add(templateParser.getDict().getLinkTypeId(linkTypeId)));
}
Set<String> documentIds = new HashSet<>();
var documentIdsUsed = false;
if (stem.getDocumentIds() != null) {
documentIdsUsed = true;
stem.getDocumentIds().forEach(documentId -> documentIds.add(templateParser.getDict().getDocumentId(documentId)));
}
List<CollectionAttributeFilter> collectionAttributeFilters = new ArrayList<>();
var filtersUsed = false;
if (stem.getFilters() != null) {
filtersUsed = true;
stem.getFilters().forEach(filter -> collectionAttributeFilters.add(new CollectionAttributeFilter(templateParser.getDict().getCollectionId(filter.getCollectionId()), filter.getAttributeId(), filter.getCondition(), filter.getConditionValues())));
}
List<LinkAttributeFilter> linkAttributeFilters = new ArrayList<>();
var linkFiltersUsed = false;
if (stem.getCollectionId() != null) {
linkFiltersUsed = true;
stem.getLinkFilters().forEach(filter -> linkAttributeFilters.add(new LinkAttributeFilter(templateParser.getDict().getLinkTypeId(filter.getLinkTypeId()), filter.getAttributeId(), filter.getCondition(), filter.getConditionValues())));
}
newStems.add(new QueryStem(null, collectionId, linkTypeIdsUsed ? linkTypeIds : null, documentIdsUsed ? documentIds : null, filtersUsed ? collectionAttributeFilters : null, linkFiltersUsed ? linkAttributeFilters : null));
});
return new Query(newStems, query.getFulltexts(), query.getPage(), query.getPageSize());
}
Aggregations