Search in sources :

Example 1 with ServerInformation

use of org.finos.waltz.model.server_information.ServerInformation 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 2 with ServerInformation

use of org.finos.waltz.model.server_information.ServerInformation 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)

Example 3 with ServerInformation

use of org.finos.waltz.model.server_information.ServerInformation in project waltz by khartec.

the class ServerGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    ServerInformationDao serverDao = ctx.getBean(ServerInformationDao.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    commonHostNames.clear();
    List<ServerInformation> servers = ListUtilities.newArrayList();
    IntStream.range(0, 10_000).forEach(i -> {
        String hostName = mkHostName(i);
        boolean isCommonHost = commonHostNames.contains(hostName);
        servers.add(ImmutableServerInformation.builder().hostname(hostName).location(isCommonHost ? SampleData.locations[0] : randomPick(SampleData.locations)).operatingSystem(isCommonHost ? SampleData.operatingSystems[0] : randomPick(SampleData.operatingSystems)).operatingSystemVersion(isCommonHost ? SampleData.operatingSystemVersions[0] : randomPick(SampleData.operatingSystemVersions)).country("UK").hardwareEndOfLifeDate(rnd.nextInt(10) > 5 ? Date.valueOf(LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3))) : null).operatingSystemEndOfLifeDate(rnd.nextInt(10) > 5 ? Date.valueOf(LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3))) : null).virtual(isCommonHost || rnd.nextInt(10) > 7).provenance(SAMPLE_DATA_PROVENANCE).lifecycleStatus(randomPick(LifecycleStatus.values())).externalId(mkExernalId(i)).build());
    });
    serverDao.bulkSave(servers);
    // create server usages
    List<Long> appIds = getAppIds(dsl);
    List<Long> serverIds = getServerIds(dsl);
    HashSet<Tuple2<Long, Long>> serverAppMappings = new HashSet<>();
    IntStream.range(0, 20_000).forEach(i -> {
        serverAppMappings.add(Tuple.tuple(randomPick(serverIds), randomPick(appIds)));
    });
    List<ServerUsageRecord> serverUsages = serverAppMappings.stream().map(t -> mkServerUsageRecord(t.v1, t.v2)).collect(Collectors.toList());
    dsl.batchInsert(serverUsages).execute();
    return null;
}
Also used : IntStream(java.util.stream.IntStream) java.util(java.util) EntityKind(org.finos.waltz.model.EntityKind) ImmutableServerInformation(org.finos.waltz.model.server_information.ImmutableServerInformation) ServerInformationDao(org.finos.waltz.data.server_information.ServerInformationDao) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) LifecycleStatus(org.finos.waltz.model.LifecycleStatus) Date(java.sql.Date) RandomUtilities(org.finos.waltz.common.RandomUtilities) Tuple2(org.jooq.lambda.tuple.Tuple2) SERVER_USAGE(org.finos.waltz.schema.tables.ServerUsage.SERVER_USAGE) Tuple(org.jooq.lambda.tuple.Tuple) SERVER_INFORMATION(org.finos.waltz.schema.tables.ServerInformation.SERVER_INFORMATION) ListUtilities(org.finos.waltz.common.ListUtilities) ServerInformation(org.finos.waltz.model.server_information.ServerInformation) LocalDate(java.time.LocalDate) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) DSLContext(org.jooq.DSLContext) ServerUsageRecord(org.finos.waltz.schema.tables.records.ServerUsageRecord) ServerInformationDao(org.finos.waltz.data.server_information.ServerInformationDao) DSLContext(org.jooq.DSLContext) ImmutableServerInformation(org.finos.waltz.model.server_information.ImmutableServerInformation) ServerInformation(org.finos.waltz.model.server_information.ServerInformation) Tuple2(org.jooq.lambda.tuple.Tuple2) ServerUsageRecord(org.finos.waltz.schema.tables.records.ServerUsageRecord)

Aggregations

ServerInformationDao (org.finos.waltz.data.server_information.ServerInformationDao)3 ServerInformation (org.finos.waltz.model.server_information.ServerInformation)3 DSLContext (org.jooq.DSLContext)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 SetUtilities.orderedUnion (org.finos.waltz.common.SetUtilities.orderedUnion)2 EntitySearchOptions (org.finos.waltz.model.entity_search.EntitySearchOptions)2 SERVER_INFORMATION (org.finos.waltz.schema.Tables.SERVER_INFORMATION)2 Condition (org.jooq.Condition)2 Date (java.sql.Date)1 LocalDate (java.time.LocalDate)1 java.util (java.util)1 IntStream (java.util.stream.IntStream)1 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)1 ListUtilities (org.finos.waltz.common.ListUtilities)1 RandomUtilities (org.finos.waltz.common.RandomUtilities)1 RandomUtilities.randomPick (org.finos.waltz.common.RandomUtilities.randomPick)1 org.finos.waltz.data (org.finos.waltz.data)1