Search in sources :

Example 1 with RatingSchemeItem

use of org.finos.waltz.model.rating.RatingSchemeItem 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)

Example 2 with RatingSchemeItem

use of org.finos.waltz.model.rating.RatingSchemeItem 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 3 with RatingSchemeItem

use of org.finos.waltz.model.rating.RatingSchemeItem 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 4 with RatingSchemeItem

use of org.finos.waltz.model.rating.RatingSchemeItem in project waltz by khartec.

the class ScenarioRatingItemService method writeUpdateRatingLog.

private void writeUpdateRatingLog(ChangeScenarioCommand command, String userId) {
    String message;
    Application application = applicationService.getById(command.appId());
    Scenario scenario = scenarioService.getById(command.scenarioId());
    List<RatingSchemeItem> ratings = ratingSchemeService.getById(command.ratingSchemeId()).ratings();
    message = String.format("Application %s (%s), moved from %s to %s for %s", ExternalIdValue.orElse(application.assetCode(), "Unknown"), application.name(), getRatingName(ratings, command.previousRating()), getRatingName(ratings, command.rating()), scenario.name());
    changeLogService.write(mkBasicLogEntry(command.scenarioId(), message, userId));
}
Also used : Application(org.finos.waltz.model.application.Application) Scenario(org.finos.waltz.model.scenario.Scenario) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem)

Example 5 with RatingSchemeItem

use of org.finos.waltz.model.rating.RatingSchemeItem in project waltz by khartec.

the class ReportGridExtractor method prepareReportRows.

private List<Tuple2<Application, ArrayList<Object>>> prepareReportRows(Set<Tuple2<ReportGridColumnDefinition, Boolean>> colsWithCommentRequirement, ReportGridInstance reportGridInstance) {
    Set<ReportGridCell> tableData = reportGridInstance.cellData();
    Map<Long, Application> applicationsById = indexById(reportGridInstance.applications());
    Map<Long, RatingSchemeItem> ratingsById = indexById(reportGridInstance.ratingSchemeItems());
    Map<Long, Collection<ReportGridCell>> tableDataByAppId = groupBy(tableData, ReportGridCell::applicationId);
    boolean allowCostsExport = settingsService.getValue(SettingsService.ALLOW_COST_EXPORTS_KEY).map(r -> StringUtilities.isEmpty(r) || Boolean.parseBoolean(r)).orElse(true);
    return tableDataByAppId.entrySet().stream().map(r -> {
        Long appId = r.getKey();
        Application app = applicationsById.getOrDefault(appId, null);
        ArrayList<Object> reportRow = new ArrayList<>();
        Collection<ReportGridCell> cells = r.getValue();
        Map<Tuple3<Long, EntityKind, Long>, ReportGridCell> cellValuesByColumnRefForApp = indexBy(cells, k -> tuple(k.columnEntityId(), k.columnEntityKind(), k.entityFieldReferenceId()));
        // find data for columns
        colsWithCommentRequirement.forEach(t -> {
            ReportGridColumnDefinition colDef = t.v1;
            Boolean needsComment = t.v2;
            boolean isCostColumn = colDef.columnEntityKind().equals(EntityKind.COST_KIND);
            if (!allowCostsExport && isCostColumn) {
                reportRow.add("REDACTED");
            } else {
                ReportGridCell cell = cellValuesByColumnRefForApp.getOrDefault(tuple(colDef.columnEntityId(), colDef.columnEntityKind(), getIdOrDefault(colDef.entityFieldReference(), null)), null);
                reportRow.add(getValueFromReportCell(ratingsById, cell));
                if (needsComment) {
                    reportRow.add(getCommentFromCell(cell));
                }
            }
        });
        return tuple(app, reportRow);
    }).sorted(Comparator.comparing(t -> t.v1.name())).collect(toList());
}
Also used : CellType(org.apache.poi.ss.usermodel.CellType) LifecyclePhase(org.finos.waltz.model.application.LifecyclePhase) java.util(java.util) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IdUtilities.getIdOrDefault(org.finos.waltz.model.utils.IdUtilities.getIdOrDefault) EntityKind(org.finos.waltz.model.EntityKind) ReportGridService(org.finos.waltz.service.report_grid.ReportGridService) org.finos.waltz.model.report_grid(org.finos.waltz.model.report_grid) SurveyQuestionService(org.finos.waltz.service.survey.SurveyQuestionService) Autowired(org.springframework.beans.factory.annotation.Autowired) Spark.post(spark.Spark.post) CollectionUtilities(org.finos.waltz.common.CollectionUtilities) CsvPreference(org.supercsv.prefs.CsvPreference) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Tuple2(org.jooq.lambda.tuple.Tuple2) Tuple3(org.jooq.lambda.tuple.Tuple3) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(org.springframework.stereotype.Service) CsvListWriter(org.supercsv.io.CsvListWriter) Cell(org.apache.poi.ss.usermodel.Cell) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet) IdUtilities.indexById(org.finos.waltz.model.utils.IdUtilities.indexById) Collectors.toSet(java.util.stream.Collectors.toSet) StringUtilities(org.finos.waltz.common.StringUtilities) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) SurveyQuestion(org.finos.waltz.model.survey.SurveyQuestion) MapUtilities(org.finos.waltz.common.MapUtilities) Application(org.finos.waltz.model.application.Application) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) NameProvider(org.finos.waltz.model.NameProvider) SettingsService(org.finos.waltz.service.settings.SettingsService) Collectors.toList(java.util.stream.Collectors.toList) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) Stream(java.util.stream.Stream) CheckedConsumer.unchecked(org.jooq.lambda.fi.util.function.CheckedConsumer.unchecked) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) ListUtilities(org.finos.waltz.common.ListUtilities) WebUtilities(org.finos.waltz.web.WebUtilities) Row(org.apache.poi.ss.usermodel.Row) EntityReference(org.finos.waltz.model.EntityReference) IdUtilities(org.finos.waltz.model.utils.IdUtilities) EntityFieldReference(org.finos.waltz.model.entity_field_reference.EntityFieldReference) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) Tuple3(org.jooq.lambda.tuple.Tuple3) Application(org.finos.waltz.model.application.Application)

Aggregations

RatingSchemeItem (org.finos.waltz.model.rating.RatingSchemeItem)7 Collectors (java.util.stream.Collectors)5 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)5 RatingSchemeDAO (org.finos.waltz.data.rating_scheme.RatingSchemeDAO)4 EntityKind (org.finos.waltz.model.EntityKind)4 Application (org.finos.waltz.model.application.Application)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 MapUtilities.indexBy (org.finos.waltz.common.MapUtilities.indexBy)3 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)3 ExternalIdValue (org.finos.waltz.model.external_identifier.ExternalIdValue)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 CsvPreference (org.supercsv.prefs.CsvPreference)3 InputStreamReader (java.io.InputStreamReader)2 String.format (java.lang.String.format)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2