try {
this.context.authenticatedUser();
this.fromApiJsonDeserializer.validate(command.json());
final Report report = this.reportRepository.findOne(reportId);
if (report == null) { throw new ReportNotFoundException(reportId); }
final Map<String, Object> changes = report.update(command);
if (changes.containsKey("reportParameters")) {
final Set<ReportParameterUsage> reportParameterUsages = assembleSetOfReportParameterUsages(report, command);
final boolean updated = report.update(reportParameterUsages);
if (!updated) {
changes.remove("reportParameters");
}
}
if (!changes.isEmpty()) {
this.reportRepository.saveAndFlush(report);
}
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
.withEntityId(report.getId()) //
.with(changes) //
.build();
} catch (final DataIntegrityViolationException dve) {
handleReportDataIntegrityIssues(command, dve);
return CommandProcessingResult.empty();