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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user