use of com.khartec.waltz.schema.tables.Measurable.MEASURABLE in project waltz by khartec.
the class MeasurableRelationshipsGenerator method main.
public static void main(String[] args) throws IOException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
MeasurableDao measurableDao = ctx.getBean(MeasurableDao.class);
List<Measurable> regions = loadMeasurablesForCategory(measurableDao, REGION_CATEGORY_EXTERNAL_ID);
List<Measurable> functions = loadMeasurablesForCategory(measurableDao, FUNCTION_CATEGORY_EXTERNAL_ID);
final int maxRelationshipCount = 50;
final int minRelationshipCount = 5;
final Random random = new Random();
List<EntityRelationshipRecord> relationshipRecords = functions.stream().flatMap(function -> {
int relationshipCount = random.nextInt(maxRelationshipCount - minRelationshipCount) + minRelationshipCount;
return IntStream.range(0, relationshipCount).mapToObj(i -> ListUtilities.randomPick(regions)).distinct().map(region -> creatRelationshipRecord(function, region, ArrayUtilities.randomPick(RelationshipKind.RELATES_TO)));
}).collect(toList());
System.out.println("Deleting existing Measurable relationships ...");
int deleteCount = dsl.deleteFrom(ENTITY_RELATIONSHIP).where(ENTITY_RELATIONSHIP.PROVENANCE.eq(PROVENANCE).and(ENTITY_RELATIONSHIP.KIND_A.eq(EntityKind.MEASURABLE.name())).and(ENTITY_RELATIONSHIP.KIND_B.eq(EntityKind.MEASURABLE.name()))).execute();
System.out.println("Deleted: " + deleteCount + " existing Measurable relationships");
System.out.println("Inserting Measurable relationships ...");
int[] insertCount = dsl.batchInsert(relationshipRecords).execute();
System.out.println("Inserted: " + insertCount.length + " Measurable relationships ...");
}
use of com.khartec.waltz.schema.tables.Measurable.MEASURABLE in project waltz by khartec.
the class MeasurablesGenerator method generateRegions.
private static void generateRegions(DSLContext dsl) throws IOException {
List<String> lines = readLines(OrgUnitGenerator.class.getResourceAsStream("/regions.csv"));
System.out.println("Deleting existing Regions & Countries ...");
int deletedCount = dsl.deleteFrom(MEASURABLE).where(MEASURABLE.MEASURABLE_CATEGORY_ID.in(DSL.select(MEASURABLE_CATEGORY.ID).from(MEASURABLE_CATEGORY).where(MEASURABLE_CATEGORY.EXTERNAL_ID.eq(REGION_CATEGORY_EXTERNAL_ID)))).and(MEASURABLE.PROVENANCE.eq("demo")).execute();
System.out.println("Deleted: " + deletedCount + " existing Regions & Countries");
Map<String, Map<String, Set<String>>> regionHierarchy = lines.stream().skip(1).map(line -> StringUtils.splitPreserveAllTokens(line, ",")).filter(cells -> notEmpty(cells[0]) && notEmpty(cells[6]) && notEmpty(cells[5])).map(cells -> Tuple.tuple(cells[0], cells[6], cells[5])).collect(groupingBy(t -> t.v3, groupingBy(t -> t.v2, mapping(t -> t.v1, toSet()))));
final long measurableCategoryId = dsl.select(MEASURABLE_CATEGORY.ID).from(MEASURABLE_CATEGORY).where(MEASURABLE_CATEGORY.EXTERNAL_ID.eq(REGION_CATEGORY_EXTERNAL_ID)).fetchAny().value1();
AtomicInteger insertCount = new AtomicInteger(0);
regionHierarchy.forEach((region, subRegionMap) -> {
final long regionId = dsl.insertInto(MEASURABLE).set(createRegion(null, region, measurableCategoryId, false)).returning(MEASURABLE.ID).fetchOne().getId();
insertCount.incrementAndGet();
subRegionMap.forEach((subRegion, countries) -> {
final long subRegionId = dsl.insertInto(MEASURABLE).set(createRegion(regionId, subRegion, measurableCategoryId, true)).returning(MEASURABLE.ID).fetchOne().getId();
insertCount.incrementAndGet();
insertCount.addAndGet(dsl.batchInsert(countries.stream().map(country -> createRegion(subRegionId, country, measurableCategoryId, true)).collect(toList())).execute().length);
});
});
System.out.println("Inserted: " + insertCount + " Regions & Countries");
}
use of com.khartec.waltz.schema.tables.Measurable.MEASURABLE in project waltz by khartec.
the class SqlServerMeasurableSearch method search.
@Override
public List<Measurable> search(DSLContext dsl, String query, EntitySearchOptions options) {
List<String> terms = mkTerms(query);
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)));
List<Measurable> measurablesViaExternalId = dsl.selectDistinct(MEASURABLE.fields()).from(MEASURABLE).where(externalIdCondition).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).orderBy(MEASURABLE.NAME).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
List<Measurable> measurablesViaFullText = dsl.selectFrom(MEASURABLE).where(JooqUtilities.MSSQL.mkContainsPrefix(terms)).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
return new ArrayList<>(orderedUnion(measurablesViaExternalId, measurablesViaName, measurablesViaFullText));
}
Aggregations