Merge remote-tracking branch 'vishwasbabu/mifosx-151'
This commit is contained in:
+1
-1
@@ -70,7 +70,7 @@ public class GLAccountsApiResource {
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAllAccounts(@Context final UriInfo uriInfo, @QueryParam("classification") final Integer classification,
|
||||
public String retrieveAllAccounts(@Context final UriInfo uriInfo, @QueryParam("type") final Integer classification,
|
||||
@QueryParam("searchParam") final String searchParam, @QueryParam("usage") final Integer usage,
|
||||
@QueryParam("manualAdjustmentsAllowed") final Boolean manualTransactionsAllowed, @QueryParam("disabled") final Boolean disabled) {
|
||||
|
||||
|
||||
+25
-10
@@ -15,6 +15,7 @@ import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.accounting.api.commands.GLJournalEntryCommand;
|
||||
import org.mifosplatform.accounting.api.data.GLJournalEntryData;
|
||||
import org.mifosplatform.accounting.api.data.JournalEntryIdentifier;
|
||||
@@ -24,6 +25,7 @@ import org.mifosplatform.accounting.api.infrastructure.DateParam;
|
||||
import org.mifosplatform.accounting.service.GLJournalEntryReadPlatformService;
|
||||
import org.mifosplatform.accounting.service.GLJournalEntryWritePlatformService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -58,9 +60,9 @@ public class GLJournalEntriesApiResource {
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAllJournalEntries(@Context final UriInfo uriInfo, @QueryParam("officeId") final Long officeId,
|
||||
@QueryParam("glAccountId") final Long glAccountId,
|
||||
@QueryParam("portfolioGenerated") final Boolean portfolioGenerated, @QueryParam("fromDate") final DateParam fromDateParam,
|
||||
@QueryParam("toDate") final DateParam toDateParam) {
|
||||
@QueryParam("glAccountId") final Long glAccountId, @QueryParam("portfolioGenerated") final Boolean portfolioGenerated,
|
||||
@QueryParam("fromDate") final DateParam fromDateParam, @QueryParam("toDate") final DateParam toDateParam,
|
||||
@QueryParam("transactionId") String transactionId) {
|
||||
|
||||
// TODO: Vishwas Add pagination, approach at
|
||||
// http://www.javaworld.com/community/node/8295 looks good
|
||||
@@ -79,8 +81,13 @@ public class GLJournalEntriesApiResource {
|
||||
if (toDateParam != null) {
|
||||
toDate = toDateParam.getDate();
|
||||
}
|
||||
glJournalEntryDatas = this.glJournalEntryReadPlatformService.retrieveAllGLJournalEntries(officeId, glAccountId,
|
||||
portfolioGenerated, fromDate, toDate);
|
||||
if (StringUtils.isBlank(transactionId)) {
|
||||
glJournalEntryDatas = this.glJournalEntryReadPlatformService.retrieveAllGLJournalEntries(officeId, glAccountId,
|
||||
portfolioGenerated, fromDate, toDate);
|
||||
} else {
|
||||
glJournalEntryDatas = this.glJournalEntryReadPlatformService.retrieveRelatedJournalEntries(transactionId);
|
||||
}
|
||||
|
||||
return this.apiJsonSerializerService.serializeGLJournalEntryDataToJson(prettyPrint, responseParameters, glJournalEntryDatas);
|
||||
}
|
||||
|
||||
@@ -88,7 +95,7 @@ public class GLJournalEntriesApiResource {
|
||||
@Path("{glJournalEntryId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retreiveAccount(@PathParam("glJournalEntryId") final Long glJournalEntryId, @Context final UriInfo uriInfo) {
|
||||
public String retreiveJournalEntryById(@PathParam("glJournalEntryId") final Long glJournalEntryId, @Context final UriInfo uriInfo) {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||
|
||||
@@ -111,13 +118,21 @@ public class GLJournalEntriesApiResource {
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{transactionId}/reversal")
|
||||
@Path("{transactionId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String createReversalJournalEntry(@PathParam("transactionId") final String transactionId) {
|
||||
|
||||
this.glJournalEntryWritePlatformService.revertJournalEntry(transactionId);
|
||||
public String createReversalJournalEntry(@PathParam("transactionId") final String transactionId,
|
||||
@QueryParam("command") final String commandParam) {
|
||||
if (is(commandParam, "reverse")) {
|
||||
this.glJournalEntryWritePlatformService.revertJournalEntry(transactionId);
|
||||
} else {
|
||||
throw new UnrecognizedQueryParamException("command", commandParam);
|
||||
}
|
||||
|
||||
return this.apiJsonSerializerService.serializeJournalEntryIdentifier(new JournalEntryIdentifier(transactionId));
|
||||
}
|
||||
|
||||
private boolean is(final String commandParam, final String commandValue) {
|
||||
return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package org.mifosplatform.accounting.exceptions;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
||||
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when journal entry resources are not found.
|
||||
*/
|
||||
public class GLJournalEntryNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
public GLJournalEntryNotFoundException(final String transactionId) {
|
||||
super("error.msg.journalEntries.transactionId.invalid", "Journal Entries with transaction Identifier " + transactionId
|
||||
+ " does not exist or are not system generated/reversible ", transactionId);
|
||||
}
|
||||
|
||||
public GLJournalEntryNotFoundException(final Long entryId) {
|
||||
super("error.msg.journalEntries.id.invalid", "Journal Entry with entry Id " + entryId + " does not exist ", entryId);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -30,7 +30,7 @@ public class GLAccountCommandValidator {
|
||||
|
||||
baseDataValidator.reset().parameter("parentId").value(command.getParentId()).ignoreIfNull().integerGreaterThanZero();
|
||||
|
||||
baseDataValidator.reset().parameter("classification").value(command.getClassification())
|
||||
baseDataValidator.reset().parameter("classification").value(command.getClassification()).notNull()
|
||||
.inMinMaxRange(GLAccountType.getMinValue(), GLAccountType.getMaxValue());
|
||||
|
||||
baseDataValidator.reset().parameter("usage").value(command.getUsage())
|
||||
|
||||
+2
@@ -10,6 +10,8 @@ public interface GLJournalEntryReadPlatformService {
|
||||
List<GLJournalEntryData> retrieveAllGLJournalEntries(Long officeId, Long glAccountId, Boolean portfolioGenerated, Date fromDate,
|
||||
Date toDate);
|
||||
|
||||
List<GLJournalEntryData> retrieveRelatedJournalEntries(String transactionId);
|
||||
|
||||
GLJournalEntryData retrieveGLJournalEntryById(long glJournalEntryId);
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public class GLAccountReadPlatformServiceImpl implements GLAccountReadPlatformSe
|
||||
|
||||
Long id = rs.getLong("id");
|
||||
String name = rs.getString("name");
|
||||
Long parentId = rs.getLong("parentId");
|
||||
Long parentId = JdbcSupport.getLong(rs,"parentId");
|
||||
String glCode = rs.getString("glCode");
|
||||
boolean disabled = rs.getBoolean("disabled");
|
||||
boolean manualEntriesAllowed = rs.getBoolean("manualEntriesAllowed");
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public class GLClosureReadPlatformServiceImpl implements GLClosureReadPlatformSe
|
||||
arrayPos = arrayPos + 1;
|
||||
}
|
||||
|
||||
sql = sql + " order by glClosure.closing_date";
|
||||
sql = sql + " order by glClosure.closing_date desc";
|
||||
|
||||
Object[] finalObjectArray = Arrays.copyOf(objectArray, arrayPos);
|
||||
return this.jdbcTemplate.query(sql, rm, finalObjectArray);
|
||||
|
||||
+18
-3
@@ -134,7 +134,7 @@ public class GLJournalEntryReadPlatformServiceImpl implements GLJournalEntryRead
|
||||
}
|
||||
}
|
||||
|
||||
sql += " order by journalEntry.entry_date,journalEntry.transaction_id";
|
||||
sql += " order by journalEntry.entry_date desc,journalEntry.transaction_id";
|
||||
|
||||
Object[] finalObjectArray = Arrays.copyOf(objectArray, arrayPos);
|
||||
return this.jdbcTemplate.query(sql, rm, finalObjectArray);
|
||||
@@ -147,12 +147,27 @@ public class GLJournalEntryReadPlatformServiceImpl implements GLJournalEntryRead
|
||||
GLJournalEntryMapper rm = new GLJournalEntryMapper();
|
||||
String sql = "select " + rm.schema() + " and journalEntry.id = ?";
|
||||
|
||||
GLJournalEntryData glAccountData = this.jdbcTemplate.queryForObject(sql, rm, new Object[] { glJournalEntryId });
|
||||
GLJournalEntryData glJournalEntryData = this.jdbcTemplate.queryForObject(sql, rm, new Object[] { glJournalEntryId });
|
||||
|
||||
return glAccountData;
|
||||
return glJournalEntryData;
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new GLJournalEntriesNotFoundException(glJournalEntryId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GLJournalEntryData> retrieveRelatedJournalEntries(String transactionId) {
|
||||
try {
|
||||
|
||||
GLJournalEntryMapper rm = new GLJournalEntryMapper();
|
||||
String sql = "select " + rm.schema() + " and journalEntry.transaction_id = ?";
|
||||
|
||||
List<GLJournalEntryData> journalEntryDatas = this.jdbcTemplate.query(sql, rm, new Object[] { transactionId });
|
||||
|
||||
return journalEntryDatas;
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new GLJournalEntriesNotFoundException(transactionId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class ProductToGLAccountMappingWritePlatformServiceImpl implements Produc
|
||||
@Transactional
|
||||
public void createLoanProductToGLAccountMapping(final Long loanProductId, final JsonCommand command) {
|
||||
final JsonElement element = this.fromApiJsonHelper.parse(command.json());
|
||||
final Integer accountingRuleTypeId = this.fromApiJsonHelper.extractIntegerNamed("accountingType", element, Locale.getDefault());
|
||||
final Integer accountingRuleTypeId = this.fromApiJsonHelper.extractIntegerNamed("accountingRule", element, Locale.getDefault());
|
||||
final AccountingRuleType accountingRuleType = AccountingRuleType.fromInt(accountingRuleTypeId);
|
||||
|
||||
switch (accountingRuleType) {
|
||||
|
||||
+17
-14
@@ -41,7 +41,7 @@ public class CommandWrapperBuilder {
|
||||
this.json = withJson;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CommandWrapperBuilder updateGlobalConfiguration() {
|
||||
this.actionName = "UPDATE";
|
||||
this.entityName = "CONFIGURATION";
|
||||
@@ -127,7 +127,7 @@ public class CommandWrapperBuilder {
|
||||
this.href = "/officetransactions/template";
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CommandWrapperBuilder deleteOfficeTransaction(final Long transactionId) {
|
||||
this.actionName = "DELETE";
|
||||
this.entityName = "OFFICETRANSACTION";
|
||||
@@ -151,28 +151,31 @@ public class CommandWrapperBuilder {
|
||||
this.href = "/staff/" + staffId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder createGuarantor() {
|
||||
|
||||
public CommandWrapperBuilder createGuarantor(final Long loanId) {
|
||||
this.actionName = "CREATE";
|
||||
this.entityName = "GUARANTOR";
|
||||
this.entityId = null;
|
||||
this.href = "/guarantors/template";
|
||||
this.loanId = loanId;
|
||||
this.href = "/loans/" + loanId + "/guarantors/template";
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder updateGuarantor(final Long guarantorId) {
|
||||
public CommandWrapperBuilder updateGuarantor(final Long loanId, final Long guarantorId) {
|
||||
this.actionName = "UPDATE";
|
||||
this.entityName = "GUARANTOR";
|
||||
this.entityId = guarantorId;
|
||||
this.href = "/guarantors/" + guarantorId;
|
||||
this.loanId = loanId;
|
||||
this.href = "/loans/" + loanId + "/guarantors/" + guarantorId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandWrapperBuilder deleteGuarantor(final Long guarantorId) {
|
||||
|
||||
public CommandWrapperBuilder deleteGuarantor(final Long loanId, final Long guarantorId) {
|
||||
this.actionName = "DELETE";
|
||||
this.entityName = "GUARANTOR";
|
||||
this.entityId = guarantorId;
|
||||
this.href = "/guarantors/" + guarantorId;
|
||||
this.loanId = loanId;
|
||||
this.href = "/loans/" + loanId + "/guarantors/" + guarantorId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -549,7 +552,7 @@ public class CommandWrapperBuilder {
|
||||
this.href = "/loans/" + loanId;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CommandWrapperBuilder unassignLoanOfficer(final Long loanId) {
|
||||
this.actionName = "REMOVELOANOFFICER";
|
||||
this.entityName = "LOAN";
|
||||
@@ -565,7 +568,7 @@ public class CommandWrapperBuilder {
|
||||
this.href = "/loans/loanreassignment";
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CommandWrapperBuilder createCodeValue(final Long codeId) {
|
||||
this.actionName = "CREATE";
|
||||
this.entityName = "CODEVALUE";
|
||||
@@ -573,7 +576,7 @@ public class CommandWrapperBuilder {
|
||||
this.href = "/codes/" + codeId + "/codevalues/template";
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CommandWrapperBuilder updateCodeValue(Long codeId, final Long codeValueId) {
|
||||
this.actionName = "UPDATE";
|
||||
this.entityName = "CODEVALUE";
|
||||
@@ -582,7 +585,7 @@ public class CommandWrapperBuilder {
|
||||
this.href = "/codes/" + codeId + "/codevalues/" + codeValueId;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CommandWrapperBuilder deleteCodeValue(Long codeId, final Long codeValueId) {
|
||||
this.actionName = "DELETE";
|
||||
this.entityName = "CODEVALUE";
|
||||
|
||||
+26
-10
@@ -34,12 +34,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Path("/guarantors")
|
||||
@Path("/loans/{loanId}/guarantors")
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class GuarantorsApiResource {
|
||||
|
||||
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("externalGuarantor", "existingClientId",
|
||||
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("guarantorTypeId", "entityId",
|
||||
"firstname", "lastname", "addressLine1", "addressLine2", "city", "state", "zip", "country", "mobileNumber", "housePhoneNumber",
|
||||
"comment", "dob"));
|
||||
|
||||
@@ -75,14 +75,28 @@ public class GuarantorsApiResource {
|
||||
return this.apiJsonSerializerService.serialize(settings, guarantorData, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveGuarantorDetails(@Context final UriInfo uriInfo, @PathParam("loanId") final Long loanId) {
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermission);
|
||||
|
||||
List<GuarantorData> guarantorDatas = guarantorReadPlatformService.retrieveGuarantorsForValidLoan(loanId);
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
return this.apiJsonSerializerService.serialize(settings, guarantorDatas, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{guarantorId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveGuarantorDetails(@Context final UriInfo uriInfo, @PathParam("guarantorId") final Long guarantorId) {
|
||||
public String retrieveGuarantorDetails(@Context final UriInfo uriInfo, @PathParam("loanId") final Long loanId,
|
||||
@PathParam("guarantorId") final Long guarantorId) {
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermission);
|
||||
|
||||
GuarantorData guarantorData = guarantorReadPlatformService.retrieveGuarantor(guarantorId);
|
||||
GuarantorData guarantorData = guarantorReadPlatformService.retrieveGuarantor(loanId, guarantorId);
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
if (settings.isTemplate()) {
|
||||
@@ -96,9 +110,9 @@ public class GuarantorsApiResource {
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String createGuarantor(final String apiRequestBodyAsJson) {
|
||||
public String createGuarantor(@PathParam("loanId") final Long loanId, final String apiRequestBodyAsJson) {
|
||||
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().createGuarantor().withJson(apiRequestBodyAsJson).build();
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().createGuarantor(loanId).withJson(apiRequestBodyAsJson).build();
|
||||
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
@@ -109,8 +123,10 @@ public class GuarantorsApiResource {
|
||||
@Path("{guarantorId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String updateGuarantor(@PathParam("guarantorId") final Long guarantorId, final String jsonRequestBody) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateGuarantor(guarantorId).withJson(jsonRequestBody).build();
|
||||
public String updateGuarantor(@PathParam("loanId") final Long loanId, @PathParam("guarantorId") final Long guarantorId,
|
||||
final String jsonRequestBody) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateGuarantor(loanId, guarantorId).withJson(jsonRequestBody)
|
||||
.build();
|
||||
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
@@ -121,8 +137,8 @@ public class GuarantorsApiResource {
|
||||
@Path("{guarantorId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String deleteGuarantor(@PathParam("guarantorId") final Long guarantorId) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteGuarantor(guarantorId).build();
|
||||
public String deleteGuarantor(@PathParam("loanId") final Long loanId, @PathParam("guarantorId") final Long guarantorId) {
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteGuarantor(loanId, guarantorId).build();
|
||||
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
|
||||
+16
-1
@@ -6,9 +6,24 @@ import org.mifosplatform.portfolio.loanaccount.guarantor.data.GuarantorData;
|
||||
|
||||
public interface GuarantorReadPlatformService {
|
||||
|
||||
/**
|
||||
* Validates the passed in loanId before retrieving Loans for the same
|
||||
*
|
||||
* @param loanId
|
||||
* @return
|
||||
*/
|
||||
List<GuarantorData> retrieveGuarantorsForValidLoan(Long loanId);
|
||||
|
||||
/**
|
||||
* Methods Returns all Guarantors for a Given loan Id (if the loan Id is
|
||||
* valid and Exists)
|
||||
*
|
||||
* @param loanId
|
||||
* @return
|
||||
*/
|
||||
List<GuarantorData> retrieveGuarantorsForLoan(Long loanId);
|
||||
|
||||
GuarantorData retrieveGuarantor(Long guarantorId);
|
||||
GuarantorData retrieveGuarantor(Long loanId, Long guarantorId);
|
||||
|
||||
GuarantorData retrieveNewGuarantorDetails();
|
||||
|
||||
|
||||
+17
-4
@@ -13,6 +13,9 @@ import org.mifosplatform.organisation.staff.data.StaffData;
|
||||
import org.mifosplatform.organisation.staff.service.StaffReadPlatformService;
|
||||
import org.mifosplatform.portfolio.client.data.ClientData;
|
||||
import org.mifosplatform.portfolio.client.service.ClientReadPlatformService;
|
||||
import org.mifosplatform.portfolio.loanaccount.domain.Loan;
|
||||
import org.mifosplatform.portfolio.loanaccount.domain.LoanRepository;
|
||||
import org.mifosplatform.portfolio.loanaccount.exception.LoanNotFoundException;
|
||||
import org.mifosplatform.portfolio.loanaccount.guarantor.data.GuarantorData;
|
||||
import org.mifosplatform.portfolio.loanaccount.guarantor.domain.GuarantorType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -26,13 +29,16 @@ public class GuarantorReadPlatformServiceImpl implements GuarantorReadPlatformSe
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final ClientReadPlatformService clientReadPlatformService;
|
||||
private final StaffReadPlatformService staffReadPlatformService;
|
||||
private final LoanRepository loanRepository;
|
||||
|
||||
@Autowired
|
||||
public GuarantorReadPlatformServiceImpl(final TenantAwareRoutingDataSource dataSource,
|
||||
final ClientReadPlatformService clientReadPlatformService, final StaffReadPlatformService staffReadPlatformService) {
|
||||
final ClientReadPlatformService clientReadPlatformService, final StaffReadPlatformService staffReadPlatformService,
|
||||
final LoanRepository loanRepository) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.clientReadPlatformService = clientReadPlatformService;
|
||||
this.staffReadPlatformService = staffReadPlatformService;
|
||||
this.loanRepository = loanRepository;
|
||||
}
|
||||
|
||||
private static final class GuarantorMapper implements RowMapper<GuarantorData> {
|
||||
@@ -68,6 +74,13 @@ public class GuarantorReadPlatformServiceImpl implements GuarantorReadPlatformSe
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GuarantorData> retrieveGuarantorsForValidLoan(Long loanId) {
|
||||
Loan loan = this.loanRepository.findOne(loanId);
|
||||
if (loan == null) { throw new LoanNotFoundException(loanId); }
|
||||
return retrieveGuarantorsForLoan(loanId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GuarantorData> retrieveGuarantorsForLoan(Long loanId) {
|
||||
final GuarantorMapper rm = new GuarantorMapper();
|
||||
@@ -84,11 +97,11 @@ public class GuarantorReadPlatformServiceImpl implements GuarantorReadPlatformSe
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuarantorData retrieveGuarantor(Long guarantorId) {
|
||||
public GuarantorData retrieveGuarantor(Long loanId, Long guarantorId) {
|
||||
final GuarantorMapper rm = new GuarantorMapper();
|
||||
String sql = "select " + rm.schema();
|
||||
sql += " where loan_id = ?";
|
||||
GuarantorData guarantorData = this.jdbcTemplate.queryForObject(sql, rm, new Object[] { guarantorId });
|
||||
sql += " where g.loan_id = ? and g.id = ?";
|
||||
GuarantorData guarantorData = this.jdbcTemplate.queryForObject(sql, rm, new Object[] { loanId, guarantorId });
|
||||
|
||||
return mergeDetailsForClientOrStaffGuarantor(guarantorData);
|
||||
}
|
||||
|
||||
+3
-1
@@ -58,7 +58,7 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto
|
||||
final GuarantorCommand guarantorCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||
guarantorCommand.validateForCreate();
|
||||
|
||||
final Long loanId = command.longValueOfParameterNamed(GUARANTOR_JSON_INPUT_PARAMS.LOAN_ID.getValue());
|
||||
final Long loanId = command.getLoanId();
|
||||
Loan loan = retrieveLoanById(loanId);
|
||||
Guarantor guarantor = null;
|
||||
guarantor = Guarantor.fromJson(loan, command);
|
||||
@@ -83,6 +83,7 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto
|
||||
final GuarantorCommand guarantorCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||
guarantorCommand.validateForUpdate();
|
||||
|
||||
// TODO: Vishwas need to fetch by both loan and Guarantor Id
|
||||
final Guarantor guarantorForUpdate = this.guarantorRepository.findOne(guarantorId);
|
||||
if (guarantorForUpdate == null) { throw new GuarantorNotFoundException(guarantorId); }
|
||||
|
||||
@@ -108,6 +109,7 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto
|
||||
@Override
|
||||
@Transactional
|
||||
public CommandProcessingResult removeGuarantor(final Long guarantorId) {
|
||||
// TODO: Vishwas need to fetch by both loan and Guarantor Id
|
||||
final Guarantor guarantorForDelete = this.guarantorRepository.findOne(guarantorId);
|
||||
if (guarantorForDelete == null) { throw new GuarantorNotFoundException(guarantorId); }
|
||||
|
||||
|
||||
+10
-9
@@ -19,7 +19,6 @@ import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosplatform.accounting.AccountingConstants.LOAN_PRODUCT_ACCOUNTING_PARAMS;
|
||||
import org.mifosplatform.accounting.api.data.GLAccountData;
|
||||
import org.mifosplatform.accounting.domain.GLAccountType;
|
||||
import org.mifosplatform.accounting.service.GLAccountReadPlatformService;
|
||||
@@ -58,12 +57,7 @@ public class LoanProductsApiResource {
|
||||
"interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType", "charges", "createdOn",
|
||||
"lastModifedOn", "currencyOptions", "amortizationTypeOptions", "interestTypeOptions", "interestCalculationPeriodTypeOptions",
|
||||
"repaymentFrequencyTypeOptions", "interestRateFrequencyTypeOptions", "fundOptions", "transactionProcessingStrategyOptions",
|
||||
"chargeOptions", "assetAccountOptions", "incomeAccountOptions", "expenseAccountOptions", "accountingType",
|
||||
LOAN_PRODUCT_ACCOUNTING_PARAMS.FEES_RECEIVABLE.getValue(), LOAN_PRODUCT_ACCOUNTING_PARAMS.FUND_SOURCE.getValue(),
|
||||
LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_FEES.getValue(), LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_PENALTIES.getValue(),
|
||||
LOAN_PRODUCT_ACCOUNTING_PARAMS.INTEREST_ON_LOANS.getValue(), LOAN_PRODUCT_ACCOUNTING_PARAMS.INTEREST_RECEIVABLE.getValue(),
|
||||
LOAN_PRODUCT_ACCOUNTING_PARAMS.LOAN_PORTFOLIO.getValue(), LOAN_PRODUCT_ACCOUNTING_PARAMS.LOSSES_WRITTEN_OFF.getValue(),
|
||||
LOAN_PRODUCT_ACCOUNTING_PARAMS.PENALTIES_RECEIVABLE.getValue()));
|
||||
"chargeOptions", "accountingOptions", "accountingRule","accountingRuleOptions","accountingMappings","accountingMappingOptions"));
|
||||
|
||||
private final String resourceNameForPermissions = "LOANPRODUCT";
|
||||
|
||||
@@ -205,22 +199,29 @@ public class LoanProductsApiResource {
|
||||
final Collection<TransactionProcessingStrategyData> transactionProcessingStrategyOptions = this.dropdownReadPlatformService
|
||||
.retreiveTransactionProcessingStrategies();
|
||||
|
||||
Map<String, List<GLAccountData>> accountOptions= new HashMap<String, List<GLAccountData>>();
|
||||
List<GLAccountData> assetAccountOptions = accountReadPlatformService.retrieveAllEnabledDetailGLAccounts(GLAccountType.ASSET);
|
||||
if (assetAccountOptions.isEmpty()) {
|
||||
assetAccountOptions = null;
|
||||
}
|
||||
accountOptions.put("assetAccountOptions", assetAccountOptions);
|
||||
|
||||
List<GLAccountData> incomeAccountOptions = accountReadPlatformService.retrieveAllEnabledDetailGLAccounts(GLAccountType.INCOME);
|
||||
if (incomeAccountOptions.isEmpty()) {
|
||||
incomeAccountOptions = null;
|
||||
}
|
||||
accountOptions.put("incomeAccountOptions", incomeAccountOptions);
|
||||
|
||||
List<GLAccountData> expenseAccountOptions = accountReadPlatformService.retrieveAllEnabledDetailGLAccounts(GLAccountType.EXPENSE);
|
||||
if (expenseAccountOptions.isEmpty()) {
|
||||
expenseAccountOptions = null;
|
||||
}
|
||||
accountOptions.put("expenseAccountOptions", expenseAccountOptions);
|
||||
|
||||
List<EnumOptionData> accountingRuleTypeOptions = dropdownReadPlatformService.retrieveAccountingRuleTypeOptions();
|
||||
|
||||
return new LoanProductData(productData, chargeOptions, currencyOptions, amortizationTypeOptions, interestTypeOptions,
|
||||
interestCalculationPeriodTypeOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions,
|
||||
interestRateFrequencyTypeOptions, fundOptions, transactionProcessingStrategyOptions, assetAccountOptions,
|
||||
incomeAccountOptions, expenseAccountOptions, accountingMappings);
|
||||
interestRateFrequencyTypeOptions, fundOptions, transactionProcessingStrategyOptions, accountOptions, accountingRuleTypeOptions,accountingMappings);
|
||||
}
|
||||
}
|
||||
+15
-18
@@ -44,8 +44,8 @@ public class LoanProductData {
|
||||
private final EnumOptionData interestType;
|
||||
private final EnumOptionData interestCalculationPeriodType;
|
||||
private final BigDecimal inArrearsTolerance;
|
||||
|
||||
private final EnumOptionData accountingType;
|
||||
|
||||
private final EnumOptionData accountingRule;
|
||||
|
||||
private final Collection<ChargeData> charges;
|
||||
|
||||
@@ -62,9 +62,8 @@ public class LoanProductData {
|
||||
private final Collection<ChargeData> chargeOptions;
|
||||
|
||||
// accounting related template fields
|
||||
private final List<GLAccountData> assetAccountOptions;
|
||||
private final List<GLAccountData> incomeAccountOptions;
|
||||
private final List<GLAccountData> expenseAccountOptions;
|
||||
private final List<EnumOptionData> accountingRuleOptions;
|
||||
private final Map<String, List<GLAccountData>> accountingMappingOptions;
|
||||
|
||||
// accounting related mapping fields
|
||||
@SuppressWarnings("unused")
|
||||
@@ -140,7 +139,7 @@ public class LoanProductData {
|
||||
productData.amortizationTypeOptions, productData.interestTypeOptions, productData.interestCalculationPeriodTypeOptions,
|
||||
productData.loanTermFrequencyTypeOptions, productData.repaymentFrequencyTypeOptions,
|
||||
productData.interestRateFrequencyTypeOptions, productData.fundOptions, productData.transactionProcessingStrategyOptions,
|
||||
productData.assetAccountOptions, productData.incomeAccountOptions, productData.expenseAccountOptions, accountingMappings);
|
||||
productData.accountingMappingOptions, productData.accountingRuleOptions, accountingMappings);
|
||||
}
|
||||
|
||||
public LoanProductData(final Long id, final String name, final String description, final CurrencyData currency,
|
||||
@@ -173,7 +172,7 @@ public class LoanProductData {
|
||||
this.transactionProcessingStrategyId = transactionProcessingStrategyId;
|
||||
this.transactionProcessingStrategyName = transactionProcessingStrategyName;
|
||||
this.charges = charges;
|
||||
this.accountingType = accountingType;
|
||||
this.accountingRule = accountingType;
|
||||
|
||||
this.chargeOptions = null;
|
||||
this.currencyOptions = null;
|
||||
@@ -186,9 +185,8 @@ public class LoanProductData {
|
||||
this.repaymentFrequencyTypeOptions = null;
|
||||
this.interestRateFrequencyTypeOptions = null;
|
||||
|
||||
this.assetAccountOptions = null;
|
||||
this.incomeAccountOptions = null;
|
||||
this.expenseAccountOptions = null;
|
||||
this.accountingMappingOptions = null;
|
||||
this.accountingRuleOptions = null;
|
||||
this.accountingMappings = null;
|
||||
}
|
||||
|
||||
@@ -198,8 +196,8 @@ public class LoanProductData {
|
||||
final List<EnumOptionData> loanTermFrequencyTypeOptions, final List<EnumOptionData> repaymentFrequencyTypeOptions,
|
||||
final List<EnumOptionData> interestRateFrequencyTypeOptions, final Collection<FundData> fundOptions,
|
||||
final Collection<TransactionProcessingStrategyData> transactionProcessingStrategyOptions,
|
||||
final List<GLAccountData> assetAccountOptions, final List<GLAccountData> incomeAccountOptions,
|
||||
final List<GLAccountData> expenseAccountOptions, final Map<String, Object> accountingMappings) {
|
||||
final Map<String, List<GLAccountData>> accountingMappingOptions, final List<EnumOptionData> accountingRuleOptions,
|
||||
final Map<String, Object> accountingMappings) {
|
||||
this.id = productData.id;
|
||||
this.name = productData.name;
|
||||
this.description = productData.description;
|
||||
@@ -221,7 +219,7 @@ public class LoanProductData {
|
||||
this.transactionProcessingStrategyId = productData.transactionProcessingStrategyId;
|
||||
this.transactionProcessingStrategyName = productData.transactionProcessingStrategyName;
|
||||
this.charges = nullIfEmpty(productData.charges());
|
||||
this.accountingType = productData.accountingType;
|
||||
this.accountingRule = productData.accountingRule;
|
||||
|
||||
this.chargeOptions = chargeOptions;
|
||||
this.currencyOptions = currencyOptions;
|
||||
@@ -239,9 +237,8 @@ public class LoanProductData {
|
||||
this.repaymentFrequencyTypeOptions = repaymentFrequencyTypeOptions;
|
||||
this.interestRateFrequencyTypeOptions = interestRateFrequencyTypeOptions;
|
||||
|
||||
this.assetAccountOptions = assetAccountOptions;
|
||||
this.incomeAccountOptions = incomeAccountOptions;
|
||||
this.expenseAccountOptions = expenseAccountOptions;
|
||||
this.accountingMappingOptions = accountingMappingOptions;
|
||||
this.accountingRuleOptions = accountingRuleOptions;
|
||||
this.accountingMappings = accountingMappings;
|
||||
}
|
||||
|
||||
@@ -262,11 +259,11 @@ public class LoanProductData {
|
||||
}
|
||||
|
||||
public EnumOptionData accountingRuleType() {
|
||||
return this.accountingType;
|
||||
return this.accountingRule;
|
||||
}
|
||||
|
||||
public boolean hasAccountingEnabled() {
|
||||
return this.accountingType.getId() > 1;
|
||||
return this.accountingRule.getId() > 1;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
|
||||
+5
-5
@@ -33,7 +33,7 @@ public final class LoanProductCommandFromApiJsonDeserializer {
|
||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("name", "description", "fundId",
|
||||
"transactionProcessingStrategyId", "currencyCode", "digitsAfterDecimal", "principal", "inArrearsTolerance",
|
||||
"interestRatePerPeriod", "repaymentEvery", "numberOfRepayments", "repaymentFrequencyType", "interestRateFrequencyType",
|
||||
"amortizationType", "interestType", "interestCalculationPeriodType", "charges", "locale", "accountingType",
|
||||
"amortizationType", "interestType", "interestCalculationPeriodType", "charges", "locale", "accountingRule",
|
||||
LOAN_PRODUCT_ACCOUNTING_PARAMS.FEES_RECEIVABLE.getValue(), LOAN_PRODUCT_ACCOUNTING_PARAMS.FUND_SOURCE.getValue(),
|
||||
LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_FEES.getValue(), LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_PENALTIES.getValue(),
|
||||
LOAN_PRODUCT_ACCOUNTING_PARAMS.INTEREST_ON_LOANS.getValue(), LOAN_PRODUCT_ACCOUNTING_PARAMS.INTEREST_RECEIVABLE.getValue(),
|
||||
@@ -114,8 +114,8 @@ public final class LoanProductCommandFromApiJsonDeserializer {
|
||||
.inMinMaxRange(0, 1);
|
||||
|
||||
// accounting related data validation
|
||||
final Integer accountingRuleType = fromApiJsonHelper.extractIntegerNamed("accountingType", element, Locale.getDefault());
|
||||
baseDataValidator.reset().parameter("accountingType").value(accountingRuleType).notNull().inMinMaxRange(1, 3);
|
||||
final Integer accountingRuleType = fromApiJsonHelper.extractIntegerNamed("accountingRule", element, Locale.getDefault());
|
||||
baseDataValidator.reset().parameter("accountingRule").value(accountingRuleType).notNull().inMinMaxRange(1, 3);
|
||||
|
||||
if (isCashBasedAccounting(accountingRuleType) || isAccrualBasedAccounting(accountingRuleType)) {
|
||||
|
||||
@@ -266,8 +266,8 @@ public final class LoanProductCommandFromApiJsonDeserializer {
|
||||
.inMinMaxRange(0, 1);
|
||||
}
|
||||
|
||||
final Integer accountingRuleType = fromApiJsonHelper.extractIntegerNamed("accountingType", element, Locale.getDefault());
|
||||
baseDataValidator.reset().parameter("accountingType").value(accountingRuleType).ignoreIfNull().inMinMaxRange(1, 3);
|
||||
final Integer accountingRuleType = fromApiJsonHelper.extractIntegerNamed("accountingRule", element, Locale.getDefault());
|
||||
baseDataValidator.reset().parameter("accountingRule").value(accountingRuleType).ignoreIfNull().inMinMaxRange(1, 3);
|
||||
|
||||
final Long fundAccountId = fromApiJsonHelper.extractLongNamed(LOAN_PRODUCT_ACCOUNTING_PARAMS.FUND_SOURCE.getValue(), element);
|
||||
baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.FUND_SOURCE.getValue()).value(fundAccountId).ignoreIfNull()
|
||||
|
||||
+2
@@ -21,4 +21,6 @@ public interface LoanDropdownReadPlatformService {
|
||||
List<EnumOptionData> retrieveInterestRateFrequencyTypeOptions();
|
||||
|
||||
Collection<TransactionProcessingStrategyData> retreiveTransactionProcessingStrategies();
|
||||
|
||||
List<EnumOptionData> retrieveAccountingRuleTypeOptions();
|
||||
}
|
||||
+9
@@ -6,6 +6,7 @@ import static org.mifosplatform.portfolio.loanproduct.service.LoanEnumerations.i
|
||||
import static org.mifosplatform.portfolio.loanproduct.service.LoanEnumerations.interestType;
|
||||
import static org.mifosplatform.portfolio.loanproduct.service.LoanEnumerations.loanTermFrequencyType;
|
||||
import static org.mifosplatform.portfolio.loanproduct.service.LoanEnumerations.repaymentFrequencyType;
|
||||
import static org.mifosplatform.portfolio.loanproduct.service.LoanEnumerations.accountingRuleType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -15,6 +16,7 @@ import java.util.List;
|
||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||
import org.mifosplatform.portfolio.loanaccount.domain.LoanTransactionProcessingStrategyRepository;
|
||||
import org.mifosplatform.portfolio.loanproduct.data.TransactionProcessingStrategyData;
|
||||
import org.mifosplatform.portfolio.loanproduct.domain.AccountingRuleType;
|
||||
import org.mifosplatform.portfolio.loanproduct.domain.AmortizationMethod;
|
||||
import org.mifosplatform.portfolio.loanproduct.domain.InterestCalculationPeriodMethod;
|
||||
import org.mifosplatform.portfolio.loanproduct.domain.InterestMethod;
|
||||
@@ -103,4 +105,11 @@ public class LoanDropdownReadPlatformServiceImpl implements LoanDropdownReadPlat
|
||||
|
||||
return strategyOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EnumOptionData> retrieveAccountingRuleTypeOptions() {
|
||||
List<EnumOptionData> accountingRuleTypeOptions = Arrays.asList(accountingRuleType(AccountingRuleType.NONE),
|
||||
accountingRuleType(AccountingRuleType.CASH_BASED),accountingRuleType(AccountingRuleType.ACCRUAL_BASED));
|
||||
return accountingRuleTypeOptions;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user