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();
});
}
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");
}
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);
}
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;
}
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;
}
Aggregations