use of org.mifos.security.MifosUser in project head by mifos.
the class ClientCustActionStrutsTest method testCreateSuccessWithAssociatedSavingsOfferings.
@Test
public void testCreateSuccessWithAssociatedSavingsOfferings() throws Exception {
SecurityContext securityContext = new SecurityContextImpl();
MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
Authentication authentication = new TestingAuthenticationToken(principal, principal);
securityContext.setAuthentication(authentication);
SecurityContextHolder.setContext(securityContext);
savingsOffering1 = TestObjectFactory.createSavingsProduct("savingsPrd1", "s1", SavingsType.MANDATORY, ApplicableTo.CLIENTS, new Date(System.currentTimeMillis()));
List<FeeDto> feesToRemove = getFees(RecurrenceType.WEEKLY);
setRequestPathInfo("/clientCustAction.do");
addRequestParameter("method", "load");
addRequestParameter("officeId", "3");
addRequestParameter("groupFlag", "0");
addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
actionPerform();
flowKey = (String) request.getAttribute(Constants.CURRENTFLOWKEY);
List<BusinessActivityEntity> povertyStatus = (List<BusinessActivityEntity>) SessionUtils.getAttribute(ClientConstants.POVERTY_STATUS, request);
List<CustomFieldDto> customFieldDefs = getCustomFieldFromSession();
setRequestPathInfo("/clientCustAction.do");
addRequestParameter("method", "next");
addRequestParameter("officeId", "3");
addRequestParameter("clientName.salutation", "1");
addRequestParameter("clientName.firstName", "Client");
addRequestParameter("clientName.lastName", "LastName");
addRequestParameter("spouseName.firstName", "Spouse");
addRequestParameter("spouseName.lastName", "LastName");
addRequestParameter("spouseName.nameType", "1");
addRequestDateParameter("dateOfBirth", "20/3/1987");
addRequestParameter("clientDetailView.gender", "1");
addRequestParameter("input", "personalInfo");
addRequestParameter("customerDetail.povertyStatus", povertyStatus.get(0).getId().toString());
int i = 0;
for (CustomFieldDto customFieldDef : customFieldDefs) {
addRequestParameter("customField[" + i + "].fieldId", customFieldDef.getFieldId().toString());
addRequestParameter("customField[" + i + "].fieldValue", "Req");
i++;
}
addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
actionPerform();
List<SavingsDetailDto> savingsOfferingList = getSavingsOfferingsFromSession();
SavingsDetailDto savingsOffering = savingsOfferingList.get(0);
setRequestPathInfo("/clientCustAction.do");
addRequestParameter("method", "preview");
addRequestParameter("input", "mfiInfo");
addRequestParameter("loanOfficerId", "1");
addRequestParameter("formedByPersonnel", "1");
addRequestParameter("savingsOffering[0]", savingsOffering.getPrdOfferingId().toString());
addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
actionPerform();
verifyNoActionErrors();
verifyNoActionMessages();
verifyForward(ActionForwards.preview_success.toString());
MeetingBO weeklyMeeting = new MeetingBuilder().weekly().every(1).occuringOnA(WeekDay.WEDNESDAY).build();
SessionUtils.setAttribute(CustomerConstants.CUSTOMER_MEETING, weeklyMeeting, request);
setRequestPathInfo("/clientCustAction.do");
addRequestParameter("method", "create");
addRequestParameter("input", "create");
addRequestParameter("status", "1");
addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
actionPerform();
verifyNoActionErrors();
verifyNoActionMessages();
verifyForward(ActionForwards.create_success.toString());
ClientCustActionForm actionForm = (ClientCustActionForm) request.getSession().getAttribute("clientCustActionForm");
client = TestObjectFactory.getClient(actionForm.getCustomerIdAsInt());
Assert.assertNotNull(client);
Assert.assertNotNull(client.getOfferingsAssociatedInCreate());
Assert.assertEquals(1, client.getOfferingsAssociatedInCreate().size());
for (ClientInitialSavingsOfferingEntity offering : client.getOfferingsAssociatedInCreate()) {
Assert.assertEquals(savingsOffering1.getPrdOfferingId(), offering.getSavingsOffering().getPrdOfferingId());
Assert.assertTrue(true);
}
removeFees(feesToRemove);
savingsOffering1 = (SavingsOfferingBO) TestObjectFactory.getObject(SavingsOfferingBO.class, savingsOffering.getPrdOfferingId());
}
use of org.mifos.security.MifosUser in project head by mifos.
the class CustomerNotesActionStrutsTest method setMifosUserFromContext.
private void setMifosUserFromContext() {
SecurityContext securityContext = new SecurityContextImpl();
MifosUser principal = new MifosUser(userContext.getId(), userContext.getBranchId(), userContext.getLevelId(), new ArrayList<Short>(userContext.getRoles()), userContext.getName(), "".getBytes(), true, true, true, true, new ArrayList<GrantedAuthority>(), userContext.getLocaleId());
Authentication authentication = new TestingAuthenticationToken(principal, principal);
securityContext.setAuthentication(authentication);
SecurityContextHolder.setContext(securityContext);
}
use of org.mifos.security.MifosUser in project head by mifos.
the class CustomerUIHelperFnStrutsTest method setUp.
@Before
public void setUp() throws Exception {
userContext = TestObjectFactory.getContext();
request.getSession().setAttribute(Constants.USER_CONTEXT_KEY, userContext);
addRequestParameter("recordLoanOfficerId", "1");
addRequestParameter("recordOfficeId", "1");
request.getSession(false).setAttribute("ActivityContext", TestObjectFactory.getActivityContext());
flowKey = createFlow(request, EditCustomerStatusAction.class);
addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
SecurityContext securityContext = new SecurityContextImpl();
MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
Authentication authentication = new TestingAuthenticationToken(principal, principal);
securityContext.setAuthentication(authentication);
SecurityContextHolder.setContext(securityContext);
}
use of org.mifos.security.MifosUser in project head by mifos.
the class LoanAccountRESTController method fullRepay.
@RequestMapping(value = "/account/loan/num-{globalAccountNum}/fullrepay", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> fullRepay(@PathVariable String globalAccountNum, @RequestParam(required = false) String paymentDate, @RequestParam(required = false) Short receiptId, @RequestParam(required = false) String receiptDate, @RequestParam(required = false) Short paymentModeId, @RequestParam Boolean waiveInterest) throws Exception {
LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNum);
validateLoanAccountState(loan);
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
RepayLoanDto repayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(globalAccountNum);
DateTime today = new DateTime();
Date paymentDateTime = new Date(today.toDate().getTime());
if (paymentDate != null && !paymentDate.isEmpty()) {
paymentDateTime = new Date(validateDateString(paymentDate, format).toDate().getTime());
}
String receiptIdString = null;
if (receiptId != null) {
receiptIdString = receiptId.toString();
}
Date receiptDateTime = null;
if (receiptDate != null && !receiptDate.isEmpty()) {
receiptDateTime = new Date(validateDateString(receiptDate, format).toDate().getTime());
}
String paymentTypeId = null;
if (paymentModeId != null) {
paymentTypeId = paymentModeId.toString();
}
validateDisbursementPaymentTypeId(paymentModeId, accountService.getLoanPaymentTypes());
BigDecimal totalRepaymentAmount = (new Money(loan.getCurrency(), repayLoanDto.getEarlyRepaymentMoney())).getAmount();
BigDecimal waivedAmount = (new Money(loan.getCurrency(), repayLoanDto.getWaivedRepaymentMoney())).getAmount();
BigDecimal earlyRepayAmount = totalRepaymentAmount;
if (Boolean.TRUE.equals(waiveInterest)) {
earlyRepayAmount = waivedAmount;
}
RepayLoanInfoDto repayLoanInfoDto = new RepayLoanInfoDto(globalAccountNum, Double.toString(earlyRepayAmount.doubleValue()), receiptIdString, receiptDateTime, paymentTypeId, (short) user.getUserId(), waiveInterest.booleanValue(), paymentDateTime, totalRepaymentAmount, waivedAmount);
Money outstandingBeforePayment = loan.getLoanSummary().getOutstandingBalance();
this.loanAccountServiceFacade.makeEarlyRepaymentWithCommit(repayLoanInfoDto);
CustomerBO client = loan.getCustomer();
Map<String, String> map = new HashMap<String, String>();
map.put("status", "success");
map.put("clientName", client.getDisplayName());
map.put("clientNumber", client.getGlobalCustNum());
map.put("loanDisplayName", loan.getLoanOffering().getPrdOfferingName());
map.put("paymentDate", today.toLocalDate().toString());
map.put("paymentTime", today.toLocalTime().toString());
map.put("paymentAmount", loan.getLastPmnt().getAmount().toString());
map.put("paymentMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
map.put("outstandingBeforePayment", outstandingBeforePayment.toString());
map.put("outstandingAfterPayment", loan.getLoanSummary().getOutstandingBalance().toString());
return map;
}
use of org.mifos.security.MifosUser in project head by mifos.
the class LoanAccountRESTController method disburseLoan.
@RequestMapping(value = "/account/loan/num-{globalAccountNum}/disburse", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> disburseLoan(@PathVariable String globalAccountNum, @RequestParam String disbursalDate, @RequestParam(required = false) Short receiptId, @RequestParam(required = false) String receiptDate, @RequestParam Short disbursePaymentTypeId, @RequestParam(required = false) Short paymentModeOfPayment) throws Exception {
String format = "dd-MM-yyyy";
DateTime trnxDate = validateDateString(disbursalDate, format);
validateDisbursementDate(trnxDate);
DateTime receiptDateTime = null;
if (receiptDate != null && !receiptDate.isEmpty()) {
receiptDateTime = validateDateString(receiptDate, format);
validateDisbursementDate(receiptDateTime);
}
validateDisbursementPaymentTypeId(disbursePaymentTypeId, accountService.getLoanDisbursementTypes());
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);
String comment = "";
Short paymentTypeId = Short.valueOf(disbursePaymentTypeId);
Money outstandingBeforeDisbursement = loan.getLoanSummary().getOutstandingBalance();
CustomerDto customerDto = null;
PaymentTypeDto paymentType = null;
AccountPaymentParametersDto loanDisbursement;
if (receiptId == null || receiptDateTime == null) {
loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto((short) user.getUserId()), new AccountReferenceDto(loan.getAccountId()), loan.getLoanAmount().getAmount(), trnxDate.toLocalDate(), paymentType, comment);
} else {
loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto((short) user.getUserId()), new AccountReferenceDto(loan.getAccountId()), loan.getLoanAmount().getAmount(), trnxDate.toLocalDate(), paymentType, comment, receiptDateTime.toLocalDate(), receiptId.toString(), customerDto);
}
// TODO : Pass the account for transfer id properly
this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, PaymentTypes.CASH.getValue(), null);
CustomerBO client = loan.getCustomer();
Map<String, String> map = new HashMap<String, String>();
map.put("status", "success");
map.put("clientName", client.getDisplayName());
map.put("clientNumber", client.getGlobalCustNum());
map.put("loanDisplayName", loan.getLoanOffering().getPrdOfferingName());
map.put("disbursementDate", trnxDate.toLocalDate().toString());
map.put("disbursementTime", new DateTime().toLocalTime().toString());
map.put("disbursementAmount", loan.getLastPmnt().getAmount().toString());
map.put("disbursementMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
map.put("outstandingBeforeDisbursement", outstandingBeforeDisbursement.toString());
map.put("outstandingAfterDisbursement", loan.getLoanSummary().getOutstandingBalance().toString());
return map;
}
Aggregations