Search in sources :

Example 21 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class SurveyQuestionResponseDao method mkRecord.

private SurveyQuestionResponseRecord mkRecord(SurveyInstanceQuestionResponse response) {
    SurveyQuestionResponse questionResponse = response.questionResponse();
    Optional<EntityReference> entityResponse = questionResponse.entityResponse();
    SurveyQuestionResponseRecord record = dsl.newRecord(SURVEY_QUESTION_RESPONSE);
    record.setSurveyInstanceId(response.surveyInstanceId());
    record.setQuestionId(questionResponse.questionId());
    record.setPersonId(response.personId());
    record.setLastUpdatedAt(Timestamp.valueOf(response.lastUpdatedAt()));
    record.setComment(questionResponse.comment().map(c -> ifEmpty(c, null)).orElse(null));
    record.setStringResponse(questionResponse.stringResponse().map(s -> ifEmpty(s, null)).orElse(null));
    record.setNumberResponse(questionResponse.numberResponse().map(BigDecimal::valueOf).orElse(null));
    record.setBooleanResponse(questionResponse.booleanResponse().orElse(null));
    record.setDateResponse(questionResponse.dateResponse().map(DateTimeUtilities::toSqlDate).orElse(null));
    record.setEntityResponseKind(entityResponse.map(er -> er.kind().name()).orElse(null));
    record.setEntityResponseId(entityResponse.map(EntityReference::id).orElse(null));
    record.setListResponseConcat(questionResponse.listResponse().filter(l -> !l.isEmpty()).map(l -> join(l, "; ")).orElse(null));
    return record;
}
Also used : StringUtilities.join(org.finos.waltz.common.StringUtilities.join) DSL(org.jooq.impl.DSL) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) Autowired(org.springframework.beans.factory.annotation.Autowired) ListUtilities.newArrayList(org.finos.waltz.common.ListUtilities.newArrayList) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) SURVEY_INSTANCE(org.finos.waltz.schema.tables.SurveyInstance.SURVEY_INSTANCE) Checks.checkTrue(org.finos.waltz.common.Checks.checkTrue) BigDecimal(java.math.BigDecimal) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) SURVEY_QUESTION_LIST_RESPONSE(org.finos.waltz.schema.Tables.SURVEY_QUESTION_LIST_RESPONSE) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) org.jooq(org.jooq) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Repository(org.springframework.stereotype.Repository) SURVEY_QUESTION_RESPONSE(org.finos.waltz.schema.tables.SurveyQuestionResponse.SURVEY_QUESTION_RESPONSE) CollectionUtilities.first(org.finos.waltz.common.CollectionUtilities.first) StringUtilities.ifEmpty(org.finos.waltz.common.StringUtilities.ifEmpty) org.finos.waltz.model.survey(org.finos.waltz.model.survey) SurveyQuestionListResponseRecord(org.finos.waltz.schema.tables.records.SurveyQuestionListResponseRecord) Optional.ofNullable(java.util.Optional.ofNullable) ListUtilities.isEmpty(org.finos.waltz.common.ListUtilities.isEmpty) Timestamp(java.sql.Timestamp) Set(java.util.Set) Collectors(java.util.stream.Collectors) Date(java.sql.Date) SURVEY_RUN(org.finos.waltz.schema.Tables.SURVEY_RUN) SurveyQuestionResponseRecord(org.finos.waltz.schema.tables.records.SurveyQuestionResponseRecord) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) InlineSelectFieldFactory(org.finos.waltz.data.InlineSelectFieldFactory) EntityReference(org.finos.waltz.model.EntityReference) Optional(java.util.Optional) SurveyQuestionResponseRecord(org.finos.waltz.schema.tables.records.SurveyQuestionResponseRecord) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) EntityReference(org.finos.waltz.model.EntityReference) BigDecimal(java.math.BigDecimal)

Example 22 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class AttestationServiceTest method cannotAttestIfNotAssociated.

@Test
public void cannotAttestIfNotAssociated() {
    String user = mkUserId("cannotAttestIfNotAssociated");
    EntityReference appRef = mkNewAppRef();
    AttestEntityCommand cmd = ImmutableAttestEntityCommand.builder().attestedEntityKind(EntityKind.LOGICAL_DATA_FLOW).entityReference(appRef).build();
    assertThrows(UpdateFailedException.class, () -> aiSvc.attestForEntity(user, cmd), "Should not be able to attest as user not associated to app");
}
Also used : EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 23 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class AttestationServiceTest method cannotAttestIfNoFlows.

@Test
public void cannotAttestIfNoFlows() {
    long invId = involvementHelper.mkInvolvementKind(mkName("cannotAttestIfNoFlows"));
    String user = mkUserId("cannotAttestIfNotAssociated");
    EntityReference appRef = mkNewAppRef();
    involvementHelper.createInvolvement(personHelper.createPerson(user), invId, appRef);
    AttestEntityCommand cmd = ImmutableAttestEntityCommand.builder().attestedEntityKind(EntityKind.LOGICAL_DATA_FLOW).entityReference(appRef).build();
    assertThrows(Exception.class, () -> aiSvc.attestForEntity(user, cmd), "Should not be able to attest as no flows");
}
Also used : EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 24 with EntityReference

use of org.finos.waltz.model.EntityReference 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 25 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class PermissionGroupService method findPermissions.

public List<Permission> findPermissions(EntityReference parentEntityRef, String username) {
    Person person = personService.getPersonByUserId(username);
    if (isNull(person)) {
        return Collections.emptyList();
    }
    List<Involvement> involvements = involvementService.findByEmployeeId(person.employeeId()).stream().filter(involvement -> involvement.entityReference().equals(parentEntityRef)).collect(Collectors.toList());
    if (involvements.isEmpty()) {
        return Collections.emptyList();
    }
    return permissionGroupDao.getDefaultPermissions();
}
Also used : Logger(org.slf4j.Logger) EntityKind(org.finos.waltz.model.EntityKind) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) PersonService(org.finos.waltz.service.person.PersonService) Collectors(java.util.stream.Collectors) Person(org.finos.waltz.model.person.Person) InvolvementService(org.finos.waltz.service.involvement.InvolvementService) List(java.util.List) Involvement(org.finos.waltz.model.involvement.Involvement) Service(org.springframework.stereotype.Service) EntityReference(org.finos.waltz.model.EntityReference) Objects.isNull(java.util.Objects.isNull) Permission(org.finos.waltz.model.permission_group.Permission) Collections(java.util.Collections) Involvement(org.finos.waltz.model.involvement.Involvement) Person(org.finos.waltz.model.person.Person)

Aggregations

EntityReference (org.finos.waltz.model.EntityReference)114 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)55 Test (org.junit.jupiter.api.Test)55 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)40 EntityKind (org.finos.waltz.model.EntityKind)23 List (java.util.List)21 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)19 Autowired (org.springframework.beans.factory.annotation.Autowired)17 DataTypeDecorator (org.finos.waltz.model.datatype.DataTypeDecorator)16 Set (java.util.Set)14 Collection (java.util.Collection)13 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)13 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)10 IdSelectionOptions.mkOpts (org.finos.waltz.model.IdSelectionOptions.mkOpts)9 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)8 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)8 Bookmark (org.finos.waltz.model.bookmark.Bookmark)8 Collections.emptyList (java.util.Collections.emptyList)7 Collectors (java.util.stream.Collectors)7 CollectionUtilities.first (org.finos.waltz.common.CollectionUtilities.first)7