removal of unused resources and tidy up.

This commit is contained in:
Keith Woodlock
2012-05-30 17:22:02 +01:00
parent bdb549253c
commit bb838509fc
10 changed files with 5 additions and 908 deletions
@@ -1,21 +0,0 @@
package org.mifosng.platform;
import org.mifosng.platform.api.commands.ImportClientCommand;
import org.mifosng.platform.api.commands.ImportLoanCommand;
import org.mifosng.platform.api.commands.ImportLoanRepaymentsCommand;
public interface ImportPlatformService {
void importClients(ImportClientCommand command);
ImportClientCommand populateClientImportFromCsv();
void importLoans(ImportLoanCommand command);
ImportLoanCommand populateLoanImportFromCsv();
void importLoanRepayments(ImportLoanRepaymentsCommand command);
ImportLoanRepaymentsCommand populateLoanRepaymentsImportFromCsv();
}
@@ -1,585 +0,0 @@
package org.mifosng.platform;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import org.mifosng.data.LoanSchedule;
import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand;
import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.api.commands.ImportClientCommand;
import org.mifosng.platform.api.commands.ImportLoanCommand;
import org.mifosng.platform.api.commands.ImportLoanRepaymentsCommand;
import org.mifosng.platform.api.commands.LoanStateTransitionCommand;
import org.mifosng.platform.api.commands.LoanTransactionCommand;
import org.mifosng.platform.api.commands.SubmitApproveDisburseLoanCommand;
import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
import org.mifosng.platform.client.domain.Client;
import org.mifosng.platform.client.domain.ClientRepository;
import org.mifosng.platform.currency.domain.Money;
import org.mifosng.platform.exceptions.UnAuthenticatedUserException;
import org.mifosng.platform.loan.domain.DefaultLoanLifecycleStateMachine;
import org.mifosng.platform.loan.domain.InterestCalculationPeriodMethod;
import org.mifosng.platform.loan.domain.Loan;
import org.mifosng.platform.loan.domain.LoanLifecycleStateMachine;
import org.mifosng.platform.loan.domain.LoanProduct;
import org.mifosng.platform.loan.domain.LoanProductRepository;
import org.mifosng.platform.loan.domain.LoanRepository;
import org.mifosng.platform.loan.domain.LoanStatus;
import org.mifosng.platform.loan.domain.LoanStatusRepository;
import org.mifosng.platform.loan.domain.LoanTransaction;
import org.mifosng.platform.loan.domain.PeriodFrequencyType;
import org.mifosng.platform.loan.service.CalculationPlatformService;
import org.mifosng.platform.loan.service.LoanAssembler;
import org.mifosng.platform.organisation.domain.Office;
import org.mifosng.platform.organisation.domain.OfficeRepository;
import org.mifosng.platform.organisation.domain.Organisation;
import org.mifosng.platform.user.domain.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.csvreader.CsvReader;
@Service
public class ImportPlatformServiceImpl implements ImportPlatformService {
private final OfficeRepository officeRepository;
private final ClientRepository clientRepository;
private final LoanProductRepository loanProductRepository;
private final CalculationPlatformService calculationPlatformService;
private final LoanRepository loanRepository;
private final LoanStatusRepository loanStatusRepository;
private final LoanAssembler loanAssembler;
@Autowired
public ImportPlatformServiceImpl(final LoanAssembler loanAssembler,
final OfficeRepository officeRepository, final ClientRepository clientRepository, final LoanProductRepository loanProductRepository,
final CalculationPlatformService calculationPlatformService, final LoanRepository loanRepository, final LoanStatusRepository loanStatusRepository) {
this.loanAssembler = loanAssembler;
this.officeRepository = officeRepository;
this.clientRepository = clientRepository;
this.loanProductRepository = loanProductRepository;
this.calculationPlatformService = calculationPlatformService;
this.loanRepository = loanRepository;
this.loanStatusRepository = loanStatusRepository;
}
private AppUser extractAuthenticatedUser() {
AppUser currentUser = null;
SecurityContext context = SecurityContextHolder.getContext();
if (context != null) {
Authentication auth = context.getAuthentication();
if (auth != null) {
currentUser = (AppUser) auth.getPrincipal();
}
}
if (currentUser == null) {
throw new UnAuthenticatedUserException();
}
return currentUser;
}
@Transactional
@Override
public void importClients(ImportClientCommand command) {
AppUser currentUser = extractAuthenticatedUser();
List<Office> allOffices = this.officeRepository.findAll(officesBelongingTo(currentUser.getOrganisation()));
List<Client> newClientCollection = new ArrayList<Client>();
for (ClientCommand client : command.getClients()) {
Office clientOffice = findById(allOffices, client.getOfficeId());
Client newClient = Client.newClient(currentUser.getOrganisation(), clientOffice, client.getFirstname(), client.getLastname(), client.getJoiningLocalDate(), client.getExternalId());
newClientCollection.add(newClient);
}
this.clientRepository.save(newClientCollection);
}
@Transactional
@Override
public void importLoans(ImportLoanCommand importCommand) {
AppUser currentUser = extractAuthenticatedUser();
List<Loan> newLoanCollection = new ArrayList<Loan>();
for (SubmitApproveDisburseLoanCommand combinedCommand : importCommand.getLoans()) {
SubmitLoanApplicationCommand command = combinedCommand.getSubmitLoanApplicationCommand();
Loan loan = loanAssembler.assembleFrom(command, currentUser.getOrganisation());
LoanLifecycleStateMachine loanLifecycleStateMachine = defaultLoanLifecycleStateMachine();
LoanStateTransitionCommand approveLoanCommand = combinedCommand.getApproveLoanCommand();
if (approveLoanCommand != null) {
loan.approve(approveLoanCommand.getEventLocalDate(), loanLifecycleStateMachine);
}
LoanStateTransitionCommand disburseLoanCommand = combinedCommand.getDisburseLoanCommand();
if (disburseLoanCommand != null) {
loan.disburse(disburseLoanCommand.getEventLocalDate(), loanLifecycleStateMachine);
}
newLoanCollection.add(loan);
}
this.loanRepository.save(newLoanCollection);
}
private LoanLifecycleStateMachine defaultLoanLifecycleStateMachine() {
List<LoanStatus> allowedLoanStatuses = this.loanStatusRepository.findAll();
return new DefaultLoanLifecycleStateMachine(allowedLoanStatuses);
}
@Transactional
@Override
public void importLoanRepayments(ImportLoanRepaymentsCommand command) {
AppUser currentUser = extractAuthenticatedUser();
LoanLifecycleStateMachine loanLifecycleStateMachine = defaultLoanLifecycleStateMachine();
List<Loan> newLoanCollection = new ArrayList<Loan>();
List<Loan> allLoans = this.loanRepository.findAll(loansBelongingTo(currentUser.getOrganisation()));
for (LoanTransactionCommand repaymentDetail : command.getRepayments()) {
Loan loan = findLoanByIdentifier(allLoans, repaymentDetail.getLoanId().toString());
Money repaymentAmount = Money.of(loan.getCurrency(), repaymentDetail.getTransactionAmountValue());
LoanTransaction loanRepayment = LoanTransaction.repayment(repaymentAmount, repaymentDetail.getTransactionLocalDate());
loan.makeRepayment(loanRepayment, loanLifecycleStateMachine);
}
this.loanRepository.save(newLoanCollection);
}
public static Specification<Office> officesBelongingTo(final Organisation organisation) {
return new Specification<Office>() {
@Override
public Predicate toPredicate(final Root<Office> root,
final CriteriaQuery<?> query, final CriteriaBuilder cb) {
return cb.equal(root.get("organisation"), organisation);
}
};
}
public static Specification<LoanProduct> productsBelongingTo(final Organisation organisation) {
return new Specification<LoanProduct>() {
@Override
public Predicate toPredicate(final Root<LoanProduct> root,
final CriteriaQuery<?> query, final CriteriaBuilder cb) {
return cb.equal(root.get("organisation"), organisation);
}
};
}
public static Specification<Loan> loansBelongingTo(final Organisation organisation) {
return new Specification<Loan>() {
@Override
public Predicate toPredicate(final Root<Loan> root,
final CriteriaQuery<?> query, final CriteriaBuilder cb) {
return cb.equal(root.get("organisation"), organisation);
}
};
}
public static Specification<Client> clientsBelongingTo(final Organisation organisation) {
return new Specification<Client>() {
@Override
public Predicate toPredicate(final Root<Client> root,
final CriteriaQuery<?> query, final CriteriaBuilder cb) {
return cb.equal(root.get("organisation"), organisation);
}
};
}
@Override
public ImportLoanRepaymentsCommand populateLoanRepaymentsImportFromCsv() {
ImportLoanRepaymentsCommand command = new ImportLoanRepaymentsCommand();
AppUser currentUser = extractAuthenticatedUser();
List<Loan> allLoans = this.loanRepository.findAll(loansBelongingTo(currentUser.getOrganisation()));
ClassPathResource repaymentsCsvFile = new ClassPathResource("creocore-loan-repayments.csv");
File file = null;
FileInputStream fileInputStream = null;
CsvReader loans = null;
try {
DateTimeFormatter isoParser = ISODateTimeFormat.date();
loans = new CsvReader(repaymentsCsvFile.getInputStream(),
Charset.defaultCharset());
loans.readHeaders();
List<LoanTransactionCommand> repaymentDetails = new ArrayList<LoanTransactionCommand>();
while (loans.readRecord()) {
String loanExternalId = loans.get("LoanExternalId");
Loan matchingLoan = findLoanByIdentifier(allLoans, loanExternalId.trim());
String paymentDate = loans.get("PaymentDate");
LocalDate paidOnDate = null;
if (StringUtils.isNotBlank(paymentDate)) {
paidOnDate = new LocalDate(isoParser.parseDateTime(paymentDate));
}
String paymentAmount = loans.get("PaymentAmount");
BigDecimal repayment = BigDecimal.ZERO;
if (StringUtils.isNotBlank(paymentAmount)) {
repayment = BigDecimal.valueOf(Double.valueOf(paymentAmount));
}
String noNoteComment = "No note due to migration from mifos.";
LoanTransactionCommand repaymentCommand = new LoanTransactionCommand(matchingLoan.getId(), paidOnDate, noNoteComment, repayment);
repaymentDetails.add(repaymentCommand);
}
command.setRepayments(repaymentDetails);
return command;
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (file != null) {
file = null;
}
if (fileInputStream != null) {
fileInputStream = null;
}
if (loans != null) {
loans = null;
}
}
}
@Override
public ImportLoanCommand populateLoanImportFromCsv() {
ImportLoanCommand command = new ImportLoanCommand();
AppUser currentUser = extractAuthenticatedUser();
List<LoanProduct> allProducts = this.loanProductRepository.findAll(productsBelongingTo(currentUser.getOrganisation()));
List<Client> allClients = this.clientRepository.findAll(clientsBelongingTo(currentUser.getOrganisation()));
ClassPathResource loanCsvFile = new ClassPathResource("creocore-loans.csv");
File file = null;
FileInputStream fileInputStream = null;
CsvReader loans = null;
try {
DateTimeFormatter isoParser = ISODateTimeFormat.date();
loans = new CsvReader(loanCsvFile.getInputStream(),
Charset.defaultCharset());
loans.readHeaders();
List<SubmitApproveDisburseLoanCommand> parsedLoanDetails = new ArrayList<SubmitApproveDisburseLoanCommand>();
while (loans.readRecord()) {
String clientIdentifier = loans.get("ClientExternalId");
Client matchingClient = findClientByIdentifier(allClients, clientIdentifier.trim());
String loanExternalId = loans.get("LoanExternalId");
String productIdentifier = loans.get("ProductExternalId");
LoanProduct matchingProduct = findProductByIdentifier(allProducts, productIdentifier);
String loanPrincipal = loans.get("LoanPrincipal");
Number principal = BigDecimal.ZERO;
if (StringUtils.isNotBlank(loanPrincipal)) {
principal = Double.valueOf(loanPrincipal);
}
String interestRateAsString = loans.get("InterestRate");
Number interestRatePerYear = BigDecimal.ZERO;
if (StringUtils.isNotBlank(interestRateAsString)) {
interestRatePerYear = Double.valueOf(interestRateAsString);
}
String submitted = loans.get("SubmittedOn");
LocalDate submittedOnDate = null;
if (StringUtils.isNotBlank(submitted)) {
submittedOnDate = new LocalDate(isoParser.parseDateTime(submitted));
}
String noNoteComment = "No note due to migration from mifos.";
String installmentsAsString = loans.get("Installments");
Integer numberOfRepayments = Integer.valueOf(0);
if (StringUtils.isNotBlank(installmentsAsString)) {
numberOfRepayments = Integer.valueOf(installmentsAsString);
}
String approved = loans.get("ApprovedOn");
LocalDate approvedDate = null;
if (StringUtils.isNotBlank(approved)) {
approvedDate = new LocalDate(isoParser.parseDateTime(approved));
}
String disbursed = loans.get("DateDisbursalTransaction");
LocalDate disbursedDate = null;
LocalDate expectedDisbursementDate = null;
if (StringUtils.isNotBlank(disbursed)) {
disbursedDate = new LocalDate(isoParser.parseDateTime(disbursed));
expectedDisbursementDate = disbursedDate;
} else {
expectedDisbursementDate = approvedDate;
}
String repaymentsStartOn = loans.get("FirstInstallmentDate");
LocalDate repaymentsStartingFromDate = null;
LocalDate interestCalculatedFromDate = null;
if (StringUtils.isNotBlank(repaymentsStartOn)) {
repaymentsStartingFromDate = new LocalDate(isoParser.parseDateTime(repaymentsStartOn));
interestCalculatedFromDate = expectedDisbursementDate;
}
String currencyCode = matchingProduct.getCurrency().getCode();
int digitsAfterDecimal = matchingProduct.getCurrency().getDigitsAfterDecimal();
Integer repaymentEvery = matchingProduct.getRepayEvery();
Integer repaymentFrequency = matchingProduct.getRepaymentPeriodFrequencyType().getValue();
Integer amortizationMethod = matchingProduct.getAmortizationMethod().getValue();
final Money toleranceAmount = matchingProduct.getInArrearsTolerance();
Number interestRatePerPeriod = interestRatePerYear;
Integer interestRatePeriodFrequency = PeriodFrequencyType.YEARS.getValue();
Integer interestMethod = matchingProduct.getInterestMethod().getValue();
Integer interestCalculationPeriodMethod = InterestCalculationPeriodMethod.SAME_AS_REPAYMENT_PERIOD.getValue();
CalculateLoanScheduleCommand calculateLoanScheduleCommand = new CalculateLoanScheduleCommand(currencyCode, digitsAfterDecimal, principal,
interestRatePerPeriod,
interestRatePeriodFrequency,
interestMethod, interestCalculationPeriodMethod,
repaymentEvery,
repaymentFrequency, numberOfRepayments, amortizationMethod, expectedDisbursementDate, repaymentsStartingFromDate, interestCalculatedFromDate);
LoanSchedule loanSchedule = this.calculationPlatformService.calculateLoanSchedule(calculateLoanScheduleCommand);
SubmitLoanApplicationCommand parsedNewLoanDetails = new SubmitLoanApplicationCommand(matchingClient.getId(), matchingProduct.getId(), submittedOnDate, noNoteComment,
expectedDisbursementDate, repaymentsStartingFromDate, interestCalculatedFromDate, loanSchedule,
currencyCode, digitsAfterDecimal, principal,
interestRatePerPeriod, interestRatePeriodFrequency, interestMethod, interestCalculationPeriodMethod,
repaymentEvery, repaymentFrequency, numberOfRepayments, amortizationMethod, toleranceAmount.getAmount());
parsedNewLoanDetails.setExternalId(loanExternalId);
LoanStateTransitionCommand approvedLoanCommand = null;
if (approvedDate != null) {
approvedLoanCommand = new LoanStateTransitionCommand(null, approvedDate, noNoteComment);
}
LoanStateTransitionCommand disburseLoanCommand = null;
if (disbursedDate != null) {
disburseLoanCommand = new LoanStateTransitionCommand(null, disbursedDate, noNoteComment);
}
SubmitApproveDisburseLoanCommand submitApproveDisburseLoanCommand = new SubmitApproveDisburseLoanCommand();
submitApproveDisburseLoanCommand.setSubmitLoanApplicationCommand(parsedNewLoanDetails);
submitApproveDisburseLoanCommand.setApproveLoanCommand(approvedLoanCommand);
submitApproveDisburseLoanCommand.setDisburseLoanCommand(disburseLoanCommand);
parsedLoanDetails.add(submitApproveDisburseLoanCommand);
}
command.setLoans(parsedLoanDetails);
return command;
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
// throw new BulkuploadFileNotFoundException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
// throw new BulkuploadInvalidDataException(e);
} catch (IOException e) {
throw new RuntimeException(e);
// throw new BulkuploadParseException(e);
} finally {
if (file != null) {
file = null;
}
if (fileInputStream != null) {
fileInputStream = null;
}
if (loans != null) {
loans = null;
}
}
}
@Override
public ImportClientCommand populateClientImportFromCsv() {
ImportClientCommand command = new ImportClientCommand();
AppUser currentUser = extractAuthenticatedUser();
List<Office> allOffices = this.officeRepository.findAll(officesBelongingTo(currentUser.getOrganisation()));
ClassPathResource clientCsv = new ClassPathResource("creocore-clients.csv");
File file = null;
FileInputStream fileInputStream = null;
CsvReader clients = null;
try {
DateTimeFormatter isoParser = ISODateTimeFormat.date();
clients = new CsvReader(clientCsv.getInputStream(),
Charset.defaultCharset());
clients.readHeaders();
// int clientCsvHeaderCount = clients.getHeaderCount();
// if (clientCsvHeaderCount != 5) {
// success = false;
// }
List<ClientCommand> parsedClients = new ArrayList<ClientCommand>();
while (clients.readRecord()) {
String externalId = clients.get("ExternalId");
String firstname = clients.get("FirstName");
String lastname = clients.get("LastName");
String joined = clients.get("Joined");
String officeIdentifier = clients.get("Office");
Office matchingOffice = findOfficeByIdentifier(allOffices, officeIdentifier.trim());
LocalDate joiningDate = new LocalDate(isoParser.parseDateTime(joined));
ClientCommand parsedClient = new ClientCommand(firstname, lastname, "", matchingOffice.getId(), joiningDate);
parsedClient.setExternalId(externalId);
parsedClients.add(parsedClient);
}
command.setClients(parsedClients);
return command;
} catch (FileNotFoundException e) {
// throw new BulkuploadFileNotFoundException(e);
} catch (IllegalArgumentException e) {
// throw new BulkuploadInvalidDataException(e);
} catch (IOException e) {
// throw new BulkuploadParseException(e);
} finally {
if (file != null) {
file = null;
}
if (fileInputStream != null) {
fileInputStream = null;
}
if (clients != null) {
clients = null;
}
}
return command;
}
private Office findById(List<Office> allOffices, Long id) {
Office match = null;
for (Office office : allOffices) {
if (id.equals(office.getId())) {
match = office;
break;
}
}
return match;
}
private Loan findLoanByIdentifier(List<Loan> allEntities, String identifier) {
Loan match = null;
for (Loan entity : allEntities) {
if (entity.identifiedBy(identifier)) {
match = entity;
break;
}
}
return match;
}
private Office findOfficeByIdentifier(List<Office> allOffices, String officeIdentifier) {
Office match = null;
for (Office office : allOffices) {
if (office.identifiedBy(officeIdentifier)) {
match = office;
break;
}
}
return match;
}
private Client findClientByIdentifier(List<Client> allClients, String identifier) {
Client match = null;
for (Client client : allClients) {
if (client.identifiedBy(identifier)) {
match = client;
break;
}
}
return match;
}
private LoanProduct findProductByIdentifier(List<LoanProduct> allProducts, String identifier) {
LoanProduct match = null;
for (LoanProduct client : allProducts) {
if (client.identifiedBy(identifier)) {
match = client;
break;
}
}
return match;
}
}
@@ -1,25 +0,0 @@
package org.mifosng.platform.api.commands;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class ImportClientCommand {
private List<ClientCommand> clients = new ArrayList<ClientCommand>();
public ImportClientCommand() {
//
}
public List<ClientCommand> getClients() {
return clients;
}
public void setClients(List<ClientCommand> clients) {
this.clients = clients;
}
}
@@ -1,25 +0,0 @@
package org.mifosng.platform.api.commands;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class ImportLoanCommand {
private List<SubmitApproveDisburseLoanCommand> loans = new ArrayList<SubmitApproveDisburseLoanCommand>();
public ImportLoanCommand() {
//
}
public List<SubmitApproveDisburseLoanCommand> getLoans() {
return loans;
}
public void setLoans(List<SubmitApproveDisburseLoanCommand> loans) {
this.loans = loans;
}
}
@@ -1,24 +0,0 @@
package org.mifosng.platform.api.commands;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class ImportLoanRepaymentsCommand {
private List<LoanTransactionCommand> repayments = new ArrayList<LoanTransactionCommand>();
public ImportLoanRepaymentsCommand() {
//
}
public List<LoanTransactionCommand> getRepayments() {
return repayments;
}
public void setRepayments(List<LoanTransactionCommand> repayments) {
this.repayments = repayments;
}
}
@@ -1,58 +0,0 @@
package org.mifosng.platform.rest;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.mifosng.platform.ImportPlatformService;
import org.mifosng.platform.api.commands.ImportClientCommand;
import org.mifosng.platform.api.commands.ImportLoanCommand;
import org.mifosng.platform.api.commands.ImportLoanRepaymentsCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Path("/protected/import")
@Component
@Scope("singleton")
public class ImportResource {
@Autowired
private ImportPlatformService importPlatformService;
@POST
@Path("clients")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response importClients(final ImportClientCommand command) {
this.importPlatformService.importClients(command);
return Response.ok().build();
}
@POST
@Path("loans")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response importLoans(final ImportLoanCommand command) {
this.importPlatformService.importLoans(command);
return Response.ok().build();
}
@POST
@Path("loanrepayments")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response importLoanRepayments(
final ImportLoanRepaymentsCommand command) {
this.importPlatformService.importLoanRepayments(command);
return Response.ok().build();
}
}
@@ -1,60 +0,0 @@
package org.mifosng.platform.rest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.mifosng.platform.ImportPlatformService;
import org.mifosng.platform.api.commands.ImportClientCommand;
import org.mifosng.platform.api.commands.ImportLoanCommand;
import org.mifosng.platform.api.commands.ImportLoanRepaymentsCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Path("/protected/import/trigger")
@Component
@Scope("singleton")
public class ImportTriggerResource {
@Autowired
private ImportPlatformService importPlatformService;
@Autowired
private ImportResource importResource;
// TODO - REMOVE THIS HARDCODED IMPORT OF CREOCORE CSV FILE
@GET
@Path("clients/creocore")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response triggerCreoCoreClientImport() {
ImportClientCommand command = this.importPlatformService.populateClientImportFromCsv();
return importResource.importClients(command);
}
// TODO - REMOVE THIS HARDCODED IMPORT OF CREOCORE CSV FILE
@GET
@Path("loans/creocore")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response triggerCreoCoreLoanImport() {
ImportLoanCommand command = this.importPlatformService.populateLoanImportFromCsv();
return importResource.importLoans(command);
}
@GET
@Path("repayments/creocore")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response triggerCreoCoreLoanRepaymentsImport() {
ImportLoanRepaymentsCommand command = this.importPlatformService.populateLoanRepaymentsImportFromCsv();
return importResource.importLoanRepayments(command);
}
}
@@ -1,109 +0,0 @@
package org.mifosng.platform.rest;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import org.mifosng.data.MoneyData;
import org.mifosng.platform.loan.service.CalculationPlatformService;
import org.mifosng.platform.loan.service.LoanPayoffReadModel;
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;
/**
* Payoff functionality was something CreoCore was looking for e.g. if paid in full on date x what should be paid? full minus any rebate or incentive provided.
*
* NOTE: JSONP functionality not needed now due to use of CORS
*/
@Deprecated
@Path("/open/loan/{loanId}")
@Component
@Scope("singleton")
public class LoanOpenResource {
@Autowired
private CalculationPlatformService calculationPlatformService;
@GET
@Path("calculatepayoff/{payoffDate}")
@Consumes({ "application/x-javascript" })
@Produces({ "application/x-javascript" })
public Response calculatePayoff(
@QueryParam("callback") @DefaultValue("callback") final String callbackName,
@PathParam("loanId") final String loanId,
@PathParam("payoffDate") final String payoffDate) {
try {
DateTimeFormatter formatter = ISODateTimeFormat.dateParser();
DateTime payoffDateTime = formatter.parseDateTime(payoffDate);
LoanPayoffReadModel loanPayoffInformation = this.calculationPlatformService
.calculatePayoffOn(Long.valueOf(loanId),
payoffDateTime.toLocalDate());
JSONObject payoffInfo = new JSONObject();
payoffInfo.put("reference", loanPayoffInformation.getReference());
payoffInfo.put("acutalDisbursementDate",
loanPayoffInformation.getAcutalDisbursementDate());
payoffInfo.put("expectedMaturityDate",
loanPayoffInformation.getExpectedMaturityDate());
payoffInfo.put("projectedMaturityDate",
loanPayoffInformation.getProjectedMaturityDate());
payoffInfo.put("expectedLoanTermInDays",
loanPayoffInformation.getExpectedLoanTermInDays());
payoffInfo.put("projectedLoanTermInDays",
loanPayoffInformation.getProjectedLoanTermInDays());
JSONObject totalPaidToDate = jsonifyMoneyReadModel(loanPayoffInformation
.getTotalPaidToDate());
payoffInfo.put("totalPaidToDate", totalPaidToDate);
JSONObject totalOutstandingBasedOnExpectedMaturityDate = jsonifyMoneyReadModel(loanPayoffInformation
.getTotalOutstandingBasedOnExpectedMaturityDate());
payoffInfo.put("totalOutstandingBasedOnExpectedMaturityDate",
totalOutstandingBasedOnExpectedMaturityDate);
JSONObject totalOutstandingBasedOnPayoffDate = jsonifyMoneyReadModel(loanPayoffInformation
.getTotalOutstandingBasedOnPayoffDate());
payoffInfo.put("totalOutstandingBasedOnPayoffDate",
totalOutstandingBasedOnPayoffDate);
JSONObject interestRebateOwed = jsonifyMoneyReadModel(loanPayoffInformation
.getInterestRebateOwed());
payoffInfo.put("interestRebateOwed", interestRebateOwed);
JSONWithPadding payoff = new JSONWithPadding(payoffInfo,
callbackName);
return Response.ok(payoff).build();
} catch (JSONException e) {
return Response.status(Status.BAD_REQUEST).build();
}
}
private JSONObject jsonifyMoneyReadModel(final MoneyData money)
throws JSONException {
JSONObject object = new JSONObject();
object.put("amount", money.getAmount());
object.put("currencyCode", money.getCurrencyCode());
object.put("currencyDigitsAfterDecimal", money.getDigitsAfterDecimal());
return object;
}
}
@@ -5,8 +5,12 @@ import org.mifosng.platform.user.domain.PlatformUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
/**
* Used in securityContext.xml as implementation of spring security's {@link UserDetailsService}.
*/
public class PlatformUserDetailsServiceImpl implements PlatformUserDetailsService {
@Autowired
@@ -8,7 +8,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
/**
* Responsible for returning the current authenticated user that is currently set in the {@link SecurityContext}.
* Wrapper around spring security's {@link SecurityContext} for extracted the current authenticated {@link AppUser}.
*/
@Service
public class SpringSecurityPlatformSecurityContext implements PlatformSecurityContext {