Search in sources :

Example 1 with EntityRelationshipRecord

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 ...");
}
Also used : IntStream(java.util.stream.IntStream) Measurable(com.khartec.waltz.model.measurable.Measurable) DSL(org.jooq.impl.DSL) ListUtilities(com.khartec.waltz.common.ListUtilities) IOException(java.io.IOException) Random(java.util.Random) MEASURABLE(com.khartec.waltz.schema.tables.Measurable.MEASURABLE) ENTITY_RELATIONSHIP(com.khartec.waltz.schema.tables.EntityRelationship.ENTITY_RELATIONSHIP) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityKind(com.khartec.waltz.model.EntityKind) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) DIConfiguration(com.khartec.waltz.service.DIConfiguration) EntityRelationshipRecord(com.khartec.waltz.schema.tables.records.EntityRelationshipRecord) RelationshipKind(com.khartec.waltz.model.entity_relationship.RelationshipKind) MEASURABLE_CATEGORY(com.khartec.waltz.schema.tables.MeasurableCategory.MEASURABLE_CATEGORY) DSLContext(org.jooq.DSLContext) ArrayUtilities(com.khartec.waltz.common.ArrayUtilities) MeasurableDao(com.khartec.waltz.data.measurable.MeasurableDao) Measurable(com.khartec.waltz.model.measurable.Measurable) EntityRelationshipRecord(com.khartec.waltz.schema.tables.records.EntityRelationshipRecord) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Random(java.util.Random) MeasurableDao(com.khartec.waltz.data.measurable.MeasurableDao) DSLContext(org.jooq.DSLContext)

Example 2 with EntityRelationshipRecord

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;
}
Also used : EntityRelationshipRecord(com.khartec.waltz.schema.tables.records.EntityRelationshipRecord)

Example 3 with EntityRelationshipRecord

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();
    }
}
Also used : EntityRelationshipRecord(com.khartec.waltz.schema.tables.records.EntityRelationshipRecord)

Aggregations

EntityRelationshipRecord (com.khartec.waltz.schema.tables.records.EntityRelationshipRecord)3 ArrayUtilities (com.khartec.waltz.common.ArrayUtilities)1 ListUtilities (com.khartec.waltz.common.ListUtilities)1 MeasurableDao (com.khartec.waltz.data.measurable.MeasurableDao)1 EntityKind (com.khartec.waltz.model.EntityKind)1 RelationshipKind (com.khartec.waltz.model.entity_relationship.RelationshipKind)1 Measurable (com.khartec.waltz.model.measurable.Measurable)1 ENTITY_RELATIONSHIP (com.khartec.waltz.schema.tables.EntityRelationship.ENTITY_RELATIONSHIP)1 MEASURABLE (com.khartec.waltz.schema.tables.Measurable.MEASURABLE)1 MEASURABLE_CATEGORY (com.khartec.waltz.schema.tables.MeasurableCategory.MEASURABLE_CATEGORY)1 DIConfiguration (com.khartec.waltz.service.DIConfiguration)1 IOException (java.io.IOException)1 List (java.util.List)1 Random (java.util.Random)1 Collectors.toList (java.util.stream.Collectors.toList)1 IntStream (java.util.stream.IntStream)1 DSLContext (org.jooq.DSLContext)1 DSL (org.jooq.impl.DSL)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1