Search in sources :

Example 1 with RatingSchemeItemRecord

use of org.finos.waltz.schema.tables.records.RatingSchemeItemRecord in project waltz by khartec.

the class ContextPopulatorTest method fooTest.

@Test
public void fooTest() {
    EntityReference a1 = appHelper.createNewApp(mkName("a1"), ouIds.a);
    EntityReference a2 = appHelper.createNewApp(mkName("a2"), ouIds.a);
    EntityReference a3 = appHelper.createNewApp(mkName("a3"), ouIds.a);
    RatingSchemeRecord scheme = dsl.newRecord(rs);
    scheme.setName(mkName("scheme"));
    scheme.setDescription("desc");
    scheme.store();
    RatingSchemeItemRecord ratingItem1 = mkRatingItem(scheme, "ratingItem1", "X");
    RatingSchemeItemRecord ratingItem2 = mkRatingItem(scheme, "ratingItem2", "Y");
    AssessmentDefinitionRecord def1 = mkAssessmentDef("def1", scheme);
    AssessmentDefinitionRecord def2 = mkAssessmentDef("anotherDef", scheme);
    mkRating(a1, def1, ratingItem1);
    mkRating(a2, def1, ratingItem2);
    mkRating(a1, def2, ratingItem2);
    Set<ContextVariableDeclaration> declarations = SetUtilities.asSet(ImmutableContextVariableDeclaration.builder().name("def1Var").ref(mkVarRef(EntityKind.ASSESSMENT_DEFINITION, def1.getExternalId())).build(), ImmutableContextVariableDeclaration.builder().name("def1VarDupe").ref(mkVarRef(EntityKind.ASSESSMENT_DEFINITION, def1.getExternalId())).build(), ImmutableContextVariableDeclaration.builder().name("def2Var").ref(mkVarRef(EntityKind.ASSESSMENT_DEFINITION, def2.getExternalId())).build());
    Set<ContextVariable<? extends ContextValue>> vars = populator.populateContext(declarations, selector);
    assertVar(vars, a1, "def1Var", mkAssessmentCodeCheck("X"), "A1");
    assertVar(vars, a1, "def2Var", mkAssessmentCodeCheck("Y"), "A1");
    assertVar(vars, a1, "def1VarDupe", mkAssessmentCodeCheck("X"), "A1");
    assertVar(vars, a2, "def1Var", mkAssessmentCodeCheck("Y"), "A2");
    assertVar(vars, a2, "def1VarDupe", mkAssessmentCodeCheck("Y"), "A2");
}
Also used : RatingSchemeRecord(org.finos.waltz.schema.tables.records.RatingSchemeRecord) RatingSchemeItemRecord(org.finos.waltz.schema.tables.records.RatingSchemeItemRecord) EntityReference(org.finos.waltz.model.EntityReference) AssessmentDefinitionRecord(org.finos.waltz.schema.tables.records.AssessmentDefinitionRecord) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with RatingSchemeItemRecord

use of org.finos.waltz.schema.tables.records.RatingSchemeItemRecord in project waltz by khartec.

the class AssessmentGenerator method createRatingScheme.

private Long createRatingScheme(DSLContext dsl, String name, Tuple3<String, String, String>... options) {
    // create
    RatingSchemeRecord ratingSchemeRecord = dsl.newRecord(RATING_SCHEME);
    ratingSchemeRecord.setName(name);
    ratingSchemeRecord.setDescription(name + " ratings");
    ratingSchemeRecord.insert();
    System.out.println("Inserted scheme " + ratingSchemeRecord.getId());
    List<RatingSchemeItemRecord> ratingRecords = Stream.of(options).map(t -> {
        RatingSchemeItemRecord itemR = dsl.newRecord(RATING_SCHEME_ITEM);
        itemR.setCode(t.v1);
        itemR.setName(t.v2);
        itemR.setColor(t.v3);
        itemR.setDescription(t.v2);
        itemR.setSchemeId(ratingSchemeRecord.getId());
        itemR.setUserSelectable(true);
        return itemR;
    }).collect(toList());
    dsl.batchInsert(ratingRecords).execute();
    return ratingSchemeRecord.getId();
}
Also used : RatingSchemeRecord(org.finos.waltz.schema.tables.records.RatingSchemeRecord) DSL(org.jooq.impl.DSL) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) RatingScheme(org.finos.waltz.model.rating.RatingScheme) RatingSchemeItemRecord(org.finos.waltz.schema.tables.records.RatingSchemeItemRecord) RatingSchemeService(org.finos.waltz.service.rating_scheme.RatingSchemeService) ApplicationContext(org.springframework.context.ApplicationContext) ColorUtilities(org.finos.waltz.common.ColorUtilities) AssessmentDefinitionRecord(org.finos.waltz.schema.tables.records.AssessmentDefinitionRecord) RandomUtilities(org.finos.waltz.common.RandomUtilities) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Tuple3(org.jooq.lambda.tuple.Tuple3) Stream(java.util.stream.Stream) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) ListUtilities(org.finos.waltz.common.ListUtilities) org.jooq(org.jooq) Map(java.util.Map) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) AssessmentRatingRecord(org.finos.waltz.schema.tables.records.AssessmentRatingRecord) RatingSchemeRecord(org.finos.waltz.schema.tables.records.RatingSchemeRecord) RatingSchemeItemRecord(org.finos.waltz.schema.tables.records.RatingSchemeItemRecord)

Example 3 with RatingSchemeItemRecord

use of org.finos.waltz.schema.tables.records.RatingSchemeItemRecord in project waltz by khartec.

the class ContextPopulatorTest method mkRatingItem.

private RatingSchemeItemRecord mkRatingItem(RatingSchemeRecord scheme, String name, String code) {
    RatingSchemeItemRecord rating = dsl.newRecord(rsi);
    rating.setName(mkName(name));
    rating.setSchemeId(scheme.getId());
    rating.setCode(code);
    rating.setDescription("Desc: " + name + " / " + code);
    rating.setColor("red");
    rating.store();
    return rating;
}
Also used : RatingSchemeItemRecord(org.finos.waltz.schema.tables.records.RatingSchemeItemRecord)

Example 4 with RatingSchemeItemRecord

use of org.finos.waltz.schema.tables.records.RatingSchemeItemRecord in project waltz by khartec.

the class RatingSchemeDAO method saveRatingItem.

public Long saveRatingItem(long schemeId, RatingSchemeItem item) {
    RatingSchemeItemRecord r = dsl.newRecord(RATING_SCHEME_ITEM);
    r.setSchemeId(schemeId);
    r.setName(item.name());
    r.setDescription(item.description());
    r.setCode(Character.toString(item.rating()));
    r.setColor(item.color());
    r.setPosition(item.position());
    r.setUserSelectable(item.userSelectable());
    return item.id().map(id -> {
        r.setId(id);
        r.changed(RATING_SCHEME_ITEM.ID, false);
        r.store();
        return id;
    }).orElseGet(() -> {
        r.insert();
        return r.getId();
    });
}
Also used : java.util(java.util) RATING_SCHEME_ITEM(org.finos.waltz.schema.tables.RatingSchemeItem.RATING_SCHEME_ITEM) DSL(org.jooq.impl.DSL) Tables(org.finos.waltz.schema.Tables) Collections.emptyList(java.util.Collections.emptyList) Optional.ofNullable(java.util.Optional.ofNullable) EntityKind(org.finos.waltz.model.EntityKind) RatingSchemeItemRecord(org.finos.waltz.schema.tables.records.RatingSchemeItemRecord) Autowired(org.springframework.beans.factory.annotation.Autowired) org.finos.waltz.model.rating(org.finos.waltz.model.rating) MEASURABLE_CATEGORY(org.finos.waltz.schema.tables.MeasurableCategory.MEASURABLE_CATEGORY) StringUtilities.firstChar(org.finos.waltz.common.StringUtilities.firstChar) RATING_SCHEME(org.finos.waltz.schema.tables.RatingScheme.RATING_SCHEME) Collectors.toList(java.util.stream.Collectors.toList) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) org.jooq(org.jooq) EntityReference(org.finos.waltz.model.EntityReference) RatingSchemeRecord(org.finos.waltz.schema.tables.records.RatingSchemeRecord) Repository(org.springframework.stereotype.Repository) RatingSchemeItemRecord(org.finos.waltz.schema.tables.records.RatingSchemeItemRecord)

Aggregations

RatingSchemeItemRecord (org.finos.waltz.schema.tables.records.RatingSchemeItemRecord)4 RatingSchemeRecord (org.finos.waltz.schema.tables.records.RatingSchemeRecord)3 Collectors.toList (java.util.stream.Collectors.toList)2 EntityKind (org.finos.waltz.model.EntityKind)2 EntityReference (org.finos.waltz.model.EntityReference)2 Tables (org.finos.waltz.schema.Tables)2 AssessmentDefinitionRecord (org.finos.waltz.schema.tables.records.AssessmentDefinitionRecord)2 org.jooq (org.jooq)2 DSL (org.jooq.impl.DSL)2 java.util (java.util)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 Map (java.util.Map)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Stream (java.util.stream.Stream)1 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)1 ColorUtilities (org.finos.waltz.common.ColorUtilities)1 ListUtilities (org.finos.waltz.common.ListUtilities)1 MapUtilities.groupBy (org.finos.waltz.common.MapUtilities.groupBy)1 RandomUtilities (org.finos.waltz.common.RandomUtilities)1