use of io.lumeer.api.model.Query in project engine by Lumeer.
the class LumeerBridge method removeDocumentsInView.
@SuppressWarnings("unused")
public void removeDocumentsInView(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());
documents.stream().filter(d -> task.getDaoContextSnapshot().increaseDeletionCounter() <= Task.MAX_CREATED_AND_DELETED_DOCUMENTS_AND_LINKS).forEach(d -> operations.add(new DocumentRemovalOperation(d)));
} catch (Exception e) {
cause = e;
throw e;
}
}
use of io.lumeer.api.model.Query in project engine by Lumeer.
the class DocumentMatcher method filterForCreation.
public Tuple<List<Document>, List<LinkInstance>> filterForCreation() {
final List<Document> documents = loadDataAndDecode(dao.getDocumentDao().getDocumentsByCollection(thatCollection.getId()));
final Query query = queryProvider.getMatchQueryForCreation(oldValue, newValue);
return filterDocuments(query, documents, List.of());
}
use of io.lumeer.api.model.Query in project engine by Lumeer.
the class DocumentMatcher method filterForRemoval.
public Tuple<List<Document>, List<LinkInstance>> filterForRemoval() {
final List<Document> documents = new ArrayList<>();
documents.add(getOldDocument());
final List<LinkInstance> links = getAllLinkInstances();
documents.addAll(getLinkedDocuments(links));
final Query query = queryProvider.getMatchQueryForRemoval(oldValue, newValue);
return filterDocuments(query, documents, links);
}
use of io.lumeer.api.model.Query 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());
}
use of io.lumeer.api.model.Query in project engine by Lumeer.
the class ZapierFacade method updateDocument.
public List<DataDocument> updateDocument(final String collectionId, final String key, final Map<String, Object> data) {
final List<DataDocument> results = new ArrayList<>();
final Collection collection = collectionFacade.getCollection(collectionId);
List<Document> documents;
if (key.equals("_id")) {
if (data != null && data.containsKey("_id")) {
documents = List.of(documentFacade.getDocument(collectionId, data.get("_id").toString()));
} else {
return List.of();
}
} else {
documents = searchFacade.searchDocuments(new Query(new QueryStem(null, collectionId, null, null, Collections.singletonList(CollectionAttributeFilter.createFromValues(collectionId, key, ConditionType.EQUALS, data.get(key))), null)), true);
}
documents.forEach(document -> {
results.add(translateAttributes(collection, addMissingAttributes(documentFacade.patchDocumentData(collectionId, document.getId(), new DataDocument(data)).getData(), collection)));
});
return results;
}
Aggregations