Search in sources :

Example 51 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class PreviewCoaController method processFormSubmit.

@RequestMapping(method = RequestMethod.POST)
public ModelAndView processFormSubmit(@RequestParam(value = EDIT_PARAM, required = false) String edit, @RequestParam(value = CANCEL_PARAM, required = false) String cancel, @ModelAttribute("formBean") CoaFormBean formBean, BindingResult result, SessionStatus status) {
    String viewName = REDIRECT_TO_COA_ADMIN_SCREEN;
    ModelAndView modelAndView = new ModelAndView();
    if (StringUtils.isNotBlank(edit)) {
        viewName = DEFINE_NEW_COA;
        modelAndView.setViewName(viewName);
        modelAndView.addObject("formBean", formBean);
    } else if (StringUtils.isNotBlank(cancel)) {
        modelAndView.setViewName(REDIRECT_TO_COA_ADMIN_SCREEN);
        status.setComplete();
    } else if (result.hasErrors()) {
        modelAndView.setViewName(PREVIEW_COA);
    } else {
        try {
            CoaDto coaDto = new CoaDto();
            coaDto.setAccountName(formBean.getCoaName());
            coaDto.setGlCodeString(formBean.getGlCode());
            coaDto.setParentId(formBean.getParentId());
            coaServiceFacade.create(coaDto);
            viewName = REDIRECT_TO_COA_ADMIN_SCREEN;
            modelAndView.setViewName(viewName);
            status.setComplete();
        } catch (BusinessRuleException e) {
            ObjectError error = new ObjectError("formBean", new String[] { e.getMessageKey() }, new Object[] {}, "default: ");
            result.addError(error);
            modelAndView.setViewName(PREVIEW_COA);
            modelAndView.addObject("formBean", formBean);
        }
    }
    return modelAndView;
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ObjectError(org.springframework.validation.ObjectError) CoaDto(org.mifos.application.admin.servicefacade.CoaDto) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 52 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class ProductCategoryPreviewController method processFormSubmit.

@RequestMapping(method = RequestMethod.POST)
public ModelAndView processFormSubmit(@RequestParam(value = EDIT_PARAM, required = false) String edit, @RequestParam(value = CANCEL_PARAM, required = false) String cancel, @ModelAttribute("formBean") ProductCategoryFormBean formBean, BindingResult result) {
    String viewName = REDIRECT_TO_ADMIN_SCREEN;
    ModelAndView modelAndView = new ModelAndView();
    if (StringUtils.isNotBlank(edit)) {
        viewName = "editCategoryInformation";
        modelAndView.setViewName(viewName);
        modelAndView.addObject("formBean", formBean);
        modelAndView.addObject("breadcrumbs", new AdminBreadcrumbBuilder().withLink("admin.viewproductcategories", "viewProductCategories.ftl").withLink(formBean.getProductCategoryName(), "").build());
    } else if (StringUtils.isNotBlank(cancel)) {
        viewName = REDIRECT_TO_ADMIN_SCREEN;
        modelAndView.setViewName(viewName);
    } else if (result.hasErrors()) {
        viewName = "categoryPreview";
        modelAndView.setViewName(viewName);
        modelAndView.addObject("formBean", formBean);
        modelAndView.addObject("breadcrumbs", new AdminBreadcrumbBuilder().withLink("admin.viewproductcategories", "viewProductCategories.ftl").withLink(formBean.getProductCategoryName(), "").build());
    } else {
        Integer productStatusId = Integer.parseInt(formBean.getProductCategoryStatusId());
        Integer productTypeId = Integer.parseInt(formBean.getProductTypeId());
        CreateOrUpdateProductCategory productCategory = new CreateOrUpdateProductCategory(productTypeId.shortValue(), formBean.getProductCategoryName(), formBean.getProductCategoryDesc(), productStatusId.shortValue(), formBean.getGlobalPrdCategoryNum());
        try {
            this.adminServiceFacade.updateProductCategory(productCategory);
            modelAndView.setViewName(REDIRECT_TO_ADMIN_SCREEN);
        } catch (BusinessRuleException e) {
            ObjectError error = new ObjectError("formBean", new String[] { e.getMessageKey() }, new Object[] {}, "default: ");
            result.addError(error);
            modelAndView.setViewName("categoryPreview");
            modelAndView.addObject("formBean", formBean);
            modelAndView.addObject("breadcrumbs", new AdminBreadcrumbBuilder().withLink("admin.viewproductcategories", "viewProductCategories.ftl").withLink(formBean.getProductCategoryName(), "").build());
        }
    }
    return modelAndView;
}
Also used : CreateOrUpdateProductCategory(org.mifos.dto.domain.CreateOrUpdateProductCategory) BusinessRuleException(org.mifos.service.BusinessRuleException) ObjectError(org.springframework.validation.ObjectError) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 53 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class UpdateCustomerMeetingScheduleTest method throwsCheckedExceptionWhenCustomerIsNotTopOfCustomerHierarchy.

@Test(expected = BusinessRuleException.class)
public void throwsCheckedExceptionWhenCustomerIsNotTopOfCustomerHierarchy() throws Exception {
    // setup
    MeetingBO newMeeting = new MeetingBuilder().build();
    // stubbing
    doThrow(new BusinessRuleException(CustomerConstants.INVALID_MEETING)).when(mockedCenter).validateIsTopOfHierarchy();
    // exercise test
    customerService.updateCustomerMeetingSchedule(newMeeting, mockedCenter);
    // verification
    verify(mockedCenter).validateIsTopOfHierarchy();
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) Test(org.junit.Test)

Example 54 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class ChangePasswordController method processFormSubmit.

@RequestMapping(method = RequestMethod.POST)
public String processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @ModelAttribute("formBean") @Valid ChangePasswordFormBean formBean, BindingResult result, SessionStatus status, HttpServletRequest request) {
    String viewName = HOME_PAGE;
    if (CANCEL_PARAM_VALUE.equals(cancel)) {
        viewName = REDIRECT_AND_LOGOUT;
        status.setComplete();
    } else if (result.hasErrors()) {
        viewName = "changePassword";
    } else {
        try {
            ChangePasswordRequest changePasswordRequest = new ChangePasswordRequest(formBean.getUsername(), formBean.getOldPassword(), formBean.getNewPassword());
            loginServiceFacade.changePassword(changePasswordRequest);
            status.setComplete();
        } catch (BusinessRuleException e) {
            ObjectError error = new ObjectError("passwordUsed", messageSource.getMessage("error.passwordAlreadyUsedException", null, RequestContextUtils.getLocale(request)));
            result.addError(error);
            viewName = "changePassword";
        }
    }
    return viewName;
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ObjectError(org.springframework.validation.ObjectError) ChangePasswordRequest(org.mifos.dto.domain.ChangePasswordRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 55 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class DefineProductCategoryPreviewController method processFormSubmit.

@RequestMapping(method = RequestMethod.POST)
public ModelAndView processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @RequestParam(value = EDIT_PARAM, required = false) String edit, @ModelAttribute("formBean") ProductCategoryFormBean bean, BindingResult result) {
    ModelAndView modelAndView = new ModelAndView("defineNewCategory");
    if (StringUtils.isNotBlank(cancel)) {
        modelAndView.setViewName(REDIRECT_TO_ADMIN);
    } else if (StringUtils.isNotBlank(edit)) {
        modelAndView.setViewName("defineNewCategory");
        modelAndView.addObject("formBean", bean);
        modelAndView.addObject("typeList", this.getProductCategoryTypes());
    } else if (result.hasErrors()) {
        modelAndView.setViewName("newProductCategoryPreview");
        modelAndView.addObject("formBean", bean);
    } else {
        CreateOrUpdateProductCategory productCategory = new CreateOrUpdateProductCategory(Short.parseShort(bean.getProductTypeId()), bean.getProductCategoryName(), bean.getProductCategoryDesc(), Short.parseShort(bean.getProductCategoryStatusId()), bean.getGlobalPrdCategoryNum());
        try {
            this.adminServiceFacade.createProductCategory(productCategory);
            modelAndView.setViewName(REDIRECT_TO_ADMIN);
        } catch (BusinessRuleException e) {
            ObjectError error = new ObjectError("formBean", new String[] { e.getMessageKey() }, new Object[] {}, "default: ");
            result.addError(error);
            modelAndView.setViewName("newProductCategoryPreview");
            modelAndView.addObject("formBean", bean);
        }
    }
    return modelAndView;
}
Also used : CreateOrUpdateProductCategory(org.mifos.dto.domain.CreateOrUpdateProductCategory) BusinessRuleException(org.mifos.service.BusinessRuleException) ObjectError(org.springframework.validation.ObjectError) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

BusinessRuleException (org.mifos.service.BusinessRuleException)140 MifosRuntimeException (org.mifos.core.MifosRuntimeException)68 UserContext (org.mifos.security.util.UserContext)63 MifosUser (org.mifos.security.MifosUser)61 AccountException (org.mifos.accounts.exceptions.AccountException)46 PersistenceException (org.mifos.framework.exceptions.PersistenceException)43 ApplicationException (org.mifos.framework.exceptions.ApplicationException)33 LocalDate (org.joda.time.LocalDate)31 ServiceException (org.mifos.framework.exceptions.ServiceException)30 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)26 ArrayList (java.util.ArrayList)23 CustomerBO (org.mifos.customers.business.CustomerBO)22 Money (org.mifos.framework.util.helpers.Money)22 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)20 CustomerException (org.mifos.customers.exceptions.CustomerException)19 LoanBO (org.mifos.accounts.loan.business.LoanBO)18 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)16 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)16 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)16 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)16