protected B2BPermissionData populateB2BPermissionDataFromForm( final B2BPermissionForm b2BPermissionForm) throws ParseException { final B2BPermissionData b2BPermissionData = new B2BPermissionData(); b2BPermissionData.setOriginalCode(b2BPermissionForm.getOriginalCode()); final String permissionCode = b2BPermissionForm.getCode(); if (StringUtils.isNotEmpty(permissionCode)) { b2BPermissionData.setCode(permissionCode); } else { b2BPermissionData.setCode(assignPermissionName(b2BPermissionForm)); } final B2BPermissionTypeData b2BPermissionTypeData = b2BPermissionForm.getB2BPermissionTypeData(); b2BPermissionData.setB2BPermissionTypeData(b2BPermissionTypeData); final CurrencyData currencyData = new CurrencyData(); currencyData.setIsocode(b2BPermissionForm.getCurrency()); b2BPermissionData.setCurrency(currencyData); b2BPermissionData.setUnit( companyB2BCommerceFacade.getUnitForUid(b2BPermissionForm.getParentUnitName())); final String permissionTimespan = b2BPermissionForm.getTimeSpan(); if (StringUtils.isNotEmpty(permissionTimespan)) { b2BPermissionData.setPeriodRange(B2BPeriodRange.valueOf(b2BPermissionForm.getTimeSpan())); } final String monetaryValue = b2BPermissionForm.getValue(); if (StringUtils.isNotEmpty(monetaryValue)) { b2BPermissionData.setValue( Double.valueOf(formatFactory.createNumberFormat().parse(monetaryValue).doubleValue())); } return b2BPermissionData; }
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())); }
protected B2BCostCenterData populateB2BCostCenterDataFromForm( final B2BCostCenterForm b2BCostCenterForm) { final B2BCostCenterData b2BCostCenterData = new B2BCostCenterData(); b2BCostCenterData.setOriginalCode(b2BCostCenterForm.getOriginalCode()); b2BCostCenterData.setCode(b2BCostCenterForm.getCode()); b2BCostCenterData.setName(b2BCostCenterForm.getName()); final CurrencyData currencyData = new CurrencyData(); currencyData.setIsocode(b2BCostCenterForm.getCurrency()); b2BCostCenterData.setCurrency(currencyData); b2BCostCenterData.setUnit( companyB2BCommerceFacade.getUnitForUid(b2BCostCenterForm.getParentB2BUnit())); return b2BCostCenterData; }
protected B2BBudgetData populateB2BBudgetDataFromForm(final B2BBudgetForm b2BBudgetForm) throws ParseException { final B2BBudgetData b2BBudgetData = new B2BBudgetData(); b2BBudgetData.setOriginalCode(b2BBudgetForm.getOriginalCode()); b2BBudgetData.setCode(b2BBudgetForm.getCode()); b2BBudgetData.setName(b2BBudgetForm.getName()); b2BBudgetData.setUnit(companyB2BCommerceFacade.getUnitForUid(b2BBudgetForm.getParentB2BUnit())); final CurrencyData currencyData = new CurrencyData(); currencyData.setIsocode(b2BBudgetForm.getCurrency()); b2BBudgetData.setCurrency(currencyData); b2BBudgetData.setStartDate(b2BBudgetForm.getStartDate()); b2BBudgetData.setEndDate(b2BBudgetForm.getEndDate()); b2BBudgetData.setBudget( BigDecimal.valueOf( formatFactory.createNumberFormat().parse(b2BBudgetForm.getBudget()).doubleValue())); return b2BBudgetData; }
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 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())); }