use of org.apache.struts.action.ActionForward in project head by mifos.
the class LoanAccountActionTest method captureQuestionResponses.
@Test
public void captureQuestionResponses() throws Exception {
String redoLoan = "redoLoan";
when(form.getPerspective()).thenReturn(redoLoan);
ActionErrors errors = mock(ActionErrors.class);
ActionForward forward = mock(ActionForward.class);
when(createLoanQuestionnaire.validateResponses(request, form)).thenReturn(errors);
when(errors.isEmpty()).thenReturn(true);
when(createLoanQuestionnaire.rejoinFlow(mapping)).thenReturn(forward);
loanAccountAction.captureQuestionResponses(mapping, form, request, response);
verify(request, times(1)).setAttribute(eq(LoanConstants.METHODCALLED), eq("captureQuestionResponses"));
verify(request, times(1)).setAttribute(PERSPECTIVE, redoLoan);
verify(createLoanQuestionnaire).rejoinFlow(mapping);
}
use of org.apache.struts.action.ActionForward in project head by mifos.
the class LoanAccountActionTest method getLoanRepaymentScheduleShouldValidateViewDate.
@Test
public void getLoanRepaymentScheduleShouldValidateViewDate() throws Exception {
ActionForward getLoanScheduleFailure = new ActionForward("getLoanRepaymentScheduleFailure");
java.sql.Date extraInterestDate = TestUtils.getSqlDate(10, 7, 2010);
Errors errors = new Errors();
errors.addError(LoanConstants.CANNOT_VIEW_REPAYMENT_SCHEDULE, new String[] { extraInterestDate.toString() });
when(loanBusinessService.computeExtraInterest(loanBO, extraInterestDate)).thenReturn(errors);
when(form.getScheduleViewDateValue(Locale.US)).thenReturn(extraInterestDate);
when(request.getParameter("accountId")).thenReturn("1");
when(mapping.findForward("getLoanRepaymentScheduleFailure")).thenReturn(getLoanScheduleFailure);
when(loanServiceFacade.retrieveOriginalLoanSchedule(Matchers.<Integer>any())).thenReturn(new OriginalScheduleInfoDto("100", new Date(), Collections.<RepaymentScheduleInstallment>emptyList()));
ActionForward forward = loanAccountAction.getLoanRepaymentSchedule(mapping, form, request, response);
assertThat(forward, is(getLoanScheduleFailure));
verify(form).resetScheduleViewDate();
}
use of org.apache.struts.action.ActionForward in project head by mifos.
the class AccountApplyGroupPaymentAction method applyPayment.
@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward applyPayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
AccountApplyPaymentActionForm actionForm = (AccountApplyPaymentActionForm) form;
String paymentType = request.getParameter(Constants.INPUT);
Integer accountId;
if (actionForm.getAccountId().isEmpty() || actionForm.getAccountId() == null) {
accountId = loanDao.findByGlobalAccountNum(actionForm.getGlobalAccountNum()).getAccountId();
} else {
accountId = Integer.valueOf(actionForm.getAccountId());
}
UserReferenceDto userReferenceDto = new UserReferenceDto(userContext.getId());
AccountPaymentDto accountPaymentDto = accountServiceFacade.getAccountPaymentInformation(accountId, paymentType, userContext.getLocaleId(), userReferenceDto, actionForm.getTrxnDate());
validateAccountPayment(accountPaymentDto, accountId, request);
validateAmount(accountPaymentDto, actionForm.getAmount());
PaymentTypeDto paymentTypeDto;
String amount = actionForm.getAmount();
if (accountPaymentDto.getAccountType().equals(AccountTypeDto.LOAN_ACCOUNT) || accountPaymentDto.getAccountType().equals(AccountTypeDto.GROUP_LOAN_ACCOUNT)) {
paymentTypeDto = getLoanPaymentTypeDtoForId(Short.valueOf(actionForm.getPaymentTypeId()));
} else {
paymentTypeDto = getFeePaymentTypeDtoForId(Short.valueOf(actionForm.getPaymentTypeId()));
}
AccountPaymentParametersDto accountPaymentParametersDto;
if (isGroupParentAccount(accountId)) {
accountPaymentParametersDto = new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(accountId), new BigDecimal(amount), actionForm.getTrxnDateAsLocalDate(), paymentTypeDto, AccountConstants.NO_COMMENT, actionForm.getReceiptDateAsLocalDate(), actionForm.getReceiptId(), accountPaymentDto.getCustomerDto(), actionForm.getIndividualValues());
} else if (isGroupMemberAccount(accountId)) {
accountPaymentParametersDto = preparePaymentParametersDto(accountId, userReferenceDto, amount, actionForm, paymentTypeDto, userContext, paymentType);
} else {
accountPaymentParametersDto = new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(accountId), new BigDecimal(amount), actionForm.getTrxnDateAsLocalDate(), paymentTypeDto, AccountConstants.NO_COMMENT, actionForm.getReceiptDateAsLocalDate(), actionForm.getReceiptId(), accountPaymentDto.getCustomerDto());
}
if (paymentTypeDto.getValue().equals(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId())) {
this.accountServiceFacade.makePaymentFromSavingsAcc(accountPaymentParametersDto, actionForm.getAccountForTransfer());
} else {
this.accountServiceFacade.makePayment(accountPaymentParametersDto);
}
request.getSession().setAttribute("globalAccountNum", ((AccountApplyPaymentActionForm) form).getGlobalAccountNum());
ActionForward findForward;
if (actionForm.getPrintReceipt()) {
findForward = mapping.findForward(getForward("PRINT"));
} else {
findForward = mapping.findForward(getForward(((AccountApplyPaymentActionForm) form).getInput()));
}
return findForward;
}
use of org.apache.struts.action.ActionForward in project head by mifos.
the class MifosRequestProcessor method processActionPerform.
/**
* This method is overridden because in case of exception we need to
* populate the request with the old values so that when the user goes back
* to the previous page it has all the values in the request.For this we
* create an object which will store the values of previous request in case
* the request is successful and if there is an exception it reads values
* from that object and context and dups all in the request.
*/
@Override
protected ActionForward processActionPerform(HttpServletRequest request, HttpServletResponse response, Action action, ActionForm form, ActionMapping mapping) throws IOException, ServletException {
ActivityContext activityContext = null;
ActionForward forward = null;
HttpSession session = request.getSession();
// gets the object where we will store values from request.
PreviousRequestValues previousRequestValues = (PreviousRequestValues) session.getAttribute(Constants.PREVIOUS_REQUEST);
if (null == previousRequestValues) {
previousRequestValues = new PreviousRequestValues();
session.setAttribute(Constants.PREVIOUS_REQUEST, previousRequestValues);
}
// getting the activity context from the session
activityContext = (ActivityContext) session.getAttribute("ActivityContext");
try {
String currentFlowKey = request.getParameter(Constants.CURRENTFLOWKEY);
if (currentFlowKey != null) {
previousRequestValues.getPreviousRequestValueMap().put(Constants.CURRENTFLOWKEY, currentFlowKey);
}
forward = (action.execute(mapping, form, request, response));
String method = request.getParameter("method");
if (method.equals(ClientConstants.METHOD_RETRIEVE_PICTURE)) {
forward = mapping.findForward("get_success");
}
// set the last forward in the activity context
if (activityContext != null) {
activityContext.setLastForward(forward);
}
// read the request and add the values to the PreviousRequestValues
// object. this will set every thing in the request apart from
// context and value object.
Enumeration requestAttributes = request.getAttributeNames();
while (requestAttributes.hasMoreElements()) {
String nextName = (String) requestAttributes.nextElement();
if (nextName.startsWith(Constants.STORE_ATTRIBUTE) || nextName.equalsIgnoreCase(Constants.CURRENTFLOWKEY)) {
logger.debug(nextName + "=" + request.getAttribute(nextName));
previousRequestValues.getPreviousRequestValueMap().put(nextName, request.getAttribute(nextName));
}
}
} catch (Exception e) {
// processException logs an error (see MifosExceptionHandler)
forward = (processException(request, response, e, form, mapping));
// set the last forward in the activity context
if (activityContext != null) {
activityContext.setLastForward(forward);
}
populateTheRequestFromPreviousValues(request, previousRequestValues);
} finally {
try {
session.removeAttribute(SecurityConstants.SECURITY_PARAM);
} catch (Exception e) {
// FIXME: yikes, what is being swallowed here?
}
}
if (null != forward) {
logger.info("forward.path=" + forward.getPath());
}
return forward;
}
use of org.apache.struts.action.ActionForward in project head by mifos.
the class LoanAccountAction method getDetails.
public ActionForward getDetails(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
String globalAccountNum = request.getParameter(GLOBAL_ACCOUNT_NUM);
ActionForward forward = null;
if (loanDao.findByGlobalAccountNum(globalAccountNum).isParentGroupLoanAccount()) {
forward = mapping.findForward("getGroupLoanAccountDetails");
} else {
forward = mapping.findForward("get");
}
return forward;
}
Aggregations