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;
}
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));
}
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));
}
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);
}
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));
}
Aggregations