Search in sources :

Example 1 with AssessmentDefinition

use of org.finos.waltz.model.assessment_definition.AssessmentDefinition in project waltz by khartec.

the class AssessmentsTest method createUpdateAndRemoveSingleRating.

@Test
public void createUpdateAndRemoveSingleRating() {
    String user = NameHelper.mkUserId("user");
    String name = NameHelper.mkName("testAssessment");
    String role = NameHelper.mkName("testRole");
    SchemeDetail schemeDetail = createScheme();
    AssessmentDefinition def = ImmutableAssessmentDefinition.builder().name(name).description("desc").isReadOnly(false).permittedRole(role).entityKind(EntityKind.APPLICATION).lastUpdatedBy(user).visibility(AssessmentVisibility.SECONDARY).ratingSchemeId(schemeDetail.id).build();
    long defId = definitionService.save(def);
    definitionService.save(ImmutableAssessmentDefinition.copyOf(def).withId(defId).withDescription("updated desc"));
    Collection<AssessmentDefinition> allDefs = definitionService.findAll();
    AssessmentDefinition found = find(d -> d.id().equals(Optional.of(defId)), allDefs).orElseThrow(AssertionError::new);
    assertEquals("updated desc", found.description());
    assertEquals(found, definitionService.getById(defId));
    EntityReference app1 = appHelper.createNewApp(NameHelper.mkName("app1"), ouIds.a);
    EntityReference app2 = appHelper.createNewApp(NameHelper.mkName("app2"), ouIds.b);
    SaveAssessmentRatingCommand cmd = ImmutableSaveAssessmentRatingCommand.builder().assessmentDefinitionId(defId).entityReference(app1).ratingId(schemeDetail.y).lastUpdatedBy(user).build();
    ratingService.store(cmd, user);
    changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(app1, Operation.ADD);
    assertNotNull(find(r -> r.assessmentDefinitionId() == defId && r.ratingId() == schemeDetail.y, ratingService.findForEntity(app1)));
    assertTrue(ratingService.findForEntity(app2).isEmpty());
    ratingService.store(ImmutableSaveAssessmentRatingCommand.copyOf(cmd).withRatingId(schemeDetail.n), user);
    changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(app1, Operation.UPDATE);
    assertNotNull(find(r -> r.assessmentDefinitionId() == defId && r.ratingId() == schemeDetail.n, ratingService.findForEntity(app1)));
    List<AssessmentRating> allRatingsAfterUpdate = ratingService.findByDefinitionId(defId);
    assertEquals(1, allRatingsAfterUpdate.size());
    assertTrue(find(r -> r.entityReference().equals(app1) && r.ratingId() == schemeDetail.n, allRatingsAfterUpdate).isPresent());
    ratingService.remove(ImmutableRemoveAssessmentRatingCommand.builder().assessmentDefinitionId(defId).entityReference(app1).lastUpdatedBy(user).build(), user);
    changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(app1, Operation.REMOVE);
    assertTrue(ratingService.findForEntity(app1).isEmpty());
    List<AssessmentRating> allRatingsAfterRemoval = ratingService.findByDefinitionId(defId);
    assertTrue(allRatingsAfterRemoval.isEmpty());
}
Also used : ImmutableSaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.ImmutableSaveAssessmentRatingCommand) SaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.SaveAssessmentRatingCommand) EntityKind(org.finos.waltz.model.EntityKind) AssessmentVisibility(org.finos.waltz.model.assessment_definition.AssessmentVisibility) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) Autowired(org.springframework.beans.factory.annotation.Autowired) ImmutableRemoveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.ImmutableRemoveAssessmentRatingCommand) RatingSchemeService(org.finos.waltz.service.rating_scheme.RatingSchemeService) ImmutableRatingSchemeItem(org.finos.waltz.model.rating.ImmutableRatingSchemeItem) AssessmentDefinition(org.finos.waltz.model.assessment_definition.AssessmentDefinition) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) ChangeLogHelper(org.finos.waltz.integration_test.inmem.helpers.ChangeLogHelper) Collection(java.util.Collection) AppHelper(org.finos.waltz.integration_test.inmem.helpers.AppHelper) NameHelper(org.finos.waltz.integration_test.inmem.helpers.NameHelper) RatingSchemeHelper(org.finos.waltz.integration_test.inmem.helpers.RatingSchemeHelper) AssessmentDefinitionService(org.finos.waltz.service.assessment_definition.AssessmentDefinitionService) Operation(org.finos.waltz.model.Operation) Test(org.junit.jupiter.api.Test) List(java.util.List) ImmutableAssessmentDefinition(org.finos.waltz.model.assessment_definition.ImmutableAssessmentDefinition) CollectionUtilities.find(org.finos.waltz.common.CollectionUtilities.find) Assertions(org.junit.jupiter.api.Assertions) EntityReference(org.finos.waltz.model.EntityReference) AssessmentRatingService(org.finos.waltz.service.assessment_rating.AssessmentRatingService) Optional(java.util.Optional) AssessmentDefinition(org.finos.waltz.model.assessment_definition.AssessmentDefinition) ImmutableAssessmentDefinition(org.finos.waltz.model.assessment_definition.ImmutableAssessmentDefinition) ImmutableSaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.ImmutableSaveAssessmentRatingCommand) SaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.SaveAssessmentRatingCommand) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with AssessmentDefinition

use of org.finos.waltz.model.assessment_definition.AssessmentDefinition in project waltz by khartec.

the class AssessmentRatingViewService method findGroupedByDefinitionAndOutcomes.

public Collection<AssessmentGroupedEntities> findGroupedByDefinitionAndOutcomes(EntityKind kind, List<Long> entityIds) {
    Condition entityCondition = isEmpty(entityIds) ? ASSESSMENT_RATING.ENTITY_KIND.eq(kind.name()) : ASSESSMENT_RATING.ENTITY_KIND.eq(kind.name()).and(ASSESSMENT_RATING.ENTITY_ID.in(entityIds));
    Map<Long, AssessmentDefinition> definitionsById = indexBy(assessmentDefinitionDao.findAll(), def -> def.id().get());
    Set<Tuple2<Long, Set<ImmutableRatingEntityList>>> groupedByDefinitionAndOutcome = assessmentRatingDao.findGroupedByDefinitionAndOutcome(entityCondition);
    return map(groupedByDefinitionAndOutcome, rel -> ImmutableAssessmentGroupedEntities.builder().assessmentDefinition(definitionsById.get(rel.v1)).ratingEntityLists(rel.v2).build());
}
Also used : Condition(org.jooq.Condition) AssessmentDefinition(org.finos.waltz.model.assessment_definition.AssessmentDefinition) Tuple2(org.jooq.lambda.tuple.Tuple2)

Example 3 with AssessmentDefinition

use of org.finos.waltz.model.assessment_definition.AssessmentDefinition in project waltz by khartec.

the class AssessmentRatingService method createChangeLogEntry.

private void createChangeLogEntry(SaveAssessmentRatingCommand command, String username, AssessmentDefinition assessmentDefinition) {
    Optional<AssessmentRating> previousRating = assessmentRatingDao.findForEntity(command.entityReference()).stream().filter(r -> r.assessmentDefinitionId() == command.assessmentDefinitionId()).findAny();
    Optional<RatingSchemeItem> previousRatingSchemeItem = previousRating.map(assessmentRating -> ratingSchemeDAO.getRatingSchemeItemById(assessmentRating.ratingId()));
    Optional<String> messagePostfix = previousRatingSchemeItem.map(rn -> format(" from assessment %s as [%s - %s]", assessmentDefinition.name(), rn.name(), previousRating.get().comment()));
    ChangeLog logEntry = ImmutableChangeLog.builder().message(format("Storing assessment %s as [%s - %s]%s", assessmentDefinition.name(), ratingSchemeDAO.getRatingSchemeItemById(command.ratingId()).name(), command.comment(), messagePostfix.orElse(""))).parentReference(mkRef(command.entityReference().kind(), command.entityReference().id())).userId(username).severity(Severity.INFORMATION).operation(Operation.UPDATE).build();
    changeLogService.write(logEntry);
}
Also used : ChangeLogService(org.finos.waltz.service.changelog.ChangeLogService) java.util(java.util) MapUtilities(org.finos.waltz.common.MapUtilities) org.finos.waltz.model(org.finos.waltz.model) GenericSelector(org.finos.waltz.data.GenericSelector) Autowired(org.springframework.beans.factory.annotation.Autowired) ImmutableChangeLog(org.finos.waltz.model.changelog.ImmutableChangeLog) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) AssessmentDefinitionDao(org.finos.waltz.data.assessment_definition.AssessmentDefinitionDao) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) GenericSelectorFactory(org.finos.waltz.data.GenericSelectorFactory) AssessmentDefinition(org.finos.waltz.model.assessment_definition.AssessmentDefinition) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) RatingSchemeDAO(org.finos.waltz.data.rating_scheme.RatingSchemeDAO) ChangeLog(org.finos.waltz.model.changelog.ChangeLog) Service(org.springframework.stereotype.Service) AssessmentRatingDao(org.finos.waltz.data.assessment_rating.AssessmentRatingDao) org.finos.waltz.model.assessment_rating(org.finos.waltz.model.assessment_rating) StringUtilities(org.finos.waltz.common.StringUtilities) ImmutableChangeLog(org.finos.waltz.model.changelog.ImmutableChangeLog) ChangeLog(org.finos.waltz.model.changelog.ChangeLog) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem)

Example 4 with AssessmentDefinition

use of org.finos.waltz.model.assessment_definition.AssessmentDefinition in project waltz by khartec.

the class AssessmentRatingService method createChangeLogs.

private void createChangeLogs(long assessmentDefinitionId, String username, Set<AssessmentRating> ratingsToAdd, Operation operation) {
    String messagePrefix = operation.equals(Operation.REMOVE) ? "Removed" : "Added";
    AssessmentDefinition assessmentDefinition = assessmentDefinitionDao.getById(assessmentDefinitionId);
    Map<Long, RatingSchemeItem> ratingItems = MapUtilities.indexBy(ratingSchemeDAO.findRatingSchemeItemsForAssessmentDefinition(assessmentDefinitionId), r -> r.id().orElse(0L));
    Set<ChangeLog> logs = ratingsToAdd.stream().map(r -> ImmutableChangeLog.builder().message(messagePrefix + format(" assessment %s as [%s - %s] for %s", assessmentDefinition.name(), ratingItems.get(r.ratingId()).name(), StringUtilities.ifEmpty(r.comment(), ""), r.entityReference().name().orElse(""))).parentReference(r.entityReference()).userId(username).severity(Severity.INFORMATION).operation(operation).build()).collect(Collectors.toSet());
    changeLogService.write(logs);
}
Also used : ChangeLogService(org.finos.waltz.service.changelog.ChangeLogService) java.util(java.util) MapUtilities(org.finos.waltz.common.MapUtilities) org.finos.waltz.model(org.finos.waltz.model) GenericSelector(org.finos.waltz.data.GenericSelector) Autowired(org.springframework.beans.factory.annotation.Autowired) ImmutableChangeLog(org.finos.waltz.model.changelog.ImmutableChangeLog) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) AssessmentDefinitionDao(org.finos.waltz.data.assessment_definition.AssessmentDefinitionDao) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) GenericSelectorFactory(org.finos.waltz.data.GenericSelectorFactory) AssessmentDefinition(org.finos.waltz.model.assessment_definition.AssessmentDefinition) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) RatingSchemeDAO(org.finos.waltz.data.rating_scheme.RatingSchemeDAO) ChangeLog(org.finos.waltz.model.changelog.ChangeLog) Service(org.springframework.stereotype.Service) AssessmentRatingDao(org.finos.waltz.data.assessment_rating.AssessmentRatingDao) org.finos.waltz.model.assessment_rating(org.finos.waltz.model.assessment_rating) StringUtilities(org.finos.waltz.common.StringUtilities) AssessmentDefinition(org.finos.waltz.model.assessment_definition.AssessmentDefinition) ImmutableChangeLog(org.finos.waltz.model.changelog.ImmutableChangeLog) ChangeLog(org.finos.waltz.model.changelog.ChangeLog) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem)

Example 5 with AssessmentDefinition

use of org.finos.waltz.model.assessment_definition.AssessmentDefinition in project waltz by khartec.

the class AssessmentRatingService method store.

public boolean store(SaveAssessmentRatingCommand command, String username) {
    AssessmentDefinition assessmentDefinition = assessmentDefinitionDao.getById(command.assessmentDefinitionId());
    createChangeLogEntry(command, username, assessmentDefinition);
    return assessmentRatingDao.store(command);
}
Also used : AssessmentDefinition(org.finos.waltz.model.assessment_definition.AssessmentDefinition)

Aggregations

AssessmentDefinition (org.finos.waltz.model.assessment_definition.AssessmentDefinition)8 Autowired (org.springframework.beans.factory.annotation.Autowired)3 String.format (java.lang.String.format)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)2 MapUtilities (org.finos.waltz.common.MapUtilities)2 StringUtilities (org.finos.waltz.common.StringUtilities)2 GenericSelector (org.finos.waltz.data.GenericSelector)2 GenericSelectorFactory (org.finos.waltz.data.GenericSelectorFactory)2 AssessmentDefinitionDao (org.finos.waltz.data.assessment_definition.AssessmentDefinitionDao)2 AssessmentRatingDao (org.finos.waltz.data.assessment_rating.AssessmentRatingDao)2 RatingSchemeDAO (org.finos.waltz.data.rating_scheme.RatingSchemeDAO)2 org.finos.waltz.model (org.finos.waltz.model)2 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)2 ImmutableAssessmentDefinition (org.finos.waltz.model.assessment_definition.ImmutableAssessmentDefinition)2 org.finos.waltz.model.assessment_rating (org.finos.waltz.model.assessment_rating)2 ChangeLog (org.finos.waltz.model.changelog.ChangeLog)2 ImmutableChangeLog (org.finos.waltz.model.changelog.ImmutableChangeLog)2 RatingSchemeItem (org.finos.waltz.model.rating.RatingSchemeItem)2