Search in sources :

Example 1 with EntitySearchOptions

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));
    });
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ImmutableEntitySearchOptions(com.khartec.waltz.model.entity_search.ImmutableEntitySearchOptions) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) EntitySearchService(com.khartec.waltz.service.entity_search.EntitySearchService)

Example 2 with EntitySearchOptions

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()));
}
Also used : Application(com.khartec.waltz.model.application.Application) ImmutableEntitySearchOptions(com.khartec.waltz.model.entity_search.ImmutableEntitySearchOptions) List(java.util.List) SqlServerAppSearch(com.khartec.waltz.data.application.search.SqlServerAppSearch) DIConfiguration(com.khartec.waltz.service.DIConfiguration) DSLContext(org.jooq.DSLContext) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityKind(com.khartec.waltz.model.EntityKind) EntityLifecycleStatus(com.khartec.waltz.model.EntityLifecycleStatus) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SqlServerAppSearch(com.khartec.waltz.data.application.search.SqlServerAppSearch) ImmutableEntitySearchOptions(com.khartec.waltz.model.entity_search.ImmutableEntitySearchOptions) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) DSLContext(org.jooq.DSLContext) Application(com.khartec.waltz.model.application.Application)

Example 3 with EntitySearchOptions

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;
}
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 4 with EntitySearchOptions

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));
}
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 5 with EntitySearchOptions

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

Aggregations

EntitySearchOptions (com.khartec.waltz.model.entity_search.EntitySearchOptions)7 List (java.util.List)6 DSLContext (org.jooq.DSLContext)6 SearchUtilities.mkTerms (com.khartec.waltz.data.SearchUtilities.mkTerms)5 Condition (org.jooq.Condition)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 ArrayList (java.util.ArrayList)4 Collectors (java.util.stream.Collectors)4 DSL (org.jooq.impl.DSL)4 Collections (java.util.Collections)3 SearchUtilities.mkRelevancyComparator (com.khartec.waltz.data.SearchUtilities.mkRelevancyComparator)2 EntityKind (com.khartec.waltz.model.EntityKind)2 Application (com.khartec.waltz.model.application.Application)2 ImmutableEntitySearchOptions (com.khartec.waltz.model.entity_search.ImmutableEntitySearchOptions)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 Checks.checkNotNull (com.khartec.waltz.common.Checks.checkNotNull)1 ListUtilities (com.khartec.waltz.common.ListUtilities)1