Search in sources :

Example 6 with ChangeLog

use of org.finos.waltz.model.changelog.ChangeLog 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 7 with ChangeLog

use of org.finos.waltz.model.changelog.ChangeLog 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 8 with ChangeLog

use of org.finos.waltz.model.changelog.ChangeLog in project waltz by khartec.

the class AssessmentRatingService method remove.

public boolean remove(RemoveAssessmentRatingCommand command, String username) {
    ChangeLog logEntry = ImmutableChangeLog.builder().message(format("Removed %s", assessmentDefinitionDao.getById(command.assessmentDefinitionId()).name())).parentReference(mkRef(command.entityReference().kind(), command.entityReference().id())).userId(username).childKind(command.entityReference().kind()).severity(Severity.INFORMATION).operation(Operation.REMOVE).build();
    changeLogService.write(logEntry);
    return assessmentRatingDao.remove(command);
}
Also used : ImmutableChangeLog(org.finos.waltz.model.changelog.ImmutableChangeLog) ChangeLog(org.finos.waltz.model.changelog.ChangeLog)

Example 9 with ChangeLog

use of org.finos.waltz.model.changelog.ChangeLog in project waltz by khartec.

the class ChangeInitiativeService method addEntityRelationship.

public boolean addEntityRelationship(long changeInitiativeId, EntityRelationshipChangeCommand command, String username) {
    checkNotNull(command, "command cannot be null");
    EntityRelationshipKey key = mkEntityRelationshipKey(changeInitiativeId, command, true);
    EntityRelationship entityRelationship = ImmutableEntityRelationship.builder().a(key.a()).b(key.b()).relationship(key.relationshipKind()).lastUpdatedBy(username).lastUpdatedAt(DateTimeUtilities.nowUtc()).build();
    ChangeLog logEntry = ImmutableChangeLog.builder().message(String.format("Relationship to %s (%s) added", command.entityReference().name().orElse(""), command.entityReference().kind().name() + "/" + command.entityReference().id())).parentReference(mkRef(CHANGE_INITIATIVE, changeInitiativeId)).userId(username).childKind(command.entityReference().kind()).severity(Severity.INFORMATION).operation(Operation.ADD).build();
    changeLogService.write(logEntry);
    return relationshipDao.save(entityRelationship) == 1;
}
Also used : ImmutableChangeLog(org.finos.waltz.model.changelog.ImmutableChangeLog) ChangeLog(org.finos.waltz.model.changelog.ChangeLog)

Example 10 with ChangeLog

use of org.finos.waltz.model.changelog.ChangeLog in project waltz by khartec.

the class ChangeInitiativeService method removeEntityRelationship.

public boolean removeEntityRelationship(long changeInitiativeId, EntityRelationshipChangeCommand command, String username) {
    checkNotNull(command, "command cannot be null");
    EntityRelationshipKey key = mkEntityRelationshipKey(changeInitiativeId, command, false);
    ChangeLog logEntry = ImmutableChangeLog.builder().message(String.format("Relationship to %s (%s) removed", command.entityReference().name().orElse(""), command.entityReference().kind().name() + "/" + command.entityReference().id())).parentReference(mkRef(CHANGE_INITIATIVE, changeInitiativeId)).userId(username).childKind(command.entityReference().kind()).severity(Severity.INFORMATION).operation(Operation.REMOVE).build();
    changeLogService.write(logEntry);
    return relationshipDao.remove(key);
}
Also used : ImmutableChangeLog(org.finos.waltz.model.changelog.ImmutableChangeLog) ChangeLog(org.finos.waltz.model.changelog.ChangeLog)

Aggregations

ChangeLog (org.finos.waltz.model.changelog.ChangeLog)18 ImmutableChangeLog (org.finos.waltz.model.changelog.ImmutableChangeLog)18 String.format (java.lang.String.format)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)3 org.finos.waltz.model (org.finos.waltz.model)3 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)3 CustomEnvironment (org.finos.waltz.model.custom_environment.CustomEnvironment)3 ChangeLogService (org.finos.waltz.service.changelog.ChangeLogService)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 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 AssessmentDefinition (org.finos.waltz.model.assessment_definition.AssessmentDefinition)2