WIP extradata - refactor code, remove from client app
This commit is contained in:
@@ -9,7 +9,6 @@ import org.mifosng.data.ClientDataWithAccountsData;
|
||||
import org.mifosng.data.CurrencyData;
|
||||
import org.mifosng.data.EntityIdentifier;
|
||||
import org.mifosng.data.EnumOptionReadModel;
|
||||
import org.mifosng.data.ExtraDatasets;
|
||||
import org.mifosng.data.LoanAccountData;
|
||||
import org.mifosng.data.LoanProductData;
|
||||
import org.mifosng.data.LoanRepaymentData;
|
||||
@@ -161,15 +160,6 @@ public interface CommonRestOperations {
|
||||
|
||||
LoanAccountData retrieveLoanAccount(Long loanId);
|
||||
|
||||
ExtraDatasets retrieveExtraDatasets(String datasetType);
|
||||
|
||||
GenericResultset retrieveExtraData(String datasetType, String datasetName,
|
||||
String datasetPKValue);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
EntityIdentifier saveExtraData(String datasetType, String datasetName,
|
||||
String datasetPKValue, Map map);
|
||||
|
||||
GenericResultset retrieveReportingData(String rptDB, String name, String type, Map<String, String> extractedQueryParams);
|
||||
|
||||
NewLoanWorkflowStepOneData retrieveNewLoanApplicationDetails(Long clientId, Long productId);
|
||||
|
||||
+1
-77
@@ -20,7 +20,6 @@ import org.mifosng.data.EnumOptionList;
|
||||
import org.mifosng.data.EnumOptionReadModel;
|
||||
import org.mifosng.data.ErrorResponse;
|
||||
import org.mifosng.data.ErrorResponseList;
|
||||
import org.mifosng.data.ExtraDatasets;
|
||||
import org.mifosng.data.LoanAccountData;
|
||||
import org.mifosng.data.LoanProductData;
|
||||
import org.mifosng.data.LoanProductList;
|
||||
@@ -53,8 +52,6 @@ import org.mifosng.data.command.UpdateOrganisationCurrencyCommand;
|
||||
import org.mifosng.data.command.UserCommand;
|
||||
import org.mifosng.data.reports.GenericResultset;
|
||||
import org.mifosng.ui.loanproduct.ClientValidationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -71,9 +68,6 @@ import com.thoughtworks.xstream.XStream;
|
||||
|
||||
@Service(value="commonRestOperations")
|
||||
public class CommonRestOperationsImpl implements CommonRestOperations {
|
||||
|
||||
private final static Logger logger = LoggerFactory
|
||||
.getLogger(CommonRestOperationsImpl.class);
|
||||
|
||||
private OAuthRestTemplate oauthRestServiceTemplate;
|
||||
private final ApplicationConfigurationService applicationConfigurationService;
|
||||
@@ -1247,80 +1241,10 @@ public class CommonRestOperationsImpl implements CommonRestOperations {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ExtraDatasets retrieveExtraDatasets(String datasetType) {
|
||||
logger.info("In CommonRestOperationsImpl - retrieveExtraDatasets");
|
||||
try {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat("api/protected/extradata/datasets/").concat(encodeURIComponent(datasetType)));
|
||||
|
||||
ResponseEntity<ExtraDatasets> s = this.oauthRestServiceTemplate
|
||||
.exchange(restUri, HttpMethod.GET, emptyRequest(), ExtraDatasets.class);
|
||||
return s.getBody();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
logger.info(e.toString());
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GenericResultset retrieveExtraData(String datasetType, String datasetName,
|
||||
String datasetPKValue) {
|
||||
try {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat("api/protected/extradata/").concat(encodeURIComponent(datasetType)).concat("/").concat(encodeURIComponent(datasetName))
|
||||
.concat("/").concat(encodeURIComponent(datasetPKValue))
|
||||
);
|
||||
|
||||
|
||||
ResponseEntity<GenericResultset> s = this.oauthRestServiceTemplate
|
||||
.exchange(restUri, HttpMethod.GET, emptyRequest(),
|
||||
GenericResultset.class);
|
||||
|
||||
return s.getBody();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public EntityIdentifier saveExtraData(String datasetType, String datasetName, String datasetPKValue, Map requestMap) {
|
||||
|
||||
String UrlString = getBaseServerUrl().concat("api/protected/extradata/").concat(encodeURIComponent(datasetType)).concat("/").concat(encodeURIComponent(datasetName))
|
||||
.concat("/").concat(encodeURIComponent(datasetPKValue));
|
||||
|
||||
String value;
|
||||
boolean firstParameter = true;
|
||||
for (Object key : requestMap.keySet()) {
|
||||
if (firstParameter) {
|
||||
UrlString += "?";
|
||||
firstParameter = false;
|
||||
}
|
||||
else {
|
||||
UrlString += "&";
|
||||
}
|
||||
|
||||
String[] valueArray = (String[]) requestMap.get(key);
|
||||
value = valueArray[0];
|
||||
if (value == null || value.equals("")) {
|
||||
value = "";
|
||||
}
|
||||
UrlString += encodeURIComponent(key.toString()) + "=" + encodeURIComponent(value);
|
||||
}
|
||||
logger.info("Url: " + UrlString);
|
||||
|
||||
try {
|
||||
URI restUri = URI.create(UrlString);
|
||||
ResponseEntity<EntityIdentifier> s = this.oauthRestServiceTemplate.postForEntity(restUri, emptyRequest(), EntityIdentifier.class);
|
||||
return s.getBody();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
//jpw prob remove after
|
||||
private static String encodeURIComponent(String component) {
|
||||
String result = null;
|
||||
|
||||
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
package org.mifosng.ui.extradata;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.mifosng.data.EntityIdentifier;
|
||||
import org.mifosng.data.ErrorResponse;
|
||||
import org.mifosng.data.ExtraDatasets;
|
||||
import org.mifosng.data.reports.GenericResultset;
|
||||
import org.mifosng.ui.CommonRestOperations;
|
||||
import org.mifosng.ui.loanproduct.ClientValidationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@Controller
|
||||
public class ExtraDataController {
|
||||
|
||||
private final CommonRestOperations commonRestOperations;
|
||||
|
||||
@Autowired
|
||||
public ExtraDataController(final CommonRestOperations commonRestOperations) {
|
||||
this.commonRestOperations = commonRestOperations;
|
||||
}
|
||||
|
||||
@ExceptionHandler(AccessDeniedException.class)
|
||||
public String accessDeniedException() {
|
||||
return "unAuthorizedAction";
|
||||
}
|
||||
|
||||
@ExceptionHandler(ClientValidationException.class)
|
||||
public @ResponseBody Collection<ErrorResponse> validationException(ClientValidationException ex, HttpServletResponse response) {
|
||||
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
response.setContentType("application/json");
|
||||
|
||||
return ex.getValidationErrors();
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(consumes="application/json", produces="application/json", value = "/extradata/datasets/{datasetType}", method = RequestMethod.GET)
|
||||
public @ResponseBody ExtraDatasets retrieveExtraDatasets(@PathVariable("datasetType") String datasetType) {
|
||||
|
||||
return this.commonRestOperations.retrieveExtraDatasets(datasetType);
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/json", produces="application/json", value = "/extradata/{datasetType}/{datasetName}/{datasetPKValue}", method = RequestMethod.GET)
|
||||
public @ResponseBody GenericResultset viewExtraData(@PathVariable("datasetType") String datasetType, @PathVariable("datasetName") String datasetName, @PathVariable("datasetPKValue") String datasetPKValue) {
|
||||
|
||||
return this.commonRestOperations.retrieveExtraData(datasetType, datasetName, datasetPKValue);
|
||||
}
|
||||
|
||||
@RequestMapping(produces="application/json", value = "/extradata/{datasetType}/{datasetName}/{datasetPKValue}", method = RequestMethod.POST)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public @ResponseBody EntityIdentifier saveExtraData(HttpServletRequest request, @PathVariable("datasetType") String datasetType,@PathVariable("datasetName") String datasetName, @PathVariable("datasetPKValue") String datasetPKValue) {
|
||||
return this.commonRestOperations.saveExtraData(datasetType, datasetName, datasetPKValue, request.getParameterMap());
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -378,9 +378,8 @@
|
||||
$(this).attr("selected", "selected");
|
||||
});
|
||||
|
||||
//var form_data = $('#entityform').serialize();
|
||||
var form_data = JSON.stringify($('#entityform').serializeObject());
|
||||
console.log(form_data);
|
||||
//console.log(form_data);
|
||||
var jqxhr = $.ajax({
|
||||
url : url,
|
||||
type : 'POST',
|
||||
@@ -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.90.js"></script>
|
||||
<script type="text/javascript" src="${resValue}/stretchydata-0.91.js"></script>
|
||||
|
||||
<c:choose>
|
||||
<c:when test="${not empty language}">
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package org.mifosng.platform;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.mifosng.data.ExtraDatasets;
|
||||
import org.mifosng.data.reports.GenericResultset;
|
||||
|
||||
public interface ReadExtraDataAndReportingService {
|
||||
|
||||
ExtraDatasets retrieveExtraDatasetNames(String datasetType);
|
||||
|
||||
GenericResultset retrieveExtraData(String datasetType, String datasetName,
|
||||
String datasetPKValue);
|
||||
|
||||
void tempSaveExtraData(String datasetType, String datasetName,
|
||||
String datasetPKValue, Map<String, String> queryParams);
|
||||
}
|
||||
+329
@@ -0,0 +1,329 @@
|
||||
package org.mifosng.platform;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.mifosng.data.ExtraDatasetRow;
|
||||
import org.mifosng.data.ExtraDatasets;
|
||||
import org.mifosng.data.reports.GenericResultset;
|
||||
import org.mifosng.data.reports.ResultsetColumnHeader;
|
||||
import org.mifosng.data.reports.ResultsetDataRow;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ReadExtraDataAndReportingServiceImpl implements ReadExtraDataAndReportingService {
|
||||
|
||||
private final static Logger logger = LoggerFactory
|
||||
.getLogger(ReadExtraDataAndReportingServiceImpl.class);
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
@Autowired
|
||||
public ReadExtraDataAndReportingServiceImpl(final DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtraDatasets retrieveExtraDatasetNames(String type) {
|
||||
|
||||
List<ExtraDatasetRow> extraDatasetRows = new ArrayList<ExtraDatasetRow>();
|
||||
Connection db_connection;
|
||||
try {
|
||||
db_connection = dataSource.getConnection();
|
||||
Statement db_statement = db_connection.createStatement();
|
||||
|
||||
String whereClause;
|
||||
if (type == null) {
|
||||
whereClause = "";
|
||||
} else {
|
||||
whereClause = "where t.`name` = '" + type + "'";
|
||||
}
|
||||
String sql = "select d.id, d.`name` as datasetName, t.`name` as datasetType from stretchydata_dataset d join stretchydata_datasettype t on t.id = d.datasettype_id "
|
||||
+ whereClause + " order by d.`name`";
|
||||
|
||||
ResultSet rs = db_statement.executeQuery(sql);
|
||||
|
||||
while (rs.next()) {
|
||||
extraDatasetRows.add(new ExtraDatasetRow(rs.getInt("id"), rs.getString("datasetName"), rs.getString("datasetType")));
|
||||
}
|
||||
|
||||
db_statement.close();
|
||||
db_statement = null;
|
||||
db_connection.close();
|
||||
db_connection = null;
|
||||
} catch (SQLException e) {
|
||||
logger.info(": Failed in retrieveExtraDatasetNames");
|
||||
throw new WebApplicationException(Response
|
||||
.status(Status.BAD_REQUEST).entity(e.getMessage()).build());
|
||||
}
|
||||
|
||||
return new ExtraDatasets(extraDatasetRows);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericResultset retrieveExtraData(String datasetType,
|
||||
String datasetName, String datasetPKValue) {
|
||||
|
||||
if (datasetType == null) {
|
||||
logger.info("Extra Data Table Type not Found");
|
||||
return null;
|
||||
}
|
||||
if (datasetName == null) {
|
||||
logger.info("Extra Data Table Name not Found");
|
||||
return null;
|
||||
}
|
||||
if (datasetPKValue == null) {
|
||||
logger.info("Extra Data Table ID not Found");
|
||||
return null;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
logger.info("STARTING EXTRA DATA TABLE: " + datasetName + " ID: "
|
||||
+ datasetPKValue);
|
||||
|
||||
try {
|
||||
GenericResultset result = fillExtraDataGenericResultSet(
|
||||
datasetType, datasetName, datasetPKValue);
|
||||
|
||||
long elapsed = System.currentTimeMillis() - startTime;
|
||||
logger.info("FINISHING EXTRA DATA TABLE: " + datasetName
|
||||
+ " Elapsed Time: " + elapsed);
|
||||
return result;
|
||||
} catch (SQLException e) {
|
||||
logger.info("Error - SQL: " + e.toString());
|
||||
throw new InvalidSqlException(e, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private GenericResultset fillExtraDataGenericResultSet(String datasetType,
|
||||
String datasetName, String datasetPKValue) throws SQLException {
|
||||
|
||||
GenericResultset result = new GenericResultset();
|
||||
String fullDatasetName = getFullDatasetName(datasetType, datasetName);
|
||||
Connection db_connection = dataSource.getConnection();
|
||||
Statement db_statement1 = db_connection.createStatement();
|
||||
Statement db_statement2 = db_connection.createStatement();
|
||||
Statement db_statement3 = db_connection.createStatement();
|
||||
String sql = "select f.`name`, f.data_type, f.data_length, f.display_type, f.allowed_list_id from stretchydata_datasettype t join stretchydata_dataset d on d.datasettype_id = t.id join stretchydata_dataset_fields f on f.dataset_id = d.id where d.`name` = '"
|
||||
+ datasetName
|
||||
+ "' and t.`name` = '"
|
||||
+ datasetType
|
||||
+ "' order by f.id";
|
||||
|
||||
//logger.info("specific: " + sql);
|
||||
ResultSet rsmd = db_statement1.executeQuery(sql);
|
||||
|
||||
List<ResultsetColumnHeader> columnHeaders = new ArrayList<ResultsetColumnHeader>();
|
||||
Boolean firstColumn = true;
|
||||
Integer allowedListId;
|
||||
String selectFieldList = "";
|
||||
String selectFieldSeparator = "";
|
||||
while (rsmd.next()) {
|
||||
ResultsetColumnHeader rsch = new ResultsetColumnHeader();
|
||||
rsch.setColumnName(rsmd.getString("name"));
|
||||
|
||||
if (firstColumn) {
|
||||
selectFieldSeparator = " ";
|
||||
firstColumn = false;
|
||||
} else {
|
||||
selectFieldSeparator = ", ";
|
||||
}
|
||||
selectFieldList += selectFieldSeparator + "`" + rsch.getColumnName() + "`";
|
||||
|
||||
rsch.setColumnType(rsmd.getString("data_type"));
|
||||
rsch.setColumnLength(rsmd.getInt("data_length"));
|
||||
rsch.setColumnDisplayType(rsmd.getString("display_type"));
|
||||
allowedListId = rsmd.getInt("allowed_list_id");
|
||||
if (allowedListId != null) {
|
||||
sql = "select v.`name` from stretchydata_allowed_value v where allowed_list_id = " + allowedListId + " order by id";
|
||||
ResultSet rsValues = db_statement2.executeQuery(sql);
|
||||
while (rsValues.next()) {
|
||||
rsch.getColumnValues().add(rsValues.getString("name"));
|
||||
}
|
||||
}
|
||||
columnHeaders.add(rsch);
|
||||
}
|
||||
result.setColumnHeaders(columnHeaders);
|
||||
|
||||
sql = "select " + selectFieldList + " from `" + fullDatasetName
|
||||
+ "` where id = " + datasetPKValue;
|
||||
|
||||
ResultSet rs = db_statement3.executeQuery(sql);
|
||||
String columnName = null;
|
||||
String columnValue = null;
|
||||
List<ResultsetDataRow> resultsetDataRows = new ArrayList<ResultsetDataRow>();
|
||||
ResultsetDataRow resultsetDataRow;
|
||||
while (rs.next()) {
|
||||
resultsetDataRow = new ResultsetDataRow();
|
||||
List<String> columnValues = new ArrayList<String>();
|
||||
|
||||
for (int i = 0; i < columnHeaders.size(); i++) {
|
||||
columnName = columnHeaders.get(i).getColumnName();
|
||||
columnValue = rs.getString(columnName);
|
||||
columnValues.add(columnValue);
|
||||
}
|
||||
resultsetDataRow.setRow(columnValues);
|
||||
resultsetDataRows.add(resultsetDataRow);
|
||||
}
|
||||
result.setData(resultsetDataRows);
|
||||
|
||||
db_statement1.close();
|
||||
db_statement1 = null;
|
||||
db_statement2.close();
|
||||
db_statement2 = null;
|
||||
db_statement3.close();
|
||||
db_statement3 = null;
|
||||
db_connection.close();
|
||||
db_connection = null;
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private String getFullDatasetName(final String datasetType,
|
||||
final String datasetName) {
|
||||
return datasetType + "_extra_" + datasetName;
|
||||
}
|
||||
|
||||
static String replace(String str, String pattern, String replace) {
|
||||
int s = 0;
|
||||
int e = 0;
|
||||
StringBuffer result = new StringBuffer();
|
||||
|
||||
while ((e = str.indexOf(pattern, s)) >= 0) {
|
||||
result.append(str.substring(s, e));
|
||||
result.append(replace);
|
||||
s = e + pattern.length();
|
||||
}
|
||||
result.append(str.substring(s));
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tempSaveExtraData(String datasetType, String datasetName,
|
||||
String datasetPKValue, Map<String, String> queryParams) {
|
||||
logger.info("SaveExtraData - DatasetType: " + datasetType
|
||||
+ " DatasetName: " + datasetName + " datasetPKValue: "
|
||||
+ datasetPKValue);
|
||||
|
||||
logger.info("startjpw: ");
|
||||
Set<String> keys = queryParams.keySet();
|
||||
String pValue = "";
|
||||
for (String key : keys) {
|
||||
pValue = queryParams.get(key);
|
||||
logger.info("jpw: " + key + " - " + pValue);
|
||||
}
|
||||
|
||||
logger.info("endjpw: ");
|
||||
|
||||
|
||||
String fullDatasetName = getFullDatasetName(datasetType, datasetName);
|
||||
String saveSql = getSaveSql(fullDatasetName, datasetPKValue,
|
||||
queryParams);
|
||||
try {
|
||||
Connection db_connection = dataSource.getConnection();
|
||||
Statement db_statement = db_connection.createStatement();
|
||||
db_statement.executeUpdate(saveSql);
|
||||
|
||||
db_statement.close();
|
||||
db_statement = null;
|
||||
db_connection.close();
|
||||
db_connection = null;
|
||||
} catch (SQLException e) {
|
||||
logger.info("SQL: " + saveSql + " ERROR: " + e.toString());
|
||||
throw new InvalidSqlException(e, e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getSaveSql(String fullDatasetName, String datasetPKValue,
|
||||
Map<String, String> queryParams) {
|
||||
|
||||
String errMsg = "";
|
||||
String transType = queryParams.get("ed_transType");
|
||||
if (!(transType.equals("E") || transType.equals("A"))) {
|
||||
errMsg = "transType not E or A - Value is: " + transType;
|
||||
logger.info(errMsg);
|
||||
throw new WebApplicationException(Response
|
||||
.status(Status.BAD_REQUEST).entity(errMsg).build());
|
||||
}
|
||||
|
||||
String pValue = "";
|
||||
String pValueWrite = "";
|
||||
String saveSql = "";
|
||||
String singleQuote = "'";
|
||||
String underscore = "_";
|
||||
String space = " ";
|
||||
Set<String> keys = queryParams.keySet();
|
||||
|
||||
if (transType.equals("E")) {
|
||||
boolean firstColumn = true;
|
||||
saveSql = "update `" + fullDatasetName + "` ";
|
||||
|
||||
for (String key : keys) {
|
||||
if (!(key.equals("ed_transType") || key.equals("id"))) {
|
||||
if (firstColumn) {
|
||||
saveSql += " set ";
|
||||
firstColumn = false;
|
||||
} else {
|
||||
saveSql += ", ";
|
||||
}
|
||||
|
||||
pValue = queryParams.get(key);
|
||||
if (pValue == null || pValue.equals("")) {
|
||||
pValueWrite = "null";
|
||||
} else {
|
||||
pValueWrite = singleQuote
|
||||
+ replace(pValue, singleQuote, singleQuote
|
||||
+ singleQuote) + singleQuote;
|
||||
}
|
||||
saveSql += "`" + replace(key, underscore, space) + "` = "
|
||||
+ pValueWrite;
|
||||
}
|
||||
}
|
||||
|
||||
saveSql += " where id = " + datasetPKValue;
|
||||
} else {
|
||||
String insertColumns = "";
|
||||
String selectColumns = "";
|
||||
String columnName = "";
|
||||
for (String key : keys) {
|
||||
pValue = queryParams.get(key);
|
||||
if (!(key.equals("ed_transType") || key.equals("id"))) {
|
||||
|
||||
pValue = queryParams.get(key);
|
||||
if (pValue == null || pValue.equals("")) {
|
||||
pValueWrite = "null";
|
||||
} else {
|
||||
pValueWrite = singleQuote
|
||||
+ replace(pValue, singleQuote, singleQuote
|
||||
+ singleQuote) + singleQuote;
|
||||
}
|
||||
columnName = "`" + replace(key, underscore, space) + "`";
|
||||
insertColumns += ", " + columnName;
|
||||
selectColumns += "," + pValueWrite + " as " + columnName;
|
||||
}
|
||||
}
|
||||
|
||||
saveSql = "insert into `" + fullDatasetName + "` (id"
|
||||
+ insertColumns + ")" + " select " + datasetPKValue
|
||||
+ " as id" + selectColumns;
|
||||
}
|
||||
//logger.info("Save SQL: " + saveSql);
|
||||
return saveSql;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import org.mifosng.data.ClientData;
|
||||
import org.mifosng.data.ClientDataWithAccountsData;
|
||||
import org.mifosng.data.CurrencyData;
|
||||
import org.mifosng.data.EnumOptionReadModel;
|
||||
import org.mifosng.data.ExtraDatasets;
|
||||
import org.mifosng.data.LoanAccountData;
|
||||
import org.mifosng.data.LoanProductData;
|
||||
import org.mifosng.data.LoanRepaymentData;
|
||||
@@ -92,11 +91,4 @@ public interface ReadPlatformService {
|
||||
|
||||
NoteData retrieveClientNote(Long clientId, Long noteId);
|
||||
|
||||
ExtraDatasets retrieveExtraDatasetNames(String datasetType);
|
||||
|
||||
GenericResultset retrieveExtraData(String datasetType, String datasetName,
|
||||
String datasetPKValue);
|
||||
|
||||
void tempSaveExtraData(String datasetType, String datasetName,
|
||||
String datasetPKValue, Map<String, String> queryParams);
|
||||
}
|
||||
@@ -33,8 +33,6 @@ import org.mifosng.data.ClientDataWithAccountsData;
|
||||
import org.mifosng.data.CurrencyData;
|
||||
import org.mifosng.data.DerivedLoanData;
|
||||
import org.mifosng.data.EnumOptionReadModel;
|
||||
import org.mifosng.data.ExtraDatasetRow;
|
||||
import org.mifosng.data.ExtraDatasets;
|
||||
import org.mifosng.data.LoanAccountData;
|
||||
import org.mifosng.data.LoanProductData;
|
||||
import org.mifosng.data.LoanRepaymentData;
|
||||
@@ -1275,167 +1273,6 @@ public class ReadPlatformServiceImpl implements ReadPlatformService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtraDatasets retrieveExtraDatasetNames(String type) {
|
||||
|
||||
List<ExtraDatasetRow> extraDatasetRows = new ArrayList<ExtraDatasetRow>();
|
||||
Connection db_connection;
|
||||
try {
|
||||
db_connection = dataSource.getConnection();
|
||||
Statement db_statement = db_connection.createStatement();
|
||||
|
||||
String whereClause;
|
||||
if (type == null) {
|
||||
whereClause = "";
|
||||
} else {
|
||||
whereClause = "where t.`name` = '" + type + "'";
|
||||
}
|
||||
String sql = "select d.id, d.`name` as datasetName, t.`name` as datasetType from stretchydata_dataset d join stretchydata_datasettype t on t.id = d.datasettype_id "
|
||||
+ whereClause + " order by d.`name`";
|
||||
|
||||
ResultSet rs = db_statement.executeQuery(sql);
|
||||
|
||||
while (rs.next()) {
|
||||
extraDatasetRows.add(new ExtraDatasetRow(rs.getInt("id"), rs.getString("datasetName"), rs.getString("datasetType")));
|
||||
}
|
||||
|
||||
db_statement.close();
|
||||
db_statement = null;
|
||||
db_connection.close();
|
||||
db_connection = null;
|
||||
} catch (SQLException e) {
|
||||
logger.info(": Failed in retrieveExtraDatasetNames");
|
||||
throw new WebApplicationException(Response
|
||||
.status(Status.BAD_REQUEST).entity(e.getMessage()).build());
|
||||
}
|
||||
|
||||
return new ExtraDatasets(extraDatasetRows);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericResultset retrieveExtraData(String datasetType,
|
||||
String datasetName, String datasetPKValue) {
|
||||
|
||||
if (datasetType == null) {
|
||||
logger.info("Extra Data Table Type not Found");
|
||||
return null;
|
||||
}
|
||||
if (datasetName == null) {
|
||||
logger.info("Extra Data Table Name not Found");
|
||||
return null;
|
||||
}
|
||||
if (datasetPKValue == null) {
|
||||
logger.info("Extra Data Table ID not Found");
|
||||
return null;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
logger.info("STARTING EXTRA DATA TABLE: " + datasetName + " ID: "
|
||||
+ datasetPKValue);
|
||||
|
||||
try {
|
||||
GenericResultset result = fillExtraDataGenericResultSet(
|
||||
datasetType, datasetName, datasetPKValue);
|
||||
|
||||
long elapsed = System.currentTimeMillis() - startTime;
|
||||
logger.info("FINISHING EXTRA DATA TABLE: " + datasetName
|
||||
+ " Elapsed Time: " + elapsed);
|
||||
return result;
|
||||
} catch (SQLException e) {
|
||||
logger.info("Error - SQL: " + e.toString());
|
||||
throw new InvalidSqlException(e, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private GenericResultset fillExtraDataGenericResultSet(String datasetType,
|
||||
String datasetName, String datasetPKValue) throws SQLException {
|
||||
|
||||
GenericResultset result = new GenericResultset();
|
||||
String fullDatasetName = getFullDatasetName(datasetType, datasetName);
|
||||
Connection db_connection = dataSource.getConnection();
|
||||
Statement db_statement1 = db_connection.createStatement();
|
||||
Statement db_statement2 = db_connection.createStatement();
|
||||
Statement db_statement3 = db_connection.createStatement();
|
||||
String sql = "select f.`name`, f.data_type, f.data_length, f.display_type, f.allowed_list_id from stretchydata_datasettype t join stretchydata_dataset d on d.datasettype_id = t.id join stretchydata_dataset_fields f on f.dataset_id = d.id where d.`name` = '"
|
||||
+ datasetName
|
||||
+ "' and t.`name` = '"
|
||||
+ datasetType
|
||||
+ "' order by f.id";
|
||||
|
||||
//logger.info("specific: " + sql);
|
||||
ResultSet rsmd = db_statement1.executeQuery(sql);
|
||||
|
||||
List<ResultsetColumnHeader> columnHeaders = new ArrayList<ResultsetColumnHeader>();
|
||||
Boolean firstColumn = true;
|
||||
Integer allowedListId;
|
||||
String selectFieldList = "";
|
||||
String selectFieldSeparator = "";
|
||||
while (rsmd.next()) {
|
||||
ResultsetColumnHeader rsch = new ResultsetColumnHeader();
|
||||
rsch.setColumnName(rsmd.getString("name"));
|
||||
|
||||
if (firstColumn) {
|
||||
selectFieldSeparator = " ";
|
||||
firstColumn = false;
|
||||
} else {
|
||||
selectFieldSeparator = ", ";
|
||||
}
|
||||
selectFieldList += selectFieldSeparator + "`" + rsch.getColumnName() + "`";
|
||||
|
||||
rsch.setColumnType(rsmd.getString("data_type"));
|
||||
rsch.setColumnLength(rsmd.getInt("data_length"));
|
||||
rsch.setColumnDisplayType(rsmd.getString("display_type"));
|
||||
allowedListId = rsmd.getInt("allowed_list_id");
|
||||
if (allowedListId != null) {
|
||||
sql = "select v.`name` from stretchydata_allowed_value v where allowed_list_id = " + allowedListId + " order by id";
|
||||
ResultSet rsValues = db_statement2.executeQuery(sql);
|
||||
while (rsValues.next()) {
|
||||
rsch.getColumnValues().add(rsValues.getString("name"));
|
||||
}
|
||||
}
|
||||
columnHeaders.add(rsch);
|
||||
}
|
||||
result.setColumnHeaders(columnHeaders);
|
||||
|
||||
sql = "select " + selectFieldList + " from `" + fullDatasetName
|
||||
+ "` where id = " + datasetPKValue;
|
||||
|
||||
ResultSet rs = db_statement3.executeQuery(sql);
|
||||
String columnName = null;
|
||||
String columnValue = null;
|
||||
List<ResultsetDataRow> resultsetDataRows = new ArrayList<ResultsetDataRow>();
|
||||
ResultsetDataRow resultsetDataRow;
|
||||
while (rs.next()) {
|
||||
resultsetDataRow = new ResultsetDataRow();
|
||||
List<String> columnValues = new ArrayList<String>();
|
||||
|
||||
for (int i = 0; i < columnHeaders.size(); i++) {
|
||||
columnName = columnHeaders.get(i).getColumnName();
|
||||
columnValue = rs.getString(columnName);
|
||||
columnValues.add(columnValue);
|
||||
}
|
||||
resultsetDataRow.setRow(columnValues);
|
||||
resultsetDataRows.add(resultsetDataRow);
|
||||
}
|
||||
result.setData(resultsetDataRows);
|
||||
|
||||
db_statement1.close();
|
||||
db_statement1 = null;
|
||||
db_statement2.close();
|
||||
db_statement2 = null;
|
||||
db_statement3.close();
|
||||
db_statement3 = null;
|
||||
db_connection.close();
|
||||
db_connection = null;
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private String getFullDatasetName(final String datasetType,
|
||||
final String datasetName) {
|
||||
return datasetType + "_extra_" + datasetName;
|
||||
}
|
||||
|
||||
private GenericResultset fillReportingGenericResultSet(final String sql)
|
||||
throws SQLException {
|
||||
@@ -1592,121 +1429,6 @@ public class ReadPlatformServiceImpl implements ReadPlatformService {
|
||||
result.append(str.substring(s));
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tempSaveExtraData(String datasetType, String datasetName,
|
||||
String datasetPKValue, Map<String, String> queryParams) {
|
||||
logger.info("SaveExtraData - DatasetType: " + datasetType
|
||||
+ " DatasetName: " + datasetName + " datasetPKValue: "
|
||||
+ datasetPKValue);
|
||||
|
||||
logger.info("startjpw: ");
|
||||
Set<String> keys = queryParams.keySet();
|
||||
String pValue = "";
|
||||
for (String key : keys) {
|
||||
pValue = queryParams.get(key);
|
||||
logger.info("jpw: " + key + " - " + pValue);
|
||||
}
|
||||
|
||||
logger.info("endjpw: ");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
String fullDatasetName = getFullDatasetName(datasetType, datasetName);
|
||||
String saveSql = getSaveSql(fullDatasetName, datasetPKValue,
|
||||
queryParams);
|
||||
try {
|
||||
Connection db_connection = dataSource.getConnection();
|
||||
Statement db_statement = db_connection.createStatement();
|
||||
db_statement.executeUpdate(saveSql);
|
||||
|
||||
db_statement.close();
|
||||
db_statement = null;
|
||||
db_connection.close();
|
||||
db_connection = null;
|
||||
} catch (SQLException e) {
|
||||
logger.info("SQL: " + saveSql + " ERROR: " + e.toString());
|
||||
throw new InvalidSqlException(e, e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getSaveSql(String fullDatasetName, String datasetPKValue,
|
||||
Map<String, String> queryParams) {
|
||||
|
||||
String errMsg = "";
|
||||
String transType = queryParams.get("ed_transType");
|
||||
if (!(transType.equals("E") || transType.equals("A"))) {
|
||||
errMsg = "transType not E or A - Value is: " + transType;
|
||||
logger.info(errMsg);
|
||||
throw new WebApplicationException(Response
|
||||
.status(Status.BAD_REQUEST).entity(errMsg).build());
|
||||
}
|
||||
|
||||
String pValue = "";
|
||||
String pValueWrite = "";
|
||||
String saveSql = "";
|
||||
String singleQuote = "'";
|
||||
String underscore = "_";
|
||||
String space = " ";
|
||||
Set<String> keys = queryParams.keySet();
|
||||
|
||||
if (transType.equals("E")) {
|
||||
boolean firstColumn = true;
|
||||
saveSql = "update `" + fullDatasetName + "` ";
|
||||
|
||||
for (String key : keys) {
|
||||
if (!(key.equals("ed_transType") || key.equals("id"))) {
|
||||
if (firstColumn) {
|
||||
saveSql += " set ";
|
||||
firstColumn = false;
|
||||
} else {
|
||||
saveSql += ", ";
|
||||
}
|
||||
|
||||
pValue = queryParams.get(key);
|
||||
if (pValue == null || pValue.equals("")) {
|
||||
pValueWrite = "null";
|
||||
} else {
|
||||
pValueWrite = singleQuote
|
||||
+ replace(pValue, singleQuote, singleQuote
|
||||
+ singleQuote) + singleQuote;
|
||||
}
|
||||
saveSql += "`" + replace(key, underscore, space) + "` = "
|
||||
+ pValueWrite;
|
||||
}
|
||||
}
|
||||
|
||||
saveSql += " where id = " + datasetPKValue;
|
||||
} else {
|
||||
String insertColumns = "";
|
||||
String selectColumns = "";
|
||||
String columnName = "";
|
||||
for (String key : keys) {
|
||||
pValue = queryParams.get(key);
|
||||
if (!(key.equals("ed_transType") || key.equals("id"))) {
|
||||
|
||||
pValue = queryParams.get(key);
|
||||
if (pValue == null || pValue.equals("")) {
|
||||
pValueWrite = "null";
|
||||
} else {
|
||||
pValueWrite = singleQuote
|
||||
+ replace(pValue, singleQuote, singleQuote
|
||||
+ singleQuote) + singleQuote;
|
||||
}
|
||||
columnName = "`" + replace(key, underscore, space) + "`";
|
||||
insertColumns += ", " + columnName;
|
||||
selectColumns += "," + pValueWrite + " as " + columnName;
|
||||
}
|
||||
}
|
||||
|
||||
saveSql = "insert into `" + fullDatasetName + "` (id"
|
||||
+ insertColumns + ")" + " select " + datasetPKValue
|
||||
+ " as id" + selectColumns;
|
||||
}
|
||||
//logger.info("Save SQL: " + saveSql);
|
||||
return saveSql;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,15 +1,10 @@
|
||||
package org.mifosng.platform.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
@@ -33,7 +28,7 @@ import org.mifosng.data.ErrorResponseList;
|
||||
import org.mifosng.data.ExtraDatasets;
|
||||
import org.mifosng.data.reports.GenericResultset;
|
||||
import org.mifosng.platform.InvalidSqlException;
|
||||
import org.mifosng.platform.ReadPlatformService;
|
||||
import org.mifosng.platform.ReadExtraDataAndReportingService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -47,18 +42,7 @@ public class ExtraDataApiResource {
|
||||
private final static Logger logger = LoggerFactory.getLogger(ExtraDataApiResource.class);
|
||||
|
||||
@Autowired
|
||||
private ReadPlatformService readPlatformService;
|
||||
|
||||
// @GET
|
||||
// @Path("{dataSetPrefix}")
|
||||
// @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
// @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
// public Response extraDataNames(@PathParam("dataSetPrefix") final String dataSetPrefix) {
|
||||
//
|
||||
// List<String> result = this.readPlatformService.retrieveExtraDataTableNames(dataSetPrefix);
|
||||
//
|
||||
// return Response.ok().entity(result).build();
|
||||
// }
|
||||
private ReadExtraDataAndReportingService readExtraDataAndReportingService;
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@@ -68,7 +52,7 @@ public class ExtraDataApiResource {
|
||||
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
|
||||
String type = queryParams.getFirst("type");
|
||||
|
||||
ExtraDatasets result = this.readPlatformService.retrieveExtraDatasetNames(type);
|
||||
ExtraDatasets result = this.readExtraDataAndReportingService.retrieveExtraDatasetNames(type);
|
||||
return Response.ok().entity(result).build();
|
||||
}
|
||||
|
||||
@@ -79,7 +63,7 @@ public class ExtraDataApiResource {
|
||||
public Response extraData(@PathParam("datasetType") final String datasetType,@PathParam("datasetName") final String datasetName, @PathParam("datasetPKValue") final String datasetPKValue, @Context UriInfo uriInfo) {
|
||||
|
||||
try {
|
||||
GenericResultset result = this.readPlatformService.retrieveExtraData(datasetType, datasetName, datasetPKValue);
|
||||
GenericResultset result = this.readExtraDataAndReportingService.retrieveExtraData(datasetType, datasetName, datasetPKValue);
|
||||
|
||||
return Response.ok().entity(result).build();
|
||||
} catch (InvalidSqlException e) {
|
||||
@@ -127,7 +111,7 @@ public class ExtraDataApiResource {
|
||||
}
|
||||
|
||||
|
||||
this.readPlatformService.tempSaveExtraData(datasetType, datasetName, datasetPKValue, queryParams);
|
||||
this.readExtraDataAndReportingService.tempSaveExtraData(datasetType, datasetName, datasetPKValue, queryParams);
|
||||
|
||||
EntityIdentifier entityIdentifier = new EntityIdentifier(Long.valueOf(datasetPKValue));
|
||||
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
package org.mifosng.platform.rest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosng.data.EntityIdentifier;
|
||||
import org.mifosng.data.ErrorResponse;
|
||||
import org.mifosng.data.ErrorResponseList;
|
||||
import org.mifosng.data.ExtraDatasets;
|
||||
import org.mifosng.data.reports.GenericResultset;
|
||||
import org.mifosng.platform.InvalidSqlException;
|
||||
import org.mifosng.platform.ReadPlatformService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Path("/protected/extradata")
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class ExtraDataResource {
|
||||
|
||||
private final static Logger logger = LoggerFactory
|
||||
.getLogger(ExtraDataResource.class);
|
||||
|
||||
@Autowired
|
||||
private ReadPlatformService readPlatformService;
|
||||
|
||||
// @GET
|
||||
// @Path("{dataSetPrefix}")
|
||||
// @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
// @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
// public Response extraDataNames(@PathParam("dataSetPrefix") final String dataSetPrefix) {
|
||||
//
|
||||
// List<String> result = this.readPlatformService.retrieveExtraDataTableNames(dataSetPrefix);
|
||||
//
|
||||
// return Response.ok().entity(result).build();
|
||||
// }
|
||||
|
||||
@GET
|
||||
@Path("datasets/{datasetType}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
public Response datasets(@PathParam("datasetType") final String datasetType, @Context UriInfo uriInfo) {
|
||||
|
||||
//MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
|
||||
//String tableName = queryParams.getFirst("tableName");
|
||||
|
||||
ExtraDatasets result = this.readPlatformService.retrieveExtraDatasetNames(datasetType);
|
||||
return Response.ok().entity(result).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{datasetType}/{datasetName}/{datasetPKValue}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
public Response extraData(@PathParam("datasetType") final String datasetType,@PathParam("datasetName") final String datasetName, @PathParam("datasetPKValue") final String datasetPKValue, @Context UriInfo uriInfo) {
|
||||
|
||||
try {
|
||||
GenericResultset result = this.readPlatformService.retrieveExtraData(datasetType, datasetName, datasetPKValue);
|
||||
|
||||
return Response.ok().entity(result).build();
|
||||
} catch (InvalidSqlException e) {
|
||||
List<ErrorResponse> allErrors = new ArrayList<ErrorResponse>();
|
||||
|
||||
ErrorResponse err = new ErrorResponse("extradata.invalid.sql", "sql", e.getSql());
|
||||
allErrors.add(err);
|
||||
|
||||
throw new WebApplicationException(Response
|
||||
.status(Status.BAD_REQUEST)
|
||||
.entity(new ErrorResponseList(allErrors)).build());
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{datasetType}/{datasetName}/{datasetPKValue}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
public Response saveExtraData(@PathParam("datasetType") final String datasetType,@PathParam("datasetName") final String datasetName, @PathParam("datasetPKValue") final String datasetPKValue, @Context UriInfo uriInfo) {
|
||||
|
||||
try {
|
||||
|
||||
MultivaluedMap<String, String> incomingParams = uriInfo.getQueryParameters();
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
|
||||
Set<String> keys = incomingParams.keySet();
|
||||
for (String key : keys) {
|
||||
String pValue = incomingParams.get(key).get(0);
|
||||
queryParams.put(key, pValue);
|
||||
logger.info(key + " - " + pValue);
|
||||
}
|
||||
|
||||
|
||||
this.readPlatformService.tempSaveExtraData(datasetType, datasetName, datasetPKValue, queryParams);
|
||||
|
||||
EntityIdentifier entityIdentifier = new EntityIdentifier(Long.valueOf(datasetPKValue));
|
||||
|
||||
return Response.ok().entity(entityIdentifier).build();
|
||||
} catch (InvalidSqlException e) {
|
||||
List<ErrorResponse> allErrors = new ArrayList<ErrorResponse>();
|
||||
|
||||
ErrorResponse err = new ErrorResponse("extradata.invalid.sql", "sql", e.getSql());
|
||||
allErrors.add(err);
|
||||
|
||||
throw new WebApplicationException(Response
|
||||
.status(Status.BAD_REQUEST)
|
||||
.entity(new ErrorResponseList(allErrors)).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
-113
@@ -1,113 +0,0 @@
|
||||
package org.mifosng.platform.rest;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosng.data.ExtraDatasets;
|
||||
import org.mifosng.data.reports.GenericResultset;
|
||||
import org.mifosng.platform.ReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.sun.jersey.api.json.JSONWithPadding;
|
||||
|
||||
/**
|
||||
* TODO - remove open reporting from application
|
||||
* @deprecated - remove from application
|
||||
*/
|
||||
@Deprecated
|
||||
@Path("/open/reporting")
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class FlexibleReportingResource {
|
||||
|
||||
@Autowired
|
||||
private ReadPlatformService readPlatformService;
|
||||
|
||||
@GET
|
||||
@Path("flexireportxxx")
|
||||
@Consumes({ "application/x-javascript" })
|
||||
@Produces({ "application/x-javascript" })
|
||||
public Response retrieveReport(
|
||||
@QueryParam("callback") @DefaultValue("callback") final String callbackName, @Context UriInfo uriInfo) {
|
||||
|
||||
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
|
||||
String rptDB = queryParams.getFirst("MRP_rptDB");
|
||||
String name = queryParams.getFirst("MRP_Name");
|
||||
String type = queryParams.getFirst("MRP_Type");
|
||||
|
||||
Map<String, String> extractedQueryParams = new HashMap<String, String>();
|
||||
|
||||
Set<String> keys = queryParams.keySet();
|
||||
String pKey;
|
||||
String pValue;
|
||||
for (String k : keys) {
|
||||
|
||||
if (k.startsWith("MRP_"))
|
||||
{
|
||||
pKey = "${" + k.substring(4) + "}";
|
||||
pValue = queryParams.get(k).get(0);
|
||||
|
||||
extractedQueryParams.put(pKey, pValue);
|
||||
}
|
||||
}
|
||||
|
||||
GenericResultset result = this.readPlatformService.retrieveGenericResultset(rptDB, name, type, extractedQueryParams);
|
||||
|
||||
JSONWithPadding paddedResult = new JSONWithPadding(result,
|
||||
callbackName);
|
||||
|
||||
return Response.ok().entity(paddedResult).build();
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Path("extradatanamesxxx")
|
||||
@Consumes({ "application/x-javascript" })
|
||||
@Produces({ "application/x-javascript" })
|
||||
public Response extraDataNames(
|
||||
@QueryParam("callback") @DefaultValue("callback") final String callbackName, @Context UriInfo uriInfo) {
|
||||
|
||||
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
|
||||
String tableName = queryParams.getFirst("tableName");
|
||||
|
||||
ExtraDatasets result = this.readPlatformService.retrieveExtraDatasetNames(tableName);
|
||||
|
||||
JSONWithPadding paddedResult = new JSONWithPadding(result,
|
||||
callbackName);
|
||||
|
||||
return Response.ok().entity(paddedResult).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("extradataxxx")
|
||||
@Consumes({ "application/x-javascript" })
|
||||
@Produces({ "application/x-javascript" })
|
||||
public Response extraData(
|
||||
@QueryParam("callback") @DefaultValue("callback") final String callbackName, @Context UriInfo uriInfo) {
|
||||
|
||||
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
|
||||
String extraDataTableName = queryParams.getFirst("extraDataTableName");
|
||||
String extraDataTableId = queryParams.getFirst("extraDataTableId");
|
||||
|
||||
GenericResultset result = this.readPlatformService.retrieveExtraData(extraDataTableName, extraDataTableName, extraDataTableId);
|
||||
|
||||
JSONWithPadding paddedResult = new JSONWithPadding(result,
|
||||
callbackName);
|
||||
|
||||
return Response.ok().entity(paddedResult).build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user