wip mifosx-195 report maintenance changes
This commit is contained in:
+7
-4
@@ -11,14 +11,17 @@ final public class ReportParameterData {
|
||||
@SuppressWarnings("unused")
|
||||
private final Long id;
|
||||
@SuppressWarnings("unused")
|
||||
private final String reportParameterName;
|
||||
private final Long parameterId;
|
||||
@SuppressWarnings("unused")
|
||||
private final String parameterName;
|
||||
@SuppressWarnings("unused")
|
||||
private final String reportParameterName;
|
||||
|
||||
public ReportParameterData(final Long id, final String reportParameterName,
|
||||
final String parameterName) {
|
||||
public ReportParameterData(final Long id, final Long parameterId,
|
||||
final String reportParameterName, final String parameterName) {
|
||||
this.id = id;
|
||||
this.reportParameterName = reportParameterName;
|
||||
this.parameterId = parameterId;
|
||||
this.parameterName = parameterName;
|
||||
this.reportParameterName = reportParameterName;
|
||||
}
|
||||
}
|
||||
+74
-64
@@ -7,82 +7,92 @@ package org.mifosplatform.infrastructure.dataqueries.data;
|
||||
|
||||
final public class ReportParameterJoinData {
|
||||
|
||||
private final Long reportId;
|
||||
private final String reportName;
|
||||
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;
|
||||
private final Long reportId;
|
||||
private final String reportName;
|
||||
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;
|
||||
|
||||
private final Long reportParameterId;
|
||||
private final String reportParameterName;
|
||||
private final String parameterName;
|
||||
private final Long reportParameterId;
|
||||
private final Long parameterId;
|
||||
private final String reportParameterName;
|
||||
private final String parameterName;
|
||||
|
||||
public ReportParameterJoinData(final Long reportId, final String reportName, final String reportType, 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) {
|
||||
this.reportId = reportId;
|
||||
this.reportName = reportName;
|
||||
this.reportType = reportType;
|
||||
this.reportSubType = reportSubType;
|
||||
this.reportCategory = reportCategory;
|
||||
this.description = description;
|
||||
this.reportSql = reportSql;
|
||||
this.coreReport = coreReport;
|
||||
this.useReport = useReport;
|
||||
this.reportParameterId = reportParameterId;
|
||||
this.reportParameterName = reportParameterName;
|
||||
this.parameterName = parameterName;
|
||||
}
|
||||
public ReportParameterJoinData(final Long reportId,
|
||||
final String reportName, final String reportType,
|
||||
final String reportSubType, final String reportCategory,
|
||||
final String description, final String reportSql,
|
||||
final Boolean coreReport, final Boolean useReport,
|
||||
final Long reportParameterId, final Long parameterId,
|
||||
final String reportParameterName, final String parameterName) {
|
||||
this.reportId = reportId;
|
||||
this.reportName = reportName;
|
||||
this.reportType = reportType;
|
||||
this.reportSubType = reportSubType;
|
||||
this.reportCategory = reportCategory;
|
||||
this.description = description;
|
||||
this.reportSql = reportSql;
|
||||
this.coreReport = coreReport;
|
||||
this.useReport = useReport;
|
||||
this.reportParameterId = reportParameterId;
|
||||
this.parameterId = parameterId;
|
||||
this.reportParameterName = reportParameterName;
|
||||
this.parameterName = parameterName;
|
||||
}
|
||||
|
||||
public Long getReportId() {
|
||||
return reportId;
|
||||
}
|
||||
public Long getReportId() {
|
||||
return reportId;
|
||||
}
|
||||
|
||||
public String getReportName() {
|
||||
return reportName;
|
||||
}
|
||||
public String getReportName() {
|
||||
return reportName;
|
||||
}
|
||||
|
||||
public String getReportType() {
|
||||
return reportType;
|
||||
}
|
||||
public String getReportType() {
|
||||
return reportType;
|
||||
}
|
||||
|
||||
public String getReportSubType() {
|
||||
return reportSubType;
|
||||
}
|
||||
public String getReportSubType() {
|
||||
return reportSubType;
|
||||
}
|
||||
|
||||
public String getReportCategory() {
|
||||
return reportCategory;
|
||||
}
|
||||
public String getReportCategory() {
|
||||
return reportCategory;
|
||||
}
|
||||
|
||||
public String getReportSql() {
|
||||
return reportSql;
|
||||
}
|
||||
public String getReportSql() {
|
||||
return reportSql;
|
||||
}
|
||||
|
||||
public Boolean getCoreReport() {
|
||||
return coreReport;
|
||||
}
|
||||
public Boolean getCoreReport() {
|
||||
return coreReport;
|
||||
}
|
||||
|
||||
public Boolean getUseReport() {
|
||||
return useReport;
|
||||
}
|
||||
public Boolean getUseReport() {
|
||||
return useReport;
|
||||
}
|
||||
|
||||
public Long getReportParameterId() {
|
||||
return reportParameterId;
|
||||
}
|
||||
public Long getReportParameterId() {
|
||||
return reportParameterId;
|
||||
}
|
||||
|
||||
public String getReportParameterName() {
|
||||
return reportParameterName;
|
||||
}
|
||||
public Long getParameterId() {
|
||||
return parameterId;
|
||||
}
|
||||
|
||||
public String getParameterName() {
|
||||
return parameterName;
|
||||
}
|
||||
public String getReportParameterName() {
|
||||
return reportParameterName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public String getParameterName() {
|
||||
return parameterName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
+214
-145
@@ -9,13 +9,18 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
@@ -27,180 +32,244 @@ import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
@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 coreReport;
|
||||
@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;
|
||||
*/
|
||||
@LazyCollection(LazyCollectionOption.FALSE)
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "report", orphanRemoval = true)
|
||||
private Set<ReportParameterUsage> reportParameterUsages = null;
|
||||
|
||||
public static Report fromJson(final JsonCommand command) {
|
||||
public static Report fromJson(
|
||||
final Set<ReportParameterUsage> reportParameterUsages,
|
||||
final JsonCommand command) {
|
||||
|
||||
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 useReport = command.booleanPrimitiveValueOfParameterNamed("useReport");
|
||||
final String reportSql = command.stringValueOfParameterNamed("reportSql");
|
||||
String reportName = null;
|
||||
String reportType = null;
|
||||
String reportSubType = null;
|
||||
String reportCategory = null;
|
||||
String description = null;
|
||||
boolean useReport = false;
|
||||
String reportSql = null;
|
||||
|
||||
return new Report(reportName, reportType, reportSubType, reportCategory, description, useReport, reportSql);
|
||||
}
|
||||
if (command.parameterExists("reportName"))
|
||||
reportName = command.stringValueOfParameterNamed("reportName");
|
||||
if (command.parameterExists("reportType"))
|
||||
reportType = command.stringValueOfParameterNamed("reportType");
|
||||
if (command.parameterExists("reportSubType"))
|
||||
reportSubType = command
|
||||
.stringValueOfParameterNamed("reportSubType");
|
||||
if (command.parameterExists("reportCategory"))
|
||||
reportCategory = command
|
||||
.stringValueOfParameterNamed("reportCategory");
|
||||
if (command.parameterExists("description"))
|
||||
description = command.stringValueOfParameterNamed("description");
|
||||
if (command.parameterExists("useReport"))
|
||||
useReport = command
|
||||
.booleanPrimitiveValueOfParameterNamed("useReport");
|
||||
if (command.parameterExists("reportSql"))
|
||||
reportSql = command.stringValueOfParameterNamed("reportSql");
|
||||
|
||||
protected Report() {
|
||||
//
|
||||
}
|
||||
return new Report(reportName, reportType, reportSubType,
|
||||
reportCategory, description, useReport, reportSql,
|
||||
reportParameterUsages);
|
||||
}
|
||||
|
||||
public Report(final String reportName, final String reportType, final String reportSubType, final String reportCategory,
|
||||
final String description, final boolean useReport, final String reportSql) {
|
||||
this.reportName = reportName;
|
||||
this.reportType = reportType;
|
||||
this.reportSubType = reportSubType;
|
||||
this.reportCategory = reportCategory;
|
||||
this.description = description;
|
||||
this.coreReport = false;
|
||||
this.useReport = useReport;
|
||||
this.reportSql = reportSql;
|
||||
validate();
|
||||
}
|
||||
protected Report() {
|
||||
//
|
||||
}
|
||||
|
||||
public Map<String, Object> update(final JsonCommand command) {
|
||||
public Report(final String reportName, final String reportType,
|
||||
final String reportSubType, final String reportCategory,
|
||||
final String description, final boolean useReport,
|
||||
final String reportSql,
|
||||
final Set<ReportParameterUsage> reportParameterUsages) {
|
||||
this.reportName = reportName;
|
||||
this.reportType = reportType;
|
||||
this.reportSubType = reportSubType;
|
||||
this.reportCategory = reportCategory;
|
||||
this.description = description;
|
||||
this.coreReport = false;
|
||||
this.useReport = useReport;
|
||||
this.reportSql = reportSql;
|
||||
this.reportParameterUsages = reportParameterUsages;
|
||||
validate();
|
||||
}
|
||||
|
||||
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(8);
|
||||
public Map<String, Object> update(final JsonCommand command) {
|
||||
|
||||
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 = "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);
|
||||
}
|
||||
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(
|
||||
8);
|
||||
|
||||
validate();
|
||||
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 = "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);
|
||||
}
|
||||
|
||||
if (!actualChanges.isEmpty()) {
|
||||
if (isCoreReport()) {
|
||||
for (final String key : actualChanges.keySet()) {
|
||||
if (!(key.equals("useReport"))) { throw new PlatformDataIntegrityException(
|
||||
"error.msg.only.use.report.can.be.updated.for.core.report",
|
||||
"Only the Use Report field can be updated for Core Reports", key); }
|
||||
}
|
||||
}
|
||||
}
|
||||
validate();
|
||||
|
||||
return actualChanges;
|
||||
}
|
||||
if (!actualChanges.isEmpty()) {
|
||||
if (isCoreReport()) {
|
||||
for (final String key : actualChanges.keySet()) {
|
||||
if (!(key.equals("useReport"))) {
|
||||
throw new PlatformDataIntegrityException(
|
||||
"error.msg.only.use.report.can.be.updated.for.core.report",
|
||||
"Only the Use Report field can be updated for Core Reports",
|
||||
key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCoreReport() {
|
||||
return coreReport;
|
||||
}
|
||||
return actualChanges;
|
||||
}
|
||||
|
||||
private void validate() {
|
||||
public boolean isCoreReport() {
|
||||
return coreReport;
|
||||
}
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("report");
|
||||
private void validate() {
|
||||
|
||||
baseDataValidator.reset().parameter("reportName").value(this.reportName).notBlank().notExceedingLengthOf(100);
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(
|
||||
dataValidationErrors).resource("report");
|
||||
|
||||
baseDataValidator.reset().parameter("reportType").value(this.reportType).notBlank()
|
||||
.isOneOfTheseValues(new Object[] { "Table", "Pentaho", "Chart" });
|
||||
baseDataValidator.reset().parameter("reportName")
|
||||
.value(this.reportName).notBlank().notExceedingLengthOf(100);
|
||||
|
||||
baseDataValidator.reset().parameter("reportSubType").value(this.reportSubType).notExceedingLengthOf(20);
|
||||
baseDataValidator
|
||||
.reset()
|
||||
.parameter("reportType")
|
||||
.value(this.reportType)
|
||||
.notBlank()
|
||||
.isOneOfTheseValues(
|
||||
new Object[] { "Table", "Pentaho", "Chart" });
|
||||
|
||||
if (StringUtils.isNotBlank(this.reportType)) {
|
||||
if (this.reportType.equals("Chart")) {
|
||||
baseDataValidator.reset().parameter("reportSubType").value(this.reportSubType)
|
||||
.cantBeBlankWhenParameterProvidedIs("reportType", this.reportType)
|
||||
.isOneOfTheseValues(new Object[] { "Bar", "Pie" });
|
||||
} else {
|
||||
baseDataValidator.reset().parameter("reportSubType").value(this.reportSubType)
|
||||
.mustBeBlankWhenParameterProvidedIs("reportType", this.reportType);
|
||||
}
|
||||
}
|
||||
baseDataValidator.reset().parameter("reportSubType")
|
||||
.value(this.reportSubType).notExceedingLengthOf(20);
|
||||
|
||||
baseDataValidator.reset().parameter("reportCategory").value(this.reportCategory).notExceedingLengthOf(45);
|
||||
if (StringUtils.isNotBlank(this.reportType)) {
|
||||
if (this.reportType.equals("Chart")) {
|
||||
baseDataValidator
|
||||
.reset()
|
||||
.parameter("reportSubType")
|
||||
.value(this.reportSubType)
|
||||
.cantBeBlankWhenParameterProvidedIs("reportType",
|
||||
this.reportType)
|
||||
.isOneOfTheseValues(new Object[] { "Bar", "Pie" });
|
||||
} else {
|
||||
baseDataValidator
|
||||
.reset()
|
||||
.parameter("reportSubType")
|
||||
.value(this.reportSubType)
|
||||
.mustBeBlankWhenParameterProvidedIs("reportType",
|
||||
this.reportType);
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(this.reportType)) {
|
||||
if ((this.reportType.equals("Table")) || (this.reportType.equals("Chart"))) {
|
||||
baseDataValidator.reset().parameter("reportSql").value(this.reportSql)
|
||||
.cantBeBlankWhenParameterProvidedIs("reportType", this.reportType);
|
||||
} else {
|
||||
baseDataValidator.reset().parameter("reportSql").value(this.reportSql)
|
||||
.mustBeBlankWhenParameterProvidedIs("reportType", this.reportType);
|
||||
}
|
||||
}
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
baseDataValidator.reset().parameter("reportCategory")
|
||||
.value(this.reportCategory).notExceedingLengthOf(45);
|
||||
|
||||
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
if (StringUtils.isNotBlank(this.reportType)) {
|
||||
if ((this.reportType.equals("Table"))
|
||||
|| (this.reportType.equals("Chart"))) {
|
||||
baseDataValidator
|
||||
.reset()
|
||||
.parameter("reportSql")
|
||||
.value(this.reportSql)
|
||||
.cantBeBlankWhenParameterProvidedIs("reportType",
|
||||
this.reportType);
|
||||
} else {
|
||||
baseDataValidator
|
||||
.reset()
|
||||
.parameter("reportSql")
|
||||
.value(this.reportSql)
|
||||
.mustBeBlankWhenParameterProvidedIs("reportType",
|
||||
this.reportType);
|
||||
}
|
||||
}
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
public String getReportName() {
|
||||
return reportName;
|
||||
}
|
||||
private void throwExceptionIfValidationWarningsExist(
|
||||
final List<ApiParameterError> dataValidationErrors) {
|
||||
if (!dataValidationErrors.isEmpty()) {
|
||||
throw new PlatformApiDataValidationException(
|
||||
"validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors);
|
||||
}
|
||||
}
|
||||
|
||||
public String getReportName() {
|
||||
return reportName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 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 javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
|
||||
@Entity
|
||||
@Table(name = "stretchy_parameter")
|
||||
public class ReportParameter extends AbstractPersistable<Long> {
|
||||
|
||||
|
||||
protected ReportParameter() {
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+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 ReportParameterRepository extends JpaRepository<ReportParameter, Long>, JpaSpecificationExecutor<ReportParameter> {
|
||||
// no added behaviour
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 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 javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
|
||||
@Entity
|
||||
@Table(name = "stretchy_report_parameter")
|
||||
public class ReportParameterUsage extends AbstractPersistable<Long> {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "report_id", nullable = false)
|
||||
private Report report;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "parameter_id", nullable = false)
|
||||
private ReportParameter parameter;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Column(name = "report_parameter_name")
|
||||
private String reportParameterName;
|
||||
|
||||
protected ReportParameterUsage() {
|
||||
//
|
||||
}
|
||||
|
||||
public ReportParameterUsage(final Report report,
|
||||
final ReportParameter parameter, final String reportParameterName) {
|
||||
this.report = report;
|
||||
this.parameter = parameter;
|
||||
this.reportParameterName = reportParameterName;
|
||||
}
|
||||
|
||||
public void setReport(Report report) {
|
||||
this.report = report;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-2
@@ -15,8 +15,7 @@ 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);
|
||||
super("error.msg.report.parameter.id.invalid", "Report Parameter with identifier " + id + " does not exist", id);
|
||||
}
|
||||
}
|
||||
+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.exception;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when report resources are not found.
|
||||
*/
|
||||
public class ReportParameterNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
public ReportParameterNotFoundException(final Long id) {
|
||||
super("error.msg.report.parameter.id.invalid", "Report Parameter with identifier " + id + " does not exist", id);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -26,7 +26,7 @@ public final class ReportCommandFromApiJsonDeserializer {
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("reportName", "reportType", "reportSubType",
|
||||
"reportCategory", "description", "reportSql", "useReport"));
|
||||
"reportCategory", "description", "reportSql", "useReport", "reportParameters"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
|
||||
|
||||
+6
-5
@@ -457,7 +457,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
||||
if (reportParameters == null) {
|
||||
reportParameters = new ArrayList<ReportParameterData>();
|
||||
}
|
||||
reportParameters.add(new ReportParameterData(rpJoin.getReportParameterId(), rpJoin.getReportParameterName(), rpJoin
|
||||
reportParameters.add(new ReportParameterData(rpJoin.getReportParameterId(), rpJoin.getParameterId(), rpJoin.getReportParameterName(), rpJoin
|
||||
.getParameterName()));
|
||||
|
||||
} else {
|
||||
@@ -484,7 +484,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
||||
if (rpJoin.getReportParameterId() != null) {
|
||||
// report has at least one parameter
|
||||
reportParameters = new ArrayList<ReportParameterData>();
|
||||
reportParameters.add(new ReportParameterData(rpJoin.getReportParameterId(), rpJoin.getReportParameterName(), rpJoin
|
||||
reportParameters.add(new ReportParameterData(rpJoin.getReportParameterId(),rpJoin.getParameterId(), rpJoin.getReportParameterName(), rpJoin
|
||||
.getParameterName()));
|
||||
} else {
|
||||
reportParameters = null;
|
||||
@@ -516,7 +516,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
||||
|
||||
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";
|
||||
+ " rp.id as reportParameterId, rp.parameter_id as parameterId, rp.report_parameter_name as reportParameterName, p.parameter_name as parameterName";
|
||||
|
||||
if (reportId != null) sql += ", r.report_sql as reportSql ";
|
||||
|
||||
@@ -564,11 +564,12 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
||||
}
|
||||
|
||||
final Long reportParameterId = JdbcSupport.getLong(rs, "reportParameterId");
|
||||
final Long parameterId = JdbcSupport.getLong(rs, "parameterId");
|
||||
final String reportParameterName = rs.getString("reportParameterName");
|
||||
final String parameterName = rs.getString("parameterName");
|
||||
|
||||
return new ReportParameterJoinData(reportId, reportName, reportType, reportSubType, reportCategory, description, reportSql,
|
||||
coreReport, useReport, reportParameterId, reportParameterName, parameterName);
|
||||
coreReport, useReport, reportParameterId, parameterId, reportParameterName, parameterName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,7 +587,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
||||
final Long id = rs.getLong("id");
|
||||
final String parameterName = rs.getString("parameterName");
|
||||
|
||||
return new ReportParameterData(id, null, parameterName);
|
||||
return new ReportParameterData(id, null, null, parameterName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+50
-2
@@ -5,15 +5,21 @@
|
||||
*/
|
||||
package org.mifosplatform.infrastructure.dataqueries.service;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
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.ReportParameter;
|
||||
import org.mifosplatform.infrastructure.dataqueries.domain.ReportParameterRepository;
|
||||
import org.mifosplatform.infrastructure.dataqueries.domain.ReportParameterUsage;
|
||||
import org.mifosplatform.infrastructure.dataqueries.domain.ReportRepository;
|
||||
import org.mifosplatform.infrastructure.dataqueries.exception.ReportNotFoundException;
|
||||
import org.mifosplatform.infrastructure.dataqueries.exception.ReportParameterNotFoundException;
|
||||
import org.mifosplatform.infrastructure.dataqueries.serialization.ReportCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.useradministration.domain.Permission;
|
||||
@@ -26,6 +32,9 @@ import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
@Service
|
||||
public class ReportWritePlatformServiceImpl implements
|
||||
ReportWritePlatformService {
|
||||
@@ -35,18 +44,21 @@ public class ReportWritePlatformServiceImpl implements
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ReportCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||
private final ReportRepository reportRepository;
|
||||
private final PermissionRepository permissionRepository;
|
||||
private final ReportRepository reportRepository;
|
||||
private final ReportParameterRepository reportParameterRepository;
|
||||
|
||||
@Autowired
|
||||
public ReportWritePlatformServiceImpl(
|
||||
final PlatformSecurityContext context,
|
||||
final ReportCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||
final ReportRepository reportRepository,
|
||||
final ReportParameterRepository reportParameterRepository,
|
||||
final PermissionRepository permissionRepository) {
|
||||
this.context = context;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.reportRepository = reportRepository;
|
||||
this.reportParameterRepository = reportParameterRepository;
|
||||
this.permissionRepository = permissionRepository;
|
||||
}
|
||||
|
||||
@@ -59,7 +71,11 @@ public class ReportWritePlatformServiceImpl implements
|
||||
|
||||
this.fromApiJsonDeserializer.validate(command.json());
|
||||
|
||||
final Report report = Report.fromJson(command);
|
||||
final Set<ReportParameterUsage> reportParameterUsages = assembleSetOfReportParameterUsages(command);
|
||||
final Report report = Report.fromJson(reportParameterUsages, command);
|
||||
for (ReportParameterUsage rpu : reportParameterUsages) {
|
||||
rpu.setReport(report);
|
||||
}
|
||||
final Permission permission = new Permission("report",
|
||||
report.getReportName(), "READ");
|
||||
this.reportRepository.save(report);
|
||||
@@ -153,4 +169,36 @@ public class ReportWritePlatformServiceImpl implements
|
||||
"Unknown data integrity issue with resource: "
|
||||
+ realCause.getMessage());
|
||||
}
|
||||
|
||||
private Set<ReportParameterUsage> assembleSetOfReportParameterUsages(final JsonCommand command) {
|
||||
|
||||
final Set<ReportParameterUsage> reportParameterUsages = new HashSet<ReportParameterUsage>();
|
||||
|
||||
|
||||
if (command.parameterExists("reportParameters")) {
|
||||
JsonArray reportParametersArray = command.arrayOfParameterNamed("reportParameters");
|
||||
if (reportParametersArray != null) {
|
||||
for (int i = 0; i < reportParametersArray.size(); i++) {
|
||||
|
||||
final JsonObject jsonObject = reportParametersArray.get(i).getAsJsonObject();
|
||||
if (jsonObject.has("id")) {
|
||||
Long id = null;
|
||||
final String idStr = jsonObject.get("id").getAsString();
|
||||
if (!(idStr.equals(""))) id = Long.parseLong(idStr);
|
||||
|
||||
final Long parameterId = jsonObject.get("parameterId").getAsLong();
|
||||
final ReportParameter parameter = this.reportParameterRepository.findOne(parameterId);
|
||||
if (parameter == null) {
|
||||
throw new ReportParameterNotFoundException(parameterId);
|
||||
}
|
||||
final String reportParameterName = jsonObject.get("reportParameterName").getAsString();
|
||||
reportParameterUsages.add(new ReportParameterUsage(null, parameter, reportParameterName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return reportParameterUsages;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user