API refactoring Additional Fields

This commit is contained in:
John Woodlock
2012-05-17 21:09:16 +10:00
parent 62ec20112f
commit 45965a3f50
4 changed files with 88 additions and 27 deletions
+3 -6
View File
@@ -505,10 +505,7 @@ Returns the Set of Additional Fields data for the ID provided. The ID is the id
<div class="method-description">
<h4>Update Additional Fields</h4>
<p>
Updates the Set of Additional Fields data for the ID provided. The ID is the id field of the Type table e.g. portfolio_client might have an id value of 4.
</p>
<p>
JPW note: currently using ed_transType = "E" for edit and ed_transType = "A" for new... probably need to not do that.
Updates (or creates) the Set of Additional Fields data for the ID provided. The ID is the id field of the Type table e.g. portfolio_client might have an id value of 4.
</p>
<h5>Arguments</h5>
<span>None</span>
@@ -519,10 +516,10 @@ JPW note: currently using ed_transType = "E" for edit and ed_transType = "A" for
<code class="method-declaration">POST https://thedomainname/v1/additionalfields/{TYPE}/{SET}/{ID}</code>
<code class="method-request">http://localhost:8080/mifosng-provider/api/v1/additionalfields/portfolio_client/Additional Information/2
Request Body:
Content-Type: application/json
Request Body:
{
"ed_transType":"E",
"Ethnic_Group":"Berber",
"Ethnic_Group_Other":"",
"Household_Location":"East Sikkim",
@@ -290,14 +290,8 @@
function extraDataBuildTemplate(data) {
var dataLength = data.data.length;
var transType = 'E';
if (dataLength == 0)
transType = 'A';
var extraDataTemplateVar = '<form id="entityform"> <div id="formerrors"></div>';
extraDataTemplateVar += '<input id="ed_transType" name="ed_transType" type="hidden" value="'
+ transType + '"/>';
extraDataTemplateVar += '<table width="100%"><tr>';
var colsPerRow = 2;
@@ -34,7 +34,7 @@
<script type="text/javascript" src="${resValue}/libs/jquery.views.js"></script>
<script type="text/javascript" src="${resValue}/libs/jquery.observable.min.js"></script>
<script type="text/javascript" src="${resValue}/libs/globalize/globalize.js"></script>
<script type="text/javascript" src="${resValue}/stretchydata-0.93.js"></script>
<script type="text/javascript" src="${resValue}/stretchydata-0.94.js"></script>
<c:choose>
<c:when test="${not empty language}">
@@ -399,6 +399,7 @@ public class ReadExtraDataAndReportingServiceImpl implements
String set, Long id) {
GenericResultset result = new GenericResultset();
try {
Connection db_connection = dataSource.getConnection();
Statement db_statement1 = db_connection.createStatement();
@@ -533,11 +534,15 @@ public class ReadExtraDataAndReportingServiceImpl implements
pValue = queryParams.get(key);
logger.info("jpw: " + key + " - " + pValue);
}
logger.info("endjpw: ");
checkResourceTypeThere(type, set);
String fullDatasetName = getFullDatasetName(type, set);
String saveSql = getSaveSql(fullDatasetName, id, queryParams);
String transType = getTransType(type, fullDatasetName, id);
String saveSql = getSaveSql(fullDatasetName, id, transType, queryParams);
logger.info("saveSQL: " + saveSql);
try {
Connection db_connection = dataSource.getConnection();
Statement db_statement = db_connection.createStatement();
@@ -556,19 +561,85 @@ public class ReadExtraDataAndReportingServiceImpl implements
}
private String getSaveSql(String fullSetName, Long id,
Map<String, String> queryParams) {
private void checkResourceTypeThere(String type, String set) {
String sql = "select 'f' from stretchydata_datasettype t join stretchydata_dataset d on d.datasettype_id = t.id where d.`name` = '"
+ set + "' and t.`name` = '" + type + "'";
try {
Connection db_connection = dataSource.getConnection();
Statement db_statement = db_connection.createStatement();
String errMsg = "";
String transType = queryParams.get("ed_transType");
if (!(transType.equals("E") || transType.equals("A"))) {
errMsg = "transType not E or A - Value is: " + transType;
ResultSet rs = db_statement.executeQuery(sql);
if (!(rs.next())) {
db_statement.close();
db_statement = null;
db_connection.close();
db_connection = null;
throw new PlatformResourceNotFoundException(
"error.msg.set.not.found",
"Additional Fields Set Not Found", "Type: " + type
+ " Set: " + set);
}
db_statement.close();
db_statement = null;
db_connection.close();
db_connection = null;
} catch (SQLException e) {
throw new PlatformDataIntegrityException("error.msg.sql.error",
"JPWWRONGMSG - " + errMsg,
"Additional Fields Full Set Name: " + fullSetName
+ " Id: " + id);
"JPWWRONGMSG - " + e.getMessage(),
"Additional Fields Type: " + type + " Set: " + set
+ " Sql: " + sql);
}
}
private String getTransType(String type, String fullDatasetName, Long id) {
String transType = null;
String sql = "select s.id from `" + type + "` t left join `"
+ fullDatasetName + "` s on s.id = t.id where t.id = "
+ id;
try {
Connection db_connection = dataSource.getConnection();
Statement db_statement = db_connection.createStatement();
ResultSet rs = db_statement.executeQuery(sql);
if (rs.next()) {
Long idValue = rs.getLong("id");
if (idValue != null) {
transType = "E";
} else {
transType = "A";
}
} else {
db_statement.close();
db_statement = null;
db_connection.close();
db_connection = null;
throw new PlatformResourceNotFoundException(
"error.msg.type.value.not.found",
"Additional Fields Type: " + type
+ " Id Not Found for " + id);
}
db_statement.close();
db_statement = null;
db_connection.close();
db_connection = null;
} catch (SQLException e) {
throw new PlatformDataIntegrityException("error.msg.sql.error",
"JPWWRONGMSG - " + e.getMessage(),
"Additional Fields Type: " + type + " Full Set Name: "
+ fullDatasetName + " Sql: " + sql);
}
return transType;
}
private String getSaveSql(String fullSetName, Long id, String transType,
Map<String, String> queryParams) {
String pValue = "";
String pValueWrite = "";
String saveSql = "";
@@ -582,7 +653,7 @@ public class ReadExtraDataAndReportingServiceImpl implements
saveSql = "update `" + fullSetName + "` ";
for (String key : keys) {
if (!(key.equals("ed_transType") || key.equals("id"))) {
if (!(key.equalsIgnoreCase("id"))) {
if (firstColumn) {
saveSql += " set ";
firstColumn = false;
@@ -610,7 +681,7 @@ public class ReadExtraDataAndReportingServiceImpl implements
String columnName = "";
for (String key : keys) {
pValue = queryParams.get(key);
if (!(key.equals("ed_transType") || key.equals("id"))) {
if (!(key.equalsIgnoreCase("id"))) {
pValue = queryParams.get(key);
if (pValue == null || pValue.equals("")) {
@@ -629,7 +700,6 @@ public class ReadExtraDataAndReportingServiceImpl implements
saveSql = "insert into `" + fullSetName + "` (id" + insertColumns
+ ")" + " select " + id + " as id" + selectColumns;
}
// logger.info("Save SQL: " + saveSql);
return saveSql;
}
}