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