Search in sources :

Example 1 with APPLICATION

use of com.khartec.waltz.schema.tables.Application.APPLICATION in project waltz by khartec.

the class ChangeLogGenerator method main.

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    // get applications and emails
    List<Long> appIds = dsl.select(APPLICATION.ID).from(APPLICATION).fetch(APPLICATION.ID);
    List<String> emails = dsl.select(PERSON.EMAIL).from(PERSON).fetch(PERSON.EMAIL);
    Set<ChangeLogRecord> records = emails.stream().flatMap(email -> Stream.of(mkChangeLog(randomPick(appIds), email), mkChangeLog(randomPick(appIds), randomPick(emails)))).collect(toSet());
    dsl.deleteFrom(CHANGE_LOG).execute();
    dsl.batchInsert(records).execute();
    System.out.println("Inserted " + records.size() + " change log entries");
}
Also used : ChangeLogRecord(com.khartec.waltz.schema.tables.records.ChangeLogRecord) Set(java.util.Set) PERSON(com.khartec.waltz.schema.tables.Person.PERSON) Severity(com.khartec.waltz.model.Severity) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityKind(com.khartec.waltz.model.EntityKind) ListUtilities.randomPick(com.khartec.waltz.common.ListUtilities.randomPick) List(java.util.List) Stream(java.util.stream.Stream) DIConfiguration(com.khartec.waltz.service.DIConfiguration) DSLContext(org.jooq.DSLContext) APPLICATION(com.khartec.waltz.schema.tables.Application.APPLICATION) CHANGE_LOG(com.khartec.waltz.schema.tables.ChangeLog.CHANGE_LOG) Collectors.toSet(java.util.stream.Collectors.toSet) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext) ChangeLogRecord(com.khartec.waltz.schema.tables.records.ChangeLogRecord)

Example 2 with APPLICATION

use of com.khartec.waltz.schema.tables.Application.APPLICATION in project waltz by khartec.

the class PhysicalSpecificationGenerator method main.

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<Long> appIds = dsl.select(APPLICATION.ID).from(APPLICATION).fetch(APPLICATION.ID);
    List<PhysicalSpecificationRecord> records = appIds.stream().flatMap(appId -> IntStream.range(0, rnd.nextInt(4)).mapToObj(i -> tuple(appId, i))).map(t -> {
        String name = mkName(t.v2);
        PhysicalSpecificationRecord record = dsl.newRecord(PHYSICAL_SPECIFICATION);
        record.setOwningEntityId(t.v1);
        record.setOwningEntityKind(EntityKind.APPLICATION.name());
        record.setFormat(randomPick(DataFormatKind.values()).name());
        record.setProvenance("DEMO");
        record.setDescription("Desc " + name + " " + t.v2);
        record.setName(name);
        record.setExternalId("ext-" + t.v1 + "." + t.v2);
        record.setLastUpdatedBy("admin");
        return record;
    }).collect(Collectors.toList());
    System.out.println("---deleting old demo records");
    dsl.deleteFrom(PHYSICAL_SPECIFICATION).where(PHYSICAL_SPECIFICATION.PROVENANCE.eq("DEMO")).execute();
    System.out.println("---saving: " + records.size());
    dsl.batchInsert(records).execute();
    System.out.println("---done");
}
Also used : IntStream(java.util.stream.IntStream) PHYSICAL_SPECIFICATION(com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION) ArrayUtilities.randomPick(com.khartec.waltz.common.ArrayUtilities.randomPick) Random(java.util.Random) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityKind(com.khartec.waltz.model.EntityKind) List(java.util.List) DIConfiguration(com.khartec.waltz.service.DIConfiguration) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) PhysicalSpecificationRecord(com.khartec.waltz.schema.tables.records.PhysicalSpecificationRecord) DataFormatKind(com.khartec.waltz.model.physical_specification.DataFormatKind) DSLContext(org.jooq.DSLContext) APPLICATION(com.khartec.waltz.schema.tables.Application.APPLICATION) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PhysicalSpecificationRecord(com.khartec.waltz.schema.tables.records.PhysicalSpecificationRecord) DSLContext(org.jooq.DSLContext)

Example 3 with APPLICATION

use of com.khartec.waltz.schema.tables.Application.APPLICATION 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)

Aggregations

EntityKind (com.khartec.waltz.model.EntityKind)3 APPLICATION (com.khartec.waltz.schema.tables.Application.APPLICATION)3 List (java.util.List)3 DSLContext (org.jooq.DSLContext)3 DIConfiguration (com.khartec.waltz.service.DIConfiguration)2 Collectors (java.util.stream.Collectors)2 ApplicationContext (org.springframework.context.ApplicationContext)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 ArrayUtilities.randomPick (com.khartec.waltz.common.ArrayUtilities.randomPick)1 ListUtilities.randomPick (com.khartec.waltz.common.ListUtilities.randomPick)1 SetUtilities.orderedUnion (com.khartec.waltz.common.SetUtilities.orderedUnion)1 DatabaseVendorSpecific (com.khartec.waltz.data.DatabaseVendorSpecific)1 FullTextSearch (com.khartec.waltz.data.FullTextSearch)1 JooqUtilities (com.khartec.waltz.data.JooqUtilities)1 SearchUtilities.mkRelevancyComparator (com.khartec.waltz.data.SearchUtilities.mkRelevancyComparator)1 SearchUtilities.mkTerms (com.khartec.waltz.data.SearchUtilities.mkTerms)1 ApplicationDao (com.khartec.waltz.data.application.ApplicationDao)1 Severity (com.khartec.waltz.model.Severity)1 Application (com.khartec.waltz.model.application.Application)1 EntitySearchOptions (com.khartec.waltz.model.entity_search.EntitySearchOptions)1