Search in sources :

Example 66 with ApplicationException

use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.

the class CenterValidationTest method cannotCreateCenterWithMultipleInstancesOfSamePeriodFee.

@Test
public void cannotCreateCenterWithMultipleInstancesOfSamePeriodFee() {
    // setup
    DateTime today = new DateTime();
    MeetingBuilder aWeeklyMeeting = new MeetingBuilder().customerMeeting().weekly();
    CenterBO center = new CenterBuilder().withName("center1").withLoanOfficer(anyLoanOfficer()).with(aWeeklyMeeting).withMfiJoiningDate(today).build();
    MeetingBuilder aWeeklyFeeMeeting = new MeetingBuilder().periodicFeeMeeting().weekly();
    AmountFeeBO montlyPeriodicFee = new FeeBuilder().appliesToCenterOnly().with(aWeeklyFeeMeeting).build();
    AccountFeesEntity accountFee = new AccountFeesEntity(null, montlyPeriodicFee, montlyPeriodicFee.getFeeAmount().getAmountDoubleValue());
    List<AccountFeesEntity> centerAccountFees = new ArrayList<AccountFeesEntity>();
    centerAccountFees.add(accountFee);
    centerAccountFees.add(accountFee);
    // exercise test
    try {
        center.validateMeetingAndFees(centerAccountFees);
        fail("cannotCreateCenterWithFeeThatHasDifferentPeriod");
    } catch (ApplicationException e) {
        assertThat(e.getKey(), is(CustomerConstants.ERRORS_DUPLICATE_PERIODIC_FEE));
    }
}
Also used : FeeBuilder(org.mifos.domain.builders.FeeBuilder) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ArrayList(java.util.ArrayList) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) DateTime(org.joda.time.DateTime) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) Test(org.junit.Test)

Example 67 with ApplicationException

use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.

the class CenterValidationTest method cannotCreateCenterWithoutAMfiJoiningDate.

@Test
public void cannotCreateCenterWithoutAMfiJoiningDate() {
    // setup
    DateTime noJoiningDate = null;
    MeetingBuilder customerMeeting = new MeetingBuilder().customerMeeting();
    center = new CenterBuilder().withName("center1").withLoanOfficer(anyLoanOfficer()).with(customerMeeting).withMfiJoiningDate(noJoiningDate).build();
    // exercise test
    try {
        center.validate();
        fail("cannotCreateCenterWithoutAMfiJoiningDate");
    } catch (ApplicationException e) {
        assertThat(e.getKey(), is(CustomerConstants.MFI_JOINING_DATE_MANDATORY));
    }
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) CenterBuilder(org.mifos.domain.builders.CenterBuilder) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 68 with ApplicationException

use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.

the class GroupIndividualLoanAccountAction method get.

@TransactionDemarcate(saveToken = true)
public ActionForward get(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    LoanAccountActionForm loanAccountActionForm = (LoanAccountActionForm) form;
    loanAccountActionForm.clearDetailsForLoan();
    String globalAccountNum = request.getParameter(GLOBAL_ACCOUNT_NUM);
    UserContext userContext = getUserContext(request);
    LoanInformationDto loanInformationDto;
    try {
        loanInformationDto = this.loanAccountServiceFacade.retrieveLoanInformation(globalAccountNum);
    } catch (MifosRuntimeException e) {
        if (e.getCause() instanceof ApplicationException) {
            throw (ApplicationException) e.getCause();
        }
        throw e;
    }
    final String accountStateNameLocalised = ApplicationContextProvider.getBean(MessageLookup.class).lookup(loanInformationDto.getAccountStateName());
    SessionUtils.removeThenSetAttribute("accountStateNameLocalised", accountStateNameLocalised, request);
    final String gracePeriodTypeNameLocalised = ApplicationContextProvider.getBean(MessageLookup.class).lookup(loanInformationDto.getGracePeriodTypeName());
    SessionUtils.removeThenSetAttribute("gracePeriodTypeNameLocalised", gracePeriodTypeNameLocalised, request);
    final String interestTypeNameLocalised = ApplicationContextProvider.getBean(MessageLookup.class).lookup(loanInformationDto.getInterestTypeName());
    SessionUtils.removeThenSetAttribute("interestTypeNameLocalised", interestTypeNameLocalised, request);
    final Set<String> accountFlagStateEntityNamesLocalised = new HashSet<String>();
    for (String name : loanInformationDto.getAccountFlagNames()) {
        accountFlagStateEntityNamesLocalised.add(ApplicationContextProvider.getBean(MessageLookup.class).lookup(name));
    }
    SessionUtils.setCollectionAttribute("accountFlagNamesLocalised", accountFlagStateEntityNamesLocalised, request);
    SessionUtils.removeAttribute(BUSINESS_KEY, request);
    Integer loanIndividualMonitoringIsEnabled = configurationPersistence.getConfigurationValueInteger(LOAN_INDIVIDUAL_MONITORING_IS_ENABLED);
    if (null != loanIndividualMonitoringIsEnabled && loanIndividualMonitoringIsEnabled.intValue() != 0) {
        SessionUtils.setAttribute(LOAN_INDIVIDUAL_MONITORING_IS_ENABLED, loanIndividualMonitoringIsEnabled.intValue(), request);
    }
    Boolean GroupLoanWithMembers = AccountingRules.isGroupLoanWithMembers();
    if (null != GroupLoanWithMembers && GroupLoanWithMembers != false) {
        SessionUtils.setAttribute("GroupLoanWithMembers", GroupLoanWithMembers.booleanValue(), request);
    }
    List<ValueListElement> allLoanPurposes = this.loanProductDao.findAllLoanPurposes();
    SessionUtils.setCollectionAttribute(MasterConstants.BUSINESS_ACTIVITIES, allLoanPurposes, request);
    if (((null != loanIndividualMonitoringIsEnabled && 0 != loanIndividualMonitoringIsEnabled.intValue()) || (null != GroupLoanWithMembers && GroupLoanWithMembers != false)) && loanInformationDto.isGroup()) {
        List<LoanAccountDetailsDto> loanAccountDetails = this.loanAccountServiceFacade.retrieveLoanAccountDetails(loanInformationDto);
        addEmptyBuisnessActivities(loanAccountDetails);
        SessionUtils.setCollectionAttribute("loanAccountDetailsView", loanAccountDetails, request);
    }
    SessionUtils.setCollectionAttribute(CUSTOM_FIELDS, new ArrayList<CustomFieldDefinitionEntity>(), request);
    // Retrieve and set into the session all collateral types from the
    // lookup_value_locale table associated with the current user context
    // locale
    SessionUtils.setCollectionAttribute(MasterConstants.COLLATERAL_TYPES, legacyMasterDao.getLookUpEntity(MasterConstants.COLLATERAL_TYPES).getCustomValueListElements(), request);
    SessionUtils.setAttribute(AccountConstants.LAST_PAYMENT_ACTION, loanBusinessService.getLastPaymentAction(loanInformationDto.getAccountId()), request);
    SessionUtils.removeThenSetAttribute("loanInformationDto", loanInformationDto, request);
    // inject preferred date
    List<LoanActivityDto> activities = loanInformationDto.getRecentAccountActivity();
    for (LoanActivityDto activity : activities) {
        activity.setUserPrefferedDate(DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), activity.getActionDate().toString()));
    }
    SessionUtils.setCollectionAttribute(RECENTACCOUNTACTIVITIES, activities, request);
    request.getSession().setAttribute("guarantyInformation", loanAccountServiceFacade.handleGuaranties(loanInformationDto));
    request.setAttribute(CustomerConstants.SURVEY_KEY, loanInformationDto.getAccountSurveys());
    request.setAttribute(CustomerConstants.SURVEY_COUNT, loanInformationDto.getActiveSurveys());
    request.setAttribute(AccountConstants.SURVEY_KEY, loanInformationDto.getAccountSurveys());
    Integer administrativeDocumentsIsEnabled = configurationPersistence.getConfigurationValueInteger(ADMINISTRATIVE_DOCUMENT_IS_ENABLED);
    if (null != administrativeDocumentsIsEnabled && administrativeDocumentsIsEnabled.intValue() == 1) {
        SessionUtils.setCollectionAttribute(AdminDocumentsContants.ADMINISTRATIVEDOCUMENTSLIST, legacyAdminDocumentDao.getAllActiveAdminDocuments(), request);
        SessionUtils.setCollectionAttribute(AdminDocumentsContants.ADMINISTRATIVEDOCUMENTSACCSTATEMIXLIST, legacyAdminDocAccStateMixDao.getAllMixedAdminDocuments(), request);
    }
    List<QuestionGroupInstanceDetail> questions = new ArrayList<QuestionGroupInstanceDetail>();
    questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "Create", "Loan"));
    questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "Approve", "Loan"));
    questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "View", "Loan"));
    questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "Disburse", "Loan"));
    questions.addAll(questionnaireServiceFacade.getQuestionGroupInstancesWithUnansweredQuestionGroups(loanInformationDto.getAccountId(), "Close", "Loan"));
    SessionUtils.setCollectionAttribute("questionGroups", questions, request);
    SessionUtils.setCollectionAttribute("personalInformationOrder", informationOrderServiceFacade.getInformationOrder("Loan"), request);
    LoanBO loan = getLoan(loanInformationDto.getAccountId());
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, loan, request);
    setCurrentPageUrl(request, loan);
    setOverpayments(request, loan);
    List<RepaymentScheduleInstallment> installments = loan.toRepaymentScheduleDto(userContext.getPreferredLocale());
    loanAccountActionForm.initializeInstallments(installments);
    return mapping.findForward(ActionForwards.get_success.toString());
}
Also used : ArrayList(java.util.ArrayList) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) LoanAccountActionForm(org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) MessageLookup(org.mifos.application.master.MessageLookup) HashSet(java.util.HashSet) QuestionGroupInstanceDetail(org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail) LoanActivityDto(org.mifos.dto.domain.LoanActivityDto) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) CustomFieldDefinitionEntity(org.mifos.application.master.business.CustomFieldDefinitionEntity) ApplicationException(org.mifos.framework.exceptions.ApplicationException) LoanInformationDto(org.mifos.dto.screen.LoanInformationDto) ValueListElement(org.mifos.dto.domain.ValueListElement) MifosRuntimeException(org.mifos.core.MifosRuntimeException) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 69 with ApplicationException

use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.

the class LoginAction method updatePassword.

//    public ActionForward load(ActionMapping mapping, @SuppressWarnings("unused") ActionForm form, HttpServletRequest request,
//            @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
//        logger.debug("Inside load of LoginAction");
//        SessionUtils.setAttribute(LoginConstants.LOGINACTIONFORM, null, request.getSession());
//        request.getSession(false).setAttribute(Constants.FLOWMANAGER, new FlowManager());
//        return mapping.findForward(ActionForwards.load_success.toString());
//    }
//    @TransactionDemarcate(saveToken = true)
//    public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request,
//            @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
//        logger.debug("Inside login of LoginAction");
//        logger.debug("Using Thread: " + Thread.currentThread().getName());
//        logger.debug("Using hibernate session: " + StaticHibernateUtil.getSessionTL().hashCode());
//
//        ShutdownManager shutdownManager = (ShutdownManager) ServletUtils.getGlobal(request, ShutdownManager.class
//                .getName());
//        if (shutdownManager.isInShutdownCountdownNotificationThreshold()) {
//            request.getSession(false).invalidate();
//            ActionErrors error = new ActionErrors();
//            error.add(LoginConstants.SHUTDOWN, new ActionMessage(LoginConstants.SHUTDOWN));
//            request.setAttribute(Globals.ERROR_KEY, error);
//            return mapping.findForward(ActionForwards.load_main_page.toString());
//        }
//
//        LoginActionForm loginActionForm = (LoginActionForm) form;
//        String userName = loginActionForm.getUserName();
//        String password = loginActionForm.getPassword();
//
//        LoginDto loginDto = loginServiceFacade.login(userName, password);
//
//        PersonnelBO user = this.personnelDao.findPersonnelById(loginDto.getUserId());
//        ActivityContext activityContext = new ActivityContext(Short.valueOf("0"), user.getOffice().getOfficeId(), user.getPersonnelId());
//        request.getSession(false).setAttribute(Constants.ACTIVITYCONTEXT, activityContext);
//
//        Locale preferredLocale = Localization.getInstance().getConfiguredLocale();
//        Short localeId = Localization.getInstance().getLocaleId();
//        UserContext userContext = new UserContext(preferredLocale, 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());
//
//        if (loginDto.isPasswordChanged()) {
//            setUserContextInSession(userContext, request);
//        } else {
//            SessionUtils.setAttribute(Constants.TEMPUSERCONTEXT, userContext, request);
//        }
//
//        //  set flow
//        Short passwordChanged = user.getPasswordChanged();
//        if (null != passwordChanged && LoginConstants.PASSWORDCHANGEDFLAG.equals(passwordChanged)) {
//            FlowManager flowManager = (FlowManager) request.getSession().getAttribute(Constants.FLOWMANAGER);
//            flowManager.removeFlow((String) request.getAttribute(Constants.CURRENTFLOWKEY));
//            request.setAttribute(Constants.CURRENTFLOWKEY, null);
//        }
//
//        final String loginForward = getLoginForward(user.getPasswordChanged());
//
//        return mapping.findForward(loginForward);
//    }
//    public ActionForward logout(ActionMapping mapping, @SuppressWarnings("unused") ActionForm form, HttpServletRequest request,
//            @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
//
//        logger.debug("Inside logout of LoginAction");
//
//        ResourceBundle resources;
//        UserContext userContext = getUserContext(request);
//        if (null == userContext) {
//            // user might have just been given an empty session, so we
//            // can't assume that their session has a preferred locale
//            resources = ResourceBundle.getBundle(FilePaths.LOGIN_UI_PROPERTY_FILE);
//        } else {
//            // get locale first
//            Locale locale = userContext.getPreferredLocale();
//            resources = ResourceBundle.getBundle(FilePaths.LOGIN_UI_PROPERTY_FILE, locale);
//        }
//
//        request.getSession(false).invalidate();
//        ActionErrors error = new ActionErrors();
//
//        String errorMessage = resources.getString(LoginConstants.LOGOUTOUT);
//
//        // ActionMessage: take errorMessage as literal
//        error.add(LoginConstants.LOGOUTOUT, new ActionMessage(errorMessage, false));
//
//        request.setAttribute(Globals.ERROR_KEY, error);
//        return mapping.findForward(ActionForwards.logout_success.toString());
//    }
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward updatePassword(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.debug("Inside updatePassword of LoginAction");
    LoginActionForm loginActionForm = (LoginActionForm) form;
    UserContext userContext = null;
    String userName = loginActionForm.getUserName();
    if (null == userName || "".equals(userName)) {
        throw new ApplicationException(LoginConstants.SESSIONTIMEOUT);
    }
    String oldPassword = loginActionForm.getOldPassword();
    String newpassword = loginActionForm.getNewPassword();
    boolean passwordWasPreviouslyChanged = this.loginServiceFacade.updatePassword(userName, oldPassword, newpassword);
    if (passwordWasPreviouslyChanged) {
        userContext = (UserContext) SessionUtils.getAttribute(Constants.USERCONTEXT, request.getSession());
    } else {
        userContext = (UserContext) SessionUtils.getAttribute(Constants.TEMPUSERCONTEXT, request);
    }
    setUserContextInSession(userContext, request);
    return mapping.findForward(ActionForwards.updatePassword_success.toString());
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) UserContext(org.mifos.security.util.UserContext) LoginActionForm(org.mifos.security.login.struts.actionforms.LoginActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 70 with ApplicationException

use of org.mifos.framework.exceptions.ApplicationException 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);
    }
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) Locale(java.util.Locale) FlowManager(org.mifos.framework.util.helpers.FlowManager) SitePreferenceHelper(org.mifos.ui.core.controller.util.helpers.SitePreferenceHelper) UserContext(org.mifos.security.util.UserContext) HttpSession(javax.servlet.http.HttpSession) LegacyPersonnelDao(org.mifos.customers.personnel.persistence.LegacyPersonnelDao) Flow(org.mifos.framework.util.helpers.Flow) ApplicationException(org.mifos.framework.exceptions.ApplicationException) Random(java.util.Random) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoginDto(org.mifos.dto.domain.LoginDto) DateTimeService(org.mifos.framework.util.DateTimeService) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

ApplicationException (org.mifos.framework.exceptions.ApplicationException)76 BusinessRuleException (org.mifos.service.BusinessRuleException)34 MifosRuntimeException (org.mifos.core.MifosRuntimeException)29 UserContext (org.mifos.security.util.UserContext)25 PersistenceException (org.mifos.framework.exceptions.PersistenceException)22 ArrayList (java.util.ArrayList)16 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)16 MifosUser (org.mifos.security.MifosUser)16 SystemException (org.mifos.framework.exceptions.SystemException)14 CustomerBO (org.mifos.customers.business.CustomerBO)10 ServiceException (org.mifos.framework.exceptions.ServiceException)10 Test (org.junit.Test)9 AccountException (org.mifos.accounts.exceptions.AccountException)9 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)9 CustomerException (org.mifos.customers.exceptions.CustomerException)9 HibernateException (org.hibernate.HibernateException)8 Session (org.hibernate.Session)7 LoanBO (org.mifos.accounts.loan.business.LoanBO)7 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)7 CenterBO (org.mifos.customers.center.business.CenterBO)7