Search in sources :

Example 26 with Measurable

use of org.finos.waltz.model.measurable.Measurable in project waltz by khartec.

the class MariaMeasurableSearch method searchFullText.

@Override
public List<Measurable> searchFullText(DSLContext dsl, EntitySearchOptions options) {
    List<String> terms = mkTerms(options.searchQuery());
    if (terms.isEmpty()) {
        return emptyList();
    }
    Condition externalIdCondition = terms.stream().map(term -> MEASURABLE.EXTERNAL_ID.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    Condition entityLifecycleCondition = MEASURABLE.ENTITY_LIFECYCLE_STATUS.in(options.entityLifecycleStatuses());
    List<Measurable> measurablesViaExternalId = dsl.selectDistinct(MEASURABLE.fields()).from(MEASURABLE).where(externalIdCondition).and(entityLifecycleCondition).orderBy(MEASURABLE.EXTERNAL_ID).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
    Condition nameCondition = terms.stream().map(term -> MEASURABLE.NAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<Measurable> measurablesViaName = dsl.selectDistinct(MEASURABLE.fields()).from(MEASURABLE).where(nameCondition).and(entityLifecycleCondition).orderBy(MEASURABLE.NAME).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
    List<Measurable> measurablesViaFullText = dsl.fetch(FULL_TEXT_QUERY, options.searchQuery(), entityLifecycleCondition, options.limit()).map(MeasurableDao.TO_DOMAIN_MAPPER);
    return new ArrayList<>(orderedUnion(measurablesViaExternalId, measurablesViaName, measurablesViaFullText));
}
Also used : Condition(org.jooq.Condition) DSL(org.jooq.impl.DSL) MeasurableDao(org.finos.waltz.data.measurable.MeasurableDao) Collections.emptyList(java.util.Collections.emptyList) DatabaseVendorSpecific(org.finos.waltz.data.DatabaseVendorSpecific) Collectors(java.util.stream.Collectors) EntitySearchOptions(org.finos.waltz.model.entity_search.EntitySearchOptions) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) List(java.util.List) Measurable(org.finos.waltz.model.measurable.Measurable) MEASURABLE(org.finos.waltz.schema.tables.Measurable.MEASURABLE) FullTextSearch(org.finos.waltz.data.FullTextSearch) DSLContext(org.jooq.DSLContext) SetUtilities.orderedUnion(org.finos.waltz.common.SetUtilities.orderedUnion) SearchUtilities.mkTerms(org.finos.waltz.data.SearchUtilities.mkTerms) Measurable(org.finos.waltz.model.measurable.Measurable) ArrayList(java.util.ArrayList)

Aggregations

Measurable (org.finos.waltz.model.measurable.Measurable)26 MeasurableDao (org.finos.waltz.data.measurable.MeasurableDao)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 EntityKind (org.finos.waltz.model.EntityKind)6 Collectors (java.util.stream.Collectors)5 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)5 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)5 DIConfiguration (org.finos.waltz.service.DIConfiguration)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 IOException (java.io.IOException)4 InputStreamReader (java.io.InputStreamReader)4 Collection (java.util.Collection)4 Map (java.util.Map)4 Checks.checkTrue (org.finos.waltz.common.Checks.checkTrue)4 MapUtilities.indexBy (org.finos.waltz.common.MapUtilities.indexBy)4 StringUtilities.lower (org.finos.waltz.common.StringUtilities.lower)4 ApplicationDao (org.finos.waltz.data.application.ApplicationDao)4 RatingSchemeDAO (org.finos.waltz.data.rating_scheme.RatingSchemeDAO)4 RoadmapDao (org.finos.waltz.data.roadmap.RoadmapDao)4