Search in sources :

Example 41 with Condition

use of org.jooq.Condition in project waltz by khartec.

the class PhysicalSpecificationSearchDao method search.

public List<PhysicalSpecification> search(String termsStr, EntitySearchOptions options) {
    List<String> terms = mkTerms(termsStr);
    if (terms.isEmpty()) {
        return newArrayList();
    }
    Condition likeName = mkBasicTermSearch(PHYSICAL_SPECIFICATION.NAME, terms);
    Condition likeDesc = mkBasicTermSearch(PHYSICAL_SPECIFICATION.DESCRIPTION, terms);
    SelectQuery<Record> query = dsl.select(PHYSICAL_SPECIFICATION.fields()).select(owningEntityNameField).from(PHYSICAL_SPECIFICATION).where(likeName).or(likeDesc).orderBy(PHYSICAL_SPECIFICATION.NAME).limit(options.limit()).getQuery();
    List<PhysicalSpecification> results = query.fetch(r -> {
        PhysicalSpecification spec = PhysicalSpecificationDao.TO_DOMAIN_MAPPER.map(r);
        String updatedDesc = String.format("%s %s", Optional.ofNullable(r.getValue(owningEntityNameField)).map(owner -> String.format("(%s)", owner)).orElse(""), spec.description());
        return ImmutablePhysicalSpecification.copyOf(spec).withDescription(updatedDesc);
    });
    results.sort(mkRelevancyComparator(ps -> ps.name(), terms.get(0)));
    return results;
}
Also used : Condition(org.jooq.Condition) Record(org.jooq.Record) PHYSICAL_SPECIFICATION(com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION) PhysicalSpecificationDao.owningEntityNameField(com.khartec.waltz.data.physical_specification.PhysicalSpecificationDao.owningEntityNameField) Checks.checkNotNull(com.khartec.waltz.common.Checks.checkNotNull) ListUtilities(com.khartec.waltz.common.ListUtilities) Autowired(org.springframework.beans.factory.annotation.Autowired) ListUtilities.newArrayList(com.khartec.waltz.common.ListUtilities.newArrayList) Condition(org.jooq.Condition) SearchUtilities.mkRelevancyComparator(com.khartec.waltz.data.SearchUtilities.mkRelevancyComparator) List(java.util.List) PhysicalSpecificationDao(com.khartec.waltz.data.physical_specification.PhysicalSpecificationDao) DSLContext(org.jooq.DSLContext) Optional(java.util.Optional) ImmutablePhysicalSpecification(com.khartec.waltz.model.physical_specification.ImmutablePhysicalSpecification) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) SelectQuery(org.jooq.SelectQuery) SearchUtilities.mkTerms(com.khartec.waltz.data.SearchUtilities.mkTerms) Repository(org.springframework.stereotype.Repository) JooqUtilities.mkBasicTermSearch(com.khartec.waltz.data.JooqUtilities.mkBasicTermSearch) PhysicalSpecification(com.khartec.waltz.model.physical_specification.PhysicalSpecification) ImmutablePhysicalSpecification(com.khartec.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(com.khartec.waltz.model.physical_specification.PhysicalSpecification) Record(org.jooq.Record)

Example 42 with Condition

use of org.jooq.Condition in project waltz by khartec.

the class SqlServerAppSearch method search.

@Override
public List<Application> search(DSLContext dsl, String query, EntitySearchOptions options) {
    List<String> terms = mkTerms(query);
    if (terms.isEmpty()) {
        return Collections.emptyList();
    }
    Condition lifecycleCondition = APPLICATION.ENTITY_LIFECYCLE_STATUS.in(options.entityLifecycleStatuses());
    Condition assetCodeCondition = terms.stream().map(term -> APPLICATION.ASSET_CODE.like(term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<Application> appsViaAssetCode = dsl.selectDistinct(APPLICATION.fields()).from(APPLICATION).where(assetCodeCondition).and(lifecycleCondition).orderBy(APPLICATION.NAME).limit(options.limit()).fetch(ApplicationDao.TO_DOMAIN_MAPPER);
    Condition aliasCondition = terms.stream().map(term -> ENTITY_ALIAS.ALIAS.like("%" + term + "%")).collect(Collectors.reducing(ENTITY_ALIAS.KIND.eq(EntityKind.APPLICATION.name()), (acc, frag) -> acc.and(frag)));
    List<Application> appsViaAlias = dsl.selectDistinct(APPLICATION.fields()).from(APPLICATION).innerJoin(ENTITY_ALIAS).on(ENTITY_ALIAS.ID.eq(APPLICATION.ID)).where(aliasCondition).and(lifecycleCondition).orderBy(APPLICATION.NAME).limit(options.limit()).fetch(ApplicationDao.TO_DOMAIN_MAPPER);
    Condition nameCondition = terms.stream().map(term -> APPLICATION.NAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<Application> appsViaName = dsl.selectDistinct(APPLICATION.fields()).from(APPLICATION).where(nameCondition).and(lifecycleCondition).orderBy(APPLICATION.NAME).limit(options.limit()).fetch(ApplicationDao.TO_DOMAIN_MAPPER);
    List<Application> appsViaFullText = dsl.select(APPLICATION.fields()).from(APPLICATION).where(JooqUtilities.MSSQL.mkContainsPrefix(terms)).and(lifecycleCondition).limit(options.limit()).fetch(ApplicationDao.TO_DOMAIN_MAPPER);
    appsViaName.sort(mkRelevancyComparator(a -> a.name(), terms.get(0)));
    return new ArrayList<>(orderedUnion(appsViaAssetCode, appsViaName, appsViaAlias, appsViaFullText));
}
Also used : Condition(org.jooq.Condition) Application(com.khartec.waltz.model.application.Application) DSL(org.jooq.impl.DSL) ApplicationDao(com.khartec.waltz.data.application.ApplicationDao) ENTITY_ALIAS(com.khartec.waltz.schema.tables.EntityAlias.ENTITY_ALIAS) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) EntityKind(com.khartec.waltz.model.EntityKind) ArrayList(java.util.ArrayList) SearchUtilities.mkRelevancyComparator(com.khartec.waltz.data.SearchUtilities.mkRelevancyComparator) List(java.util.List) DSLContext(org.jooq.DSLContext) APPLICATION(com.khartec.waltz.schema.tables.Application.APPLICATION) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) SearchUtilities.mkTerms(com.khartec.waltz.data.SearchUtilities.mkTerms) JooqUtilities(com.khartec.waltz.data.JooqUtilities) DatabaseVendorSpecific(com.khartec.waltz.data.DatabaseVendorSpecific) Collections(java.util.Collections) SetUtilities.orderedUnion(com.khartec.waltz.common.SetUtilities.orderedUnion) FullTextSearch(com.khartec.waltz.data.FullTextSearch) ArrayList(java.util.ArrayList) Application(com.khartec.waltz.model.application.Application)

Example 43 with Condition

use of org.jooq.Condition in project waltz by khartec.

the class SqlServerChangeInitiativeSearch method search.

@Override
public List<ChangeInitiative> search(DSLContext dsl, String query, EntitySearchOptions options) {
    List<String> terms = mkTerms(query);
    if (terms.isEmpty()) {
        return Collections.emptyList();
    }
    Condition nameCondition = terms.stream().map(term -> CHANGE_INITIATIVE.NAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<ChangeInitiative> ciViaName = dsl.selectDistinct(CHANGE_INITIATIVE.fields()).from(CHANGE_INITIATIVE).where(nameCondition).orderBy(CHANGE_INITIATIVE.NAME).limit(options.limit()).fetch(ChangeInitiativeDao.TO_DOMAIN_MAPPER);
    List<ChangeInitiative> ciViaFullText = dsl.select(CHANGE_INITIATIVE.fields()).from(CHANGE_INITIATIVE).where(JooqUtilities.MSSQL.mkContainsPrefix(terms)).limit(options.limit()).fetch(ChangeInitiativeDao.TO_DOMAIN_MAPPER);
    return new ArrayList<>(orderedUnion(ciViaName, ciViaFullText));
}
Also used : Condition(org.jooq.Condition) DSL(org.jooq.impl.DSL) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) ChangeInitiative(com.khartec.waltz.model.change_initiative.ChangeInitiative) List(java.util.List) ChangeInitiativeDao(com.khartec.waltz.data.change_initiative.ChangeInitiativeDao) DSLContext(org.jooq.DSLContext) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) SearchUtilities.mkTerms(com.khartec.waltz.data.SearchUtilities.mkTerms) CHANGE_INITIATIVE(com.khartec.waltz.schema.tables.ChangeInitiative.CHANGE_INITIATIVE) JooqUtilities(com.khartec.waltz.data.JooqUtilities) DatabaseVendorSpecific(com.khartec.waltz.data.DatabaseVendorSpecific) Collections(java.util.Collections) SetUtilities.orderedUnion(com.khartec.waltz.common.SetUtilities.orderedUnion) FullTextSearch(com.khartec.waltz.data.FullTextSearch) ChangeInitiative(com.khartec.waltz.model.change_initiative.ChangeInitiative) ArrayList(java.util.ArrayList)

Example 44 with Condition

use of org.jooq.Condition in project waltz by khartec.

the class LogicalFlowIdSelectorFactory method wrapAppIdSelector.

private Select<Record1<Long>> wrapAppIdSelector(IdSelectionOptions options) {
    Select<Record1<Long>> appIdSelector = applicationIdSelectorFactory.apply(options);
    Condition sourceCondition = LOGICAL_FLOW.SOURCE_ENTITY_ID.in(appIdSelector).and(LOGICAL_FLOW.SOURCE_ENTITY_KIND.eq(EntityKind.APPLICATION.name()));
    Condition targetCondition = LOGICAL_FLOW.TARGET_ENTITY_ID.in(appIdSelector).and(LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name()));
    return DSL.select(LOGICAL_FLOW.ID).from(LOGICAL_FLOW).where(sourceCondition.or(targetCondition)).and(NOT_REMOVED);
}
Also used : Condition(org.jooq.Condition) Record1(org.jooq.Record1)

Example 45 with Condition

use of org.jooq.Condition in project waltz by khartec.

the class SqlServerMeasurableSearch method search.

@Override
public List<Measurable> search(DSLContext dsl, String query, EntitySearchOptions options) {
    List<String> terms = mkTerms(query);
    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)));
    List<Measurable> measurablesViaExternalId = dsl.selectDistinct(MEASURABLE.fields()).from(MEASURABLE).where(externalIdCondition).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).orderBy(MEASURABLE.NAME).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
    List<Measurable> measurablesViaFullText = dsl.selectFrom(MEASURABLE).where(JooqUtilities.MSSQL.mkContainsPrefix(terms)).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
    return new ArrayList<>(orderedUnion(measurablesViaExternalId, measurablesViaName, measurablesViaFullText));
}
Also used : Condition(org.jooq.Condition) Measurable(com.khartec.waltz.model.measurable.Measurable) DSL(org.jooq.impl.DSL) Collections.emptyList(java.util.Collections.emptyList) MEASURABLE(com.khartec.waltz.schema.tables.Measurable.MEASURABLE) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) List(java.util.List) DSLContext(org.jooq.DSLContext) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) SearchUtilities.mkTerms(com.khartec.waltz.data.SearchUtilities.mkTerms) JooqUtilities(com.khartec.waltz.data.JooqUtilities) DatabaseVendorSpecific(com.khartec.waltz.data.DatabaseVendorSpecific) SetUtilities.orderedUnion(com.khartec.waltz.common.SetUtilities.orderedUnion) FullTextSearch(com.khartec.waltz.data.FullTextSearch) MeasurableDao(com.khartec.waltz.data.measurable.MeasurableDao) Measurable(com.khartec.waltz.model.measurable.Measurable) ArrayList(java.util.ArrayList)

Aggregations

Condition (org.jooq.Condition)47 Field (org.jooq.Field)17 ArrayList (java.util.ArrayList)14 List (java.util.List)11 GroupField (org.jooq.GroupField)11 SortField (org.jooq.SortField)11 TableField (org.jooq.TableField)11 DSLContext (org.jooq.DSLContext)7 Record1 (org.jooq.Record1)7 SearchUtilities.mkTerms (com.khartec.waltz.data.SearchUtilities.mkTerms)6 Collectors (java.util.stream.Collectors)6 DSL (org.jooq.impl.DSL)6 EntitySearchOptions (com.khartec.waltz.model.entity_search.EntitySearchOptions)5 SetUtilities.orderedUnion (com.khartec.waltz.common.SetUtilities.orderedUnion)4 DatabaseVendorSpecific (com.khartec.waltz.data.DatabaseVendorSpecific)4 FullTextSearch (com.khartec.waltz.data.FullTextSearch)4 JooqUtilities (com.khartec.waltz.data.JooqUtilities)4 Collections.emptyList (java.util.Collections.emptyList)4 Record (org.jooq.Record)4 EntityKind (com.khartec.waltz.model.EntityKind)3