Skip to content

Commit

Permalink
Merge pull request finos#4978 from deutschebank/db-contrib/waltz-4965…
Browse files Browse the repository at this point in the history
…_audit_logs_change_rating_display_old_rating

Db contrib/waltz 4965 audit logs change rating display old rating
  • Loading branch information
davidwatkins73 authored Jul 2, 2020
2 parents 2856dd7 + 2760406 commit c80bc93
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ public static char firstChar(String str, char dflt) {
: dflt;
}

public static Optional<Character> firstChar(String str) {
return mkSafe(str).length() > 0
? Optional.of(str.charAt(0))
: Optional.empty();
}


public static Optional<String> toOptional(String str) {
return isEmpty(str)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
public abstract class SaveMeasurableRatingCommand extends MeasurableRatingCommand implements DescriptionProvider, ProvenanceProvider {

public abstract char rating();
public abstract Optional<Character> previousRating();

}

Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ function controller($q,
["rating", "rating"]);

const doRatingSave = (rating, description) => {
const currentRating = !_.isEmpty(vm.selected.rating) ? vm.selected.rating.rating : null;
return serviceBroker
.execute(
CORE_API.MeasurableRatingStore.save,
[vm.parentEntityRef, vm.selected.measurable.id, rating, description])
[vm.parentEntityRef, vm.selected.measurable.id, rating, currentRating, description])
.then(r => { vm.ratings = r.data })
.then(() => recalcTabs())
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ function store($http, baseApiUrl) {
.then(d => d.data);
};

const save = (ref, measurableId, rating = "Z", description = "") => {
const save = (ref, measurableId, rating = "Z", previousRating, description = "") => {
checkIsEntityRef(ref);
return $http
.post(`${baseUrl}/entity/${ref.kind}/${ref.id}/measurable/${measurableId}`, { rating, description })
.post(`${baseUrl}/entity/${ref.kind}/${ref.id}/measurable/${measurableId}`, { rating, previousRating, description })
.then(d => d.data);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,21 @@ public Collection<MeasurableRating> save(SaveMeasurableRatingCommand command) {

String entityName = getEntityName(command);

String previousRatingMessage = command.previousRating().isPresent()
? "from " + command.previousRating().get() : "";

writeChangeLogEntry(
command,
format("Saved: %s with a rating of: %s for %s",
format("Saved: %s with a rating of: %s %s for %s",
measurable.name(),
command.rating(),
previousRatingMessage,
entityName),
format("Saved: %s has assigned %s with a rating of: %s",
format("Saved: %s has assigned %s with a rating of: %s %s",
entityName,
measurable.name(),
command.rating()),
command.rating(),
previousRatingMessage),
operationThatWasPerformed);

return findForEntity(command.entityReference());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private SaveMeasurableRatingCommand mkCommand(Request request) throws IOExceptio
.entityReference(getEntityReference(request))
.measurableId(getLong(request, "measurableId"))
.rating(firstChar(body.getOrDefault("rating", "Z"), 'Z'))
.previousRating(firstChar(body.getOrDefault("previousRating", "")))
.description(body.getOrDefault("description", ""))
.lastUpdate(UserTimestamp.mkForUser(username))
.provenance("waltz")
Expand Down

0 comments on commit c80bc93

Please sign in to comment.