Search in sources :

Example 1 with CreateOrUpdateProductCategory

use of org.mifos.dto.domain.CreateOrUpdateProductCategory 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 2 with CreateOrUpdateProductCategory

use of org.mifos.dto.domain.CreateOrUpdateProductCategory 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

CreateOrUpdateProductCategory (org.mifos.dto.domain.CreateOrUpdateProductCategory)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 ObjectError (org.springframework.validation.ObjectError)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2