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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations