Search in sources :

Example 1 with ENTITY_RELATIONSHIP

use of com.khartec.waltz.schema.tables.EntityRelationship.ENTITY_RELATIONSHIP 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)

Aggregations

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 EntityRelationshipRecord (com.khartec.waltz.schema.tables.records.EntityRelationshipRecord)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