use of com.khartec.waltz.schema.tables.records.EntityRelationshipRecord 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.records.EntityRelationshipRecord in project waltz by khartec.
the class MeasurableRelationshipsGenerator method creatRelationshipRecord.
private static EntityRelationshipRecord creatRelationshipRecord(Measurable function, Measurable region, RelationshipKind relationshipKind) {
EntityRelationshipRecord record = new EntityRelationshipRecord();
record.setIdA(function.id().get());
record.setKindA(EntityKind.MEASURABLE.name());
record.setIdB(region.id().get());
record.setKindB(EntityKind.MEASURABLE.name());
record.setRelationship(relationshipKind.name());
record.setProvenance(PROVENANCE);
return record;
}
use of com.khartec.waltz.schema.tables.records.EntityRelationshipRecord in project waltz by khartec.
the class ChangeInitiativeGenerator method maybeBuildGroupLink.
private static Stream<TableRecord<?>> maybeBuildGroupLink(ChangeInitiativeRecord r, List<Long> groupIds) {
if (rnd.nextInt(100) < 5) {
EntityRelationshipRecord record = new EntityRelationshipRecord();
record.setKindA(APP_GROUP.name());
record.setIdA(ListUtilities.randomPick(groupIds));
record.setKindB(EntityKind.CHANGE_INITIATIVE.name());
record.setIdB(r.getId());
record.setRelationship(RelationshipKind.RELATES_TO.name());
return Stream.of(record);
} else {
return Stream.empty();
}
}
Aggregations