Search in sources :

Example 41 with DSLContext

use of org.jooq.DSLContext in project waltz by khartec.

the class ChangeInitiativeGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<Long> groupIds = dsl.select(APPLICATION_GROUP.ID).from(APPLICATION_GROUP).fetch(APPLICATION_GROUP.ID);
    List<String> employeeIds = dsl.select(PERSON.EMPLOYEE_ID).from(PERSON).fetch(PERSON.EMPLOYEE_ID);
    List<Long> orgUnitIds = dsl.select(ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT).fetch(ORGANISATIONAL_UNIT.ID);
    List<TableRecord<?>> records = LongStream.range(0, 400).mapToObj(i -> {
        String name = randomPick(p1) + " " + randomPick(p2) + " " + randomPick(p3);
        Long ouId = randomPick(orgUnitIds.toArray(new Long[0]));
        return Tuple.tuple(i, name, ouId);
    }).map(t -> buildChangeInitiativeRecord(t)).flatMap(r -> Stream.concat(Stream.of(r), buildLinks(r, groupIds, employeeIds))).collect(toList());
    System.out.println("-- deleting");
    dsl.deleteFrom(CHANGE_INITIATIVE).execute();
    System.out.println("-- inserting");
    dsl.batchInsert(records).execute();
    System.out.println(" -- done");
}
Also used : IntStream(java.util.stream.IntStream) InvolvementRecord(com.khartec.waltz.schema.tables.records.InvolvementRecord) Random(java.util.Random) EntityKind(com.khartec.waltz.model.EntityKind) Tuple3(org.jooq.lambda.tuple.Tuple3) DIConfiguration(com.khartec.waltz.service.DIConfiguration) DSLContext(org.jooq.DSLContext) APP_GROUP(com.khartec.waltz.model.EntityKind.APP_GROUP) LongStream(java.util.stream.LongStream) LifecyclePhase(com.khartec.waltz.model.application.LifecyclePhase) ArrayUtilities.randomPick(com.khartec.waltz.common.ArrayUtilities.randomPick) ListUtilities(com.khartec.waltz.common.ListUtilities) PERSON(com.khartec.waltz.schema.tables.Person.PERSON) TableRecord(org.jooq.TableRecord) Instant(java.time.Instant) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Date(java.sql.Date) List(java.util.List) ORGANISATIONAL_UNIT(com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) Collectors.toList(java.util.stream.Collectors.toList) Tuple(org.jooq.lambda.tuple.Tuple) Stream(java.util.stream.Stream) EntityRelationshipRecord(com.khartec.waltz.schema.tables.records.EntityRelationshipRecord) APPLICATION_GROUP(com.khartec.waltz.schema.tables.ApplicationGroup.APPLICATION_GROUP) RelationshipKind(com.khartec.waltz.model.entity_relationship.RelationshipKind) CHANGE_INITIATIVE(com.khartec.waltz.schema.tables.ChangeInitiative.CHANGE_INITIATIVE) ChangeInitiativeRecord(com.khartec.waltz.schema.tables.records.ChangeInitiativeRecord) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext) TableRecord(org.jooq.TableRecord)

Example 42 with DSLContext

use of org.jooq.DSLContext 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 43 with DSLContext

use of org.jooq.DSLContext in project waltz by khartec.

the class DataTypeGenerator method main.

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    dsl.deleteFrom(DATA_TYPE).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "BOOK").set(DATA_TYPE.DESCRIPTION, "Book Data").set(DATA_TYPE.NAME, "Book Data").set(DATA_TYPE.ID, 1000L).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "PARTY").set(DATA_TYPE.DESCRIPTION, "Party Data").set(DATA_TYPE.NAME, "Counterparty etc.").set(DATA_TYPE.ID, 2000L).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "PRICING").set(DATA_TYPE.DESCRIPTION, "Pricing Data").set(DATA_TYPE.NAME, "Pricing Data").set(DATA_TYPE.ID, 3000L).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "TRADE").set(DATA_TYPE.DESCRIPTION, "Trade Data").set(DATA_TYPE.NAME, "Transactions etc.").set(DATA_TYPE.ID, 4000L).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "RATE").set(DATA_TYPE.DESCRIPTION, "Rates").set(DATA_TYPE.NAME, "Interest rates etc").set(DATA_TYPE.ID, 5000L).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "CURRENCY").set(DATA_TYPE.DESCRIPTION, "Currency").set(DATA_TYPE.NAME, "Currencies etc").set(DATA_TYPE.ID, 6000L).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "VIRTUAL_CURRENCIES").set(DATA_TYPE.DESCRIPTION, "Virtual Currencies eg: Bitcoin").set(DATA_TYPE.NAME, "Virtual Currencies").set(DATA_TYPE.ID, 6100L).set(DATA_TYPE.PARENT_ID, 6000L).execute();
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext)

Example 44 with DSLContext

use of org.jooq.DSLContext in project waltz by khartec.

the class DatabaseGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<String> codes = dsl.select(APPLICATION.ASSET_CODE).from(APPLICATION).fetch(APPLICATION.ASSET_CODE);
    List<DatabaseInformationRecord> databaseRecords = new LinkedList<>();
    for (int i = 0; i < 300; i++) {
        int num = rnd.nextInt(10);
        for (int j = 0; j < num; j++) {
            SoftwarePackage pkg = ArrayUtilities.randomPick(DatabaseSoftwarePackages.dbs);
            DatabaseInformationRecord databaseRecord = dsl.newRecord(DATABASE_INFORMATION);
            databaseRecord.setDatabaseName("DB_LON_" + i + "_" + j);
            databaseRecord.setInstanceName("DB_INST_" + i);
            databaseRecord.setEnvironment(ArrayUtilities.randomPick("PROD", "PROD", "QA", "DEV", "DEV"));
            databaseRecord.setDbmsVendor(pkg.vendor());
            databaseRecord.setDbmsName(pkg.name());
            databaseRecord.setDbmsVersion(pkg.version());
            databaseRecord.setExternalId("ext_" + i + "_" + j);
            databaseRecord.setProvenance("RANDOM_GENERATOR");
            databaseRecord.setAssetCode(randomPick(codes));
            databaseRecord.setLifecycleStatus(ArrayUtilities.randomPick(LifecycleStatus.values()).toString());
            databaseRecord.setEndOfLifeDate(rnd.nextInt(10) > 5 ? Date.valueOf(LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3))) : null);
            databaseRecords.add(databaseRecord);
        }
    }
    // insert duplicate database instance records (more than one app using the same database)
    SoftwarePackage dupDbPackage = ArrayUtilities.randomPick(DatabaseSoftwarePackages.dbs);
    String dupDbEnvironment = ArrayUtilities.randomPick("PROD", "PROD", "QA", "DEV", "DEV");
    Date dupDbEolDate = rnd.nextInt(10) > 5 ? Date.valueOf(LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3))) : null;
    for (int i = 0; i < 10; i++) {
        DatabaseInformationRecord databaseRecord = dsl.newRecord(DATABASE_INFORMATION);
        databaseRecord.setDatabaseName("DB_LON_REF_DATA");
        databaseRecord.setInstanceName("DB_INST_REF_DATA");
        databaseRecord.setEnvironment(dupDbEnvironment);
        databaseRecord.setDbmsVendor(dupDbPackage.vendor());
        databaseRecord.setDbmsName(dupDbPackage.name());
        databaseRecord.setDbmsVersion(dupDbPackage.version());
        databaseRecord.setExternalId("ext_ref_data");
        databaseRecord.setProvenance("RANDOM_GENERATOR");
        databaseRecord.setAssetCode(randomPick(codes));
        databaseRecord.setLifecycleStatus(ArrayUtilities.randomPick(LifecycleStatus.values()).toString());
        databaseRecord.setEndOfLifeDate(dupDbEolDate);
        databaseRecords.add(databaseRecord);
    }
    System.out.println("-- deleting db records");
    dsl.deleteFrom(DATABASE_INFORMATION).where(DATABASE_INFORMATION.PROVENANCE.eq("RANDOM_GENERATOR")).execute();
    System.out.println("-- storing db records ( " + databaseRecords.size() + " )");
    databaseRecords.forEach(r -> r.store());
    System.out.println("-- done inserting db records");
    System.out.println("-- done");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DatabaseInformationRecord(com.khartec.waltz.schema.tables.records.DatabaseInformationRecord) DSLContext(org.jooq.DSLContext) SoftwarePackage(com.khartec.waltz.model.software_catalog.SoftwarePackage) LinkedList(java.util.LinkedList) Date(java.sql.Date) LocalDate(java.time.LocalDate)

Example 45 with DSLContext

use of org.jooq.DSLContext in project waltz by khartec.

the class EndUserAppInvolvmentGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<Long> appIds = dsl.select(END_USER_APPLICATION.ID).from(END_USER_APPLICATION).fetch(END_USER_APPLICATION.ID);
    List<String> empIds = dsl.select(PERSON.EMPLOYEE_ID).from(PERSON).innerJoin(PERSON_HIERARCHY).on(PERSON.EMPLOYEE_ID.eq(PERSON_HIERARCHY.EMPLOYEE_ID)).where(PERSON_HIERARCHY.LEVEL.lt(4)).fetch(PERSON.EMPLOYEE_ID);
    List<InvolvementRecord> records = ListUtilities.map(appIds, id -> {
        InvolvementRecord record = dsl.newRecord(INVOLVEMENT);
        record.setProvenance("RANDOM_GENERATOR");
        record.setEmployeeId(randomPick(empIds));
        record.setEntityId(id);
        record.setEntityKind(EntityKind.END_USER_APPLICATION.name());
        record.setKindId(Long.valueOf(rnd.nextInt(13) + 1));
        return record;
    });
    System.out.println("---saving: " + records.size());
    dsl.batchInsert(records).execute();
    System.out.println("---done");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext) InvolvementRecord(com.khartec.waltz.schema.tables.records.InvolvementRecord)

Aggregations

DSLContext (org.jooq.DSLContext)109 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)55 Connection (java.sql.Connection)23 SQLException (java.sql.SQLException)17 List (java.util.List)17 DIConfiguration (com.khartec.waltz.service.DIConfiguration)14 Collectors (java.util.stream.Collectors)14 EntityKind (com.khartec.waltz.model.EntityKind)11 ArrayList (java.util.ArrayList)9 DSL (org.jooq.impl.DSL)9 EntityReference (com.khartec.waltz.model.EntityReference)8 Timestamp (java.sql.Timestamp)8 Random (java.util.Random)8 IntStream (java.util.stream.IntStream)8 Application (com.khartec.waltz.model.application.Application)7 LogicalFlowDao (com.khartec.waltz.data.logical_flow.LogicalFlowDao)6 OrganisationalUnit (com.khartec.waltz.model.orgunit.OrganisationalUnit)6 Field (org.jooq.Field)6 Record1 (org.jooq.Record1)6 Test (org.junit.Test)6