WIP mifosx-195 more maintenance work plus fix reportId, parameterId in list reports api
This commit is contained in:
@@ -479,5 +479,9 @@ public class CommandWrapper {
|
||||
public boolean isCenterResource() {
|
||||
return this.entityName.equalsIgnoreCase("CENTER");
|
||||
}
|
||||
|
||||
public boolean isReportResource() {
|
||||
return this.entityName.equalsIgnoreCase("REPORT");
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -199,6 +199,14 @@ public class CommandWrapperBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder createReport() {
|
||||
this.actionName = "CREATE";
|
||||
this.entityName = "REPORT";
|
||||
this.entityId = null;
|
||||
this.href = "/reports/template";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder updateCurrencies() {
|
||||
this.actionName = "UPDATE";
|
||||
this.entityName = "CURRENCY";
|
||||
|
||||
+12
@@ -415,6 +415,18 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
||||
throw new UnsupportedCommandException(wrapper.commandName());
|
||||
}
|
||||
|
||||
} else if (wrapper.isReportResource()) {
|
||||
|
||||
if (wrapper.isCreate()) {
|
||||
handler = applicationContext.getBean("createReportCommandHandler", NewCommandSourceHandler.class);
|
||||
} else if (wrapper.isUpdate()) {
|
||||
handler = applicationContext.getBean("updateReportCommandHandler", NewCommandSourceHandler.class);
|
||||
} else if (wrapper.isDelete()) {
|
||||
handler = applicationContext.getBean("deleteReportCommandHandler", NewCommandSourceHandler.class);
|
||||
} else {
|
||||
throw new UnsupportedCommandException(wrapper.commandName());
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new UnsupportedCommandException(wrapper.commandName());
|
||||
}
|
||||
|
||||
+179
-103
@@ -6,13 +6,16 @@
|
||||
package org.mifosplatform.infrastructure.dataqueries.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
@@ -24,7 +27,13 @@ import javax.ws.rs.core.Response.ResponseBuilder;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
|
||||
import org.mifosplatform.infrastructure.dataqueries.data.ReportData;
|
||||
@@ -42,136 +51,203 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("singleton")
|
||||
public class ReportsApiResource {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ToApiJsonSerializer<GenericResultsetData> toApiJsonSerializer;
|
||||
private final ReadReportingService readExtraDataAndReportingService;
|
||||
private final GenericDataService genericDataService;
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(
|
||||
Arrays.asList("id", "reportName", "reportType", "reportSubType",
|
||||
"reportCategory", "description", "reportSql", "coreReport",
|
||||
"useReport", "reportParameters"));
|
||||
|
||||
@Autowired
|
||||
public ReportsApiResource(final PlatformSecurityContext context, final ReadReportingService readExtraDataAndReportingService,
|
||||
final GenericDataService genericDataService, final ToApiJsonSerializer<GenericResultsetData> toApiJsonSerializer) {
|
||||
this.context = context;
|
||||
this.readExtraDataAndReportingService = readExtraDataAndReportingService;
|
||||
this.genericDataService = genericDataService;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
}
|
||||
private final String resourceNameForPermissions = "FUND";
|
||||
private final PlatformSecurityContext context;
|
||||
private final ToApiJsonSerializer<ReportData> toApiJsonSerializer;
|
||||
private final ReadReportingService readExtraDataAndReportingService;
|
||||
private final GenericDataService genericDataService;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public Response retrieveReportList(@Context final UriInfo uriInfo) {
|
||||
@Autowired
|
||||
public ReportsApiResource(
|
||||
final PlatformSecurityContext context,
|
||||
final ReadReportingService readExtraDataAndReportingService,
|
||||
final GenericDataService genericDataService,
|
||||
final ToApiJsonSerializer<ReportData> toApiJsonSerializer,
|
||||
PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
|
||||
final ApiRequestParameterHelper apiRequestParameterHelper) {
|
||||
this.context = context;
|
||||
this.readExtraDataAndReportingService = readExtraDataAndReportingService;
|
||||
this.genericDataService = genericDataService;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveReportList(@Context final UriInfo uriInfo) {
|
||||
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
context.authenticatedUser().validateHasReadPermission(
|
||||
resourceNameForPermissions);
|
||||
|
||||
final Collection<ReportData> result = this.readExtraDataAndReportingService.retrieveReportList();
|
||||
final String json = this.toApiJsonSerializer.serializePretty(prettyPrint, result);
|
||||
final Collection<ReportData> result = this.readExtraDataAndReportingService
|
||||
.retrieveReportList();
|
||||
|
||||
return Response.ok().entity(json).build();
|
||||
}
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper
|
||||
.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, result,
|
||||
RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{reportName}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON, "application/x-msdownload", "application/vnd.ms-excel", "application/pdf", "text/html" })
|
||||
public Response retrieveReport(@PathParam("reportName") final String reportName, @Context final UriInfo uriInfo) {
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String createReport(final String apiRequestBodyAsJson) {
|
||||
|
||||
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder()
|
||||
.createReport().withJson(apiRequestBodyAsJson).build();
|
||||
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
boolean exportCsv = ApiParameterHelper.exportCsv(uriInfo.getQueryParameters());
|
||||
boolean parameterType = ApiParameterHelper.parameterType(uriInfo.getQueryParameters());
|
||||
boolean exportPdf = ApiParameterHelper.exportPdf(uriInfo.getQueryParameters());
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService
|
||||
.logCommandSource(commandRequest);
|
||||
|
||||
checkUserPermissionForReport(reportName, parameterType);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
String parameterTypeValue = null;
|
||||
if (!parameterType) {
|
||||
parameterTypeValue = "report";
|
||||
if (this.readExtraDataAndReportingService.getReportType(reportName).equalsIgnoreCase("Pentaho")) {
|
||||
Map<String, String> reportParams = getReportParams(queryParams, true);
|
||||
return this.readExtraDataAndReportingService.processPentahoRequest(reportName, queryParams.getFirst("output-type"),
|
||||
reportParams);
|
||||
}
|
||||
} else {
|
||||
parameterTypeValue = "parameter";
|
||||
}
|
||||
@GET
|
||||
@Path("{reportName}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON, "application/x-msdownload",
|
||||
"application/vnd.ms-excel", "application/pdf", "text/html" })
|
||||
public Response retrieveReport(
|
||||
@PathParam("reportName") final String reportName,
|
||||
@Context final UriInfo uriInfo) {
|
||||
|
||||
// PDF format
|
||||
MultivaluedMap<String, String> queryParams = uriInfo
|
||||
.getQueryParameters();
|
||||
|
||||
if (exportPdf) {
|
||||
Map<String, String> reportParams = getReportParams(queryParams, false);
|
||||
String pdfFileName = this.readExtraDataAndReportingService.retrieveReportPDF(reportName, parameterTypeValue, reportParams);
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo
|
||||
.getQueryParameters());
|
||||
boolean exportCsv = ApiParameterHelper.exportCsv(uriInfo
|
||||
.getQueryParameters());
|
||||
boolean parameterType = ApiParameterHelper.parameterType(uriInfo
|
||||
.getQueryParameters());
|
||||
boolean exportPdf = ApiParameterHelper.exportPdf(uriInfo
|
||||
.getQueryParameters());
|
||||
|
||||
File file = new File(pdfFileName);
|
||||
checkUserPermissionForReport(reportName, parameterType);
|
||||
|
||||
ResponseBuilder response = Response.ok(file);
|
||||
response.header("Content-Disposition", "attachment; filename=\"" + pdfFileName + "\"");
|
||||
response.header("content-Type", "application/pdf");
|
||||
String parameterTypeValue = null;
|
||||
if (!parameterType) {
|
||||
parameterTypeValue = "report";
|
||||
if (this.readExtraDataAndReportingService.getReportType(reportName)
|
||||
.equalsIgnoreCase("Pentaho")) {
|
||||
Map<String, String> reportParams = getReportParams(queryParams,
|
||||
true);
|
||||
return this.readExtraDataAndReportingService
|
||||
.processPentahoRequest(reportName,
|
||||
queryParams.getFirst("output-type"),
|
||||
reportParams);
|
||||
}
|
||||
} else {
|
||||
parameterTypeValue = "parameter";
|
||||
}
|
||||
|
||||
return response.build();
|
||||
// PDF format
|
||||
|
||||
}
|
||||
if (exportPdf) {
|
||||
Map<String, String> reportParams = getReportParams(queryParams,
|
||||
false);
|
||||
String pdfFileName = this.readExtraDataAndReportingService
|
||||
.retrieveReportPDF(reportName, parameterTypeValue,
|
||||
reportParams);
|
||||
|
||||
if (!exportCsv) {
|
||||
Map<String, String> reportParams = getReportParams(queryParams, false);
|
||||
File file = new File(pdfFileName);
|
||||
|
||||
GenericResultsetData result = this.readExtraDataAndReportingService.retrieveGenericResultset(reportName, parameterTypeValue,
|
||||
reportParams);
|
||||
ResponseBuilder response = Response.ok(file);
|
||||
response.header("Content-Disposition", "attachment; filename=\""
|
||||
+ pdfFileName + "\"");
|
||||
response.header("content-Type", "application/pdf");
|
||||
|
||||
String json = "";
|
||||
final boolean genericResultSetIsPassed = ApiParameterHelper.genericResultSetPassed(uriInfo.getQueryParameters());
|
||||
final boolean genericResultSet = ApiParameterHelper.genericResultSet(uriInfo.getQueryParameters());
|
||||
if (genericResultSetIsPassed) {
|
||||
if (genericResultSet) {
|
||||
json = this.toApiJsonSerializer.serializePretty(prettyPrint, result);
|
||||
} else {
|
||||
json = this.genericDataService.generateJsonFromGenericResultsetData(result);
|
||||
}
|
||||
} else {
|
||||
json = this.toApiJsonSerializer.serializePretty(prettyPrint, result);
|
||||
}
|
||||
return response.build();
|
||||
|
||||
return Response.ok().entity(json).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
|
||||
// CSV Export
|
||||
Map<String, String> reportParams = getReportParams(queryParams, false);
|
||||
StreamingOutput result = this.readExtraDataAndReportingService.retrieveReportCSV(reportName, parameterTypeValue, reportParams);
|
||||
if (!exportCsv) {
|
||||
Map<String, String> reportParams = getReportParams(queryParams,
|
||||
false);
|
||||
|
||||
return Response.ok().entity(result).type("application/x-msdownload")
|
||||
.header("Content-Disposition", "attachment;filename=" + reportName.replaceAll(" ", "") + ".csv").build();
|
||||
}
|
||||
GenericResultsetData result = this.readExtraDataAndReportingService
|
||||
.retrieveGenericResultset(reportName, parameterTypeValue,
|
||||
reportParams);
|
||||
|
||||
private void checkUserPermissionForReport(final String reportName, final boolean parameterType) {
|
||||
String json = "";
|
||||
final boolean genericResultSetIsPassed = ApiParameterHelper
|
||||
.genericResultSetPassed(uriInfo.getQueryParameters());
|
||||
final boolean genericResultSet = ApiParameterHelper
|
||||
.genericResultSet(uriInfo.getQueryParameters());
|
||||
if (genericResultSetIsPassed) {
|
||||
if (genericResultSet) {
|
||||
json = this.toApiJsonSerializer.serializePretty(
|
||||
prettyPrint, result);
|
||||
} else {
|
||||
json = this.genericDataService
|
||||
.generateJsonFromGenericResultsetData(result);
|
||||
}
|
||||
} else {
|
||||
json = this.toApiJsonSerializer.serializePretty(prettyPrint,
|
||||
result);
|
||||
}
|
||||
|
||||
// Anyone can run a 'report' that is simply getting possible parameter
|
||||
// (dropdown listbox) values.
|
||||
if (!parameterType) {
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
if (currentUser.hasNotPermissionForReport(reportName)) { throw new NoAuthorizationException("Not authorised to run report: "
|
||||
+ reportName); }
|
||||
}
|
||||
}
|
||||
return Response.ok().entity(json).type(MediaType.APPLICATION_JSON)
|
||||
.build();
|
||||
}
|
||||
|
||||
private Map<String, String> getReportParams(final MultivaluedMap<String, String> queryParams, final Boolean isPentaho) {
|
||||
// CSV Export
|
||||
Map<String, String> reportParams = getReportParams(queryParams, false);
|
||||
StreamingOutput result = this.readExtraDataAndReportingService
|
||||
.retrieveReportCSV(reportName, parameterTypeValue, reportParams);
|
||||
|
||||
Map<String, String> reportParams = new HashMap<String, String>();
|
||||
Set<String> keys = queryParams.keySet();
|
||||
String pKey;
|
||||
String pValue;
|
||||
for (String k : keys) {
|
||||
return Response
|
||||
.ok()
|
||||
.entity(result)
|
||||
.type("application/x-msdownload")
|
||||
.header("Content-Disposition",
|
||||
"attachment;filename=" + reportName.replaceAll(" ", "")
|
||||
+ ".csv").build();
|
||||
}
|
||||
|
||||
if (k.startsWith("R_")) {
|
||||
if (isPentaho)
|
||||
pKey = k.substring(2);
|
||||
else
|
||||
pKey = "${" + k.substring(2) + "}";
|
||||
private void checkUserPermissionForReport(final String reportName,
|
||||
final boolean parameterType) {
|
||||
|
||||
pValue = queryParams.get(k).get(0);
|
||||
reportParams.put(pKey, pValue);
|
||||
}
|
||||
}
|
||||
return reportParams;
|
||||
}
|
||||
// Anyone can run a 'report' that is simply getting possible parameter
|
||||
// (dropdown listbox) values.
|
||||
if (!parameterType) {
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
if (currentUser.hasNotPermissionForReport(reportName)) {
|
||||
throw new NoAuthorizationException(
|
||||
"Not authorised to run report: " + reportName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> getReportParams(
|
||||
final MultivaluedMap<String, String> queryParams,
|
||||
final Boolean isPentaho) {
|
||||
|
||||
Map<String, String> reportParams = new HashMap<String, String>();
|
||||
Set<String> keys = queryParams.keySet();
|
||||
String pKey;
|
||||
String pValue;
|
||||
for (String k : keys) {
|
||||
|
||||
if (k.startsWith("R_")) {
|
||||
if (isPentaho)
|
||||
pKey = k.substring(2);
|
||||
else
|
||||
pKey = "${" + k.substring(2) + "}";
|
||||
|
||||
pValue = queryParams.get(k).get(0);
|
||||
reportParams.put(pKey, pValue);
|
||||
}
|
||||
}
|
||||
return reportParams;
|
||||
}
|
||||
}
|
||||
+8
-5
@@ -10,7 +10,7 @@ import java.util.Collection;
|
||||
final public class ReportData {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Long reportId;
|
||||
private final Long id;
|
||||
@SuppressWarnings("unused")
|
||||
private final String reportName;
|
||||
@SuppressWarnings("unused")
|
||||
@@ -20,6 +20,8 @@ final public class ReportData {
|
||||
@SuppressWarnings("unused")
|
||||
private final String reportCategory;
|
||||
@SuppressWarnings("unused")
|
||||
private final String description;
|
||||
@SuppressWarnings("unused")
|
||||
private final String reportSql;
|
||||
@SuppressWarnings("unused")
|
||||
private final Boolean coreReport;
|
||||
@@ -28,20 +30,21 @@ final public class ReportData {
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<ReportParameterData> reportParameters;
|
||||
|
||||
public ReportData(final Long reportId, final String reportName,
|
||||
public ReportData(final Long id, final String reportName,
|
||||
final String reportType, final String reportSubType,
|
||||
final String reportCategory, final String reportSql,
|
||||
final String reportCategory, final String description, final String reportSql,
|
||||
final Boolean coreReport, final Boolean useReport,
|
||||
final Collection<ReportParameterData> reportParameters) {
|
||||
this.reportId = reportId;
|
||||
this.id = id;
|
||||
this.reportName = reportName;
|
||||
this.reportType = reportType;
|
||||
this.reportSubType = reportSubType;
|
||||
this.reportCategory = reportCategory;
|
||||
this.description = description;
|
||||
this.reportParameters = reportParameters;
|
||||
this.reportSql = reportSql;
|
||||
this.coreReport = coreReport;
|
||||
this.useReport = useReport;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+3
-3
@@ -8,15 +8,15 @@ package org.mifosplatform.infrastructure.dataqueries.data;
|
||||
final public class ReportParameterData {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Long reportParameterId;
|
||||
private final Long id;
|
||||
@SuppressWarnings("unused")
|
||||
private final String reportParameterName;
|
||||
@SuppressWarnings("unused")
|
||||
private final String parameterName;
|
||||
|
||||
public ReportParameterData(final Long reportParameterId,
|
||||
public ReportParameterData(final Long id,
|
||||
final String reportParameterName, final String parameterName) {
|
||||
this.reportParameterId = reportParameterId;
|
||||
this.id = id;
|
||||
this.reportParameterName = reportParameterName;
|
||||
this.parameterName = parameterName;
|
||||
}
|
||||
|
||||
+7
-1
@@ -12,6 +12,7 @@ final public class ReportParameterJoinData {
|
||||
private final String reportType;
|
||||
private final String reportSubType;
|
||||
private final String reportCategory;
|
||||
private final String description;
|
||||
private final String reportSql;
|
||||
private final Boolean coreReport;
|
||||
private final Boolean useReport;
|
||||
@@ -22,7 +23,7 @@ final public class ReportParameterJoinData {
|
||||
|
||||
public ReportParameterJoinData(final Long reportId,
|
||||
final String reportName, final String reportType,
|
||||
final String reportSubType, final String reportCategory,
|
||||
final String reportSubType, final String reportCategory, final String description,
|
||||
final String reportSql, final Boolean coreReport,
|
||||
final Boolean useReport, final Long reportParameterId,
|
||||
final String reportParameterName, final String parameterName) {
|
||||
@@ -31,6 +32,7 @@ final public class ReportParameterJoinData {
|
||||
this.reportType = reportType;
|
||||
this.reportSubType = reportSubType;
|
||||
this.reportCategory = reportCategory;
|
||||
this.description = description;
|
||||
this.reportSql = reportSql;
|
||||
this.coreReport = coreReport;
|
||||
this.useReport = useReport;
|
||||
@@ -83,4 +85,8 @@ final public class ReportParameterJoinData {
|
||||
return parameterName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
}
|
||||
+113
-86
@@ -5,123 +5,150 @@
|
||||
*/
|
||||
package org.mifosplatform.infrastructure.dataqueries.domain;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
|
||||
@Entity
|
||||
@Table(name = "stretchy_report", uniqueConstraints = { @UniqueConstraint(columnNames = { "report_name" }, name = "unq_report_name") })
|
||||
public class Report extends AbstractPersistable<Long> {
|
||||
|
||||
@Column(name = "report_name", nullable = false, unique = true)
|
||||
private String reportName;
|
||||
@Column(name = "report_name", nullable = false, unique = true)
|
||||
private String reportName;
|
||||
|
||||
@Column(name = "report_type", nullable = false)
|
||||
private String reportType;
|
||||
@Column(name = "report_type", nullable = false)
|
||||
private String reportType;
|
||||
|
||||
@Column(name = "report_subtype")
|
||||
private String reportSubType;
|
||||
@Column(name = "report_subtype")
|
||||
private String reportSubType;
|
||||
|
||||
@Column(name = "report_category")
|
||||
private String reportCategory;
|
||||
@Column(name = "report_category")
|
||||
private String reportCategory;
|
||||
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
|
||||
@Column(name = "core_report", nullable = false)
|
||||
private boolean core_Report;
|
||||
@Column(name = "core_report", nullable = false)
|
||||
private boolean coreReport;
|
||||
|
||||
//only defines if report should appear in reference app UI List
|
||||
@Column(name = "use_report", nullable = false)
|
||||
private boolean useReport;
|
||||
// only defines if report should appear in reference app UI List
|
||||
@Column(name = "use_report", nullable = false)
|
||||
private boolean useReport;
|
||||
|
||||
@Column(name = "report_sql")
|
||||
private String reportSql;
|
||||
@Column(name = "report_sql")
|
||||
private String reportSql;
|
||||
|
||||
/*
|
||||
@ManyToMany
|
||||
@JoinTable(name = "stretchy_report_parameter", joinColumns = @JoinColumn(name = "reportn_id"), inverseJoinColumns = @JoinColumn(name = "parameter_id"))
|
||||
private List<Charge> charges;
|
||||
*/
|
||||
/*
|
||||
* @ManyToMany
|
||||
*
|
||||
* @JoinTable(name = "stretchy_report_parameter", joinColumns =
|
||||
* @JoinColumn(name = "reportn_id"), inverseJoinColumns = @JoinColumn(name =
|
||||
* "parameter_id")) private List<Charge> charges;
|
||||
*/
|
||||
|
||||
public static Report fromJson(final JsonCommand command) {
|
||||
|
||||
public Report(final String reportName, final String reportType, final String reportSubType, final String reportCategory, final String description,
|
||||
final boolean core_Report, final boolean useReport, final String reportSql) {
|
||||
this.reportName = reportName;
|
||||
this.reportType = reportType;
|
||||
this.reportSubType = reportSubType;
|
||||
this.reportCategory = reportCategory;
|
||||
this.description = description;
|
||||
this.core_Report = core_Report;
|
||||
this.useReport = useReport;
|
||||
this.reportSql = reportSql;
|
||||
}
|
||||
final String reportName = command
|
||||
.stringValueOfParameterNamed("reportName");
|
||||
final String reportType = command
|
||||
.stringValueOfParameterNamed("reportType");
|
||||
final String reportSubType = command
|
||||
.stringValueOfParameterNamed("reportSubType");
|
||||
final String reportCategory = command
|
||||
.stringValueOfParameterNamed("reportCategory");
|
||||
final String description = command
|
||||
.stringValueOfParameterNamed("description");
|
||||
final boolean coreReport = command
|
||||
.booleanPrimitiveValueOfParameterNamed("coreReport");
|
||||
final boolean useReport = command
|
||||
.booleanPrimitiveValueOfParameterNamed("useReport");
|
||||
final String reportSql = command
|
||||
.stringValueOfParameterNamed("reportSql");
|
||||
|
||||
public String getReportName() {
|
||||
return reportName;
|
||||
return new Report(reportName, reportType, reportSubType,
|
||||
reportCategory, description, coreReport, useReport, reportSql);
|
||||
}
|
||||
|
||||
public void setReportName(String reportName) {
|
||||
protected Report() {
|
||||
//
|
||||
}
|
||||
|
||||
public Report(final String reportName, final String reportType,
|
||||
final String reportSubType, final String reportCategory,
|
||||
final String description, final boolean coreReport,
|
||||
final boolean useReport, final String reportSql) {
|
||||
this.reportName = reportName;
|
||||
}
|
||||
|
||||
public String getReportType() {
|
||||
return reportType;
|
||||
}
|
||||
|
||||
public void setReportType(String reportType) {
|
||||
this.reportType = reportType;
|
||||
}
|
||||
|
||||
public String getReportSubType() {
|
||||
return reportSubType;
|
||||
}
|
||||
|
||||
public void setReportSubType(String reportSubType) {
|
||||
this.reportSubType = reportSubType;
|
||||
}
|
||||
|
||||
public String getReportCategory() {
|
||||
return reportCategory;
|
||||
}
|
||||
|
||||
public void setReportCategory(String reportCategory) {
|
||||
this.reportCategory = reportCategory;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean isCore_Report() {
|
||||
return core_Report;
|
||||
}
|
||||
|
||||
public void setCore_Report(boolean core_Report) {
|
||||
this.core_Report = core_Report;
|
||||
}
|
||||
|
||||
public boolean isUseReport() {
|
||||
return useReport;
|
||||
}
|
||||
|
||||
public void setUseReport(boolean useReport) {
|
||||
this.coreReport = coreReport;
|
||||
this.useReport = useReport;
|
||||
}
|
||||
|
||||
public String getReportSql() {
|
||||
return reportSql;
|
||||
}
|
||||
|
||||
public void setReportSql(String reportSql) {
|
||||
this.reportSql = reportSql;
|
||||
}
|
||||
|
||||
public Map<String, Object> update(final JsonCommand command) {
|
||||
|
||||
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(8);
|
||||
|
||||
String paramName = "reportName";
|
||||
if (command.isChangeInStringParameterNamed(paramName, this.reportName)) {
|
||||
final String newValue = command.stringValueOfParameterNamed(paramName);
|
||||
actualChanges.put(paramName, newValue);
|
||||
this.reportName = StringUtils.defaultIfEmpty(newValue, null);
|
||||
}
|
||||
paramName = "reportType";
|
||||
if (command.isChangeInStringParameterNamed(paramName, this.reportType)) {
|
||||
final String newValue = command.stringValueOfParameterNamed(paramName);
|
||||
actualChanges.put(paramName, newValue);
|
||||
this.reportType = StringUtils.defaultIfEmpty(newValue, null);
|
||||
}
|
||||
paramName = "reportSubType";
|
||||
if (command.isChangeInStringParameterNamed(paramName, this.reportSubType)) {
|
||||
final String newValue = command.stringValueOfParameterNamed(paramName);
|
||||
actualChanges.put(paramName, newValue);
|
||||
this.reportSubType = StringUtils.defaultIfEmpty(newValue, null);
|
||||
}
|
||||
paramName = "reportCategory";
|
||||
if (command.isChangeInStringParameterNamed(paramName, this.reportCategory)) {
|
||||
final String newValue = command.stringValueOfParameterNamed(paramName);
|
||||
actualChanges.put(paramName, newValue);
|
||||
this.reportCategory = StringUtils.defaultIfEmpty(newValue, null);
|
||||
}
|
||||
paramName = "description";
|
||||
if (command.isChangeInStringParameterNamed(paramName, this.description)) {
|
||||
final String newValue = command.stringValueOfParameterNamed(paramName);
|
||||
actualChanges.put(paramName, newValue);
|
||||
this.description = StringUtils.defaultIfEmpty(newValue, null);
|
||||
}
|
||||
paramName = "coreReport";
|
||||
if (command.isChangeInBooleanParameterNamed(paramName, this.coreReport)) {
|
||||
final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(paramName);
|
||||
actualChanges.put(paramName, newValue);
|
||||
this.coreReport = newValue;
|
||||
}
|
||||
paramName = "useReport";
|
||||
if (command.isChangeInBooleanParameterNamed(paramName, this.useReport)) {
|
||||
final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(paramName);
|
||||
actualChanges.put(paramName, newValue);
|
||||
this.useReport = newValue;
|
||||
}
|
||||
paramName = "reportSql";
|
||||
if (command.isChangeInStringParameterNamed(paramName, this.reportSql)) {
|
||||
final String newValue = command.stringValueOfParameterNamed(paramName);
|
||||
actualChanges.put(paramName, newValue);
|
||||
this.reportSql = StringUtils.defaultIfEmpty(newValue, null);
|
||||
}
|
||||
|
||||
return actualChanges;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.infrastructure.dataqueries.domain;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
public interface ReportRepository extends JpaRepository<Report, Long>, JpaSpecificationExecutor<Report> {
|
||||
// no added behaviour
|
||||
}
|
||||
+4
@@ -15,4 +15,8 @@ public class ReportNotFoundException extends AbstractPlatformResourceNotFoundExc
|
||||
public ReportNotFoundException(final String reportSql) {
|
||||
super("error.msg.report.name.not.found", "Reporting meta-data entry not found.", "Input sql: " + reportSql);
|
||||
}
|
||||
|
||||
public ReportNotFoundException(final Long id) {
|
||||
super("error.msg.report.id.invalid", "Report with identifier " + id + " does not exist", id);
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.infrastructure.dataqueries.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
@Component
|
||||
public final class ReportCommandFromApiJsonDeserializer {
|
||||
|
||||
/**
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<String>(
|
||||
Arrays.asList("reportName", "reportType", "reportSubType",
|
||||
"reportCategory", "reportSql", "useReport"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public ReportCommandFromApiJsonDeserializer(
|
||||
final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
public void validateForCreate(final String json) {
|
||||
if (StringUtils.isBlank(json)) {
|
||||
throw new InvalidJsonException();
|
||||
}
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {
|
||||
}.getType();
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json,
|
||||
supportedParameters);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(
|
||||
dataValidationErrors).resource("report");
|
||||
|
||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||
/* WIP JPW
|
||||
Arrays.asList("reportName", "reportType", "reportSubType",
|
||||
"reportCategory", "reportSql", "useReport"));
|
||||
final String name = fromApiJsonHelper.extractStringNamed("name",
|
||||
element);
|
||||
baseDataValidator.reset().parameter("name").value(name).notBlank()
|
||||
.notExceedingLengthOf(100);
|
||||
|
||||
final String externalId = fromApiJsonHelper.extractStringNamed(
|
||||
"externalId", element);
|
||||
baseDataValidator.reset().parameter("externalId").value(externalId)
|
||||
.notExceedingLengthOf(100);
|
||||
*/
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
public void validateForUpdate(final String json) {
|
||||
if (StringUtils.isBlank(json)) {
|
||||
throw new InvalidJsonException();
|
||||
}
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {
|
||||
}.getType();
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json,
|
||||
supportedParameters);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(
|
||||
dataValidationErrors).resource("report");
|
||||
|
||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||
|
||||
/* wip jpw
|
||||
if (fromApiJsonHelper.parameterExists("name", element)) {
|
||||
final String name = fromApiJsonHelper.extractStringNamed("name",
|
||||
element);
|
||||
baseDataValidator.reset().parameter("name").value(name).notBlank()
|
||||
.notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
if (fromApiJsonHelper.parameterExists("externalId", element)) {
|
||||
final String externalId = fromApiJsonHelper.extractStringNamed(
|
||||
"externalId", element);
|
||||
baseDataValidator.reset().parameter("externalId").value(externalId)
|
||||
.notExceedingLengthOf(100);
|
||||
}
|
||||
*/
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
private void throwExceptionIfValidationWarningsExist(
|
||||
final List<ApiParameterError> dataValidationErrors) {
|
||||
if (!dataValidationErrors.isEmpty()) {
|
||||
throw new PlatformApiDataValidationException(
|
||||
"validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-8
@@ -529,6 +529,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
||||
String reportType = null;
|
||||
String reportSubType = null;
|
||||
String reportCategory = null;
|
||||
String description = null;
|
||||
Boolean coreReport = null;
|
||||
Boolean useReport = null;
|
||||
String reportSql = null;
|
||||
@@ -552,7 +553,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
||||
// write report entry
|
||||
reportList
|
||||
.add(new ReportData(reportId, reportName,
|
||||
reportType, reportSubType, reportCategory,
|
||||
reportType, reportSubType, reportCategory, description,
|
||||
reportSql, coreReport, useReport,
|
||||
reportParameters));
|
||||
}
|
||||
@@ -564,6 +565,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
||||
reportType = rpJoin.getReportType();
|
||||
reportSubType = rpJoin.getReportSubType();
|
||||
reportCategory = rpJoin.getReportCategory();
|
||||
description = rpJoin.getDescription();
|
||||
reportSql = rpJoin.getReportSql();
|
||||
coreReport = rpJoin.getCoreReport();
|
||||
useReport = rpJoin.getUseReport();
|
||||
@@ -583,7 +585,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
||||
}
|
||||
// write last report
|
||||
reportList.add(new ReportData(reportId, reportName, reportType,
|
||||
reportSubType, reportCategory, reportSql, coreReport,
|
||||
reportSubType, reportCategory, description, reportSql, coreReport,
|
||||
useReport, reportParameters));
|
||||
|
||||
return reportList;
|
||||
@@ -594,16 +596,16 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
||||
|
||||
public String schema(boolean includeSql, Long userId) {
|
||||
|
||||
String sql = "select r.report_id as reportId, r.report_name as reportName, r.report_type as reportType, "
|
||||
+ " r.report_subtype as reportSubType, r.report_category as reportCategory, r.core_report as coreReport, r.use_report as useReport, "
|
||||
String sql = "select r.id as reportId, r.report_name as reportName, r.report_type as reportType, "
|
||||
+ " r.report_subtype as reportSubType, r.report_category as reportCategory, r.description, r.core_report as coreReport, r.use_report as useReport, "
|
||||
+ " rp.parameter_id as reportParameterId, rp.report_parameter_name as reportParameterName, p.parameter_name as parameterName";
|
||||
|
||||
if (includeSql)
|
||||
sql += ", r.report_sql as reportSql ";
|
||||
|
||||
sql += " from stretchy_report r"
|
||||
+ " left join stretchy_report_parameter rp on rp.report_id = r.report_id"
|
||||
+ " left join stretchy_parameter p on p.parameter_id = rp.parameter_id"
|
||||
+ " left join stretchy_report_parameter rp on rp.report_id = r.id"
|
||||
+ " left join stretchy_parameter p on p.id = rp.parameter_id"
|
||||
+ " where exists"
|
||||
+ " (select 'f'"
|
||||
+ " from m_appuser_role ur "
|
||||
@@ -613,7 +615,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
||||
+ " where ur.appuser_id = "
|
||||
+ userId
|
||||
+ " and (p.code in ('ALL_FUNCTIONS', 'ALL_FUNCTIONS_READ') or p.code = concat('READ_', r.report_name))) "
|
||||
+ " order by r.report_id, rp.parameter_id";
|
||||
+ " order by r.id, rp.parameter_id";
|
||||
|
||||
return sql;
|
||||
}
|
||||
@@ -628,6 +630,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
||||
final String reportType = rs.getString("reportType");
|
||||
final String reportSubType = rs.getString("reportSubType");
|
||||
final String reportCategory = rs.getString("reportCategory");
|
||||
final String description = rs.getString("description");
|
||||
final Boolean coreReport = rs.getBoolean("coreReport");
|
||||
final Boolean useReport = rs.getBoolean("useReport");
|
||||
|
||||
@@ -646,7 +649,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
||||
final String parameterName = rs.getString("parameterName");
|
||||
|
||||
return new ReportParameterJoinData(reportId, reportName,
|
||||
reportType, reportSubType, reportCategory, reportSql,
|
||||
reportType, reportSubType, reportCategory, description, reportSql,
|
||||
coreReport, useReport, reportParameterId,
|
||||
reportParameterName, parameterName);
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.infrastructure.dataqueries.service;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
|
||||
public interface ReportWritePlatformService {
|
||||
|
||||
CommandProcessingResult createReport(JsonCommand command);
|
||||
|
||||
CommandProcessingResult updateReport(Long reportId, JsonCommand command);
|
||||
|
||||
CommandProcessingResult deleteReport(Long reportId);
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.infrastructure.dataqueries.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||
import org.mifosplatform.infrastructure.dataqueries.domain.Report;
|
||||
import org.mifosplatform.infrastructure.dataqueries.domain.ReportRepository;
|
||||
import org.mifosplatform.infrastructure.dataqueries.exception.ReportNotFoundException;
|
||||
import org.mifosplatform.infrastructure.dataqueries.serialization.ReportCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class ReportWritePlatformServiceImpl implements
|
||||
ReportWritePlatformService {
|
||||
|
||||
private final static Logger logger = LoggerFactory
|
||||
.getLogger(ReportWritePlatformServiceImpl.class);
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ReportCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||
private final ReportRepository reportRepository;
|
||||
|
||||
@Autowired
|
||||
public ReportWritePlatformServiceImpl(
|
||||
final PlatformSecurityContext context,
|
||||
final ReportCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||
final ReportRepository reportRepository) {
|
||||
this.context = context;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.reportRepository = reportRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult createReport(final JsonCommand command) {
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
this.fromApiJsonDeserializer.validateForCreate(command.json());
|
||||
|
||||
final Report report = Report.fromJson(command);
|
||||
|
||||
this.reportRepository.save(report);
|
||||
|
||||
return new CommandProcessingResultBuilder()
|
||||
.withCommandId(command.commandId())
|
||||
.withEntityId(report.getId()).build();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleReportDataIntegrityIssues(command, dve);
|
||||
return CommandProcessingResult.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult updateReport(final Long reportId,
|
||||
final JsonCommand command) {
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
this.fromApiJsonDeserializer.validateForUpdate(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.isEmpty()) {
|
||||
this.reportRepository.saveAndFlush(report);
|
||||
}
|
||||
|
||||
return new CommandProcessingResultBuilder()
|
||||
.withCommandId(command.commandId())
|
||||
.withEntityId(report.getId()).with(changes).build();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleReportDataIntegrityIssues(command, dve);
|
||||
return CommandProcessingResult.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult deleteReport(final Long reportId) {
|
||||
|
||||
final Report report = this.reportRepository.findOne(reportId);
|
||||
if (report == null) {
|
||||
throw new ReportNotFoundException(reportId);
|
||||
}
|
||||
|
||||
this.reportRepository.delete(report);
|
||||
|
||||
return new CommandProcessingResultBuilder().withEntityId(reportId)
|
||||
.build();
|
||||
}
|
||||
|
||||
/*
|
||||
* Guaranteed to throw an exception no matter what the data integrity issue
|
||||
* is.
|
||||
*/
|
||||
private void handleReportDataIntegrityIssues(final JsonCommand command,
|
||||
DataIntegrityViolationException dve) {
|
||||
|
||||
Throwable realCause = dve.getMostSpecificCause();
|
||||
if (realCause.getMessage().contains("unq_report_name")) {
|
||||
final String name = command
|
||||
.stringValueOfParameterNamed("reportName");
|
||||
throw new PlatformDataIntegrityException(
|
||||
"error.msg.report.duplicate.name", "A report with name '"
|
||||
+ name + "' already exists", "name", name);
|
||||
}
|
||||
|
||||
logger.error(dve.getMessage(), dve);
|
||||
throw new PlatformDataIntegrityException(
|
||||
"error.msg.report.unknown.data.integrity.issue",
|
||||
"Unknown data integrity issue with resource: "
|
||||
+ realCause.getMessage());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user