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;
}
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;
}
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();
}
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;
}
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;
}
Aggregations