Search in sources :

Example 1 with MeasurableRecord

use of org.finos.waltz.schema.tables.records.MeasurableRecord in project waltz by khartec.

the class MeasurableHelper method createMeasurable.

public long createMeasurable(String name, long categoryId) {
    return dsl.select(MEASURABLE.ID).from(MEASURABLE).where(MEASURABLE.EXTERNAL_ID.eq(name)).and(MEASURABLE.MEASURABLE_CATEGORY_ID.eq(categoryId)).fetchOptional(MEASURABLE.ID).orElseGet(() -> {
        MeasurableRecord record = dsl.newRecord(MEASURABLE);
        record.setMeasurableCategoryId(categoryId);
        record.setName(name);
        record.setDescription(name);
        record.setConcrete(true);
        record.setExternalId(name);
        record.setProvenance(PROVENANCE);
        record.setLastUpdatedBy(LAST_UPDATE_USER);
        record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
        record.store();
        return record.getId();
    });
}
Also used : MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord)

Example 2 with MeasurableRecord

use of org.finos.waltz.schema.tables.records.MeasurableRecord in project waltz by khartec.

the class MeasurableStressGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    LOG.info("Ensuring category exists");
    Long categoryId = WaltzUtilities.getOrCreateMeasurableCategory(dsl, "STRESS", "Stress Test");
    LOG.info("Deleting existing records");
    dsl.deleteFrom(MEASURABLE).where(MEASURABLE.MEASURABLE_CATEGORY_ID.eq(categoryId)).execute();
    LOG.info("Generating records");
    List<MeasurableRecord> records = mkNodes(1, "").stream().map(t -> {
        MeasurableRecord mr = new MeasurableRecord();
        mr.setExternalId(t.v1);
        mr.setExternalParentId(t.v2);
        mr.setDescription(t.v1);
        mr.setName(t.v1);
        mr.setConcrete(true);
        mr.setLastUpdatedBy("admin");
        mr.setProvenance("stress");
        mr.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
        mr.setMeasurableCategoryId(categoryId);
        return mr;
    }).collect(Collectors.toList());
    LOG.info("Inserting {} records into category {}", records.size(), categoryId);
    dsl.batchInsert(records).execute();
    LOG.info("Done");
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) DIConfiguration(org.finos.waltz.service.DIConfiguration) Random(java.util.Random) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ArrayList(java.util.ArrayList) WaltzUtilities(org.finos.waltz.jobs.WaltzUtilities) RandomUtilities(org.finos.waltz.common.RandomUtilities) Tuple2(org.jooq.lambda.tuple.Tuple2) List(java.util.List) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) MEASURABLE(org.finos.waltz.schema.tables.Measurable.MEASURABLE) MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord) DSLContext(org.jooq.DSLContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord) DSLContext(org.jooq.DSLContext)

Example 3 with MeasurableRecord

use of org.finos.waltz.schema.tables.records.MeasurableRecord in project waltz by khartec.

the class ProcessGenerator method setupMeasurables.

private void setupMeasurables(DSLContext dsl, long category) {
    List<MeasurableRecord> records = new ArrayList<>();
    for (long g = 1; g <= NUM_PROCESS_GROUPS; g++) {
        System.out.println("mkGroup: " + g);
        MeasurableRecord record = dsl.newRecord(MEASURABLE);
        record.setDescription("Process Group: " + g);
        record.setName("Process Group " + g);
        record.setMeasurableCategoryId(category);
        record.setConcrete(false);
        record.setProvenance(SAMPLE_DATA_PROVENANCE);
        record.setLastUpdatedBy("admin");
        record.insert();
        long groupId = record.getId();
        for (long p = 0; p < NUM_PROCESSES_IN_GROUP; p++) {
            MeasurableRecord record2 = dsl.newRecord(MEASURABLE);
            String name = randomPick(p1) + " " + randomPick(p2);
            record2.setDescription("Process: " + name);
            record2.setName(name);
            record2.setParentId(groupId);
            record2.setMeasurableCategoryId(category);
            record2.setConcrete(true);
            record2.setProvenance(SAMPLE_DATA_PROVENANCE);
            record2.setLastUpdatedBy("admin");
            records.add(record2);
            System.out.print(".");
        }
    }
    int[] rcs = dsl.batchInsert(records).execute();
    System.out.println("\nBatch inserted: " + rcs.length);
}
Also used : MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord) ArrayList(java.util.ArrayList)

Example 4 with MeasurableRecord

use of org.finos.waltz.schema.tables.records.MeasurableRecord in project waltz by khartec.

the class GenericTaxonomyLoader method mkMeasurableRecord.

private MeasurableRecord mkMeasurableRecord(Long categoryId, String name, String desc, String parentName, Timestamp creationTime) {
    MeasurableRecord r = new MeasurableRecord();
    r.setMeasurableCategoryId(categoryId);
    r.setName(name);
    r.setDescription(desc);
    r.setConcrete(true);
    r.setExternalId(toExtId(name));
    r.setLastUpdatedAt(creationTime);
    r.setLastUpdatedBy("admin");
    r.setProvenance("SAMPLE");
    if (parentName != null) {
        r.setExternalParentId(toExtId(parentName));
    }
    return r;
}
Also used : MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord)

Example 5 with MeasurableRecord

use of org.finos.waltz.schema.tables.records.MeasurableRecord in project waltz by khartec.

the class MeasurableGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    System.out.println("Importing data for category: " + category);
    Supplier<List<String>> lineSupplier = Unchecked.supplier(() -> readLines(getClass().getResourceAsStream("/" + category + ".tsv")));
    long categoryId = getCategory(dsl);
    List<String> lines = lineSupplier.get();
    List<String[]> sheet = lineSupplier.get().stream().skip(1).map(line -> line.split("\\t")).filter(cells -> cells.length > 3).collect(Collectors.toList());
    List<MeasurableRecord> records = sheet.stream().map(cells -> {
        MeasurableRecord record = dsl.newRecord(MEASURABLE);
        record.setName(cells[2]);
        record.setDescription(cells[3]);
        record.setMeasurableCategoryId(categoryId);
        record.setLastUpdatedBy("admin");
        record.setProvenance(SAMPLE_DATA_PROVENANCE);
        record.setConcrete(!StringUtilities.isEmpty(cells[1]));
        record.setExternalId(category + " _ " + cells[0]);
        return record;
    }).collect(Collectors.toList());
    dsl.batchStore(records).execute();
    sheet.stream().filter(cells -> !StringUtilities.isEmpty(cells[1])).forEach(cells -> {
        String pExtId = cells[1];
        System.out.println(Arrays.toString(cells));
        long pId = dsl.select(MEASURABLE.ID).from(MEASURABLE).where(MEASURABLE.EXTERNAL_ID.eq(category + " _ " + pExtId)).fetchOne(MEASURABLE.ID);
        dsl.update(MEASURABLE).set(MEASURABLE.PARENT_ID, pId).where(MEASURABLE.EXTERNAL_ID.equal(category + " _ " + cells[0])).execute();
    });
    EntityHierarchyService ehSvc = ctx.getBean(EntityHierarchyService.class);
    ehSvc.buildFor(EntityKind.MEASURABLE);
    return null;
}
Also used : Arrays(java.util.Arrays) Checks.checkNotEmpty(org.finos.waltz.common.Checks.checkNotEmpty) Unchecked(org.jooq.lambda.Unchecked) IOUtilities.readLines(org.finos.waltz.common.IOUtilities.readLines) EntityKind(org.finos.waltz.model.EntityKind) MeasurableCategoryRecord(org.finos.waltz.schema.tables.records.MeasurableCategoryRecord) MEASURABLE_CATEGORY(org.finos.waltz.schema.tables.MeasurableCategory.MEASURABLE_CATEGORY) ApplicationContext(org.springframework.context.ApplicationContext) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) SelectConditionStep(org.jooq.SelectConditionStep) List(java.util.List) MEASURABLE(org.finos.waltz.schema.tables.Measurable.MEASURABLE) MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord) Map(java.util.Map) DSLContext(org.jooq.DSLContext) StringUtilities(org.finos.waltz.common.StringUtilities) EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService) MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord) EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService) DSLContext(org.jooq.DSLContext) List(java.util.List)

Aggregations

MeasurableRecord (org.finos.waltz.schema.tables.records.MeasurableRecord)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 MEASURABLE (org.finos.waltz.schema.tables.Measurable.MEASURABLE)2 DSLContext (org.jooq.DSLContext)2 Arrays (java.util.Arrays)1 Map (java.util.Map)1 Random (java.util.Random)1 Supplier (java.util.function.Supplier)1 Checks.checkNotEmpty (org.finos.waltz.common.Checks.checkNotEmpty)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 IOUtilities.readLines (org.finos.waltz.common.IOUtilities.readLines)1 RandomUtilities (org.finos.waltz.common.RandomUtilities)1 StringUtilities (org.finos.waltz.common.StringUtilities)1 WaltzUtilities (org.finos.waltz.jobs.WaltzUtilities)1 EntityKind (org.finos.waltz.model.EntityKind)1 MEASURABLE_CATEGORY (org.finos.waltz.schema.tables.MeasurableCategory.MEASURABLE_CATEGORY)1 MeasurableCategoryRecord (org.finos.waltz.schema.tables.records.MeasurableCategoryRecord)1 DIConfiguration (org.finos.waltz.service.DIConfiguration)1