Search in sources :

Example 1 with AssessmentRating

use of org.finos.waltz.model.assessment_rating.AssessmentRating 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 AssessmentRating

use of org.finos.waltz.model.assessment_rating.AssessmentRating in project waltz by khartec.

the class ChangeUnitViewService method findPhysicalFlowChangeUnitsByChangeSetId.

public Set<PhysicalFlowChangeUnitViewItem> findPhysicalFlowChangeUnitsByChangeSetId(long changeSetId) {
    IdSelectionOptions idSelectionOptions = mkOptsForAllLifecycleStates(mkRef(EntityKind.CHANGE_SET, changeSetId), HierarchyQueryScope.EXACT);
    Collection<PhysicalFlow> physicalFlows = physicalFlowService.findBySelector(idSelectionOptions);
    Collection<PhysicalSpecification> physicalSpecs = physicalSpecificationService.findByIds(map(physicalFlows, PhysicalFlow::specificationId));
    // TODO: Move to a logical flow selector based upon change set #5626
    Collection<LogicalFlow> logicalFlows = logicalFlowService.findAllByFlowIds(map(physicalFlows, PhysicalFlow::logicalFlowId));
    List<AssessmentRating> assessmentRatings = assessmentRatingService.findByTargetKindForRelatedSelector(EntityKind.CHANGE_UNIT, idSelectionOptions);
    Map<Long, RatingSchemeItem> ratingSchemeItemsById = indexBy(ratingSchemeService.getAllRatingSchemeItems(), item -> item.id().get());
    Map<Long, PhysicalFlow> physicalFlowsById = indexBy(physicalFlows, flow -> flow.id().get());
    Map<Long, LogicalFlow> logicalFlowsById = indexBy(logicalFlows, flow -> flow.id().get());
    Map<Long, PhysicalSpecification> specsById = indexBy(physicalSpecs, spec -> spec.id().get());
    Map<Long, Collection<AssessmentRating>> assessmentRatingsByEntityId = groupBy(rating -> rating.entityReference().id(), assessmentRatings);
    List<ChangeUnit> changeUnits = changeUnitService.findByChangeSetId(changeSetId);
    return changeUnits.stream().filter(cu -> cu.subjectEntity().kind().equals(EntityKind.PHYSICAL_FLOW)).map(cu -> {
        PhysicalFlow physicalFlow = physicalFlowsById.get(cu.subjectEntity().id());
        PhysicalSpecification spec = specsById.get(physicalFlow.specificationId());
        LogicalFlow logicalFlow = logicalFlowsById.get(physicalFlow.logicalFlowId());
        Long changeUnitId = cu.id().get();
        Collection<AssessmentRating> assessmentRatingsForChangeUnit = assessmentRatingsByEntityId.getOrDefault(changeUnitId, emptySet());
        Set<AssessmentRatingDetail> assessmentRatingDetailForChangeUnit = map(assessmentRatingsForChangeUnit, rating -> mkAssessmentDefinitionDetail(rating, ratingSchemeItemsById.get(rating.ratingId())));
        return ImmutablePhysicalFlowChangeUnitViewItem.builder().changeUnit(cu).physicalSpecification(spec).logicalFlow(logicalFlow).assessments(assessmentRatingDetailForChangeUnit).build();
    }).collect(toSet());
}
Also used : ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) PhysicalSpecificationService(org.finos.waltz.service.physical_specification.PhysicalSpecificationService) EntityKind(org.finos.waltz.model.EntityKind) PhysicalFlowChangeUnitViewItem(org.finos.waltz.model.change_unit.PhysicalFlowChangeUnitViewItem) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) Autowired(org.springframework.beans.factory.annotation.Autowired) RatingSchemeService(org.finos.waltz.service.rating_scheme.RatingSchemeService) AssessmentRatingDetail(org.finos.waltz.model.assessment_rating.AssessmentRatingDetail) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) ImmutablePhysicalFlowChangeUnitViewItem(org.finos.waltz.model.change_unit.ImmutablePhysicalFlowChangeUnitViewItem) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) Service(org.springframework.stereotype.Service) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) Map(java.util.Map) LogicalFlowService(org.finos.waltz.service.logical_flow.LogicalFlowService) Collectors.toSet(java.util.stream.Collectors.toSet) IdSelectionOptions.mkOptsForAllLifecycleStates(org.finos.waltz.model.IdSelectionOptions.mkOptsForAllLifecycleStates) PhysicalFlowService(org.finos.waltz.service.physical_flow.PhysicalFlowService) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Collections.emptySet(java.util.Collections.emptySet) Collection(java.util.Collection) Set(java.util.Set) MapUtilities.indexBy(org.finos.waltz.common.MapUtilities.indexBy) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) AssessmentRatingService(org.finos.waltz.service.assessment_rating.AssessmentRatingService) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) ImmutableAssessmentRatingDetail(org.finos.waltz.model.assessment_rating.ImmutableAssessmentRatingDetail) HierarchyQueryScope(org.finos.waltz.model.HierarchyQueryScope) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) Collectors.toSet(java.util.stream.Collectors.toSet) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) Collection(java.util.Collection) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Aggregations

Collection (java.util.Collection)2 List (java.util.List)2 EntityKind (org.finos.waltz.model.EntityKind)2 AssessmentRating (org.finos.waltz.model.assessment_rating.AssessmentRating)2 AssessmentRatingService (org.finos.waltz.service.assessment_rating.AssessmentRatingService)2 RatingSchemeService (org.finos.waltz.service.rating_scheme.RatingSchemeService)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Collections.emptySet (java.util.Collections.emptySet)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)1 CollectionUtilities.find (org.finos.waltz.common.CollectionUtilities.find)1 MapUtilities.groupBy (org.finos.waltz.common.MapUtilities.groupBy)1 MapUtilities.indexBy (org.finos.waltz.common.MapUtilities.indexBy)1 SetUtilities.map (org.finos.waltz.common.SetUtilities.map)1 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)1 AppHelper (org.finos.waltz.integration_test.inmem.helpers.AppHelper)1 ChangeLogHelper (org.finos.waltz.integration_test.inmem.helpers.ChangeLogHelper)1