Search in sources :

Example 61 with ApplicationException

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

the class HolidayDaoHibernate method validateNoExtraFutureHolidaysApplicableOnParentOffice.

@Override
public void validateNoExtraFutureHolidaysApplicableOnParentOffice(Short oldParentOfficeId, Short newParentOfficeId) throws ApplicationException {
    List<Holiday> previousApplicableHolidays = retrieveCurrentAndFutureHolidaysForOfficeHierarchyInAscendingOrder(oldParentOfficeId);
    List<Holiday> possibleApplicableHolidays = retrieveCurrentAndFutureHolidaysForOfficeHierarchyInAscendingOrder(newParentOfficeId);
    if (previousApplicableHolidays.size() != possibleApplicableHolidays.size()) {
        throw new ApplicationException(OfficeConstants.ERROR_REPARENT_NOT_ALLOWED_AS_FUTURE_APPLICABLE_HOLIDAYS_ARE_DIFFERENT_ON_PREVIOUS_AND_NEW_PARENT);
    }
    for (Holiday holiday : previousApplicableHolidays) {
        HolidayBO applicableHoliday = (HolidayBO) holiday;
        if (!possibleApplicableHolidays.contains(applicableHoliday)) {
            throw new ApplicationException(OfficeConstants.ERROR_REPARENT_NOT_ALLOWED_AS_FUTURE_APPLICABLE_HOLIDAYS_ARE_DIFFERENT_ON_PREVIOUS_AND_NEW_PARENT);
        }
    }
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) Holiday(org.mifos.application.holiday.business.Holiday) HolidayBO(org.mifos.application.holiday.business.HolidayBO)

Example 62 with ApplicationException

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

the class GroupCustAction method get.

@TransactionDemarcate(saveToken = true)
public ActionForward get(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.debug("In GroupCustAction get method ");
    // John W - UserContext object passed because some status' need to be looked up for internationalisation based
    // on UserContext info
    String groupSystemId = ((GroupCustActionForm) form).getGlobalCustNum();
    GroupInformationDto groupInformationDto;
    try {
        groupInformationDto = this.groupServiceFacade.getGroupInformationDto(groupSystemId);
    } catch (MifosRuntimeException e) {
        if (e.getCause() instanceof ApplicationException) {
            throw (ApplicationException) e.getCause();
        }
        throw e;
    }
    SessionUtils.removeThenSetAttribute("groupInformationDto", groupInformationDto, request);
    // John W - - not sure whether to leave these rules as is or do something else like bake the logic into the main
    // dto and out of the jsp
    SessionUtils.setAttribute(GroupConstants.IS_GROUP_LOAN_ALLOWED, ClientRules.getGroupCanApplyLoans(), request);
    SessionUtils.setAttribute(GroupConstants.CENTER_HIERARCHY_EXIST, ClientRules.getCenterHierarchyExists(), request);
    // John W - 'BusinessKey' attribute linked to GroupBo is still used by other actions (e.g. meeting related)
    // further on and also breadcrumb.
    GroupBO groupBO = (GroupBO) this.customerDao.findCustomerById(groupInformationDto.getGroupDisplay().getCustomerId());
    SessionUtils.removeThenSetAttribute(Constants.BUSINESS_KEY, groupBO, request);
    setCurrentPageUrl(request, groupBO);
    setQuestionGroupInstances(request, groupBO);
    logger.debug("Exiting GroupCustAction get method ");
    return mapping.findForward(ActionForwards.get_success.toString());
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) GroupBO(org.mifos.customers.group.business.GroupBO) GroupCustActionForm(org.mifos.customers.group.struts.actionforms.GroupCustActionForm) GroupInformationDto(org.mifos.dto.screen.GroupInformationDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 63 with ApplicationException

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

the class GroupCustAction method create.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    GroupCustActionForm actionForm = (GroupCustActionForm) form;
    MeetingBO meeting = (MeetingBO) SessionUtils.getAttribute(CustomerConstants.CUSTOMER_MEETING, request);
    UserContext userContext = getUserContext(request);
    String groupName = actionForm.getDisplayName();
    String externalId = actionForm.getExternalId();
    boolean trained = actionForm.isCustomerTrained();
    DateTime trainedOn = new DateTime(actionForm.getTrainedDateValue(userContext.getPreferredLocale()));
    AddressDto addressDto = null;
    if (actionForm.getAddress() != null) {
        addressDto = Address.toDto(actionForm.getAddress());
    }
    Short customerStatusId = actionForm.getStatusValue().getValue();
    String centerSystemId = "";
    boolean isCenterHierarchyExists = ClientRules.getCenterHierarchyExists();
    if (isCenterHierarchyExists) {
        centerSystemId = actionForm.getParentCustomer().getGlobalCustNum();
    }
    Short officeId = actionForm.getOfficeIdValue();
    MeetingDto meetingDto = null;
    if (meeting != null) {
        meetingDto = meeting.toDto();
    }
    DateTime mfiJoiningDate = new DateTime().toDateMidnight().toDateTime();
    DateTime activationDate = new DateTime().toDateMidnight().toDateTime();
    try {
        GroupCreationDetail groupCreationDetail = new GroupCreationDetail(groupName, externalId, addressDto, actionForm.getFormedByPersonnelValue(), actionForm.getFeesToApply(), customerStatusId, trained, trainedOn, centerSystemId, officeId, mfiJoiningDate, activationDate);
        CustomerDetailsDto centerDetails = this.groupServiceFacade.createNewGroup(groupCreationDetail, meetingDto);
        createGroupQuestionnaire.saveResponses(request, actionForm, centerDetails.getId());
        actionForm.setCustomerId(centerDetails.getId().toString());
        actionForm.setGlobalCustNum(centerDetails.getGlobalCustNum());
    } catch (BusinessRuleException e) {
        throw new ApplicationException(e.getMessageKey(), e);
    }
    SessionUtils.setAttribute(GroupConstants.IS_GROUP_LOAN_ALLOWED, ClientRules.getGroupCanApplyLoans(), request);
    return mapping.findForward(ActionForwards.create_success.toString());
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) UserContext(org.mifos.security.util.UserContext) AddressDto(org.mifos.dto.domain.AddressDto) GroupCreationDetail(org.mifos.dto.domain.GroupCreationDetail) DateTime(org.joda.time.DateTime) MeetingDto(org.mifos.dto.domain.MeetingDto) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) GroupCustActionForm(org.mifos.customers.group.struts.actionforms.GroupCustActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 64 with ApplicationException

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

the class GroupCustActionForm method validateFields.

@Override
protected ActionErrors validateFields(HttpServletRequest request, String method) throws ApplicationException {
    ActionErrors errors = new ActionErrors();
    try {
        if (method.equals(Methods.previewManage.toString())) {
            validateName(errors);
            validateTrained(request, errors);
            validateConfigurableMandatoryFields(request, errors, EntityType.GROUP);
            validateCustomFieldsForCustomers(request, errors);
        } else if (method.equals(Methods.preview.toString()) || method.equals(Methods.previewOnly.toString())) {
            validateName(errors);
            validateLO(errors);
            validateFormedByPersonnel(errors);
            validateTrained(request, errors);
            validateConfigurableMandatoryFields(request, errors, EntityType.GROUP);
            validateCustomFieldsForCustomers(request, errors);
            validateFees(request, errors);
        }
    } catch (ApplicationException ae) {
        // Discard other errors (is that right?)
        ae.printStackTrace();
        errors = new ActionErrors();
        errors.add(ae.getKey(), new ActionMessage(ae.getKey(), ae.getValues()));
    }
    if (!errors.isEmpty()) {
        request.setAttribute(GroupConstants.METHODCALLED, method);
    }
    return errors;
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors)

Example 65 with ApplicationException

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

the class CustomerApplyAdjustmentAction method previewAdjustment.

@TransactionDemarcate(joinToken = true)
public ActionForward previewAdjustment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    request.setAttribute(CustomerConstants.METHOD, CustomerConstants.METHOD_PREVIEW_ADJUSTMENT);
    CustomerApplyAdjustmentActionForm applyAdjustmentActionForm = (CustomerApplyAdjustmentActionForm) form;
    String globalCustNum = applyAdjustmentActionForm.getGlobalCustNum();
    CustomerBO customerBO = this.customerDao.findCustomerBySystemId(globalCustNum);
    SessionUtils.removeAttribute(Constants.BUSINESS_KEY, request);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, customerBO, request);
    if (null == customerBO.getCustomerAccount().findMostRecentNonzeroPaymentByPaymentDate()) {
        request.setAttribute(CustomerConstants.METHOD, CustomerConstants.METHOD_LOAD_ADJUSTMENT);
        request.setAttribute("isDisabled", "true");
        throw new ApplicationException(AccountExceptionConstants.ZEROAMNTADJUSTMENT);
    }
    return mapping.findForward(CustomerConstants.METHOD_PREVIEW_ADJUSTMENT_SUCCESS);
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerApplyAdjustmentActionForm(org.mifos.customers.struts.actionforms.CustomerApplyAdjustmentActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

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