fix failing test cases
This commit is contained in:
+20
-16
@@ -105,25 +105,29 @@ public class LoanTransactionHelper {
|
||||
}
|
||||
|
||||
public HashMap approveLoan(final String approvalDate, final Integer loanID) {
|
||||
return performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID), getApproveLoanAsJSON(approvalDate));
|
||||
String loanApprovalCommand = createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID);
|
||||
String loanApprovalRequest = getApproveLoanAsJSON(approvalDate);
|
||||
System.out.println("Loan approval command:" + loanApprovalCommand);
|
||||
System.out.println("Loan approval request:" + loanApprovalRequest);
|
||||
return performLoanTransaction(loanApprovalCommand, loanApprovalRequest);
|
||||
}
|
||||
|
||||
public HashMap approveLoanWithApproveAmount(final String approvalDate, final String expectedDisbursementDate, final String approvalAmount, final Integer loanID,
|
||||
List<HashMap> tranches) {
|
||||
public HashMap approveLoanWithApproveAmount(final String approvalDate, final String expectedDisbursementDate,
|
||||
final String approvalAmount, final Integer loanID, List<HashMap> tranches) {
|
||||
return performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID),
|
||||
getApproveLoanAsJSON(approvalDate, expectedDisbursementDate, approvalAmount, tranches));
|
||||
}
|
||||
|
||||
public List<HashMap<String, Object>> approveLoanForTranches(final String approvalDate, final String expectedDisbursementDate, final String approvalAmount, final Integer loanID,
|
||||
List<HashMap> tranches, final String responseAttribute) {
|
||||
return (List<HashMap<String, Object>>) performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID),
|
||||
|
||||
public List<HashMap<String, Object>> approveLoanForTranches(final String approvalDate, final String expectedDisbursementDate,
|
||||
final String approvalAmount, final Integer loanID, List<HashMap> tranches, final String responseAttribute) {
|
||||
return (List<HashMap<String, Object>>) performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID),
|
||||
getApproveLoanAsJSON(approvalDate, expectedDisbursementDate, approvalAmount, tranches), responseAttribute);
|
||||
}
|
||||
|
||||
public Object approveLoan(final String approvalDate, final String approvalAmount, final Integer loanID, final String responseAttribute) {
|
||||
|
||||
final String approvalURL = createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID);
|
||||
final String approvalJSONData = getApproveLoanAsJSON(approvalDate,null, approvalAmount, null);
|
||||
final String approvalJSONData = getApproveLoanAsJSON(approvalDate, null, approvalAmount, null);
|
||||
|
||||
return performLoanTransaction(approvalURL, approvalJSONData, responseAttribute);
|
||||
}
|
||||
@@ -233,11 +237,11 @@ public class LoanTransactionHelper {
|
||||
}
|
||||
|
||||
private String getApproveLoanAsJSON(final String approvalDate) {
|
||||
return getApproveLoanAsJSON(approvalDate,null, null, null);
|
||||
return getApproveLoanAsJSON(approvalDate, null, null, null);
|
||||
}
|
||||
|
||||
private String getApproveLoanAsJSON(final String approvalDate, final String expectedDisbursementDate, final String approvalAmount,
|
||||
List<HashMap> tranches) {
|
||||
private String getApproveLoanAsJSON(final String approvalDate, final String expectedDisbursementDate, final String approvalAmount,
|
||||
List<HashMap> tranches) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
@@ -245,11 +249,11 @@ public class LoanTransactionHelper {
|
||||
map.put("approvedLoanAmount", approvalAmount);
|
||||
}
|
||||
map.put("approvedOnDate", approvalDate);
|
||||
if(expectedDisbursementDate != null){
|
||||
map.put("expectedDisbursementDate", expectedDisbursementDate);
|
||||
if (expectedDisbursementDate != null) {
|
||||
map.put("expectedDisbursementDate", expectedDisbursementDate);
|
||||
}
|
||||
if(tranches != null && tranches.size() > 0){
|
||||
map.put("disbursementData",tranches);
|
||||
if (tranches != null && tranches.size() > 0) {
|
||||
map.put("disbursementData", tranches);
|
||||
}
|
||||
map.put("note", "Approval NOTE");
|
||||
return new Gson().toJson(map);
|
||||
@@ -407,7 +411,7 @@ public class LoanTransactionHelper {
|
||||
private Object performLoanTransaction(final String postURLForLoanTransaction, final String jsonToBeSent, final String responseAttribute) {
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForLoanTransaction, jsonToBeSent, responseAttribute);
|
||||
}
|
||||
|
||||
|
||||
public Object adjustLoanTransaction(final Integer loanId, final Integer transactionId, final String date,
|
||||
final String transactionAmount, final String responseAttribute) {
|
||||
return adjustLoanTransaction(loanId, transactionId, getAdjustTransactionJSON(date, transactionAmount), responseAttribute);
|
||||
|
||||
-1
@@ -36,7 +36,6 @@ public class JournalEntryData {
|
||||
private final BigDecimal amount;
|
||||
@SuppressWarnings("unused")
|
||||
private final CurrencyData currency;
|
||||
@SuppressWarnings("unused")
|
||||
private final String transactionId;
|
||||
@SuppressWarnings("unused")
|
||||
private final Boolean manualEntry;
|
||||
|
||||
+1
-7
@@ -25,7 +25,6 @@ public class CommandWrapperBuilder {
|
||||
private String transactionId;
|
||||
private Long productId;
|
||||
private Long templateId;
|
||||
private Long tellerId;
|
||||
|
||||
public CommandWrapper build() {
|
||||
return new CommandWrapper(this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId, this.actionName,
|
||||
@@ -62,11 +61,6 @@ public class CommandWrapperBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder withTellerId(final Long withTellerId) {
|
||||
this.tellerId = withTellerId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder withJson(final String withJson) {
|
||||
this.json = withJson;
|
||||
return this;
|
||||
@@ -744,7 +738,7 @@ public class CommandWrapperBuilder {
|
||||
this.actionName = "UPDATE";
|
||||
this.entityName = "DISBURSEMENTDETAIL";
|
||||
this.entityId = null;
|
||||
this.loanId = loanId;
|
||||
this.loanId = loanId;
|
||||
this.href = "/loans/" + loanId + "/editdisbursementdetails/";
|
||||
return this;
|
||||
}
|
||||
|
||||
+1
-2
@@ -14,7 +14,6 @@ public class CodeValueData implements Serializable {
|
||||
|
||||
private final Long id;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final String name;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -53,7 +52,7 @@ public class CodeValueData implements Serializable {
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
+20
-26
@@ -74,7 +74,6 @@ import org.mifosplatform.portfolio.loanaccount.exception.LoanApplicationDateExce
|
||||
import org.mifosplatform.portfolio.loanaccount.exception.LoanApplicationNotInSubmittedAndPendingApprovalStateCannotBeDeleted;
|
||||
import org.mifosplatform.portfolio.loanaccount.exception.LoanApplicationNotInSubmittedAndPendingApprovalStateCannotBeModified;
|
||||
import org.mifosplatform.portfolio.loanaccount.exception.LoanNotFoundException;
|
||||
import org.mifosplatform.portfolio.loanaccount.exception.MultiDisbursementDataRequiredException;
|
||||
import org.mifosplatform.portfolio.loanaccount.loanschedule.domain.AprCalculator;
|
||||
import org.mifosplatform.portfolio.loanaccount.loanschedule.domain.LoanScheduleModel;
|
||||
import org.mifosplatform.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler;
|
||||
@@ -140,7 +139,6 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
private final ConfigurationDomainService configurationDomainService;
|
||||
private final LoanScheduleAssembler loanScheduleAssembler;
|
||||
|
||||
|
||||
@Autowired
|
||||
public LoanApplicationWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final FromJsonHelper fromJsonHelper,
|
||||
final LoanApplicationTransitionApiJsonValidator loanApplicationTransitionApiJsonValidator,
|
||||
@@ -740,21 +738,17 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
.build();
|
||||
}
|
||||
|
||||
public void validateMultiDisbursementData(final JsonCommand command, LocalDate expectedDisbursementDate){
|
||||
final String json = command.json();
|
||||
final JsonElement element = this.fromJsonHelper.parse(json);
|
||||
public void validateMultiDisbursementData(final JsonCommand command, LocalDate expectedDisbursementDate) {
|
||||
final String json = command.json();
|
||||
final JsonElement element = this.fromJsonHelper.parse(json);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan");
|
||||
final JsonArray disbursementDataArray = command.arrayOfParameterNamed(LoanApiConstants.disbursementDataParameterName);
|
||||
if(disbursementDataArray == null || disbursementDataArray.size() == 0){
|
||||
final String errorMessage = "For this loan product, disbursement details must be provided";
|
||||
throw new MultiDisbursementDataRequiredException(LoanApiConstants.disbursementDataParameterName, errorMessage);
|
||||
}
|
||||
final BigDecimal principal = this.fromJsonHelper.extractBigDecimalWithLocaleNamed("approvedLoanAmount", element);
|
||||
final BigDecimal principal = this.fromJsonHelper.extractBigDecimalWithLocaleNamed("approvedLoanAmount", element);
|
||||
fromApiJsonDeserializer.validateLoanMultiDisbursementdate(element, baseDataValidator, expectedDisbursementDate, principal);
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult approveApplication(final Long loanId, final JsonCommand command) {
|
||||
@@ -763,43 +757,43 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
LocalDate expectedDisbursementDate = null;
|
||||
|
||||
this.loanApplicationTransitionApiJsonValidator.validateApproval(command.json());
|
||||
|
||||
|
||||
final Loan loan = retrieveLoanBy(loanId);
|
||||
|
||||
|
||||
final JsonArray disbursementDataArray = command.arrayOfParameterNamed(LoanApiConstants.disbursementDataParameterName);
|
||||
|
||||
expectedDisbursementDate = command.localDateValueOfParameterNamed(LoanApiConstants.disbursementDateParameterName);
|
||||
if(expectedDisbursementDate == null){
|
||||
expectedDisbursementDate = loan.getExpectedDisbursedOnLocalDate();
|
||||
if (expectedDisbursementDate == null) {
|
||||
expectedDisbursementDate = loan.getExpectedDisbursedOnLocalDate();
|
||||
}
|
||||
if(loan.loanProduct().isMultiDisburseLoan()){
|
||||
this.validateMultiDisbursementData(command, expectedDisbursementDate);
|
||||
if (loan.loanProduct().isMultiDisburseLoan()) {
|
||||
this.validateMultiDisbursementData(command, expectedDisbursementDate);
|
||||
}
|
||||
|
||||
|
||||
checkClientOrGroupActive(loan);
|
||||
|
||||
// validate expected disbursement date against meeting date
|
||||
|
||||
// validate expected disbursement date against meeting date
|
||||
if (loan.isSyncDisbursementWithMeeting() && (loan.isGroupLoan() || loan.isJLGLoan())) {
|
||||
final CalendarInstance calendarInstance = this.calendarInstanceRepository.findCalendarInstaneByEntityId(loan.getId(),
|
||||
CalendarEntityType.LOANS.getValue());
|
||||
final Calendar calendar = calendarInstance.getCalendar();
|
||||
final Calendar calendar = calendarInstance.getCalendar();
|
||||
this.loanScheduleAssembler.validateDisbursementDateWithMeetingDates(expectedDisbursementDate, calendar);
|
||||
}
|
||||
|
||||
final Map<String, Object> changes = loan.loanApplicationApproval(currentUser, command, disbursementDataArray, defaultLoanLifecycleStateMachine());
|
||||
|
||||
|
||||
final Map<String, Object> changes = loan.loanApplicationApproval(currentUser, command, disbursementDataArray,
|
||||
defaultLoanLifecycleStateMachine());
|
||||
|
||||
if (!changes.isEmpty()) {
|
||||
|
||||
// If loan approved amount less than loan demanded amount, then need
|
||||
// to recompute the schedule
|
||||
if (changes.containsKey(LoanApiConstants.approvedLoanAmountParameterName)) {
|
||||
ScheduleGeneratorDTO scheduleGeneratorDTO = loanAccountDomainService.buildScheduleGeneratorDTO(loan);
|
||||
loan.regenerateRepaymentSchedule(scheduleGeneratorDTO, currentUser);
|
||||
loan.regenerateRepaymentSchedule(scheduleGeneratorDTO, currentUser);
|
||||
}
|
||||
|
||||
this.loanRepository.save(loan);
|
||||
|
||||
|
||||
final String noteText = command.stringValueOfParameterNamed("note");
|
||||
if (StringUtils.isNotBlank(noteText)) {
|
||||
final Note note = Note.loanNote(loan, noteText);
|
||||
|
||||
+11
-24
@@ -23,7 +23,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.mifosplatform.template.domain.Template;
|
||||
import org.mifosplatform.template.domain.TemplateFunctions;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
@@ -49,19 +48,15 @@ public class TemplateMergeService {
|
||||
this.authToken = authToken;
|
||||
}
|
||||
|
||||
public String compile(final Template template,
|
||||
final Map<String, Object> scopes) throws MalformedURLException,
|
||||
IOException {
|
||||
public String compile(final Template template, final Map<String, Object> scopes) throws MalformedURLException, IOException {
|
||||
|
||||
this.scopes = scopes;
|
||||
this.scopes.put("static", new TemplateFunctions());
|
||||
|
||||
final MustacheFactory mf = new DefaultMustacheFactory();
|
||||
final Mustache mustache = mf.compile(
|
||||
new StringReader(template.getText()), template.getName());
|
||||
final Mustache mustache = mf.compile(new StringReader(template.getText()), template.getName());
|
||||
|
||||
final Map<String, Object> mappers = getCompiledMapFromMappers(template
|
||||
.getMappersAsMap());
|
||||
final Map<String, Object> mappers = getCompiledMapFromMappers(template.getMappersAsMap());
|
||||
this.scopes.putAll(mappers);
|
||||
|
||||
final StringWriter stringWriter = new StringWriter();
|
||||
@@ -70,16 +65,14 @@ public class TemplateMergeService {
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
private Map<String, Object> getCompiledMapFromMappers(
|
||||
final Map<String, String> data) {
|
||||
private Map<String, Object> getCompiledMapFromMappers(final Map<String, String> data) {
|
||||
|
||||
final MustacheFactory mf = new DefaultMustacheFactory();
|
||||
|
||||
if (data != null) {
|
||||
for (final Map.Entry<String, String> entry : data.entrySet()) {
|
||||
|
||||
final Mustache mappersMustache = mf.compile(new StringReader(
|
||||
entry.getValue()), "");
|
||||
final Mustache mappersMustache = mf.compile(new StringReader(entry.getValue()), "");
|
||||
final StringWriter stringWriter = new StringWriter();
|
||||
|
||||
mappersMustache.execute(stringWriter, this.scopes);
|
||||
@@ -100,13 +93,11 @@ public class TemplateMergeService {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> getMapFromUrl(final String url)
|
||||
throws MalformedURLException, IOException {
|
||||
private Map<String, Object> getMapFromUrl(final String url) throws MalformedURLException, IOException {
|
||||
|
||||
final HttpURLConnection connection = getConnection(url);
|
||||
|
||||
final String response = getStringFromInputStream(connection
|
||||
.getInputStream());
|
||||
final String response = getStringFromInputStream(connection.getInputStream());
|
||||
HashMap<String, Object> result = new HashMap<>();
|
||||
if (connection.getContentType().equals("text/plain")) {
|
||||
result.put("src", response);
|
||||
@@ -119,17 +110,14 @@ public class TemplateMergeService {
|
||||
private HttpURLConnection getConnection(final String url) {
|
||||
|
||||
if (this.authToken == null) {
|
||||
final String name = SecurityContextHolder.getContext()
|
||||
.getAuthentication().getName();
|
||||
final String password = SecurityContextHolder.getContext()
|
||||
.getAuthentication().getCredentials().toString();
|
||||
final String name = SecurityContextHolder.getContext().getAuthentication().getName();
|
||||
final String password = SecurityContextHolder.getContext().getAuthentication().getCredentials().toString();
|
||||
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(name, password
|
||||
.toCharArray());
|
||||
return new PasswordAuthentication(name, password.toCharArray());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -138,8 +126,7 @@ public class TemplateMergeService {
|
||||
try {
|
||||
connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
if (this.authToken != null) {
|
||||
connection.setRequestProperty("Authorization", "Basic "
|
||||
+ this.authToken);
|
||||
connection.setRequestProperty("Authorization", "Basic " + this.authToken);
|
||||
}
|
||||
TrustModifier.relaxHostChecking(connection);
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
INSERT INTO `job` (`name`, `display_name`, `cron_expression`, `create_time`) VALUES ('Generate Mandatory Savings Schedule', 'Generate Mandatory Savings Schedule', '0 5 0 1/1 * ? *', now());
|
||||
|
||||
Reference in New Issue
Block a user