use of org.finos.waltz.schema.tables.Measurable.MEASURABLE 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.Measurable.MEASURABLE in project waltz by khartec.
the class BookmarkGenerator method create.
@Override
public Map<String, Integer> create(ApplicationContext ctx) {
DSLContext dsl = getDsl(ctx);
List<EntityReference> appRefs = dsl.select(APPLICATION.NAME, APPLICATION.ID).from(APPLICATION).fetch(r -> EntityReference.mkRef(EntityKind.APPLICATION, r.value2(), r.value1()));
List<EntityReference> measurableRefs = dsl.select(MEASURABLE.NAME, MEASURABLE.ID).from(MEASURABLE).fetch(r -> EntityReference.mkRef(EntityKind.MEASURABLE, r.value2(), r.value1()));
List<EntityReference> ouRefs = dsl.select(ORGANISATIONAL_UNIT.NAME, ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT).fetch(r -> EntityReference.mkRef(EntityKind.ORG_UNIT, r.value2(), r.value1()));
List<EntityReference> appGroupRefs = dsl.select(APPLICATION_GROUP.NAME, APPLICATION_GROUP.ID).from(APPLICATION_GROUP).fetch(r -> EntityReference.mkRef(EntityKind.APP_GROUP, r.value2(), r.value1()));
List<EntityReference> refs = ListUtilities.concat(appRefs, measurableRefs, ouRefs, appGroupRefs);
List<BookmarkRecord> bookmarks = refs.stream().flatMap(r -> RandomUtilities.randomlySizedIntStream(2, 15).mapToObj(idx -> {
BookmarkRecord record = dsl.newRecord(BOOKMARK);
record.setParentKind(r.kind().name());
record.setParentId(r.id());
record.setTitle(mkText(r.name().get()));
record.setDescription(mkText(r.name().get()));
record.setKind(randomPick(bookmarkKinds));
record.setUrl(mkUrl(r.name().get()));
record.setProvenance(SAMPLE_DATA_PROVENANCE);
record.setLastUpdatedBy("admin");
record.setUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
record.setCreatedAt(DateTimeUtilities.nowUtcTimestamp());
return record;
})).collect(Collectors.toList());
dsl.batchStore(bookmarks).execute();
return null;
}
use of org.finos.waltz.schema.tables.Measurable.MEASURABLE 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;
}
use of org.finos.waltz.schema.tables.Measurable.MEASURABLE in project waltz by khartec.
the class MariaMeasurableSearch method searchFullText.
@Override
public List<Measurable> searchFullText(DSLContext dsl, EntitySearchOptions options) {
List<String> terms = mkTerms(options.searchQuery());
if (terms.isEmpty()) {
return emptyList();
}
Condition externalIdCondition = terms.stream().map(term -> MEASURABLE.EXTERNAL_ID.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
Condition entityLifecycleCondition = MEASURABLE.ENTITY_LIFECYCLE_STATUS.in(options.entityLifecycleStatuses());
List<Measurable> measurablesViaExternalId = dsl.selectDistinct(MEASURABLE.fields()).from(MEASURABLE).where(externalIdCondition).and(entityLifecycleCondition).orderBy(MEASURABLE.EXTERNAL_ID).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
Condition nameCondition = terms.stream().map(term -> MEASURABLE.NAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
List<Measurable> measurablesViaName = dsl.selectDistinct(MEASURABLE.fields()).from(MEASURABLE).where(nameCondition).and(entityLifecycleCondition).orderBy(MEASURABLE.NAME).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
List<Measurable> measurablesViaFullText = dsl.fetch(FULL_TEXT_QUERY, options.searchQuery(), entityLifecycleCondition, options.limit()).map(MeasurableDao.TO_DOMAIN_MAPPER);
return new ArrayList<>(orderedUnion(measurablesViaExternalId, measurablesViaName, measurablesViaFullText));
}
Aggregations