Search in sources :

Example 1 with ConstraintData

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

the class SearchFacade method searchDocumentsAndLinks.

private Tuple<List<Document>, List<LinkInstance>> searchDocumentsAndLinks(final Query query, boolean includeChildDocuments, boolean shouldCheckQuery, final Map<String, Collection> collectionsMap, final Map<String, LinkType> linkTypesMap, @Nullable final Function<Document, Boolean> documentFilter, boolean isPublic) {
    final Query encodedQuery = checkQuery(query, collectionsMap, linkTypesMap, shouldCheckQuery);
    final Set<Document> allDocuments = new HashSet<>();
    final Set<LinkInstance> allLinkInstances = new HashSet<>();
    if (encodedQuery.containsStems()) {
        ConstraintData constraintData = createConstraintData();
        encodedQuery.getStems().forEach(stem -> {
            var result = stem.containsAnyFilter() || encodedQuery.getFulltexts().size() > 0 ? searchDocumentsAndLinksInStem(stem, encodedQuery.getFulltexts(), collectionsMap, linkTypesMap, documentFilter, constraintData, includeChildDocuments) : searchDocumentsAndLinksInStemWithoutFilters(stem, collectionsMap, linkTypesMap, documentFilter, isPublic);
            allDocuments.addAll(result.getFirst());
            allLinkInstances.addAll(result.getSecond());
        });
    } else if (encodedQuery.getFulltexts().size() > 0) {
        var result = searchDocumentsAndLinksByFulltexts(encodedQuery.getFulltexts(), collectionsMap, linkTypesMap, documentFilter, createConstraintData(), includeChildDocuments);
        allDocuments.addAll(result.getFirst());
        allLinkInstances.addAll(result.getSecond());
    } else {
        var result = searchDocumentsAndLinksByEmptyQuery(collectionsMap, linkTypesMap, documentFilter, isPublic);
        allDocuments.addAll(result.getFirst());
        allLinkInstances.addAll(result.getSecond());
    }
    var mappedDocuments = documentAdapter.mapDocumentsData(new ArrayList<>(allDocuments), getCurrentUserId(), workspaceKeeper.getProjectId());
    var mappedLinkInstances = linkInstanceAdapter.mapLinkInstancesData(new ArrayList<>(allLinkInstances));
    return new Tuple<>(mappedDocuments, mappedLinkInstances);
}
Also used : ConstraintData(io.lumeer.api.model.ConstraintData) Query(io.lumeer.api.model.Query) LinkInstance(io.lumeer.api.model.LinkInstance) Document(io.lumeer.api.model.Document) Tuple(io.lumeer.core.util.Tuple) HashSet(java.util.HashSet)

Example 2 with ConstraintData

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

the class DocumentMatcher method initializeLocalizationData.

private void initializeLocalizationData() {
    language = Language.fromString(ruleTask.getCurrentLocale());
    final String timeZone = ruleTask.getTimeZone();
    final TranslationManager translationManager = new TranslationManager();
    constraintData = new ConstraintData(dao.getUserDao().getAllUsers(this.organization.getId()), ruleTask.getInitiator(), translationManager.translateDurationUnitsMap(language), new CurrencyData(translationManager.translateAbbreviations(language), translationManager.translateOrdinals(language)), timeZone != null ? timeZone : TimeZone.getDefault().getID(), dao.getGroupDao().getAllGroups(this.organization.getId()), dao.getSelectionListDao().getAllLists(Collections.singletonList(project.getId())));
}
Also used : ConstraintData(io.lumeer.api.model.ConstraintData) CurrencyData(io.lumeer.api.model.CurrencyData) TranslationManager(io.lumeer.core.facade.translate.TranslationManager)

Example 3 with ConstraintData

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

the class DocumentUtils method getDocuments.

public static List<Document> getDocuments(final CollectionDao collectionDao, final DocumentDao documentDao, final DataDao dataDao, final UserDao userDao, final GroupDao groupDao, final SelectionListDao selectionListDao, final Organization organization, final Project project, final Query query, final User user, final Language language, final AllowedPermissions permissions, final String timeZone) {
    if (organization != null && query.getCollectionIds().size() > 0) {
        final String collectionId = query.getCollectionIds().iterator().next();
        final Collection collection = collectionDao.getCollectionById(collectionId);
        final List<Document> documents = documentDao.getDocumentsByCollection(collectionId);
        final Map<String, Document> documentsByIds = documents.stream().collect(Collectors.toMap(Document::getId, Function.identity()));
        dataDao.getData(collectionId, documents.stream().map(Document::getId).collect(Collectors.toSet())).forEach(data -> {
            final Document doc = documentsByIds.get(data.getId());
            if (doc != null) {
                doc.setData(data);
            }
        });
        final TranslationManager translationManager = new TranslationManager();
        final ConstraintData constraintData = new ConstraintData(userDao.getAllUsers(organization.getId()), user, translationManager.translateDurationUnitsMap(language), new CurrencyData(translationManager.translateAbbreviations(language), translationManager.translateOrdinals(language)), timeZone != null ? timeZone : TimeZone.getDefault().getID(), groupDao.getAllGroups(organization.getId()), selectionListDao.getAllLists(Collections.singletonList(project.getId())));
        final Tuple<List<Document>, List<LinkInstance>> result = DataFilter.filterDocumentsAndLinksByQueryDecodingFromJson(documents, List.of(collection), List.of(), List.of(), query, Map.of(collectionId, permissions), Map.of(), constraintData, true, language);
        return result.getFirst();
    }
    return List.of();
}
Also used : ConstraintData(io.lumeer.api.model.ConstraintData) CurrencyData(io.lumeer.api.model.CurrencyData) Collection(io.lumeer.api.model.Collection) ArrayList(java.util.ArrayList) List(java.util.List) TranslationManager(io.lumeer.core.facade.translate.TranslationManager) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document)

Example 4 with ConstraintData

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

the class AutoLinkBatchTask method setupBatch.

public void setupBatch(final AutoLinkRule rule, final LinkType linkType, final Collection collection, final Attribute attribute, final Collection otherCollection, final Attribute otherAttribute, final User user, final Map<String, AllowedPermissions> permissions) {
    this.rule = rule;
    this.linkType = linkType;
    this.collection = collection;
    this.attribute = attribute;
    this.otherCollection = otherCollection;
    this.otherAttribute = otherAttribute;
    this.permissions = permissions;
    this.user = user;
    sourceDocuments = daoContextSnapshot.getDocumentDao().getDocumentsByCollection(collection.getId());
    targetDocuments = daoContextSnapshot.getDocumentDao().getDocumentsByCollection(otherCollection.getId());
    existingLinks = daoContextSnapshot.getLinkInstanceDao().getLinkInstancesByLinkType(linkType.getId());
    language = requestDataKeeper.getUserLanguage();
    timeZone = requestDataKeeper.getTimezone();
    final TranslationManager translationManager = new TranslationManager();
    final String organizationId = daoContextSnapshot.getSelectedWorkspace().getOrganization().get().getId();
    final String projectId = daoContextSnapshot.getSelectedWorkspace().getProject().get().getId();
    constraintData = new ConstraintData(daoContextSnapshot.getUserDao().getAllUsers(organizationId), user, translationManager.translateDurationUnitsMap(language), new CurrencyData(translationManager.translateAbbreviations(language), translationManager.translateOrdinals(language)), timeZone != null ? timeZone : TimeZone.getDefault().getID(), daoContextSnapshot.getGroupDao().getAllGroups(organizationId), daoContextSnapshot.getSelectionListDao().getAllLists(Collections.singletonList(projectId)));
    matchQuery = MatchQueryFactory.getMatchQuery(attribute, otherCollection, otherAttribute);
}
Also used : ConstraintData(io.lumeer.api.model.ConstraintData) CurrencyData(io.lumeer.api.model.CurrencyData) TranslationManager(io.lumeer.core.facade.translate.TranslationManager)

Aggregations

ConstraintData (io.lumeer.api.model.ConstraintData)4 CurrencyData (io.lumeer.api.model.CurrencyData)3 TranslationManager (io.lumeer.core.facade.translate.TranslationManager)3 Document (io.lumeer.api.model.Document)2 Collection (io.lumeer.api.model.Collection)1 LinkInstance (io.lumeer.api.model.LinkInstance)1 Query (io.lumeer.api.model.Query)1 Tuple (io.lumeer.core.util.Tuple)1 DataDocument (io.lumeer.engine.api.data.DataDocument)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1