Search in sources :

Example 31 with Person

use of org.finos.waltz.model.person.Person in project waltz by khartec.

the class SurveyInstanceService method logPersonChange.

private void logPersonChange(String username, long instanceId, long personId, Operation op, String msg) {
    Person recipient = getPersonById(personId);
    changeLogService.write(ImmutableChangeLog.builder().operation(op).userId(username).parentReference(EntityReference.mkRef(EntityKind.SURVEY_INSTANCE, instanceId)).childKind(EntityKind.PERSON).message(format(msg, recipient.name())).build());
}
Also used : Person(org.finos.waltz.model.person.Person)

Example 32 with Person

use of org.finos.waltz.model.person.Person in project waltz by khartec.

the class SurveyInstanceService method copyResponses.

public int copyResponses(long sourceSurveyId, CopySurveyResponsesCommand copyCommand, String username) {
    copyCommand.targetSurveyInstanceIds().forEach(trgInstanceId -> checkPersonIsRecipientOrOwnerOrAdmin(username, trgInstanceId));
    Person person = personDao.getByUserEmail(username);
    int updated = surveyQuestionResponseDao.copyResponses(sourceSurveyId, copyCommand, person.id().get());
    String willBeOverwrittenMessage = copyCommand.overrideExistingResponses() ? "existing responses were overwritten" : "existing responses were unchanged";
    String questionMessage = isEmpty(copyCommand.questionIds()) ? "All questions" : format("Questions: %s", copyCommand.questionIds().toString());
    copyCommand.targetSurveyInstanceIds().forEach(trgInstanceId -> {
        updateStatus(username, trgInstanceId, ImmutableSurveyInstanceStatusChangeCommand.builder().action(SurveyInstanceAction.SAVING).reason(format("Questions copied from survey instance: %d, %s", sourceSurveyId, willBeOverwrittenMessage)).build());
        changeLogService.write(ImmutableChangeLog.builder().operation(Operation.UPDATE).userId(username).parentReference(EntityReference.mkRef(EntityKind.SURVEY_INSTANCE, trgInstanceId)).message(format("%s copied from survey instance: %d, %s", questionMessage, sourceSurveyId, willBeOverwrittenMessage)).build());
    });
    return updated;
}
Also used : Person(org.finos.waltz.model.person.Person)

Example 33 with Person

use of org.finos.waltz.model.person.Person in project waltz by khartec.

the class SurveyInstanceService method saveResponse.

public boolean saveResponse(String userName, long instanceId, SurveyQuestionResponse questionResponse) {
    checkNotNull(userName, "userName cannot be null");
    checkNotNull(questionResponse, "questionResponse cannot be null");
    Person person = checkPersonIsRecipient(userName, instanceId);
    SurveyInstance surveyInstance = surveyInstanceDao.getById(instanceId);
    checkTrue(surveyInstance.status() == SurveyInstanceStatus.NOT_STARTED || surveyInstance.status() == SurveyInstanceStatus.IN_PROGRESS || surveyInstance.status() == SurveyInstanceStatus.REJECTED, "Survey instance cannot be updated, current status: " + surveyInstance.status());
    SurveyInstanceQuestionResponse instanceQuestionResponse = ImmutableSurveyInstanceQuestionResponse.builder().surveyInstanceId(instanceId).personId(person.id().get()).lastUpdatedAt(DateTimeUtilities.nowUtc()).questionResponse(questionResponse).build();
    surveyQuestionResponseDao.saveResponse(instanceQuestionResponse);
    return true;
}
Also used : Person(org.finos.waltz.model.person.Person)

Example 34 with Person

use of org.finos.waltz.model.person.Person in project waltz by khartec.

the class SurveyRunServiceTest method surveysAreIssuedToRecipientsViaInvolvementKind.

@Test
public void surveysAreIssuedToRecipientsViaInvolvementKind() throws InsufficientPrivelegeException {
    String stem = "srt_surveysAreIssuedToRecipientsViaInvolvementKind";
    String admin = mkName(stem, "admin");
    personHelper.createPerson(admin);
    String u1 = mkName(stem, "user1");
    Long u1Id = personHelper.createPerson(u1);
    String u2a = mkName(stem, "user2a");
    Long u2aId = personHelper.createPerson(u2a);
    String u2b = mkName(stem, "user2b");
    Long u2bId = personHelper.createPerson(u2b);
    EntityReference appA = appHelper.createNewApp(mkName(stem, "appA"), ouIds.a);
    EntityReference appB = appHelper.createNewApp(mkName(stem, "appB"), ouIds.b);
    long invKind = involvementHelper.mkInvolvementKind(mkName(stem, "invKind"));
    involvementHelper.createInvolvement(u1Id, invKind, appA);
    involvementHelper.createInvolvement(u2aId, invKind, appB);
    involvementHelper.createInvolvement(u2bId, invKind, appB);
    Long grpId = groupHelper.createAppGroupWithAppRefs(mkName(stem, "group"), asSet(appA, appB));
    long tId = templateHelper.createTemplate(admin, mkName("test"));
    // remove person 2
    personHelper.updateIsRemoved(u2aId, true);
    SurveyRunCreateCommand cmd = ImmutableSurveyRunCreateCommand.builder().issuanceKind(SurveyIssuanceKind.GROUP).name("test").description("run desc").selectionOptions(IdSelectionOptions.mkOpts(EntityReference.mkRef(EntityKind.APP_GROUP, grpId))).surveyTemplateId(tId).addInvolvementKindIds(invKind).dueDate(DateTimeUtilities.today().plusMonths(1)).approvalDueDate(DateTimeUtilities.today().plusMonths(1)).contactEmail("someone@somewhere.com").build();
    IdCommandResponse runResp = runService.createSurveyRun(admin, cmd);
    Long surveyRunId = runResp.id().orElseThrow(() -> new AssertionFailedError("Failed to create run"));
    ImmutableInstancesAndRecipientsCreateCommand createCmd = ImmutableInstancesAndRecipientsCreateCommand.builder().surveyRunId(surveyRunId).dueDate(toLocalDate(nowUtcTimestamp())).approvalDueDate(toLocalDate(nowUtcTimestamp())).excludedRecipients(emptySet()).build();
    runService.createSurveyInstancesAndRecipients(createCmd);
    Set<SurveyInstance> instances = instanceService.findForSurveyRun(surveyRunId);
    assertEquals(2, instances.size(), "should be 2 instances");
    SurveyInstance instanceA = findInstanceForApp(instances, appA);
    SurveyInstance instanceB = findInstanceForApp(instances, appB);
    assertNotNull(instanceA);
    assertNotNull(instanceB);
    assertEquals(SurveyInstanceStatus.NOT_STARTED, instanceA.status(), "instance won't have been started yet");
    assertEquals(SurveyInstanceStatus.NOT_STARTED, instanceB.status(), "instance won't have been started yet");
    Long instanceAId = instanceA.id().orElseThrow(() -> new AssertionFailedError("Failed to find instance for app A"));
    Long instanceBId = instanceB.id().orElseThrow(() -> new AssertionFailedError("Failed to find instance for app B"));
    assertNotNull(instanceService.checkPersonIsRecipient(u1, instanceAId), "check user 1 via api");
    assertNotNull(instanceService.checkPersonIsOwnerOrAdmin(admin, instanceAId), "admin is owner of instance A");
    assertNotNull(instanceService.checkPersonIsOwnerOrAdmin(admin, instanceBId), "admin is owner of instance B");
    Set<SurveyInstance> instancesForU1 = instanceService.findForRecipient(u1Id);
    Set<SurveyInstance> instancesForU2a = instanceService.findForRecipient(u2aId);
    assertEquals(asSet(instanceA), instancesForU1, "instances for u1 should be just an instance for appA");
    assertEquals(Collections.emptySet(), instancesForU2a, "should be no instances for user 2A");
    assertEquals(instanceService.findForRecipient(u1Id), instanceService.findForRecipient(u1), "can find by name or id (1)");
    assertEquals(instanceService.findForRecipient(u2bId), instanceService.findForRecipient(u2b), "can find by name or id (2a)");
    assertThrows(IllegalArgumentException.class, () -> instanceService.findForRecipient(u2a), "finding by removed user throws an exception");
    List<Person> aRecips = instanceService.findRecipients(instanceAId);
    List<Person> bRecips = instanceService.findRecipients(instanceBId);
    assertEquals(asSet(u1), recipsToUserIds(aRecips), "Expect user1 to be the recipient");
    assertEquals(asSet(u2b), recipsToUserIds(bRecips), "app B has only one recipient (u2a) as the other involved person (u2a) has been removed");
}
Also used : IdCommandResponse(org.finos.waltz.model.IdCommandResponse) EntityReference(org.finos.waltz.model.EntityReference) AssertionFailedError(junit.framework.AssertionFailedError) Person(org.finos.waltz.model.person.Person) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Person (org.finos.waltz.model.person.Person)34 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Service (org.springframework.stereotype.Service)5 LocalDate (java.time.LocalDate)4 java.util (java.util)4 PersonDao (org.finos.waltz.data.person.PersonDao)4 EntityKind (org.finos.waltz.model.EntityKind)4 org.finos.waltz.model.survey (org.finos.waltz.model.survey)4 Record1 (org.jooq.Record1)4 Select (org.jooq.Select)4 Collectors (java.util.stream.Collectors)3 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)3 ListUtilities.map (org.finos.waltz.common.ListUtilities.map)3 MapUtilities.indexBy (org.finos.waltz.common.MapUtilities.indexBy)3 ImmutableChangeLog (org.finos.waltz.model.changelog.ImmutableChangeLog)3 IOException (java.io.IOException)2 List (java.util.List)2 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)2 Collectors.toList (java.util.stream.Collectors.toList)2 Checks.checkTrue (org.finos.waltz.common.Checks.checkTrue)2