use of org.mifos.framework.util.helpers.FlowManager in project head by mifos.
the class FlowKeyInterceptor method joinToken.
private void joinToken(HttpServletRequest request) throws PageExpiredException {
String flowKey = request.getParameter(Constants.CURRENTFLOWKEY);
if (null == flowKey) {
flowKey = (String) request.getAttribute(Constants.CURRENTFLOWKEY);
}
FlowManager flowManager = (FlowManager) request.getSession().getAttribute(Constants.FLOWMANAGER);
if (flowKey == null || !flowManager.isFlowValid(flowKey)) {
throw new PageExpiredException("no flow for key " + flowKey);
}
}
use of org.mifos.framework.util.helpers.FlowManager in project head by mifos.
the class LoanAccountActionFormTest method testValidateAdditionalFeesWithMultipleInstancesOfTheSameOneTimeFee.
public void testValidateAdditionalFeesWithMultipleInstancesOfTheSameOneTimeFee() throws Exception {
List<FeeDto> additionalFeeList = createDefaultFees();
List<FeeDto> additionalFeeList2 = createDefaultFees();
additionalFeeList2.add(additionalFeeList.get(0));
FlowManager flowMgrMock = createMock(FlowManager.class);
HttpSession sessionMock = createMock(HttpSession.class);
HttpServletRequest requestMock = createMock(HttpServletRequest.class);
expect(requestMock.getSession()).andReturn(sessionMock);
expect(requestMock.getAttribute(Constants.CURRENTFLOWKEY)).andReturn("currentFlowKey");
expect(sessionMock.getAttribute(Constants.FLOWMANAGER)).andReturn(flowMgrMock);
expect(flowMgrMock.getFromFlow("currentFlowKey", LoanConstants.ADDITIONAL_FEES_LIST)).andReturn(additionalFeeList);
ActionErrors errors = new ActionErrors();
form.validateAdditionalFee(errors, Locale.ENGLISH, TestUtils.RUPEE, requestMock);
Assert.assertEquals("There should be a 'Multiple instances of the same one-time fee are not allowed' error", 1, errors.size());
ActionMessage actionMessage = (ActionMessage) errors.get().next();
Assert.assertEquals("There should be a 'Multiple instances of the same one-time fee are not allowed' error", ProductDefinitionConstants.MULTIPLE_ONE_TIME_FEES_NOT_ALLOWED, actionMessage.getKey());
}
use of org.mifos.framework.util.helpers.FlowManager in project head by mifos.
the class LoanActivityTag method doStartTag.
@Override
public int doStartTag() throws JspException {
XmlBuilder xmlBuilder = new XmlBuilder();
try {
String currentFlowKey = (String) pageContext.getRequest().getAttribute(Constants.CURRENTFLOWKEY);
HttpSession session = pageContext.getSession();
FlowManager flowManager = (FlowManager) session.getAttribute(Constants.FLOWMANAGER);
Object object = flowManager.getFromFlow(currentFlowKey, LoanConstants.LOAN_ALL_ACTIVITY_VIEW);
if (object == null) {
// for spring/ftl
object = pageContext.getRequest().getAttribute(LoanConstants.LOAN_ALL_ACTIVITY_VIEW);
}
if (null != object) {
UserContext userContext = (UserContext) pageContext.getSession().getAttribute(Constants.USER_CONTEXT_KEY);
locale = userContext.getPreferredLocale();
xmlBuilder.startTag("table", "width", "100%", "border", "0", "cellspacing", "0", "cellpadding", "0", "id", "accountActivityTable");
xmlBuilder.startTag("tr");
xmlBuilder.startTag("td", "colspan", "8");
//xmlBuilder.nonBreakingSpace();
xmlBuilder.endTag("td");
xmlBuilder.startTag("td", "colspan", "4", "class", "drawtablerowboldnoline");
xmlBuilder.text(getLabel("loan.running_bal", locale));
xmlBuilder.endTag("td");
xmlBuilder.endTag("tr");
xmlBuilder.startTag("tr", "class", "drawtablerowbold");
xmlBuilder.startTag("td", "width", "9%", "class", "drawtablerowbold");
xmlBuilder.text(getLabel("loan.date", locale));
xmlBuilder.endTag("td");
xmlBuilder.startTag("td", "width", "19%", "class", "drawtablerowbold");
xmlBuilder.text(getLabel("loan.activity", locale));
xmlBuilder.endTag("td");
xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
xmlBuilder.text(getLabel("loan.principal", locale));
xmlBuilder.endTag("td");
xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
xmlBuilder.text(ApplicationContextProvider.getBean(MessageLookup.class).lookupLabel(ConfigurationConstants.INTEREST));
xmlBuilder.endTag("td");
xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
xmlBuilder.text(getLabel("loan.fees", locale));
xmlBuilder.endTag("td");
xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
xmlBuilder.text(getLabel("loan.penalty", locale));
xmlBuilder.endTag("td");
xmlBuilder.startTag("td", "width", "6%", "align", "right", "class", "drawtablerowbold");
xmlBuilder.text(getLabel("loan.total", locale));
xmlBuilder.endTag("td");
xmlBuilder.startTag("td", "width", "4", "align", "right", "class", "fontnormalbold");
//xmlBuilder.nonBreakingSpace();
xmlBuilder.endTag("td");
xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
xmlBuilder.text(getLabel("loan.principal", locale));
xmlBuilder.endTag("td");
xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
xmlBuilder.text(ApplicationContextProvider.getBean(MessageLookup.class).lookupLabel(ConfigurationConstants.INTEREST));
xmlBuilder.endTag("td");
xmlBuilder.startTag("td", "width", "8%", "align", "right", "class", "drawtablerowbold");
xmlBuilder.text(getLabel("loan.fees", locale));
xmlBuilder.endTag("td");
xmlBuilder.startTag("td", "width", "6%", "align", "right", "class", "drawtablerowbold");
xmlBuilder.text(getLabel("loan.total", locale));
xmlBuilder.endTag("td");
xmlBuilder.endTag("tr");
List<LoanActivityDto> loanRecentActivityViewSet = (List<LoanActivityDto>) object;
Iterator<LoanActivityDto> it = loanRecentActivityViewSet.iterator();
while (it.hasNext()) {
LoanActivityDto loanActivityDto = it.next();
xmlBuilder.startTag("tr", "valign", "top");
xmlBuilder.append(buildLeftHeaderRows(loanActivityDto));
xmlBuilder.append(buildRightHeaderRows(loanActivityDto));
xmlBuilder.endTag("tr");
}
xmlBuilder.endTag("table");
}
pageContext.getOut().write(xmlBuilder.toString());
} catch (Exception e) {
throw new JspException(e);
}
return SKIP_BODY;
}
use of org.mifos.framework.util.helpers.FlowManager in project head by mifos.
the class LoanRepaymentTag method doStartTag.
@Override
public int doStartTag() throws JspException {
boolean twoTables = false;
XmlBuilder html = new XmlBuilder();
LoanBO loanBO = null;
try {
String currentFlowKey = (String) pageContext.getRequest().getAttribute(Constants.CURRENTFLOWKEY);
HttpSession session = pageContext.getSession();
FlowManager flowManager = (FlowManager) session.getAttribute(Constants.FLOWMANAGER);
loanBO = (LoanBO) flowManager.getFromFlow(currentFlowKey, Constants.BUSINESS_KEY);
if (StringUtils.isNotBlank(memberGlobalNum)) {
loanBO = loanBO.findMemberByGlobalNum(memberGlobalNum);
}
Date viewDate = getViewDate(currentFlowKey, flowManager);
Money totalPrincipal = new Money(loanBO.getCurrency(), "0");
Money totalInterest = new Money(loanBO.getCurrency(), "0");
Money totalFees = new Money(loanBO.getCurrency(), "0");
Money totalPenalties = new Money(loanBO.getCurrency(), "0");
/*
* LoanBO loanBO = (LoanBO) pageContext.getRequest().getAttribute( Constants.BUSINESS_KEY);
*/
List<AccountActionDateEntity> list = new ArrayList<AccountActionDateEntity>();
if (isNewGropLoan) {
List<LoanBO> memberAccounts = getMemberScheduleDetails(loanBO.getAccountId());
list.addAll(generateGroupSchedule(memberAccounts, loanBO));
} else {
list.addAll(loanBO.getAccountActionDates());
}
UserContext userContext = (UserContext) pageContext.getSession().getAttribute(Constants.USER_CONTEXT_KEY);
locale = userContext.getPreferredLocale();
if (list.size() != 0) {
// topmost table
html.startTag("table", "width", "100%", "border", "0", "cellspacing", "0", "cellpadding", "0");
// Left side header
XmlBuilder htmlHeader1 = new XmlBuilder();
htmlHeader1.startTag("tr");
htmlHeader1.startTag("td", "width", "6%", "class", "drawtablerowbold");
htmlHeader1.text(getLabel("loan.no", locale));
htmlHeader1.endTag("td");
htmlHeader1.startTag("td", "width", "15%", "class", "drawtablerowbold");
htmlHeader1.text(getLabel("loan.due_date", locale));
htmlHeader1.endTag("td");
htmlHeader1.startTag("td", "width", "15%", "class", "drawtablerowbold");
htmlHeader1.text(getLabel("loan.date_paid", locale));
htmlHeader1.endTag("td");
htmlHeader1.startTag("td", "width", "12%", "align", "right", "class", "drawtablerowbold");
htmlHeader1.text(getLabel("loan.principal", locale));
htmlHeader1.endTag("td");
htmlHeader1.startTag("td", "width", "10%", "align", "right", "class", "drawtablerowbold");
htmlHeader1.text(ApplicationContextProvider.getBean(MessageLookup.class).lookupLabel(ConfigurationConstants.INTEREST));
htmlHeader1.endTag("td");
htmlHeader1.startTag("td", "width", "10%", "align", "right", "class", "drawtablerowbold");
htmlHeader1.text(getLabel("loan.fees", locale));
htmlHeader1.endTag("td");
htmlHeader1.startTag("td", "width", "11%", "align", "right", "class", "drawtablerowbold");
htmlHeader1.text(getLabel("loan.penalty", locale));
htmlHeader1.endTag("td");
htmlHeader1.startTag("td", "width", "11%", "align", "right", "class", "drawtablerowbold");
htmlHeader1.text(getLabel("loan.daysLate", locale));
htmlHeader1.endTag("td");
htmlHeader1.startTag("td", "width", "10%", "align", "right", "class", "drawtablerowbold");
htmlHeader1.text(getLabel("loan.total", locale));
htmlHeader1.endTag("td");
htmlHeader1.endTag("tr");
for (AccountActionDateEntity acctDate : list) {
LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) acctDate;
totalPrincipal = totalPrincipal.add(loanScheduleEntity.getPrincipal());
totalInterest = totalInterest.add(loanScheduleEntity.getEffectiveInterest());
totalFees = totalFees.add(loanScheduleEntity.getTotalScheduledFeeAmountWithMiscFee());
totalPenalties = totalPenalties.add(loanScheduleEntity.getTotalPenalty());
}
// check if at least the first installment is paid
LoanScheduleEntity firstInstallment = (LoanScheduleEntity) list.get(0);
XmlBuilder html1 = new XmlBuilder();
XmlBuilder html2 = new XmlBuilder();
XmlBuilder htmlHeader2 = new XmlBuilder();
if (!firstInstallment.getTotalDueWithFees().equals(firstInstallment.getTotalScheduleAmountWithFees())) {
twoTables = true;
// installments paid and running balance table is
// required
htmlHeader2.startTag("tr");
htmlHeader2.startTag("td", "width", "20%", "align", "right", "class", "drawtablerowbold");
htmlHeader2.text(getLabel("loan.principal", locale));
htmlHeader2.endTag("td");
htmlHeader2.startTag("td", "width", "20%", "align", "right", "class", "drawtablerowbold");
htmlHeader2.text(ApplicationContextProvider.getBean(MessageLookup.class).lookupLabel(ConfigurationConstants.INTEREST));
htmlHeader2.endTag("td");
htmlHeader2.startTag("td", "width", "20%", "align", "right", "class", "drawtablerowbold");
htmlHeader2.text(getLabel("loan.fees", locale));
htmlHeader2.endTag("td");
htmlHeader2.startTag("td", "width", "20%", "align", "right", "class", "drawtablerowbold");
htmlHeader2.text(getLabel("loan.penalty", locale));
htmlHeader2.endTag("td");
htmlHeader2.startTag("td", "width", "20%", "align", "right", "class", "drawtablerowbold");
htmlHeader2.text(getLabel("loan.total", locale));
htmlHeader2.endTag("td");
htmlHeader2.endTag("tr");
}
html1.startTag("tr");
html1.startTag("td", "colspan", "9", "class", "drawtablerowbold");
html1.nonBreakingSpace();
html1.endTag("td");
html1.endTag("tr");
html2.startTag("tr");
html2.startTag("td", "colspan", "5", "class", "drawtablerowbold");
html2.text(getLabel("loan.running_bal", locale));
html2.endTag("td");
html2.endTag("tr");
html1.append(htmlHeader1);
html2.append(htmlHeader2);
if (twoTables) {
html1.startTag("tr");
html1.startTag("td", "colspan", "9", "class", "drawtablerowbold");
html1.text(getLabel("loan.instt_paid", locale));
html1.endTag("td");
html1.endTag("tr");
html2.startTag("tr");
html2.startTag("td", "colspan", "5", "class", "drawtablerowbold");
html2.nonBreakingSpace();
html2.endTag("td");
html2.endTag("tr");
}
int index = 0;
boolean toContinue = true;
LoanScheduleEntity installment = (LoanScheduleEntity) list.get(index);
while (index <= list.size() - 1 && toContinue && !installment.getTotalDueWithFees().equals(installment.getTotalScheduleAmountWithFees())) {
html1.append(createInstallmentRow(installment, true, isNewGropLoan));
html2.append(createRunningBalanceRow(installment, totalPrincipal, totalInterest, totalFees, totalPenalties));
totalPrincipal = totalPrincipal.subtract(installment.getPrincipalPaid());
totalInterest = totalInterest.subtract(installment.getEffectiveInterestPaid());
totalFees = totalFees.subtract(installment.getTotalFeeAmountPaidWithMiscFee());
totalPenalties = totalPenalties.subtract(installment.getPenaltyPaid());
if (index != list.size() - 1 && installment.isPaid()) {
index++;
installment = (LoanScheduleEntity) list.get(index);
} else {
toContinue = false;
}
}
boolean dueInstallments = false;
if (!installment.isPaid() && installment.getActionDate().getTime() <= viewDate.getTime()) {
dueInstallments = true;
}
if (dueInstallments) {
html1.startTag("tr");
html1.startTag("td", "colspan", "9", "class", "drawtablerowbold");
html1.text(getLabel("loan.instt_due", locale));
html1.endTag("td");
html1.endTag("tr");
while (index < list.size() - 1 && !installment.isPaid() && installment.getActionDate().getTime() <= viewDate.getTime()) {
index++;
html1.append(createInstallmentRow(installment, false, isNewGropLoan));
installment = (LoanScheduleEntity) list.get(index);
}
}
boolean futureInstallments = false;
if (!installment.isPaid() && installment.getActionDate().getTime() > viewDate.getTime()) {
futureInstallments = true;
}
if (futureInstallments) {
html1.startTag("tr");
html1.startTag("td", "colspan", "9", "class", "drawtablerowbold");
html1.text(getLabel("loan.future_install", locale));
html1.endTag("td");
html1.endTag("tr");
while (index < list.size() - 1) {
index++;
html1.append(createInstallmentRow(installment, false, isNewGropLoan));
installment = (LoanScheduleEntity) list.get(index);
}
}
// append the last transaction
if (!installment.isPaid()) {
html1.append(createInstallmentRow(installment, false, isNewGropLoan));
}
long totalDaysLate = 0;
for (AccountActionDateEntity accountActionDateEntity : list) {
totalDaysLate += accountActionDateEntity.getDaysLate();
}
XmlBuilder totalDaysLateXmlBuilder = new XmlBuilder();
totalDaysLateXmlBuilder.startTag("tr");
totalDaysLateXmlBuilder.startTag("td", "class", "drawtablerow", "colspan", "8", "align", "right");
totalDaysLateXmlBuilder.text(getLabel("loan.total", locale) + ": " + totalDaysLate);
totalDaysLateXmlBuilder.endTag("td");
totalDaysLateXmlBuilder.startTag("td", "class", "drawtablerow");
totalDaysLateXmlBuilder.nonBreakingSpace();
totalDaysLateXmlBuilder.endTag("td");
totalDaysLateXmlBuilder.endTag("tr");
html1.append(totalDaysLateXmlBuilder);
if (twoTables) {
// add a tr with 2 td for each of the 2 tables
html.startTag("tr");
html.startTag("td", "width", "70%");
html.startTag("table", "width", "95%", "border", "0", "cellspacing", "0", "cellpadding", "5", "id", "repaymentScheduleTable");
html.append(html1);
html.endTag("table");
html.endTag("td");
html.startTag("td", "width", "25%", "valign", "top");
html.startTag("table", "width", "95%", "border", "0", "cellspacing", "0", "cellpadding", "5", "id", "runningBalanceTable");
html.append(html2);
html.endTag("table");
html.endTag("td");
html.endTag("tr");
html.endTag("table");
} else {
html.startTag("tr");
html.startTag("td", "width", "100%");
html.startTag("table", "id", "installments", "width", "95%", "border", "0", "cellspacing", "0", "cellpadding", "5");
html.append(html1);
html.endTag("table");
html.endTag("td");
html.endTag("tr");
html.endTag("table");
}
}
pageContext.getOut().write(html.toString());
} catch (Exception e) {
throw new JspException(e);
}
return SKIP_BODY;
}
use of org.mifos.framework.util.helpers.FlowManager in project head by mifos.
the class MifosLegacyUsernamePasswordAuthenticationFilter method handleLegacySuccessfulAuthentication.
private void handleLegacySuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, final String username, final String password) {
try {
FlowManager flowManager = new FlowManager();
String flowKey = String.valueOf(new DateTimeService().getCurrentDateTime().getMillis());
flowManager.addFLow(flowKey, new Flow(), this.getFilterName());
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
request.getSession(false).setAttribute(Constants.FLOWMANAGER, flowManager);
request.getSession(false).setAttribute(Constants.RANDOMNUM, new Random().nextLong());
boolean flag = AccountingRules.getSimpleAccountingStatus();
request.getSession(false).setAttribute("accountingActivationStatus", flag);
LoginDto loginActivity = loginServiceFacade.login(username, password);
PersonnelBO user = ApplicationContextProvider.getBean(LegacyPersonnelDao.class).findPersonnelById(loginActivity.getUserId());
SitePreferenceHelper sitePreferenceHelper = new SitePreferenceHelper();
sitePreferenceHelper.setSitePreferenceCookie(SitePreferenceType.getSitePreference(user.getSitePreference()), response);
ActivityContext activityContext = new ActivityContext(Short.valueOf("0"), user.getOffice().getOfficeId(), user.getPersonnelId());
request.getSession(false).setAttribute(Constants.ACTIVITYCONTEXT, activityContext);
request.setAttribute("activityDto", loginActivity);
Short localeId = user.getPreferredLocale();
Locale preferredLocale = Localization.getInstance().getLocaleById(localeId);
UserContext userContext = new UserContext();
userContext.setPreferredLocale(preferredLocale);
userContext.setLocaleId(localeId);
userContext.setId(user.getPersonnelId());
userContext.setName(user.getDisplayName());
userContext.setLevel(user.getLevelEnum());
userContext.setRoles(user.getRoles());
userContext.setLastLogin(user.getLastLogin());
userContext.setPasswordChanged(user.getPasswordChanged());
userContext.setBranchId(user.getOffice().getOfficeId());
userContext.setBranchGlobalNum(user.getOffice().getGlobalOfficeNum());
userContext.setOfficeLevelId(user.getOffice().getLevel().getId());
request.setAttribute(Constants.USERCONTEXT, userContext);
request.getSession(false).setAttribute(Constants.USERCONTEXT, userContext);
request.removeAttribute("CURRENT_LOCALE_ID");
request.setAttribute("CURRENT_LOCALE_ID", localeId);
if (loginActivity.isPasswordChanged()) {
HttpSession hs = request.getSession(false);
hs.setAttribute(Constants.USERCONTEXT, userContext);
hs.setAttribute(Globals.LOCALE_KEY, userContext.getCurrentLocale());
} else {
flowManager.addObjectToFlow(flowKey, Constants.TEMPUSERCONTEXT, userContext);
}
if (loginActivity.isPasswordChanged()) {
flowManager.removeFlow((String) request.getAttribute(Constants.CURRENTFLOWKEY));
request.setAttribute(Constants.CURRENTFLOWKEY, null);
}
} catch (ApplicationException e1) {
throw new MifosRuntimeException(e1);
}
}
Aggregations