use of com.khartec.waltz.model.entity_search.EntitySearchOptions in project waltz by khartec.
the class EntitySearchHarness method main.
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
EntitySearchService searchService = ctx.getBean(EntitySearchService.class);
EntitySearchOptions searchOptions = ImmutableEntitySearchOptions.builder().entityKinds(ListUtilities.newArrayList(EntityKind.ACTOR, EntityKind.APPLICATION, EntityKind.APP_GROUP, EntityKind.CHANGE_INITIATIVE, EntityKind.ORG_UNIT, EntityKind.MEASURABLE, EntityKind.PERSON)).userId("admin").build();
String[] searchTerms = { "cat", "admin", "test", "enhance", "ceo", "equities" };
Arrays.stream(searchTerms).forEach(term -> {
System.out.println("-------------------");
System.out.printf("Searching for '%s'\n", term);
System.out.println("-------------------");
printResults(searchService.search(term, searchOptions));
});
}
use of com.khartec.waltz.model.entity_search.EntitySearchOptions in project waltz by khartec.
the class MsSqlSearchHarness method main.
public static void main(String[] args) {
ApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
SqlServerAppSearch appSearch = new SqlServerAppSearch();
EntitySearchOptions searchOptions = ImmutableEntitySearchOptions.builder().addEntityKinds(EntityKind.APPLICATION).userId("admin").limit(50).build();
List<Application> results = appSearch.search(dsl, "sap", searchOptions);
results.stream().filter(a -> a.entityLifecycleStatus() != EntityLifecycleStatus.REMOVED).forEach(a -> System.out.println(a.name() + " - " + a.lifecyclePhase()));
}
use of com.khartec.waltz.model.entity_search.EntitySearchOptions 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 com.khartec.waltz.model.entity_search.EntitySearchOptions 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 com.khartec.waltz.model.entity_search.EntitySearchOptions 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));
}
Aggregations