wip mifosx-195 report maintenance changes
This commit is contained in:
+7
-4
@@ -11,14 +11,17 @@ final public class ReportParameterData {
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private final Long id;
|
private final Long id;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private final String reportParameterName;
|
private final Long parameterId;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private final String parameterName;
|
private final String parameterName;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private final String reportParameterName;
|
||||||
|
|
||||||
public ReportParameterData(final Long id, final String reportParameterName,
|
public ReportParameterData(final Long id, final Long parameterId,
|
||||||
final String parameterName) {
|
final String reportParameterName, final String parameterName) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.reportParameterName = reportParameterName;
|
this.parameterId = parameterId;
|
||||||
this.parameterName = parameterName;
|
this.parameterName = parameterName;
|
||||||
|
this.reportParameterName = reportParameterName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+74
-64
@@ -7,82 +7,92 @@ package org.mifosplatform.infrastructure.dataqueries.data;
|
|||||||
|
|
||||||
final public class ReportParameterJoinData {
|
final public class ReportParameterJoinData {
|
||||||
|
|
||||||
private final Long reportId;
|
private final Long reportId;
|
||||||
private final String reportName;
|
private final String reportName;
|
||||||
private final String reportType;
|
private final String reportType;
|
||||||
private final String reportSubType;
|
private final String reportSubType;
|
||||||
private final String reportCategory;
|
private final String reportCategory;
|
||||||
private final String description;
|
private final String description;
|
||||||
private final String reportSql;
|
private final String reportSql;
|
||||||
private final Boolean coreReport;
|
private final Boolean coreReport;
|
||||||
private final Boolean useReport;
|
private final Boolean useReport;
|
||||||
|
|
||||||
private final Long reportParameterId;
|
private final Long reportParameterId;
|
||||||
private final String reportParameterName;
|
private final Long parameterId;
|
||||||
private final String parameterName;
|
private final String reportParameterName;
|
||||||
|
private final String parameterName;
|
||||||
|
|
||||||
public ReportParameterJoinData(final Long reportId, final String reportName, final String reportType, final String reportSubType,
|
public ReportParameterJoinData(final Long reportId,
|
||||||
final String reportCategory, final String description, final String reportSql, final Boolean coreReport,
|
final String reportName, final String reportType,
|
||||||
final Boolean useReport, final Long reportParameterId, final String reportParameterName, final String parameterName) {
|
final String reportSubType, final String reportCategory,
|
||||||
this.reportId = reportId;
|
final String description, final String reportSql,
|
||||||
this.reportName = reportName;
|
final Boolean coreReport, final Boolean useReport,
|
||||||
this.reportType = reportType;
|
final Long reportParameterId, final Long parameterId,
|
||||||
this.reportSubType = reportSubType;
|
final String reportParameterName, final String parameterName) {
|
||||||
this.reportCategory = reportCategory;
|
this.reportId = reportId;
|
||||||
this.description = description;
|
this.reportName = reportName;
|
||||||
this.reportSql = reportSql;
|
this.reportType = reportType;
|
||||||
this.coreReport = coreReport;
|
this.reportSubType = reportSubType;
|
||||||
this.useReport = useReport;
|
this.reportCategory = reportCategory;
|
||||||
this.reportParameterId = reportParameterId;
|
this.description = description;
|
||||||
this.reportParameterName = reportParameterName;
|
this.reportSql = reportSql;
|
||||||
this.parameterName = parameterName;
|
this.coreReport = coreReport;
|
||||||
}
|
this.useReport = useReport;
|
||||||
|
this.reportParameterId = reportParameterId;
|
||||||
|
this.parameterId = parameterId;
|
||||||
|
this.reportParameterName = reportParameterName;
|
||||||
|
this.parameterName = parameterName;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getReportId() {
|
public Long getReportId() {
|
||||||
return reportId;
|
return reportId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReportName() {
|
public String getReportName() {
|
||||||
return reportName;
|
return reportName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReportType() {
|
public String getReportType() {
|
||||||
return reportType;
|
return reportType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReportSubType() {
|
public String getReportSubType() {
|
||||||
return reportSubType;
|
return reportSubType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReportCategory() {
|
public String getReportCategory() {
|
||||||
return reportCategory;
|
return reportCategory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReportSql() {
|
public String getReportSql() {
|
||||||
return reportSql;
|
return reportSql;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getCoreReport() {
|
public Boolean getCoreReport() {
|
||||||
return coreReport;
|
return coreReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getUseReport() {
|
public Boolean getUseReport() {
|
||||||
return useReport;
|
return useReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getReportParameterId() {
|
public Long getReportParameterId() {
|
||||||
return reportParameterId;
|
return reportParameterId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReportParameterName() {
|
public Long getParameterId() {
|
||||||
return reportParameterName;
|
return parameterId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getParameterName() {
|
public String getReportParameterName() {
|
||||||
return parameterName;
|
return reportParameterName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getParameterName() {
|
||||||
return description;
|
return parameterName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+214
-145
@@ -9,13 +9,18 @@ import java.util.ArrayList;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.persistence.UniqueConstraint;
|
import javax.persistence.UniqueConstraint;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
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.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
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") })
|
@Table(name = "stretchy_report", uniqueConstraints = { @UniqueConstraint(columnNames = { "report_name" }, name = "unq_report_name") })
|
||||||
public class Report extends AbstractPersistable<Long> {
|
public class Report extends AbstractPersistable<Long> {
|
||||||
|
|
||||||
@Column(name = "report_name", nullable = false, unique = true)
|
@Column(name = "report_name", nullable = false, unique = true)
|
||||||
private String reportName;
|
private String reportName;
|
||||||
|
|
||||||
@Column(name = "report_type", nullable = false)
|
@Column(name = "report_type", nullable = false)
|
||||||
private String reportType;
|
private String reportType;
|
||||||
|
|
||||||
@Column(name = "report_subtype")
|
@Column(name = "report_subtype")
|
||||||
private String reportSubType;
|
private String reportSubType;
|
||||||
|
|
||||||
@Column(name = "report_category")
|
@Column(name = "report_category")
|
||||||
private String reportCategory;
|
private String reportCategory;
|
||||||
|
|
||||||
@Column(name = "description")
|
@Column(name = "description")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@Column(name = "core_report", nullable = false)
|
@Column(name = "core_report", nullable = false)
|
||||||
private boolean coreReport;
|
private boolean coreReport;
|
||||||
|
|
||||||
// only defines if report should appear in reference app UI List
|
// only defines if report should appear in reference app UI List
|
||||||
@Column(name = "use_report", nullable = false)
|
@Column(name = "use_report", nullable = false)
|
||||||
private boolean useReport;
|
private boolean useReport;
|
||||||
|
|
||||||
@Column(name = "report_sql")
|
@Column(name = "report_sql")
|
||||||
private String reportSql;
|
private String reportSql;
|
||||||
|
|
||||||
/*
|
@LazyCollection(LazyCollectionOption.FALSE)
|
||||||
* @ManyToMany
|
@OneToMany(cascade = CascadeType.ALL, mappedBy = "report", orphanRemoval = true)
|
||||||
*
|
private Set<ReportParameterUsage> reportParameterUsages = null;
|
||||||
* @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 static Report fromJson(
|
||||||
|
final Set<ReportParameterUsage> reportParameterUsages,
|
||||||
|
final JsonCommand command) {
|
||||||
|
|
||||||
final String reportName = command.stringValueOfParameterNamed("reportName");
|
String reportName = null;
|
||||||
final String reportType = command.stringValueOfParameterNamed("reportType");
|
String reportType = null;
|
||||||
final String reportSubType = command.stringValueOfParameterNamed("reportSubType");
|
String reportSubType = null;
|
||||||
final String reportCategory = command.stringValueOfParameterNamed("reportCategory");
|
String reportCategory = null;
|
||||||
final String description = command.stringValueOfParameterNamed("description");
|
String description = null;
|
||||||
final boolean useReport = command.booleanPrimitiveValueOfParameterNamed("useReport");
|
boolean useReport = false;
|
||||||
final String reportSql = command.stringValueOfParameterNamed("reportSql");
|
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,
|
protected Report() {
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
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";
|
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(
|
||||||
if (command.isChangeInStringParameterNamed(paramName, this.reportName)) {
|
8);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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()) {
|
validate();
|
||||||
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); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 actualChanges;
|
||||||
return coreReport;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void validate() {
|
public boolean isCoreReport() {
|
||||||
|
return coreReport;
|
||||||
|
}
|
||||||
|
|
||||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
private void validate() {
|
||||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("report");
|
|
||||||
|
|
||||||
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()
|
baseDataValidator.reset().parameter("reportName")
|
||||||
.isOneOfTheseValues(new Object[] { "Table", "Pentaho", "Chart" });
|
.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)) {
|
baseDataValidator.reset().parameter("reportSubType")
|
||||||
if (this.reportType.equals("Chart")) {
|
.value(this.reportSubType).notExceedingLengthOf(20);
|
||||||
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("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)) {
|
baseDataValidator.reset().parameter("reportCategory")
|
||||||
if ((this.reportType.equals("Table")) || (this.reportType.equals("Chart"))) {
|
.value(this.reportCategory).notExceedingLengthOf(45);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
if (StringUtils.isNotBlank(this.reportType)) {
|
||||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
if ((this.reportType.equals("Table"))
|
||||||
"Validation errors exist.", dataValidationErrors); }
|
|| (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() {
|
private void throwExceptionIfValidationWarningsExist(
|
||||||
return reportName;
|
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) {
|
public ReportNotFoundException(final String reportSql) {
|
||||||
super("error.msg.report.name.not.found", "Reporting meta-data entry not found.", "Input sql: " + reportSql);
|
super("error.msg.report.name.not.found", "Reporting meta-data entry not found.", "Input sql: " + reportSql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReportNotFoundException(final Long id) {
|
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.
|
* The parameters supported for this command.
|
||||||
*/
|
*/
|
||||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("reportName", "reportType", "reportSubType",
|
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;
|
private final FromJsonHelper fromApiJsonHelper;
|
||||||
|
|
||||||
|
|||||||
+6
-5
@@ -457,7 +457,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
|||||||
if (reportParameters == null) {
|
if (reportParameters == null) {
|
||||||
reportParameters = new ArrayList<ReportParameterData>();
|
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()));
|
.getParameterName()));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -484,7 +484,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
|||||||
if (rpJoin.getReportParameterId() != null) {
|
if (rpJoin.getReportParameterId() != null) {
|
||||||
// report has at least one parameter
|
// report has at least one parameter
|
||||||
reportParameters = new ArrayList<ReportParameterData>();
|
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()));
|
.getParameterName()));
|
||||||
} else {
|
} else {
|
||||||
reportParameters = null;
|
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, "
|
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, "
|
+ " 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 ";
|
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 reportParameterId = JdbcSupport.getLong(rs, "reportParameterId");
|
||||||
|
final Long parameterId = JdbcSupport.getLong(rs, "parameterId");
|
||||||
final String reportParameterName = rs.getString("reportParameterName");
|
final String reportParameterName = rs.getString("reportParameterName");
|
||||||
final String parameterName = rs.getString("parameterName");
|
final String parameterName = rs.getString("parameterName");
|
||||||
|
|
||||||
return new ReportParameterJoinData(reportId, reportName, reportType, reportSubType, reportCategory, description, reportSql,
|
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 Long id = rs.getLong("id");
|
||||||
final String parameterName = rs.getString("parameterName");
|
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;
|
package org.mifosplatform.infrastructure.dataqueries.service;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||||
import org.mifosplatform.infrastructure.dataqueries.domain.Report;
|
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.domain.ReportRepository;
|
||||||
import org.mifosplatform.infrastructure.dataqueries.exception.ReportNotFoundException;
|
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.dataqueries.serialization.ReportCommandFromApiJsonDeserializer;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.useradministration.domain.Permission;
|
import org.mifosplatform.useradministration.domain.Permission;
|
||||||
@@ -26,6 +32,9 @@ import org.springframework.dao.DataIntegrityViolationException;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ReportWritePlatformServiceImpl implements
|
public class ReportWritePlatformServiceImpl implements
|
||||||
ReportWritePlatformService {
|
ReportWritePlatformService {
|
||||||
@@ -35,18 +44,21 @@ public class ReportWritePlatformServiceImpl implements
|
|||||||
|
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final ReportCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
private final ReportCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||||
private final ReportRepository reportRepository;
|
|
||||||
private final PermissionRepository permissionRepository;
|
private final PermissionRepository permissionRepository;
|
||||||
|
private final ReportRepository reportRepository;
|
||||||
|
private final ReportParameterRepository reportParameterRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ReportWritePlatformServiceImpl(
|
public ReportWritePlatformServiceImpl(
|
||||||
final PlatformSecurityContext context,
|
final PlatformSecurityContext context,
|
||||||
final ReportCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
final ReportCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||||
final ReportRepository reportRepository,
|
final ReportRepository reportRepository,
|
||||||
|
final ReportParameterRepository reportParameterRepository,
|
||||||
final PermissionRepository permissionRepository) {
|
final PermissionRepository permissionRepository) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||||
this.reportRepository = reportRepository;
|
this.reportRepository = reportRepository;
|
||||||
|
this.reportParameterRepository = reportParameterRepository;
|
||||||
this.permissionRepository = permissionRepository;
|
this.permissionRepository = permissionRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +71,11 @@ public class ReportWritePlatformServiceImpl implements
|
|||||||
|
|
||||||
this.fromApiJsonDeserializer.validate(command.json());
|
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",
|
final Permission permission = new Permission("report",
|
||||||
report.getReportName(), "READ");
|
report.getReportName(), "READ");
|
||||||
this.reportRepository.save(report);
|
this.reportRepository.save(report);
|
||||||
@@ -153,4 +169,36 @@ public class ReportWritePlatformServiceImpl implements
|
|||||||
"Unknown data integrity issue with resource: "
|
"Unknown data integrity issue with resource: "
|
||||||
+ realCause.getMessage());
|
+ 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