Search in sources :

Example 1 with MEASURABLE

use of org.finos.waltz.schema.Tables.MEASURABLE in project waltz by khartec.

the class MeasurableRatingGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    List<Long> appIds = getAppIds(dsl);
    List<Long> mIds = dsl.select(MEASURABLE.ID).from(MEASURABLE).where(MEASURABLE.CONCRETE.isTrue()).fetch().getValues(MEASURABLE.ID);
    List<MeasurableRatingRecord> records = appIds.stream().flatMap(appId -> randomlySizedIntStream(0, MAX_RATINGS_PER_APP).mapToObj(idx -> Tuple.tuple(appId, randomPick(mIds)))).map(t -> {
        MeasurableRatingRecord record = dsl.newRecord(MEASURABLE_RATING);
        record.setEntityId(t.v1);
        record.setEntityKind(EntityKind.APPLICATION.name());
        record.setRating(randomPick("R", "A", "G"));
        record.setMeasurableId(t.v2);
        record.setLastUpdatedBy("admin");
        record.setProvenance(SAMPLE_DATA_PROVENANCE);
        return record;
    }).collect(Collectors.toList());
    Set<MeasurableRatingRecord> dedupedRecords = uniqBy(records, r -> Tuple.tuple(r.getMeasurableId(), r.getEntityId()));
    dsl.batchStore(dedupedRecords).execute();
    return null;
}
Also used : EntityKind(org.finos.waltz.model.EntityKind) SetUtilities.uniqBy(org.finos.waltz.common.SetUtilities.uniqBy) Set(java.util.Set) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) List(java.util.List) Tuple(org.jooq.lambda.tuple.Tuple) Map(java.util.Map) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) RandomUtilities.randomlySizedIntStream(org.finos.waltz.common.RandomUtilities.randomlySizedIntStream) DSLContext(org.jooq.DSLContext) MeasurableRatingRecord(org.finos.waltz.schema.tables.records.MeasurableRatingRecord) MEASURABLE_RATING(org.finos.waltz.schema.Tables.MEASURABLE_RATING) MEASURABLE(org.finos.waltz.schema.Tables.MEASURABLE) MeasurableRatingRecord(org.finos.waltz.schema.tables.records.MeasurableRatingRecord) DSLContext(org.jooq.DSLContext)

Example 2 with MEASURABLE

use of org.finos.waltz.schema.Tables.MEASURABLE in project waltz by khartec.

the class HigherEducationTaxonomyImport method updateParentIdsUsingExtIds.

private int updateParentIdsUsingExtIds(DSLContext tx, long categoryId) {
    // clear existing parent ids
    dsl.update(MEASURABLE).setNull(MEASURABLE.PARENT_ID).where(MEASURABLE.MEASURABLE_CATEGORY_ID.eq(categoryId)).execute();
    Measurable c = MEASURABLE.as("c");
    Measurable p = MEASURABLE.as("p");
    return tx.update(c).set(c.PARENT_ID, DSL.select(p.ID).from(p).where(p.EXTERNAL_ID.eq(c.EXTERNAL_PARENT_ID)).and(p.MEASURABLE_CATEGORY_ID.eq(categoryId))).where(c.MEASURABLE_CATEGORY_ID.eq(categoryId)).execute();
}
Also used : Measurable(org.finos.waltz.schema.tables.Measurable)

Example 3 with MEASURABLE

use of org.finos.waltz.schema.Tables.MEASURABLE in project waltz by khartec.

the class ScenarioExtractor method extract.

private Object extract(Request request, Response response) throws Exception {
    long scenarioId = WebUtilities.getId(request);
    Measurable rowMeasurable = MEASURABLE.as("rowMeasurable");
    Measurable colMeasurable = MEASURABLE.as("colMeasurable");
    ScenarioAxisItem rowAxisItem = SCENARIO_AXIS_ITEM.as("rowAxisItem");
    ScenarioAxisItem colAxisItem = SCENARIO_AXIS_ITEM.as("colAxisItem");
    Condition rowMeasurableJoin = rowMeasurable.ID.eq(SCENARIO_RATING_ITEM.ROW_ID).and(SCENARIO_RATING_ITEM.ROW_KIND.eq(EntityKind.MEASURABLE.name()));
    Condition colMeasurableJoin = colMeasurable.ID.eq(SCENARIO_RATING_ITEM.COLUMN_ID).and(SCENARIO_RATING_ITEM.COLUMN_KIND.eq(EntityKind.MEASURABLE.name()));
    Condition appJoin = APPLICATION.ID.eq(SCENARIO_RATING_ITEM.DOMAIN_ITEM_ID).and(SCENARIO_RATING_ITEM.DOMAIN_ITEM_KIND.eq(EntityKind.APPLICATION.name()));
    Condition rowAxisItemJoin = rowAxisItem.DOMAIN_ITEM_ID.eq(SCENARIO_RATING_ITEM.ROW_ID).and(rowAxisItem.ORIENTATION.eq(AxisOrientation.ROW.name())).and(rowAxisItem.SCENARIO_ID.eq(SCENARIO_RATING_ITEM.SCENARIO_ID));
    Condition colAxisItemJoin = colAxisItem.DOMAIN_ITEM_ID.eq(SCENARIO_RATING_ITEM.COLUMN_ID).and(colAxisItem.ORIENTATION.eq(AxisOrientation.COLUMN.name())).and(colAxisItem.SCENARIO_ID.eq(SCENARIO_RATING_ITEM.SCENARIO_ID));
    SelectConditionStep<Record6<String, String, String, String, String, String>> qry = dsl.select(APPLICATION.NAME.as("Application"), APPLICATION.ASSET_CODE.as("App Asset Code"), colMeasurable.NAME.as("Column"), rowMeasurable.NAME.as("Row"), RATING_SCHEME_ITEM.NAME.as("Rating"), SCENARIO_RATING_ITEM.DESCRIPTION.as("Description")).from(SCENARIO_RATING_ITEM).innerJoin(APPLICATION).on(appJoin).innerJoin(rowMeasurable).on(rowMeasurableJoin).innerJoin(colMeasurable).on(colMeasurableJoin).innerJoin(rowAxisItem).on(rowAxisItemJoin).innerJoin(colAxisItem).on(colAxisItemJoin).innerJoin(SCENARIO).on(SCENARIO.ID.eq(scenarioId)).innerJoin(ROADMAP).on(ROADMAP.ID.eq(SCENARIO.ROADMAP_ID)).innerJoin(RATING_SCHEME_ITEM).on(RATING_SCHEME_ITEM.SCHEME_ID.eq(ROADMAP.RATING_SCHEME_ID).and(RATING_SCHEME_ITEM.CODE.eq(SCENARIO_RATING_ITEM.RATING))).where(SCENARIO_RATING_ITEM.SCENARIO_ID.eq(scenarioId));
    String scenarioName = dsl.select(SCENARIO.NAME).from(SCENARIO).where(SCENARIO.ID.eq(scenarioId)).fetchOne(SCENARIO.NAME);
    String suggestedFilename = "scenario-" + scenarioName;
    return writeExtract(suggestedFilename, qry, request, response);
}
Also used : Condition(org.jooq.Condition) Measurable(org.finos.waltz.schema.tables.Measurable) ScenarioAxisItem(org.finos.waltz.schema.tables.ScenarioAxisItem) Record6(org.jooq.Record6)

Aggregations

Measurable (org.finos.waltz.schema.tables.Measurable)2 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 RandomUtilities.randomPick (org.finos.waltz.common.RandomUtilities.randomPick)1 RandomUtilities.randomlySizedIntStream (org.finos.waltz.common.RandomUtilities.randomlySizedIntStream)1 SetUtilities.uniqBy (org.finos.waltz.common.SetUtilities.uniqBy)1 EntityKind (org.finos.waltz.model.EntityKind)1 MEASURABLE (org.finos.waltz.schema.Tables.MEASURABLE)1 MEASURABLE_RATING (org.finos.waltz.schema.Tables.MEASURABLE_RATING)1 ScenarioAxisItem (org.finos.waltz.schema.tables.ScenarioAxisItem)1 MeasurableRatingRecord (org.finos.waltz.schema.tables.records.MeasurableRatingRecord)1 Condition (org.jooq.Condition)1 DSLContext (org.jooq.DSLContext)1 Record6 (org.jooq.Record6)1 Tuple (org.jooq.lambda.tuple.Tuple)1 ApplicationContext (org.springframework.context.ApplicationContext)1