Search in sources :

Example 1 with LOGICAL_DATA_ELEMENT

use of org.finos.waltz.schema.tables.LogicalDataElement.LOGICAL_DATA_ELEMENT in project waltz by khartec.

the class LogicalDataElementSearchDao method search.

@Override
public List<LogicalDataElement> search(EntitySearchOptions options) {
    List<String> terms = SearchUtilities.mkTerms(options.searchQuery());
    if (terms.isEmpty()) {
        return Collections.emptyList();
    }
    Set<String> validStatusNames = EnumUtilities.names(options.entityLifecycleStatuses());
    Condition statusCondition = LOGICAL_DATA_ELEMENT.ENTITY_LIFECYCLE_STATUS.in(validStatusNames);
    Condition likeName = JooqUtilities.mkBasicTermSearch(LOGICAL_DATA_ELEMENT.NAME, terms);
    Condition likeDesc = JooqUtilities.mkBasicTermSearch(LOGICAL_DATA_ELEMENT.DESCRIPTION, terms);
    List<LogicalDataElement> results = dsl.select(LOGICAL_DATA_ELEMENT.fields()).from(LOGICAL_DATA_ELEMENT).where(likeName.and(statusCondition)).union(dsl.select(LOGICAL_DATA_ELEMENT.fields()).from(LOGICAL_DATA_ELEMENT).where(likeDesc.and(statusCondition))).orderBy(LOGICAL_DATA_ELEMENT.NAME).limit(options.limit()).fetch(LogicalDataElementDao.TO_DOMAIN_MAPPER);
    List<LogicalDataElement> sortedResults = sort(results, SearchUtilities.mkRelevancyComparator(a -> a.name(), terms.get(0)));
    return sortedResults;
}
Also used : Condition(org.jooq.Condition) JooqUtilities(org.finos.waltz.data.JooqUtilities) LOGICAL_DATA_ELEMENT(org.finos.waltz.schema.tables.LogicalDataElement.LOGICAL_DATA_ELEMENT) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) CollectionUtilities.sort(org.finos.waltz.common.CollectionUtilities.sort) LogicalDataElementDao(org.finos.waltz.data.logical_data_element.LogicalDataElementDao) EnumUtilities(org.finos.waltz.common.EnumUtilities) SearchUtilities(org.finos.waltz.data.SearchUtilities) EntitySearchOptions(org.finos.waltz.model.entity_search.EntitySearchOptions) LogicalDataElement(org.finos.waltz.model.logical_data_element.LogicalDataElement) Condition(org.jooq.Condition) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) DSLContext(org.jooq.DSLContext) SearchDao(org.finos.waltz.data.SearchDao) Repository(org.springframework.stereotype.Repository) Collections(java.util.Collections) LogicalDataElement(org.finos.waltz.model.logical_data_element.LogicalDataElement)

Aggregations

Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)1 CollectionUtilities.sort (org.finos.waltz.common.CollectionUtilities.sort)1 EnumUtilities (org.finos.waltz.common.EnumUtilities)1 JooqUtilities (org.finos.waltz.data.JooqUtilities)1 SearchDao (org.finos.waltz.data.SearchDao)1 SearchUtilities (org.finos.waltz.data.SearchUtilities)1 LogicalDataElementDao (org.finos.waltz.data.logical_data_element.LogicalDataElementDao)1 EntitySearchOptions (org.finos.waltz.model.entity_search.EntitySearchOptions)1 LogicalDataElement (org.finos.waltz.model.logical_data_element.LogicalDataElement)1 LOGICAL_DATA_ELEMENT (org.finos.waltz.schema.tables.LogicalDataElement.LOGICAL_DATA_ELEMENT)1 Condition (org.jooq.Condition)1 DSLContext (org.jooq.DSLContext)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Repository (org.springframework.stereotype.Repository)1