use of com.khartec.waltz.data.measurable.MeasurableDao 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 ...");
}
Aggregations