Search in sources :

Example 1 with EntitySearchOptions

use of org.finos.waltz.model.entity_search.EntitySearchOptions in project waltz by khartec.

the class DataTypeServiceTest method search.

@Test
public void search() {
    dataTypeHelper.clearAllDataTypes();
    assertThrows(IllegalArgumentException.class, () -> dtSvc.search(null), "null search options throws exception");
    EntitySearchOptions dt1Search = mkDataTypeSearchOptions("dt1");
    EntitySearchOptions emptySearch = mkDataTypeSearchOptions("");
    EntitySearchOptions testSearch = mkDataTypeSearchOptions("TEST");
    assertEquals(emptyList(), dtSvc.search(dt1Search), "Search will return an empty list when no datatypes");
    dataTypeHelper.createDataType(1L, "dt1", "DT1");
    dataTypeHelper.createDataType(2L, "dt2", "DT2");
    dataTypeHelper.createDataType(3L, "dt10", "DT10");
    assertEquals(asSet(1L, 2L, 3L), map(dtSvc.search(emptySearch), dt -> dt.id().get()), "Empty search string will return all dts");
    assertEquals(emptyList(), dtSvc.search(testSearch), "Search will return an empty list when no match");
    assertEquals(asSet(1L, 3L), map(dtSvc.search(dt1Search), dt -> dt.id().get()), "Search will return all where matches to part of name");
    dataTypeHelper.createDataType(4L, "test", "TESTING");
    assertEquals(asSet(4L), map(dtSvc.search(testSearch), dt -> dt.id().get()), "search is case insensitive");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Collections.emptyList(java.util.Collections.emptyList) EntityKind(org.finos.waltz.model.EntityKind) Collection(java.util.Collection) AppHelper(org.finos.waltz.integration_test.inmem.helpers.AppHelper) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) SetUtilities.asSet(org.finos.waltz.common.SetUtilities.asSet) LogicalFlowHelper(org.finos.waltz.integration_test.inmem.helpers.LogicalFlowHelper) DataTypeHelper(org.finos.waltz.integration_test.inmem.helpers.DataTypeHelper) EntitySearchOptions(org.finos.waltz.model.entity_search.EntitySearchOptions) DataType(org.finos.waltz.model.datatype.DataType) Test(org.junit.jupiter.api.Test) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) List(java.util.List) Assertions(org.junit.jupiter.api.Assertions) EntityReference(org.finos.waltz.model.EntityReference) ImmutableEntitySearchOptions(org.finos.waltz.model.entity_search.ImmutableEntitySearchOptions) DataTypeService(org.finos.waltz.service.data_type.DataTypeService) EntitySearchOptions(org.finos.waltz.model.entity_search.EntitySearchOptions) ImmutableEntitySearchOptions(org.finos.waltz.model.entity_search.ImmutableEntitySearchOptions) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with EntitySearchOptions

use of org.finos.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(EntitySearchOptions.DEFAULT_SEARCH_RESULTS_LIMIT).searchQuery("sap").build();
    List<Application> results = appSearch.searchFullText(dsl, searchOptions);
    results.stream().filter(a -> a.entityLifecycleStatus() != EntityLifecycleStatus.REMOVED).forEach(a -> System.out.println(a.name() + " - " + a.lifecyclePhase()));
}
Also used : List(java.util.List) Application(org.finos.waltz.model.application.Application) EntityKind(org.finos.waltz.model.EntityKind) DSLContext(org.jooq.DSLContext) ImmutableEntitySearchOptions(org.finos.waltz.model.entity_search.ImmutableEntitySearchOptions) DIConfiguration(org.finos.waltz.service.DIConfiguration) ApplicationContext(org.springframework.context.ApplicationContext) SqlServerAppSearch(org.finos.waltz.data.application.search.SqlServerAppSearch) EntitySearchOptions(org.finos.waltz.model.entity_search.EntitySearchOptions) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityLifecycleStatus(org.finos.waltz.model.EntityLifecycleStatus) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SqlServerAppSearch(org.finos.waltz.data.application.search.SqlServerAppSearch) ImmutableEntitySearchOptions(org.finos.waltz.model.entity_search.ImmutableEntitySearchOptions) EntitySearchOptions(org.finos.waltz.model.entity_search.EntitySearchOptions) DSLContext(org.jooq.DSLContext) Application(org.finos.waltz.model.application.Application)

Example 3 with EntitySearchOptions

use of org.finos.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.APPLICATION,
    EntityKind.LOGICAL_DATA_ELEMENT)).searchQuery("desk").userId("admin").build();
    String[] searchTerms = { "cat", "admin", "test", "enhance", "ceo", "equities" };
    searchService.search(searchOptions).forEach(d -> System.out.println(d.name()));
    System.exit(-1);
    Arrays.stream(searchTerms).forEach(term -> {
        System.out.println("-------------------");
        System.out.printf("Searching for '%s'\n", term);
        System.out.println("-------------------");
        printResults(searchService.search(searchOptions));
    });
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ImmutableEntitySearchOptions(org.finos.waltz.model.entity_search.ImmutableEntitySearchOptions) EntitySearchOptions(org.finos.waltz.model.entity_search.EntitySearchOptions) EntitySearchService(org.finos.waltz.service.entity_search.EntitySearchService)

Example 4 with EntitySearchOptions

use of org.finos.waltz.model.entity_search.EntitySearchOptions in project waltz by khartec.

the class MariaServerInformationSearch method searchFullText.

@Override
public List<ServerInformation> searchFullText(DSLContext dsl, EntitySearchOptions options) {
    List<String> terms = SearchUtilities.mkTerms(options.searchQuery());
    if (terms.isEmpty()) {
        return Collections.emptyList();
    }
    Condition externalIdCondition = terms.stream().map(term -> SERVER_INFORMATION.EXTERNAL_ID.like(term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<ServerInformation> serversViaExternalId = dsl.selectDistinct(SERVER_INFORMATION.fields()).from(SERVER_INFORMATION).where(externalIdCondition).orderBy(SERVER_INFORMATION.HOSTNAME).limit(options.limit()).fetch(ServerInformationDao.TO_DOMAIN_MAPPER);
    Condition hostnameCondition = terms.stream().map(term -> SERVER_INFORMATION.HOSTNAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<ServerInformation> serversViaHostname = dsl.selectDistinct(SERVER_INFORMATION.fields()).from(SERVER_INFORMATION).where(hostnameCondition).orderBy(SERVER_INFORMATION.HOSTNAME).limit(options.limit()).fetch(ServerInformationDao.TO_DOMAIN_MAPPER);
    List<ServerInformation> serversViaFullText = dsl.select(SERVER_INFORMATION.fields()).from(SERVER_INFORMATION).where("MATCH(hostname, external_id, operating_system, location) AGAINST (?)", options.searchQuery()).limit(options.limit()).fetch(ServerInformationDao.TO_DOMAIN_MAPPER);
    serversViaHostname.sort(SearchUtilities.mkRelevancyComparator(a -> a.hostname(), terms.get(0)));
    serversViaExternalId.sort(SearchUtilities.mkRelevancyComparator(a -> a.externalId().orElse(null), terms.get(0)));
    return new ArrayList<>(orderedUnion(serversViaExternalId, serversViaHostname, serversViaFullText));
}
Also used : Condition(org.jooq.Condition) SERVER_INFORMATION(org.finos.waltz.schema.Tables.SERVER_INFORMATION) DSL(org.jooq.impl.DSL) DatabaseVendorSpecific(org.finos.waltz.data.DatabaseVendorSpecific) ServerInformationDao(org.finos.waltz.data.server_information.ServerInformationDao) SearchUtilities(org.finos.waltz.data.SearchUtilities) 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) ServerInformation(org.finos.waltz.model.server_information.ServerInformation) FullTextSearch(org.finos.waltz.data.FullTextSearch) DSLContext(org.jooq.DSLContext) Collections(java.util.Collections) SetUtilities.orderedUnion(org.finos.waltz.common.SetUtilities.orderedUnion) ServerInformation(org.finos.waltz.model.server_information.ServerInformation) ArrayList(java.util.ArrayList)

Example 5 with EntitySearchOptions

use of org.finos.waltz.model.entity_search.EntitySearchOptions in project waltz by khartec.

the class ServerInformationSearchDao method search.

@Override
public List<ServerInformation> search(EntitySearchOptions options) {
    checkNotNull(options, "options cannot be null");
    List<String> terms = SearchUtilities.mkTerms(options.searchQuery());
    if (terms.isEmpty()) {
        return Collections.emptyList();
    }
    Condition externalIdCondition = JooqUtilities.mkStartsWithTermSearch(SERVER_INFORMATION.EXTERNAL_ID, terms);
    List<ServerInformation> serversViaExternalId = dsl.select(SERVER_INFORMATION.fields()).from(SERVER_INFORMATION).where(externalIdCondition).orderBy(SERVER_INFORMATION.HOSTNAME).limit(options.limit()).fetch(ServerInformationDao.TO_DOMAIN_MAPPER);
    Condition hostnameCondition = JooqUtilities.mkBasicTermSearch(SERVER_INFORMATION.HOSTNAME, terms);
    List<ServerInformation> serversViaHostname = dsl.select(SERVER_INFORMATION.fields()).from(SERVER_INFORMATION).where(hostnameCondition).orderBy(SERVER_INFORMATION.HOSTNAME).limit(options.limit()).fetch(ServerInformationDao.TO_DOMAIN_MAPPER);
    List<ServerInformation> serversViaFullText = searcher.searchFullText(dsl, options);
    serversViaHostname.sort(SearchUtilities.mkRelevancyComparator(ServerInformation::hostname, terms.get(0)));
    serversViaExternalId.sort(SearchUtilities.mkRelevancyComparator(a -> a.externalId().orElse(null), terms.get(0)));
    return new ArrayList<>(orderedUnion(serversViaExternalId, serversViaHostname, serversViaFullText));
}
Also used : Condition(org.jooq.Condition) SERVER_INFORMATION(org.finos.waltz.schema.Tables.SERVER_INFORMATION) Autowired(org.springframework.beans.factory.annotation.Autowired) ServerInformationDao(org.finos.waltz.data.server_information.ServerInformationDao) EntitySearchOptions(org.finos.waltz.model.entity_search.EntitySearchOptions) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) org.finos.waltz.data(org.finos.waltz.data) ServerInformation(org.finos.waltz.model.server_information.ServerInformation) DSLContext(org.jooq.DSLContext) SQLDialect(org.jooq.SQLDialect) Repository(org.springframework.stereotype.Repository) Collections(java.util.Collections) SetUtilities.orderedUnion(org.finos.waltz.common.SetUtilities.orderedUnion) ServerInformation(org.finos.waltz.model.server_information.ServerInformation) ArrayList(java.util.ArrayList)

Aggregations

EntitySearchOptions (org.finos.waltz.model.entity_search.EntitySearchOptions)7 List (java.util.List)6 DSLContext (org.jooq.DSLContext)5 Condition (org.jooq.Condition)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 SetUtilities.orderedUnion (org.finos.waltz.common.SetUtilities.orderedUnion)3 ImmutableEntitySearchOptions (org.finos.waltz.model.entity_search.ImmutableEntitySearchOptions)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Collections.emptyList (java.util.Collections.emptyList)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)2 DatabaseVendorSpecific (org.finos.waltz.data.DatabaseVendorSpecific)2 FullTextSearch (org.finos.waltz.data.FullTextSearch)2 SearchUtilities (org.finos.waltz.data.SearchUtilities)2 ServerInformationDao (org.finos.waltz.data.server_information.ServerInformationDao)2 EntityKind (org.finos.waltz.model.EntityKind)2 ServerInformation (org.finos.waltz.model.server_information.ServerInformation)2 SERVER_INFORMATION (org.finos.waltz.schema.Tables.SERVER_INFORMATION)2