final String catalogCategoryId = catalogCategoryForm.getId();
final String parentCatalogCategoryId = catalogCategoryForm.getDefaultParentCategoryId();
if(StringUtils.isNotEmpty(catalogCategoryId)){
final String catalogCategoryCode = catalogCategoryForm.getCode();
final CatalogCategoryMaster catalogCategory = catalogCategoryService.getMasterCatalogCategoryByCode(catalogCategoryCode, requestData.getMasterCatalogCode(), new FetchPlan(categoryMasterFetchPlans));
// SANITY CHECK
if(catalogCategory == null){
final String url = backofficeUrlService.generateUrl(BoUrls.MASTER_CATALOG, requestData);
return new ModelAndView(new RedirectView(url));
}
// UPDATE CATEORY
if (result.hasErrors()) {
if(StringUtils.isNotEmpty(parentCatalogCategoryId)){
// CHIELD CATEGORY
final CatalogCategoryMaster parentCatalogCategory = catalogCategoryService.getMasterCatalogCategoryById(parentCatalogCategoryId, new FetchPlan(categoryMasterFetchPlans));
initProductMasterCategoryModelAndView(request, modelAndView, parentCatalogCategory);
return modelAndView;
} else {
// ROOT CATEGORY
initProductMasterCategoryModelAndView(request, modelAndView, catalogCategory);
return modelAndView;
}
}
// UPDATE CATEGORY
try {
// CatalogCategoryMaster catalogCategoryMaster = new CatalogCategoryMaster();
webBackofficeService.updateCatalogCategory(requestData, currentMarketArea, currentRetailer, currentLocalization, catalogCategory, catalogCategoryForm);
addSuccessMessage(request, coreMessageSource.getMessage("business.catalog.category.edit.success.message", locale));
final String urlRedirect = backofficeUrlService.generateUrl(BoUrls.MASTER_CATEGORY_DETAILS, requestData, catalogCategory);;
return new ModelAndView(new RedirectView(urlRedirect));
} catch (UniqueConstraintCodeCategoryException e) {
addErrorMessage(request, coreMessageSource.getMessage("business.catalog.category.edit.error.message", locale));
if(StringUtils.isNotEmpty(parentCatalogCategoryId)){
// CHIELD CATEGORY
final CatalogCategoryMaster parentCatalogCategory = catalogCategoryService.getMasterCatalogCategoryById(parentCatalogCategoryId, new FetchPlan(categoryMasterFetchPlans));
initProductMasterCategoryModelAndView(request, modelAndView, parentCatalogCategory);
return modelAndView;
} else {
// ROOT CATEGORY
initProductMasterCategoryModelAndView(request, modelAndView, catalogCategory);
return modelAndView;
}
}
} else {
CatalogCategoryMaster parentCatalogCategory = null;
if(StringUtils.isNotEmpty(parentCatalogCategoryId)){
parentCatalogCategory = catalogCategoryService.getMasterCatalogCategoryById(parentCatalogCategoryId, new FetchPlan(categoryMasterFetchPlans));
}
// CREATE A NEW CATEORY
if (result.hasErrors()) {
if(StringUtils.isNotEmpty(parentCatalogCategoryId)){
// CHIELD CATEGORY
initProductMasterCategoryModelAndView(request, modelAndView, null);
return modelAndView;
} else {
// ROOT CATEGORY
initProductMasterCategoryModelAndView(request, modelAndView, null);
return modelAndView;
}
}
// SAVE CATEGORY
try {
CatalogCategoryMaster catalogCategoryMaster = new CatalogCategoryMaster();
CatalogCategoryMaster savedCatalogCategory = webBackofficeService.createCatalogCategory(requestData, currentMarketArea, currentLocalization, parentCatalogCategory, catalogCategoryMaster, catalogCategoryForm);
addSuccessMessage(request, coreMessageSource.getMessage("business.catalog.category.add.success.message", locale));
final String urlRedirect = backofficeUrlService.generateUrl(BoUrls.MASTER_CATEGORY_DETAILS, requestData, savedCatalogCategory);
return new ModelAndView(new RedirectView(urlRedirect));