protected String editCostCenterDetails(final String costCenterCode, final Model model) throws CMSItemNotFoundException { if (!model.containsAttribute("b2BCostCenterForm")) { final B2BCostCenterData b2BCostCenterData = b2bCostCenterFacade.getCostCenterDataForCode(costCenterCode); final B2BCostCenterForm b2BCostCenterform = new B2BCostCenterForm(); b2BCostCenterform.setOriginalCode(costCenterCode); b2BCostCenterform.setCode(b2BCostCenterData.getCode()); b2BCostCenterform.setCurrency(b2BCostCenterData.getCurrency().getIsocode()); b2BCostCenterform.setName(b2BCostCenterData.getName()); b2BCostCenterform.setParentB2BUnit(b2BCostCenterData.getUnit().getUid()); model.addAttribute(b2BCostCenterform); } storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); setUpMetaDataForContentPage( model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.createManageCostCenterBreadCrumbs(); myCompanyBreadcrumbBuilder.addViewCostCenterBreadCrumbs(breadcrumbs, costCenterCode); breadcrumbs.add( new Breadcrumb( String.format(MANAGE_COSTCENTERS_EDIT_URL, costCenterCode), getMessageSource() .getMessage( "text.company.costCenter.editPage.breadcrumb", new Object[] {costCenterCode}, getI18nService().getCurrentLocale()), null)); model.addAttribute("breadcrumbs", breadcrumbs); model.addAttribute("metaRobots", "no-index,no-follow"); return ControllerConstants.Views.Pages.MyCompany.MyCompanyCostCenterEditPage; }
protected String viewCostCenterDetails(final String costCenterCode, final Model model) throws CMSItemNotFoundException { model.addAttribute( "b2bCostCenter", b2bCostCenterFacade.getCostCenterDataForCode(costCenterCode)); storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); setUpMetaDataForContentPage( model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.createManageCostCenterBreadCrumbs(); myCompanyBreadcrumbBuilder.addViewCostCenterBreadCrumbs(breadcrumbs, costCenterCode); model.addAttribute("breadcrumbs", breadcrumbs); model.addAttribute("metaRobots", "no-index,no-follow"); return ControllerConstants.Views.Pages.MyCompany.MyCompanyCostCenterViewPage; }
protected String createUser( final B2BCustomerForm b2BCustomerForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectModel) throws CMSItemNotFoundException { if (bindingResult.hasErrors()) { GlobalMessages.addErrorMessage(model, "form.global.error"); model.addAttribute(b2BCustomerForm); return editUser(b2BCustomerForm.getUid(), model); } final CustomerData b2bCustomerData = new CustomerData(); b2bCustomerData.setTitleCode(b2BCustomerForm.getTitleCode()); b2bCustomerData.setFirstName(b2BCustomerForm.getFirstName()); b2bCustomerData.setLastName(b2BCustomerForm.getLastName()); b2bCustomerData.setEmail(b2BCustomerForm.getEmail()); b2bCustomerData.setDisplayUid(b2BCustomerForm.getEmail()); b2bCustomerData.setUnit( companyB2BCommerceFacade.getUnitForUid(b2BCustomerForm.getParentB2BUnit())); b2bCustomerData.setRoles(b2BCustomerForm.getRoles()); model.addAttribute(b2BCustomerForm); model.addAttribute("titleData", getUserFacade().getTitles()); model.addAttribute("roles", populateRolesCheckBoxes(companyB2BCommerceFacade.getUserGroups())); storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); setUpMetaDataForContentPage( model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.getBreadcrumbs(null); breadcrumbs.add( new Breadcrumb( "/my-company/organization-management/", getMessageSource() .getMessage( "text.company.organizationManagement", null, getI18nService().getCurrentLocale()), null)); breadcrumbs.add( new Breadcrumb( "/my-company/organization-management/manage-user", getMessageSource() .getMessage("text.company.manageUsers", null, getI18nService().getCurrentLocale()), null)); model.addAttribute("breadcrumbs", breadcrumbs); try { b2bCommerceUserFacade.updateCustomer(b2bCustomerData); b2bCustomerData.setUid(b2BCustomerForm.getEmail().toLowerCase()); GlobalMessages.addFlashMessage( redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "text.confirmation.user.added"); } catch (final DuplicateUidException e) { bindingResult.rejectValue("email", "text.manageuser.error.email.exists.title"); GlobalMessages.addErrorMessage(model, "form.global.error"); model.addAttribute("b2BCustomerForm", b2BCustomerForm); return editUser(b2BCustomerForm.getUid(), model); } return String.format(REDIRECT_TO_USER_DETAILS, urlEncode(b2bCustomerData.getUid())); }
@RequestMapping(value = "/my-company", method = RequestMethod.GET) @RequireHardLogIn public String myCompany(final Model model) throws CMSItemNotFoundException { storeCmsPageInModel(model, getContentPageForLabelOrId(MY_COMPANY_CMS_PAGE)); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(MY_COMPANY_CMS_PAGE)); model.addAttribute("breadcrumbs", myCompanyBreadcrumbBuilder.getBreadcrumbs(null)); model.addAttribute("unitUid", companyB2BCommerceFacade.getParentUnit().getUid()); model.addAttribute("userUid", customerFacade.getCurrentCustomer().getUid()); model.addAttribute("metaRobots", "no-index,no-follow"); return getViewForPage(model); }
protected String manageUserDetail( final String user, final Model model, final HttpServletRequest request) throws CMSItemNotFoundException { final CustomerData customerData = companyB2BCommerceFacade.getCustomerDataForUid(user); model.addAttribute("customerData", customerData); storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); setUpMetaDataForContentPage( model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.createManageUserDetailsBreadcrumb(user); model.addAttribute("breadcrumbs", breadcrumbs); if (!customerData.getUnit().isActive()) { GlobalMessages.addInfoMessage(model, "text.parentunit.disabled.warning"); } model.addAttribute("metaRobots", "no-index,no-follow"); return ControllerConstants.Views.Pages.MyCompany.MyCompanyManageUserDetailPage; }
public String editPermission( final B2BPermissionForm b2BPermissionForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectModel) throws CMSItemNotFoundException, ParseException { b2BPermissionFormValidator.validate(b2BPermissionForm, bindingResult); if (bindingResult.hasErrors()) { model.addAttribute(b2BPermissionForm); GlobalMessages.addErrorMessage(model, "form.global.error"); return editPermission(b2BPermissionForm.getOriginalCode(), model); } final B2BPermissionData b2BPermissionData = populateB2BPermissionDataFromForm(b2BPermissionForm); try { b2bCommercePermissionFacade.updatePermissionDetails(b2BPermissionData); } catch (final Exception e) { LOG.warn("Exception while saving the permission details " + e); model.addAttribute(b2BPermissionForm); GlobalMessages.addErrorMessage(model, "form.global.error"); bindingResult.rejectValue("code", "text.company.managePermissions.code.exists.error.title"); return editPermission(b2BPermissionForm.getOriginalCode(), model); } storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); setUpMetaDataForContentPage( model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.createManagePermissionsBreadcrumb(); breadcrumbs.add( new Breadcrumb( "/my-company/organization-management/manage-budgets/update", getMessageSource() .getMessage( "text.company.budget.editPage", null, getI18nService().getCurrentLocale()), null)); model.addAttribute("breadcrumbs", breadcrumbs); GlobalMessages.addFlashMessage( redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "text.confirmation.permission.updated"); return String.format(REDIRECT_TO_PERMISSION_DETAILS, urlEncode(b2BPermissionData.getCode())); }
public String editUser(final String user, final Model model) throws CMSItemNotFoundException { if (!model.containsAttribute("b2BCustomerForm")) { final CustomerData customerData = companyB2BCommerceFacade.getCustomerDataForUid(user); final B2BCustomerForm b2bCustomerForm = new B2BCustomerForm(); b2bCustomerForm.setUid(customerData.getUid()); b2bCustomerForm.setTitleCode(customerData.getTitleCode()); b2bCustomerForm.setFirstName(customerData.getFirstName()); b2bCustomerForm.setLastName(customerData.getLastName()); b2bCustomerForm.setEmail(customerData.getDisplayUid()); b2bCustomerForm.setParentB2BUnit( b2bCommerceUserFacade.getParentUnitForCustomer(customerData.getUid()).getUid()); b2bCustomerForm.setActive(customerData.isActive()); b2bCustomerForm.setApproverGroups(customerData.getApproverGroups()); b2bCustomerForm.setApprovers(customerData.getApprovers()); b2bCustomerForm.setRoles(customerData.getRoles()); model.addAttribute(b2bCustomerForm); } model.addAttribute("titleData", getUserFacade().getTitles()); model.addAttribute("roles", populateRolesCheckBoxes(companyB2BCommerceFacade.getUserGroups())); storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); setUpMetaDataForContentPage( model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.createManageUserDetailsBreadcrumb(user); breadcrumbs.add( new Breadcrumb( String.format( "/my-company/organization-management/manage-users/edit?user=%s", urlEncode(user)), getMessageSource() .getMessage( "text.company.manageusers.edit", new Object[] {user}, "Edit {0} User", getI18nService().getCurrentLocale()), null)); model.addAttribute("breadcrumbs", breadcrumbs); model.addAttribute("metaRobots", "no-index,no-follow"); return ControllerConstants.Views.Pages.MyCompany.MyCompanyManageUserAddEditFormPage; }
public String editPermission(final String permissionCode, final Model model) throws CMSItemNotFoundException { if (!model.containsAttribute("b2BPermissionForm")) { final B2BPermissionData b2BPermissionData = b2bCommercePermissionFacade.getPermissionDetails(permissionCode); final B2BPermissionForm b2BPermissionForm = new B2BPermissionForm(); b2BPermissionForm.setCode(b2BPermissionData.getCode()); b2BPermissionForm.setOriginalCode(b2BPermissionData.getCode()); b2BPermissionForm.setParentUnitName(b2BPermissionData.getUnit().getUid()); b2BPermissionForm.setPermissionType(b2BPermissionData.getB2BPermissionTypeData().getName()); b2BPermissionForm.setB2BPermissionTypeData(b2BPermissionData.getB2BPermissionTypeData()); if (!(B2BPermissionTypeEnum.B2BBUDGETEXCEEDEDPERMISSION.equals( B2BPermissionTypeEnum.valueOf(b2BPermissionData.getB2BPermissionTypeData().getCode())))) { b2BPermissionForm.setTimeSpan(b2BPermissionData.getTimeSpan()); b2BPermissionForm.setValue( formatFactory.createNumberFormat().format(b2BPermissionData.getValue())); b2BPermissionForm.setCurrency(b2BPermissionData.getCurrency().getIsocode()); } model.addAttribute(b2BPermissionForm); } storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); setUpMetaDataForContentPage( model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.createManagePermissionsBreadcrumb(); breadcrumbs.add( new Breadcrumb( String.format(MANAGE_PERMISSIONS_EDIT_URL, permissionCode), getMessageSource() .getMessage( "text.company.managePermissions.edit.page", new Object[] {permissionCode}, "Edit Order Threshold {0}", getI18nService().getCurrentLocale()), null)); model.addAttribute("breadcrumbs", breadcrumbs); model.addAttribute("metaRobots", "no-index,no-follow"); return ControllerConstants.Views.Pages.MyCompany.MyCompanyManagePermissionsEditPage; }
protected String saveCostCenter( @Valid final B2BCostCenterForm b2BCostCenterForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectModel) throws CMSItemNotFoundException { if (bindingResult.hasFieldErrors()) { model.addAttribute(b2BCostCenterForm); return addCostCenter(model); } final B2BCostCenterData b2BCostCenterData = populateB2BCostCenterDataFromForm(b2BCostCenterForm); try { b2bCostCenterFacade.addCostCenter(b2BCostCenterData); } catch (final Exception e) { LOG.warn("Exception while saving the cost center details " + e); model.addAttribute(b2BCostCenterForm); bindingResult.rejectValue("code", "text.company.costCenter.code.exists.error.title"); GlobalMessages.addErrorMessage(model, "form.global.error"); return addCostCenter(model); } storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); setUpMetaDataForContentPage( model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.createManageCostCenterBreadCrumbs(); breadcrumbs.add( new Breadcrumb( ADD_COSTCENTER_URL, getMessageSource() .getMessage( "text.company.costCenter.addPage", null, getI18nService().getCurrentLocale()), null)); model.addAttribute("breadcrumbs", breadcrumbs); GlobalMessages.addFlashMessage( redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "text.company.costCenter.create.success"); return String.format(REDIRECT_TO_COSTCENTER_DETAILS, urlEncode(b2BCostCenterData.getCode())); }
protected String addCostCenter(final Model model) throws CMSItemNotFoundException { if (!model.containsAttribute("b2BCostCenterForm")) { final B2BCostCenterForm b2BCostCenterForm = new B2BCostCenterForm(); b2BCostCenterForm.setParentB2BUnit(companyB2BCommerceFacade.getParentUnit().getUid()); model.addAttribute(b2BCostCenterForm); } storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); setUpMetaDataForContentPage( model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.createManageCostCenterBreadCrumbs(); breadcrumbs.add( new Breadcrumb( ADD_COSTCENTER_URL, getMessageSource() .getMessage( "text.company.costCenter.addPage", null, getI18nService().getCurrentLocale()), null)); model.addAttribute("breadcrumbs", breadcrumbs); model.addAttribute("metaRobots", "no-index,no-follow"); return ControllerConstants.Views.Pages.MyCompany.MyCompanyAddCostCenterPage; }
protected String unitDetails( final String unit, final Model model, final HttpServletRequest request) throws CMSItemNotFoundException { storeCmsPageInModel(model, getContentPageForLabelOrId(MANAGE_UNITS_CMS_PAGE)); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(MANAGE_UNITS_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.createManageUnitsDetailsBreadcrumbs(unit); model.addAttribute("breadcrumbs", breadcrumbs); B2BUnitData unitData = companyB2BCommerceFacade.getUnitForUid(unit); if (unitData == null) { unitData = new B2BUnitData(); GlobalMessages.addErrorMessage(model, "b2bunit.notfound"); } else if (!unitData.isActive()) { GlobalMessages.addInfoMessage(model, "b2bunit.disabled.infomsg"); } model.addAttribute("unit", unitData); model.addAttribute("user", customerFacade.getCurrentCustomer()); model.addAttribute("metaRobots", "no-index,no-follow"); return ControllerConstants.Views.Pages.MyCompany.MyCompanyManageUnitDetailsPage; }
protected String createUser(final Model model) throws CMSItemNotFoundException { if (!model.containsAttribute("b2BCustomerForm")) { final B2BCustomerForm b2bCustomerForm = new B2BCustomerForm(); b2bCustomerForm.setParentB2BUnit(companyB2BCommerceFacade.getParentUnit().getUid()); // Add the b2bcustomergroup role by default b2bCustomerForm.setRoles(Collections.singletonList("b2bcustomergroup")); model.addAttribute(b2bCustomerForm); } model.addAttribute("titleData", getUserFacade().getTitles()); model.addAttribute("roles", populateRolesCheckBoxes(companyB2BCommerceFacade.getUserGroups())); storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); setUpMetaDataForContentPage( model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.getBreadcrumbs(null); breadcrumbs.add( new Breadcrumb( "/my-company/organization-management/manage-users/create", getMessageSource() .getMessage( "text.company.organizationManagement.createuser", null, getI18nService().getCurrentLocale()), null)); breadcrumbs.add( new Breadcrumb( "/my-company/organization-management/manage-user", getMessageSource() .getMessage("text.company.manageUsers", null, getI18nService().getCurrentLocale()), null)); model.addAttribute("breadcrumbs", breadcrumbs); model.addAttribute("metaRobots", "no-index,no-follow"); return ControllerConstants.Views.Pages.MyCompany.MyCompanyManageUserAddEditFormPage; }
protected String editUser( final String user, final B2BCustomerForm b2BCustomerForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectModel) throws CMSItemNotFoundException { if (bindingResult.hasErrors()) { GlobalMessages.addErrorMessage(model, "form.global.error"); model.addAttribute(b2BCustomerForm); return editUser(b2BCustomerForm.getUid(), model); } // A B2B Admin should not be able to downgrade their roles, they must at lest belong to B2B // Administrator role if (customerFacade.getCurrentCustomer().getUid().equals(b2BCustomerForm.getUid())) { final Collection<String> roles = b2BCustomerForm.getRoles() != null ? b2BCustomerForm.getRoles() : new ArrayList<String>(); if (!roles.contains(B2BConstants.B2BADMINGROUP)) { GlobalMessages.addErrorMessage(model, "form.b2bcustomer.adminrole.error"); roles.add(B2BConstants.B2BADMINGROUP); b2BCustomerForm.setRoles(roles); model.addAttribute(b2BCustomerForm); return editUser(b2BCustomerForm.getUid(), model); } else { // A session user can't modify their own parent unit. final B2BUnitData parentUnit = companyB2BCommerceFacade.getParentUnit(); if (!parentUnit.getUid().equals(b2BCustomerForm.getParentB2BUnit())) { GlobalMessages.addErrorMessage(model, "form.b2bcustomer.parentunit.error"); b2BCustomerForm.setParentB2BUnit(parentUnit.getUid()); model.addAttribute(b2BCustomerForm); return editUser(b2BCustomerForm.getUid(), model); } } } final CustomerData b2bCustomerData = new CustomerData(); b2bCustomerData.setUid(b2BCustomerForm.getUid()); b2bCustomerData.setTitleCode(b2BCustomerForm.getTitleCode()); b2bCustomerData.setFirstName(b2BCustomerForm.getFirstName()); b2bCustomerData.setLastName(b2BCustomerForm.getLastName()); b2bCustomerData.setEmail(b2BCustomerForm.getEmail()); b2bCustomerData.setDisplayUid(b2BCustomerForm.getEmail()); b2bCustomerData.setUnit( companyB2BCommerceFacade.getUnitForUid(b2BCustomerForm.getParentB2BUnit())); b2bCustomerData.setRoles( b2BCustomerForm.getRoles() != null ? b2BCustomerForm.getRoles() : Collections.<String>emptyList()); model.addAttribute(b2BCustomerForm); model.addAttribute("titleData", getUserFacade().getTitles()); model.addAttribute("roles", populateRolesCheckBoxes(companyB2BCommerceFacade.getUserGroups())); storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); setUpMetaDataForContentPage( model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE)); final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.createManageUserDetailsBreadcrumb(user); model.addAttribute("breadcrumbs", breadcrumbs); try { b2bCommerceUserFacade.updateCustomer(b2bCustomerData); b2bCustomerData.setUid(b2BCustomerForm.getEmail().toLowerCase()); GlobalMessages.addFlashMessage( redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "text.confirmation.user.edited"); } catch (final DuplicateUidException e) { bindingResult.rejectValue("email", "text.manageuser.error.email.exists.title"); GlobalMessages.addErrorMessage(model, "form.global.error"); model.addAttribute("b2BCustomerForm", b2BCustomerForm); return editUser(b2BCustomerForm.getUid(), model); } return String.format(REDIRECT_TO_USER_DETAILS, urlEncode(b2bCustomerData.getUid())); }