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 AddressForm getPreparedAddressForm() { final CustomerData currentCustomerData = customerFacade.getCurrentCustomer(); final AddressForm addressForm = new AddressForm(); addressForm.setFirstName(currentCustomerData.getFirstName()); addressForm.setLastName(currentCustomerData.getLastName()); addressForm.setTitleCode(currentCustomerData.getTitleCode()); return addressForm; }
@Test(expected = ConversionException.class) public void testPopulateLanguageUnknownIdent() { final CustomerData customerData = mock(CustomerData.class); final CustomerModel customerModel = new CustomerModel(); final LanguageData languageData = mock(LanguageData.class); given(customerData.getLanguage()).willReturn(languageData); given(languageData.getIsocode()).willReturn("languageIso"); given(commonI18NService.getLanguage("languageIso")) .willThrow(new UnknownIdentifierException("")); customerReversePopulator.populate(customerData, customerModel); }
@Test public void testPopulateEssencial() { final CustomerData customerData = mock(CustomerData.class); final CustomerModel customerModel = new CustomerModel(); given(customerData.getFirstName()).willReturn("firstName"); given(customerData.getLastName()).willReturn("lastName"); given(customerData.getTitleCode()).willReturn(null); given(customerNameStrategy.getName("firstName", "lastName")).willReturn("firstName lastName"); customerReversePopulator.populate(customerData, customerModel); Assert.assertEquals("firstName lastName", customerModel.getName()); Assert.assertNull(customerModel.getTitle()); }
@Override public void updateCustomer(final CustomerData customerData) throws DuplicateUidException { validateParameterNotNullStandardMessage("customerData", customerData); final EnergizerB2BCustomerModel energizerB2BCustomerModel; if (StringUtils.isEmpty(customerData.getUid())) { energizerB2BCustomerModel = this.getModelService().create(EnergizerB2BCustomerModel.class); energizerB2BCustomerModel.setRegistrationEmailFlag(Boolean.TRUE); } else { energizerB2BCustomerModel = (EnergizerB2BCustomerModel) userService.getUserForUID(customerData.getUid()); } if (null != customerData && null != energizerB2BCustomerModel) { energizerCustomerReversePopulator.populate(customerData, energizerB2BCustomerModel); companyB2BCommerceService.saveModel(energizerB2BCustomerModel); } }
/* * (non-Javadoc) * * @see de.hybris.platform.b2bacceleratorfacades.company.CompanyB2BCommerceFacade#getContactNumber(java.lang.String) */ @Override public String getContactNumber(final String uuid, final CustomerData customerData) { final EnergizerB2BCustomerModel model = userService.getUserForUID(uuid, EnergizerB2BCustomerModel.class); contactNumberPopulator.populate(model, customerData); return customerData.getContactNumber(); }
protected void setupAuthenticationHandler() { BDDMockito.doReturn(Boolean.FALSE) .when(authenticationSuccessHandler) .isAlwaysUseDefaultTargetUrl(); BDDMockito.doNothing().when(customerFacade).loginSuccess(); final CustomerData customer = BDDMockito.mock(CustomerData.class); BDDMockito.given(customer.getUid()).willReturn("customer"); BDDMockito.given(customerFacade.getCurrentCustomer()).willReturn(customer); BDDMockito.given(authenticationSuccessHandler.getCartFacade().getCartsForCurrentUser()) .willReturn(savedCarts); BDDMockito.given(cartFacade.hasSessionCart()).willReturn(Boolean.TRUE); BDDMockito.given(cartFacade.getSessionCart()).willReturn(sessionCart); BDDMockito.doNothing().when(bruteForceAttackCounter).resetUserCounter("customer"); }
@RequestMapping(value = "/update-email", method = RequestMethod.GET) @RequireHardLogIn public String editEmail(final Model model) throws CMSItemNotFoundException { final CustomerData customerData = customerFacade.getCurrentCustomer(); final UpdateEmailForm updateEmailForm = new UpdateEmailForm(); updateEmailForm.setEmail(customerData.getDisplayUid()); model.addAttribute("updateEmailForm", updateEmailForm); storeCmsPageInModel(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE)); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE)); model.addAttribute( "breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile")); model.addAttribute("metaRobots", "no-index,no-follow"); return ControllerConstants.Views.Pages.Account.AccountProfileEmailEditPage; }
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; }
@RequestMapping(value = "/profile", method = RequestMethod.GET) @RequireHardLogIn public String profile(final Model model) throws CMSItemNotFoundException { final List<TitleData> titles = userFacade.getTitles(); final CustomerData customerData = customerFacade.getCurrentCustomer(); if (customerData.getTitleCode() != null) { model.addAttribute("title", findTitleForCode(titles, customerData.getTitleCode())); } model.addAttribute("customerData", customerData); storeCmsPageInModel(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE)); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE)); model.addAttribute( "breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile")); model.addAttribute("metaRobots", "no-index,no-follow"); return ControllerConstants.Views.Pages.Account.AccountProfilePage; }
@Test public void testPopulateAll() { final CustomerData customerData = mock(CustomerData.class); final CustomerModel customerModel = new CustomerModel(); final CurrencyData currencyData = mock(CurrencyData.class); final LanguageData languageData = mock(LanguageData.class); final CurrencyModel currencyModel = mock(CurrencyModel.class); final LanguageModel languageModel = mock(LanguageModel.class); given(customerData.getFirstName()).willReturn("firstName"); given(customerData.getLastName()).willReturn("lastName"); given(customerData.getTitleCode()).willReturn(null); given(customerNameStrategy.getName("firstName", "lastName")).willReturn("firstName lastName"); given(customerData.getCurrency()).willReturn(currencyData); given(currencyData.getIsocode()).willReturn("USD"); given(currencyModel.getIsocode()).willReturn("USD"); given(commonI18NService.getCurrency("USD")).willReturn(currencyModel); given(customerData.getLanguage()).willReturn(languageData); given(languageData.getIsocode()).willReturn("en"); given(languageModel.getIsocode()).willReturn("en"); given(commonI18NService.getLanguage("en")).willReturn(languageModel); customerReversePopulator.populate(customerData, customerModel); Assert.assertEquals("firstName lastName", customerModel.getName()); Assert.assertNull(customerModel.getTitle()); Assert.assertEquals("USD", customerModel.getSessionCurrency().getIsocode()); Assert.assertEquals("en", customerModel.getSessionLanguage().getIsocode()); }
@RequestMapping(value = "/update-profile", method = RequestMethod.GET) @RequireHardLogIn public String editProfile(final Model model) throws CMSItemNotFoundException { model.addAttribute("titleData", userFacade.getTitles()); final CustomerData customerData = customerFacade.getCurrentCustomer(); final UpdateProfileForm updateProfileForm = new UpdateProfileForm(); updateProfileForm.setTitleCode(customerData.getTitleCode()); updateProfileForm.setFirstName(customerData.getFirstName()); updateProfileForm.setLastName(customerData.getLastName()); model.addAttribute("updateProfileForm", updateProfileForm); storeCmsPageInModel(model, getContentPageForLabelOrId(UPDATE_PROFILE_CMS_PAGE)); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(UPDATE_PROFILE_CMS_PAGE)); model.addAttribute( "breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile")); model.addAttribute("metaRobots", "noindex,nofollow"); return getViewForPage(model); }
@RequestMapping(value = "/update-profile", method = RequestMethod.POST) @RequireHardLogIn public String updateProfile( final UpdateProfileForm updateProfileForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException { getProfileValidator().validate(updateProfileForm, bindingResult); String returnAction = ControllerConstants.Views.Pages.Account.AccountProfileEditPage; final CustomerData currentCustomerData = customerFacade.getCurrentCustomer(); final CustomerData customerData = new CustomerData(); customerData.setTitleCode(updateProfileForm.getTitleCode()); customerData.setFirstName(updateProfileForm.getFirstName()); customerData.setLastName(updateProfileForm.getLastName()); customerData.setUid(currentCustomerData.getUid()); customerData.setDisplayUid(currentCustomerData.getDisplayUid()); model.addAttribute("titleData", userFacade.getTitles()); if (bindingResult.hasErrors()) { GlobalMessages.addErrorMessage(model, "form.global.error"); } else { try { customerFacade.updateProfile(customerData); GlobalMessages.addFlashMessage( redirectAttributes, GlobalMessages.CONF_MESSAGES_HOLDER, "text.account.profile.confirmationUpdated", null); returnAction = REDIRECT_TO_PROFILE_PAGE; } catch (final DuplicateUidException e) { bindingResult.rejectValue("email", "registration.error.account.exists.title"); GlobalMessages.addErrorMessage(model, "form.global.error"); } } storeCmsPageInModel(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE)); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE)); model.addAttribute( "breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile")); return returnAction; }
/** As per enhancement added new group b2bviewergroup */ public void populateRolesByCustomer(final String uuid, final CustomerData target) { final List<String> roles = new ArrayList<String>(); final EnergizerB2BCustomerModel model = userService.getUserForUID(uuid, EnergizerB2BCustomerModel.class); final Set<PrincipalGroupModel> roleModels = new HashSet<PrincipalGroupModel>(model.getGroups()); CollectionUtils.filter( roleModels, PredicateUtils.notPredicate(PredicateUtils.instanceofPredicate(B2BUnitModel.class))); CollectionUtils.filter( roleModels, PredicateUtils.notPredicate(PredicateUtils.instanceofPredicate(B2BUserGroupModel.class))); for (final PrincipalGroupModel role : roleModels) { // only display allowed usergroups if (energizerGroupsLookUpStrategy.getUserGroups().contains(role.getUid())) { roles.add(role.getUid()); } } target.setRoles(roles); }
/* * (non-Javadoc) * * @see * com.energizer.facades.accounts.EnergizerCompanyB2BCommerceFacade#updateProfile(de.hybris.platform.commercefacades * .user.data.CustomerData) */ @SuppressWarnings("deprecation") @Override public void updateProfile(final CustomerData customerData) { try { validateDataBeforeUpdate(customerData); final String name = getCustomerNameStrategy() .getName(customerData.getFirstName(), customerData.getLastName()); final EnergizerB2BCustomerModel customer = (EnergizerB2BCustomerModel) getCurrentSessionCustomer(); customer.setOriginalUid(customerData.getDisplayUid()); customer.setContactNumber(customerData.getContactNumber()); customerAccountService.updateProfile( customer, customerData.getTitleCode(), name, customerData.getUid()); getModelService().save(customer); } catch (final DuplicateUidException e) { e.printStackTrace(); } }
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; }
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())); }