Merge pull request #435 from vishwasbabu/develop
quick fix for enabling mifosx-443 enable separate datatables for centers
This commit is contained in:
+1
-1
@@ -47,7 +47,7 @@ public class DatatableCommandFromApiJsonDeserializer {
|
|||||||
private final Set<String> supportedParametersForDropColumns = new HashSet<String>(Arrays.asList(
|
private final Set<String> supportedParametersForDropColumns = new HashSet<String>(Arrays.asList(
|
||||||
"name"));
|
"name"));
|
||||||
private final Object[] supportedColumnTypes = { "String", "Number", "Decimal", "Date", "Text", "Dropdown" };
|
private final Object[] supportedColumnTypes = { "String", "Number", "Decimal", "Date", "Text", "Dropdown" };
|
||||||
private final Object[] supportedApptableNames = { "m_loan", "m_savings_account", "m_client", "m_group", "m_office", "m_savings_product", "m_product_loan" };
|
private final Object[] supportedApptableNames = { "m_loan", "m_savings_account", "m_client", "m_group", "m_center", "m_office", "m_savings_product", "m_product_loan" };
|
||||||
|
|
||||||
private final FromJsonHelper fromApiJsonHelper;
|
private final FromJsonHelper fromApiJsonHelper;
|
||||||
|
|
||||||
|
|||||||
+30
-13
@@ -365,6 +365,15 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
String apptableName = this.fromJsonHelper.extractStringNamed("apptableName", element);
|
String apptableName = this.fromJsonHelper.extractStringNamed("apptableName", element);
|
||||||
Boolean multiRow = this.fromJsonHelper.extractBooleanNamed("multiRow", element);
|
Boolean multiRow = this.fromJsonHelper.extractBooleanNamed("multiRow", element);
|
||||||
|
|
||||||
|
/***
|
||||||
|
* In cases of tables storing hierarchical entities (like m_group),
|
||||||
|
* different entities would end up being stored in the same table.
|
||||||
|
*
|
||||||
|
* Ex: Centers are a specific type of group, add abstractions for
|
||||||
|
* the same
|
||||||
|
***/
|
||||||
|
String actualAppTableName = mapToActualAppTable(apptableName);
|
||||||
|
|
||||||
if (multiRow == null) {
|
if (multiRow == null) {
|
||||||
multiRow = false;
|
multiRow = false;
|
||||||
}
|
}
|
||||||
@@ -395,10 +404,10 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
sqlBuilder = sqlBuilder.append(", PRIMARY KEY (`id`)")
|
sqlBuilder = sqlBuilder.append(", PRIMARY KEY (`id`)")
|
||||||
.append(", KEY `fk_" + apptableName.substring(2) + "_id` (`" + fkColumnName + "`)")
|
.append(", KEY `fk_" + apptableName.substring(2) + "_id` (`" + fkColumnName + "`)")
|
||||||
.append(", CONSTRAINT `fk_" + fkName + "` ").append("FOREIGN KEY (`" + fkColumnName + "`) ")
|
.append(", CONSTRAINT `fk_" + fkName + "` ").append("FOREIGN KEY (`" + fkColumnName + "`) ")
|
||||||
.append("REFERENCES `" + apptableName + "` (`id`)");
|
.append("REFERENCES `" + actualAppTableName + "` (`id`)");
|
||||||
} else {
|
} else {
|
||||||
sqlBuilder = sqlBuilder.append(", PRIMARY KEY (`" + fkColumnName + "`)").append(", CONSTRAINT `fk_" + fkName + "` ")
|
sqlBuilder = sqlBuilder.append(", PRIMARY KEY (`" + fkColumnName + "`)").append(", CONSTRAINT `fk_" + fkName + "` ")
|
||||||
.append("FOREIGN KEY (`" + fkColumnName + "`) ").append("REFERENCES `" + apptableName + "` (`id`)");
|
.append("FOREIGN KEY (`" + fkColumnName + "`) ").append("REFERENCES `" + actualAppTableName + "` (`id`)");
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlBuilder = sqlBuilder.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
sqlBuilder = sqlBuilder.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||||
@@ -546,6 +555,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
if (!StringUtils.equals(oldApptableName, apptableName)) {
|
if (!StringUtils.equals(oldApptableName, apptableName)) {
|
||||||
String oldFKName = oldApptableName.substring(2) + "_id";
|
String oldFKName = oldApptableName.substring(2) + "_id";
|
||||||
String newFKName = apptableName.substring(2) + "_id";
|
String newFKName = apptableName.substring(2) + "_id";
|
||||||
|
String actualAppTableName = mapToActualAppTable(apptableName);
|
||||||
String oldConstraintName = datatableName.toLowerCase().replaceAll("\\s", "_") + "_" + oldFKName;
|
String oldConstraintName = datatableName.toLowerCase().replaceAll("\\s", "_") + "_" + oldFKName;
|
||||||
String newConstraintName = datatableName.toLowerCase().replaceAll("\\s", "_") + "_" + newFKName;
|
String newConstraintName = datatableName.toLowerCase().replaceAll("\\s", "_") + "_" + newFKName;
|
||||||
StringBuilder sqlBuilder = new StringBuilder();
|
StringBuilder sqlBuilder = new StringBuilder();
|
||||||
@@ -556,13 +566,13 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
.append("CHANGE COLUMN `" + oldFKName + "` `" + newFKName + "` BIGINT(20) NOT NULL,")
|
.append("CHANGE COLUMN `" + oldFKName + "` `" + newFKName + "` BIGINT(20) NOT NULL,")
|
||||||
.append("ADD KEY `fk_" + newFKName + "` (`" + newFKName + "`),")
|
.append("ADD KEY `fk_" + newFKName + "` (`" + newFKName + "`),")
|
||||||
.append("ADD CONSTRAINT `fk_" + newConstraintName + "` ").append("FOREIGN KEY (`" + newFKName + "`) ")
|
.append("ADD CONSTRAINT `fk_" + newConstraintName + "` ").append("FOREIGN KEY (`" + newFKName + "`) ")
|
||||||
.append("REFERENCES `" + apptableName + "` (`id`)");
|
.append("REFERENCES `" + actualAppTableName + "` (`id`)");
|
||||||
} else {
|
} else {
|
||||||
sqlBuilder = sqlBuilder.append("ALTER TABLE `" + datatableName + "` ")
|
sqlBuilder = sqlBuilder.append("ALTER TABLE `" + datatableName + "` ")
|
||||||
.append("DROP FOREIGN KEY `fk_" + oldConstraintName + "`,")
|
.append("DROP FOREIGN KEY `fk_" + oldConstraintName + "`,")
|
||||||
.append("CHANGE COLUMN `" + oldFKName + "` `" + newFKName + "` BIGINT(20) NOT NULL,")
|
.append("CHANGE COLUMN `" + oldFKName + "` `" + newFKName + "` BIGINT(20) NOT NULL,")
|
||||||
.append("ADD CONSTRAINT `fk_" + newConstraintName + "` ").append("FOREIGN KEY (`" + newFKName + "`) ")
|
.append("ADD CONSTRAINT `fk_" + newConstraintName + "` ").append("FOREIGN KEY (`" + newFKName + "`) ")
|
||||||
.append("REFERENCES `" + apptableName + "` (`id`)");
|
.append("REFERENCES `" + actualAppTableName + "` (`id`)");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.jdbcTemplate.execute(sqlBuilder.toString());
|
this.jdbcTemplate.execute(sqlBuilder.toString());
|
||||||
@@ -762,8 +772,6 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
|
|
||||||
checkMainResourceExistsWithinScope(appTable, appTableId);
|
checkMainResourceExistsWithinScope(appTable, appTableId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final List<ResultsetColumnHeaderData> columnHeaders = this.genericDataService.fillResultsetColumnHeaders(dataTableName);
|
final List<ResultsetColumnHeaderData> columnHeaders = this.genericDataService.fillResultsetColumnHeaders(dataTableName);
|
||||||
|
|
||||||
String sql = "";
|
String sql = "";
|
||||||
@@ -827,8 +835,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
.withGroupId(groupId) //
|
.withGroupId(groupId) //
|
||||||
.withClientId(clientId) //
|
.withClientId(clientId) //
|
||||||
.withSavingsId(savingsId) //
|
.withSavingsId(savingsId) //
|
||||||
.withLoanId(LoanId)
|
.withLoanId(LoanId).withEntityId(entityId)//
|
||||||
.withEntityId(entityId)//
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -885,12 +892,16 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
}
|
}
|
||||||
if (appTable.equalsIgnoreCase("m_client")) {
|
if (appTable.equalsIgnoreCase("m_client")) {
|
||||||
scopedSQL = "select o.id as officeId, null as groupId, c.id as clientId, null as savingsId, null as loanId, null as entityId from m_client c "
|
scopedSQL = "select o.id as officeId, null as groupId, c.id as clientId, null as savingsId, null as loanId, null as entityId from m_client c "
|
||||||
+ " join m_office o on o.id = c.office_id and o.hierarchy like '" + currentUser.getOffice().getHierarchy() + "%'"
|
+ " join m_office o on o.id = c.office_id and o.hierarchy like '"
|
||||||
|
+ currentUser.getOffice().getHierarchy()
|
||||||
|
+ "%'"
|
||||||
+ " where c.id = " + appTableId;
|
+ " where c.id = " + appTableId;
|
||||||
}
|
}
|
||||||
if (appTable.equalsIgnoreCase("m_group")) {
|
if (appTable.equalsIgnoreCase("m_group") || appTable.equalsIgnoreCase("m_center")) {
|
||||||
scopedSQL = "select o.id as officeId, g.id as groupId, null as clientId, null as savingsId, null as loanId, null as entityId from m_group g "
|
scopedSQL = "select o.id as officeId, g.id as groupId, null as clientId, null as savingsId, null as loanId, null as entityId from m_group g "
|
||||||
+ " join m_office o on o.id = g.office_id and o.hierarchy like '" + currentUser.getOffice().getHierarchy() + "%'"
|
+ " join m_office o on o.id = g.office_id and o.hierarchy like '"
|
||||||
|
+ currentUser.getOffice().getHierarchy()
|
||||||
|
+ "%'"
|
||||||
+ " where g.id = " + appTableId;
|
+ " where g.id = " + appTableId;
|
||||||
}
|
}
|
||||||
if (appTable.equalsIgnoreCase("m_office")) {
|
if (appTable.equalsIgnoreCase("m_office")) {
|
||||||
@@ -899,8 +910,8 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (appTable.equalsIgnoreCase("m_product_loan") || appTable.equalsIgnoreCase("m_savings_product")) {
|
if (appTable.equalsIgnoreCase("m_product_loan") || appTable.equalsIgnoreCase("m_savings_product")) {
|
||||||
scopedSQL = "select null as officeId, null as groupId, null as clientId, null as savingsId, null as loanId, p.id as entityId from " + appTable
|
scopedSQL = "select null as officeId, null as groupId, null as clientId, null as savingsId, null as loanId, p.id as entityId from "
|
||||||
+ " as p WHERE p.id = " + appTableId;
|
+ appTable + " as p WHERE p.id = " + appTableId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scopedSQL == null) { throw new PlatformDataIntegrityException("error.msg.invalid.dataScopeCriteria", "Application Table: "
|
if (scopedSQL == null) { throw new PlatformDataIntegrityException("error.msg.invalid.dataScopeCriteria", "Application Table: "
|
||||||
@@ -916,6 +927,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
if (appTable.equalsIgnoreCase("m_savings_account")) return;
|
if (appTable.equalsIgnoreCase("m_savings_account")) return;
|
||||||
if (appTable.equalsIgnoreCase("m_client")) return;
|
if (appTable.equalsIgnoreCase("m_client")) return;
|
||||||
if (appTable.equalsIgnoreCase("m_group")) return;
|
if (appTable.equalsIgnoreCase("m_group")) return;
|
||||||
|
if (appTable.equalsIgnoreCase("m_center")) return;
|
||||||
if (appTable.equalsIgnoreCase("m_office")) return;
|
if (appTable.equalsIgnoreCase("m_office")) return;
|
||||||
if (appTable.equalsIgnoreCase("m_product_loan")) return;
|
if (appTable.equalsIgnoreCase("m_product_loan")) return;
|
||||||
if (appTable.equalsIgnoreCase("m_savings_product")) return;
|
if (appTable.equalsIgnoreCase("m_savings_product")) return;
|
||||||
@@ -923,6 +935,11 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
throw new PlatformDataIntegrityException("error.msg.invalid.application.table", "Invalid Application Table: " + appTable);
|
throw new PlatformDataIntegrityException("error.msg.invalid.application.table", "Invalid Application Table: " + appTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String mapToActualAppTable(final String appTable) {
|
||||||
|
if (appTable.equalsIgnoreCase("m_center")) { return "m_group"; }
|
||||||
|
return appTable;
|
||||||
|
}
|
||||||
|
|
||||||
private List<ResultsetRowData> fillDatatableResultSetDataRows(final String sql) {
|
private List<ResultsetRowData> fillDatatableResultSetDataRows(final String sql) {
|
||||||
|
|
||||||
final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
|
final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
|
||||||
|
|||||||
Reference in New Issue
Block a user