Example usage for com.liferay.portal.kernel.util StringPool COMMA

List of usage examples for com.liferay.portal.kernel.util StringPool COMMA

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringPool COMMA.

Prototype

String COMMA

To view the source code for com.liferay.portal.kernel.util StringPool COMMA.

Click Source Link

Usage

From source file:com.stoxx.portlet.controller.RegistrationController.java

/**
 * @param registrationBean/*from w ww.  j a v a2  s. c o  m*/
 * @param themeDisplay
 * @param liferayStoxxUser
 * @throws SystemException
 * @throws PortalException
 * @throws STOXXException
 */
private RegistrationBean populateFields(RegistrationBean registrationBean, ThemeDisplay themeDisplay,
        User liferayStoxxUser) throws SystemException, PortalException, STOXXException {
    registrationBean.setFirstName(liferayStoxxUser.getFirstName());
    registrationBean.setLastName(liferayStoxxUser.getLastName());
    registrationBean.setJobTitle(liferayStoxxUser.getJobTitle());
    registrationBean.setCity(liferayStoxxUser.getAddresses().get(0).getCity());
    registrationBean.setCountryId(liferayStoxxUser.getAddresses().get(0).getCountryId());
    Map<String, Integer> titleList = STOXXUtil.getTitleList();
    registrationBean.setTitleList(titleList);
    String gender = LanguageUtil.get(themeDisplay.getLocale(), "stoxx-registration-female");
    if (liferayStoxxUser.isMale()) {
        gender = LanguageUtil.get(themeDisplay.getLocale(), "stoxx-registration-male");
    }
    registrationBean.setGender(gender);
    Date dateToConvert = liferayStoxxUser.getBirthday();
    String dateOfBirth = STOXXDateUtil.convertDateToStringInStoxxApplicationDateFormat(dateToConvert);
    String defaultBitrhday = PropsUtil.get("stoxx-registration-default-date-of-birthday");
    if (StringUtils.isNotBlank(defaultBitrhday)) {
        defaultBitrhday = defaultBitrhday.replace(StringPool.COMMA, StringPool.COMMA + StringPool.SPACE);
    }
    if (StringUtils.isNotBlank(dateOfBirth)) {
        if (defaultBitrhday.equalsIgnoreCase(dateOfBirth.trim())) {
            dateOfBirth = StringPool.BLANK;
        } else {
            registrationBean.setDateOfBirth(dateOfBirth);
        }
    } else {
        dateOfBirth = StringPool.BLANK;
    }
    log.info("The date of birth is >>>>>>>>" + dateOfBirth);
    registrationBean.setDateOfBirth(dateOfBirth);
    if (StringUtils.isNotBlank(dateOfBirth)) {
        registrationBean.setDateOfBirth(dateOfBirth);
    }
    if (Validator.isNotNull(registrationBean) && Validator.isNotNull(registrationBean.isEmailContactPref())) {
        registrationBean.setEmailContactPref(registrationBean.isEmailContactPref());
    }
    liferayStoxxUser.getAddresses().get(0).getCountry().getName(themeDisplay.getLocale());
    registrationBean.setPhoneNumber(liferayStoxxUser.getPhones().get(0).getNumber());
    registrationBean.setUserZipCode(liferayStoxxUser.getAddresses().get(0).getZip());
    registrationBean.setUserAddress(liferayStoxxUser.getAddresses().get(0).getStreet1());
    registrationBean.setUserAddress1(liferayStoxxUser.getAddresses().get(0).getStreet2());
    return registrationBean;
}

From source file:com.stoxx.portlet.datatransformer.PreRegCustomerRegistrationTransformer.java

public static SalesEntryEditVO convertToSalesEntryEditVO(SalesEntry salesEntry) {
    SalesEntryEditVO salesEntryEditVO = new SalesEntryEditVO();
    salesEntryEditVO.setSalesEntryId(salesEntry.getSalesEntryId());
    salesEntryEditVO.setCompanyName(salesEntry.getCompanyName());
    salesEntryEditVO.setGroupName(salesEntry.getGroupName());
    salesEntryEditVO.setProfile(salesEntry.getProfile());
    salesEntryEditVO.setPackages(ListUtil.fromString(salesEntry.getPackageNames(), StringPool.COMMA));
    try {/*  w  w  w  .  j av  a 2s . com*/
        salesEntryEditVO.setLicenseStartDate(
                STOXXDateUtil.convertDateToStringInStoxxApplicationDateFormat(salesEntry.getStartDate()));
    } catch (Exception e1) {
        log.error(e1.getMessage());
    }
    try {
        salesEntryEditVO.setLicenseEndDate(
                STOXXDateUtil.convertDateToStringInStoxxApplicationDateFormat(salesEntry.getEndDate()));
    } catch (Exception e1) {
        log.error(e1.getMessage());
    }

    salesEntryEditVO.setCountryId(salesEntry.getCountryId());
    if (salesEntry.getCountryId() > 0) {
        try {
            salesEntryEditVO.setCountryName(
                    CountryServiceUtil.getCountry(salesEntry.getCountryId()).getNameCurrentValue());
        } catch (PortalException e) {
            log.error(e.getMessage());
        } catch (SystemException e) {
            log.error(e.getMessage());
        }
    }
    salesEntryEditVO.setUsersAllowed(salesEntry.getUsersAllowed());
    salesEntryEditVO.setKeyAccountHolderEmailAddress(salesEntry.getKeyEmailAddress());
    return salesEntryEditVO;
}

From source file:com.stoxx.portlet.manageusers.controller.ManageUsersController.java

@RenderMapping(params = "action=savePackageNames")
public String savePackageNamesToCompany(@ModelAttribute(MANAGEUSERSBEAN) ManageUsersBean manageUsersBean,
        RenderRequest renderRequest, RenderResponse renderResponse, Model model) {
    log.info("Inside savePackageNamesToCompany  method>>>> ");
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    try {//from  w w  w. j a  va 2s  .c o  m
        log.info("The added packages are" + manageUsersBean.getAddedPackageNames());
        log.info("The deleted packages are" + manageUsersBean.getDeletedPackageNames());
        log.info("The sales entry id is" + manageUsersBean.getSalesEntryID());
        log.info("The updated packages are" + manageUsersBean.getNewPackageNames());
        List<String> newPackagesSubscribedList = new ArrayList<String>();
        List<String> alreadyPackagesSubscribedList = new ArrayList<String>();
        List<String> deletedUnscribedPackageNamesList = new ArrayList<String>();
        deletedUnscribedPackageNamesList = deleteUnscribedList(manageUsersBean,
                deletedUnscribedPackageNamesList);
        log.info("The deletedUnscribedPackageNamesList is" + deletedUnscribedPackageNamesList);
        newPackagesSubscribedList = getSubscribedPackages(manageUsersBean, newPackagesSubscribedList);
        log.info("The company name is " + manageUsersBean.getCompanyName());
        manageUsersBean.setAllPackageNames(manageUsersBean.getAllPackageNames());
        manageUsersBean.setCompanyName(manageUsersBean.getCompanyName());
        manageUsersBean.setPackagesSubscribedByCommaSeperation(
                manageUsersBean.getPackagesSubscribedByCommaSeperation());
        DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(SalesEntry.class,
                PortalClassLoaderUtil.getClassLoader());
        Criterion criterion = RestrictionsFactoryUtil.eq("companyName", manageUsersBean.getCompanyName());
        dynamicQuery.add(criterion);
        List<SalesEntry> salesEntryList = null;
        List<Long> liferrayUserIDsForCustomer = new ArrayList<Long>();
        salesEntryList = SalesEntryLocalServiceUtil.dynamicQuery(dynamicQuery);

        if (Validator.isNotNull(salesEntryList) && salesEntryList.size() > 0) {
            SalesEntry salesEntry = salesEntryList.get(0);
            if (!Validator.isBlank(salesEntry.getPackageNames())) {
                if (salesEntry.getPackageNames().contains(StringPool.COMMA)) {
                    alreadyPackagesSubscribedList = Arrays.asList(salesEntry.getPackageNames().split(","));
                } else {
                    alreadyPackagesSubscribedList.add(salesEntry.getPackageNames());
                }
            }
            salesEntry.setPackageNames(manageUsersBean.getNewPackageNames());
            SalesEntryLocalServiceUtil.updateSalesEntry(salesEntry);
            List<String> customerEmaiAddressList = userProfileService
                    .getLicensedUsersEmailAddress(manageUsersBean.getSalesEntryID());
            if (Validator.isNotNull(customerEmaiAddressList) && customerEmaiAddressList.size() > 0) {
                for (String emailAddress : customerEmaiAddressList) {
                    User user = UserLocalServiceUtil.fetchUserByEmailAddress(themeDisplay.getCompanyId(),
                            emailAddress);
                    if (Validator.isNotNull(user)) {
                        liferrayUserIDsForCustomer.add(user.getUserId());
                    }
                }
            }
            log.info("The new packagesSubscribedList is" + newPackagesSubscribedList);
            log.info("The already packagesSubscribedList is" + alreadyPackagesSubscribedList);
            log.info("The deletedUnscribedPackageNamesList is" + deletedUnscribedPackageNamesList);
            log.info("The no of users under this group is" + liferrayUserIDsForCustomer.size());
            addRole(themeDisplay, newPackagesSubscribedList, alreadyPackagesSubscribedList,
                    liferrayUserIDsForCustomer);
            removeRoles(themeDisplay, deletedUnscribedPackageNamesList, liferrayUserIDsForCustomer);
            SessionMessages.add(renderRequest, "packages-subscribed");
        }
    } catch (Exception e) {
        log.error(SYSTEM_EXCEPTION + e);
    } finally {
        List<String> allPackageNames;
        try {
            allPackageNames = manageUsersDeligate.getDistinctPackageNames();
            String packagesSubscribed = manageUsersDeligate
                    .getSubscibedpackagesForCompany(manageUsersBean.getCompanyName());
            manageUsersBean.setAllPackageNames(allPackageNames);
            manageUsersBean.setPackagesSubscribedByCommaSeperation(packagesSubscribed);
            model.addAttribute("manageUserVO", manageUsersBean);
        } catch (STOXXException e) {
            log.error(e.getMessage(), e);
        }
    }
    return SHOW_PACKAGES_SUBSCRIBED;

}

From source file:com.stoxx.portlet.manageusers.controller.ManageUsersController.java

/**
 * @param manageUsersBean// w  w w.j  av a  2s  .  c  om
 * @param deletedUnscribedPackageNamesList
 * @return
 */
private List<String> deleteUnscribedList(ManageUsersBean manageUsersBean,
        List<String> deletedUnscribedPackageNamesList) {
    if (Validator.isNotNull(manageUsersBean.getDeletedPackageNames())
            && !manageUsersBean.getDeletedPackageNames().isEmpty()) {
        if (manageUsersBean.getDeletedPackageNames().contains(StringPool.COMMA)) {
            deletedUnscribedPackageNamesList = Arrays
                    .asList(manageUsersBean.getDeletedPackageNames().split(","));
        } else {
            deletedUnscribedPackageNamesList.add(manageUsersBean.getDeletedPackageNames());
        }
    }
    return deletedUnscribedPackageNamesList;
}

From source file:com.stoxx.portlet.manageusers.controller.ManageUsersController.java

/**
 * @param manageUsersBean/*from  w w w .  ja v  a  2s.co  m*/
 * @param newPackagesSubscribedList
 * @return
 */
private List<String> getSubscribedPackages(ManageUsersBean manageUsersBean,
        List<String> newPackagesSubscribedList) {
    if (Validator.isNotNull(manageUsersBean.getAddedPackageNames())
            && !manageUsersBean.getAddedPackageNames().isEmpty()) {
        if (manageUsersBean.getAddedPackageNames().contains(StringPool.COMMA)) {
            newPackagesSubscribedList = Arrays.asList(manageUsersBean.getAddedPackageNames().split(","));
        } else {
            newPackagesSubscribedList.add(manageUsersBean.getAddedPackageNames());
        }
    }
    return newPackagesSubscribedList;
}

From source file:com.stoxx.portlet.manageusers.controller.ManageUsersController.java

/**
 * @param userModel//  www.j a va  2s. co  m
 * @param assignedUnsetUserRoleNames
 * @return
 */
private List<String> unsetRoles(UserModel userModel, List<String> assignedUnsetUserRoleNames) {
    if (Validator.isNotNull(userModel.getDeletedRoles()) && !userModel.getDeletedRoles().isEmpty()) {
        if (userModel.getDeletedRoles().contains(StringPool.COMMA)) {
            assignedUnsetUserRoleNames = Arrays.asList(userModel.getDeletedRoles().split(","));
        } else {
            assignedUnsetUserRoleNames.add(userModel.getDeletedRoles());
        }
    }
    return assignedUnsetUserRoleNames;
}

From source file:com.stoxx.portlet.manageusers.controller.ManageUsersController.java

/**
 * @param userModel/*from  ww w .  j  ava  2  s. c o m*/
 * @param assignedUserRoleNames
 * @return
 */
private List<String> assignRoles(UserModel userModel, List<String> assignedUserRoleNames) {
    if (Validator.isNotNull(userModel.getAddedRoles()) && !userModel.getAddedRoles().isEmpty()) {
        if (userModel.getAddedRoles().contains(StringPool.COMMA)) {
            assignedUserRoleNames = Arrays.asList(userModel.getAddedRoles().split(","));
        } else {
            assignedUserRoleNames.add(userModel.getAddedRoles());
        }
    }
    return assignedUserRoleNames;
}

From source file:com.stoxx.portlet.preregcustomeradmin.delegate.CustomerAdminDelegate.java

private void processEmailAddress(ThemeDisplay themeDisplay, Map<String, List<String>> resultMap,
        long salesEntryId, String companyName, String emailAddress, UserProfileDetails userProfileDetail,
        boolean isKeyAccountHolder, List<Long> roleIdsToRemove, List<Long> roleIdsToAdd)
        throws STOXXException, SystemException, PortalException {
    log.info("Processing email address:" + emailAddress);
    long companyId = themeDisplay.getCompanyId();
    if (Validator.isNotNull(emailAddress)) {
        emailAddress = StringUtil.toLowerCase(emailAddress);
        if (userProfileDetail == null) {
            log.info("Creating new user as customer with email:" + emailAddress);
            boolean userCreationSuccess = createNewCustomer(themeDisplay, emailAddress, salesEntryId,
                    companyName, isKeyAccountHolder);
            if (!userCreationSuccess) {
                addToSkippedEmails(resultMap, emailAddress);
            } else if (isKeyAccountHolder) {
                try {
                    SalesEntryLocalServiceUtil.updateKeyAccountHolderEmail(salesEntryId, emailAddress);
                } catch (NoSuchSalesEntryException e) {
                    log.error("Sales entry not found with id " + salesEntryId
                            + " while updating key account holder");
                }//from  www .  ja  v  a2  s.  c o m
            }
        } else if (Validator.equals(userProfileDetail.getStatus(), Integer.valueOf(4))) {
            boolean deletedUserHandled = handleDeletedUser(userProfileDetail, salesEntryId, companyName,
                    themeDisplay, isKeyAccountHolder);
            if (!deletedUserHandled) {
                addToSkippedEmails(resultMap, emailAddress);
            } else if (isKeyAccountHolder) {
                try {
                    SalesEntryLocalServiceUtil.updateKeyAccountHolderEmail(salesEntryId, emailAddress);
                } catch (NoSuchSalesEntryException e) {
                    log.error("Sales entry not found with id " + salesEntryId
                            + " while updating key account holder");
                }
            }
        } else if (STOXXConstants.STOXX_GENERAL_USER.equals(userProfileDetail.getUserType())) {
            boolean userTypeChangeSuccess = changeGeneralUserToCustomer(userProfileDetail, salesEntryId,
                    themeDisplay);
            if (userTypeChangeSuccess) {
                List<Long> roleIdList = new ArrayList<Long>();
                SalesEntry salesEntry = SalesEntryLocalServiceUtil.getSalesEntry(salesEntryId);
                if (Validator.isNotNull(salesEntry)) {
                    String packageNames = salesEntry.getPackageNames();
                    String[] roleNames = StringUtils.split(packageNames, StringPool.COMMA);
                    if (ArrayUtils.isNotEmpty(roleNames)) {
                        for (String role : roleNames) {
                            Role liferayRole = RoleLocalServiceUtil.fetchRole(companyId, role.trim());
                            if (Validator.isNotNull(liferayRole)) {
                                roleIdList.add(liferayRole.getRoleId());
                            }
                        }
                    }
                }
                if (Validator.isNotNull(roleIdList) && roleIdList.size() > 0) {
                    roleIdsToAdd = new ArrayList<Long>();
                    roleIdsToAdd.addAll(roleIdList);
                }
                updateRoleAssignments(themeDisplay, roleIdsToRemove, roleIdsToAdd,
                        userProfileDetail.getEmailAddress());
                if (isKeyAccountHolder) {
                    log.info("Updating sales entry with KAH=" + emailAddress);
                    try {
                        SalesEntryLocalServiceUtil.updateKeyAccountHolderEmail(salesEntryId, emailAddress);
                        try {
                            User existingKAHUser = UserLocalServiceUtil
                                    .getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);
                            Role gatewayUserRole = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(),
                                    STOXX_KEY_ACCOUNT_HOLDER_ROLE);
                            RoleLocalServiceUtil.addUserRole(existingKAHUser.getUserId(), gatewayUserRole);
                        } catch (NoSuchUserException ex) {
                            log.error("Key acount holder not yet registered. " + ex.getMessage());
                        } catch (PortalException ex) {
                            log.error("PortalException while adding key account holder role to user.", ex);
                        }
                    } catch (NoSuchSalesEntryException e) {
                        log.error("Sales entry not found with id " + salesEntryId
                                + " while updating key account holder");
                    }
                }
            } else {
                log.info("Adding emailAddress '" + emailAddress
                        + "' to skipped list because unable to convert it to customer.");
                addToSkippedEmails(resultMap, emailAddress);
            }

        } else if (STOXXConstants.STOXX_STAFF_USER.equals(userProfileDetail.getUserType())) {
            log.info("Skipping emailaddress '" + emailAddress + "' as it is staff in system.");
            addToSkippedEmails(resultMap, emailAddress);
        } else if (STOXXConstants.STOXX_VENDOR_USER.equals(userProfileDetail.getUserType())) {
            log.info("Skipping emailaddress '" + emailAddress + "' as it is vendor in system.");
            addToSkippedEmails(resultMap, emailAddress);
        } else if (GetterUtil.getLong(userProfileDetail.getSalesEntryId()) != salesEntryId) {
            log.info("Skipping emailaddress '" + emailAddress
                    + "' as it is customer for another sales entry id:" + userProfileDetail.getSalesEntryId());
            addToSkippedEmails(resultMap, emailAddress);
        } else if (Validator.isNotNull(userProfileDetail.getSalesEntryId())
                && STOXXConstants.STOXX_REGISTERED_USER.equalsIgnoreCase(userProfileDetail.getUserType())
                && GetterUtil.getLong(userProfileDetail.getSalesEntryId()) == salesEntryId) {
            SalesEntry salesEntry = SalesEntryLocalServiceUtil
                    .getSalesEntry(userProfileDetail.getSalesEntryId());
            log.info("salesEntry Id latest   is    >>> " + salesEntry.getSalesEntryId());
            boolean isKeyAccountRole = Boolean.FALSE;
            String keyEmailAddress = salesEntry.getKeyEmailAddress();
            log.info("salesEntry Id latest   is    >>> " + keyEmailAddress + " and the emailAddress is "
                    + emailAddress);
            if (StringUtils.isNotBlank(keyEmailAddress) && keyEmailAddress.equalsIgnoreCase(emailAddress)) {
                isKeyAccountRole = Boolean.TRUE;
            }
            log.info("from front end isKeyAccountRole is >>> " + isKeyAccountRole
                    + " and from back end isKeyAccountRole >>> " + isKeyAccountRole);

            if ((isKeyAccountHolder && isKeyAccountRole) || (!isKeyAccountHolder && !isKeyAccountRole)) {
                log.info("Skipping emailaddress '" + emailAddress
                        + "' as it is customer for another sales entry id:"
                        + userProfileDetail.getSalesEntryId());
                addToSkippedEmails(resultMap, emailAddress);

            }
        }
    }
}

From source file:com.stoxx.portlet.preregcustomeradmin.delegate.CustomerAdminDelegate.java

public Map<String, List<String>> updateSalesEntry(SalesEntryEditVO salesEntryEditVO, ThemeDisplay themeDisplay)
        throws STOXXException, PortalException, SystemException {
    Map<String, List<String>> resultMap = initiateResultMap();

    SalesEntry existingSalesEntry = SalesEntryLocalServiceUtil
            .getSalesEntry(salesEntryEditVO.getSalesEntryId());
    String newKAHEmailAddress = salesEntryEditVO.getKeyAccountHolderEmailAddress();
    String existingKAHEmailAddress = existingSalesEntry.getKeyEmailAddress();
    List<String> existingPagkageList = ListUtil.fromString(existingSalesEntry.getPackageNames(),
            StringPool.COMMA);
    long salesEntryId = existingSalesEntry.getSalesEntryId();
    if (Validator.isNotNull(newKAHEmailAddress)
            && !newKAHEmailAddress.equalsIgnoreCase(existingKAHEmailAddress)) {
        UserProfileDetails userProfileDetails = getUserProfileDetail(newKAHEmailAddress);
        if (userProfileDetails == null) {
            processEmailAddress(themeDisplay, resultMap, salesEntryId, salesEntryEditVO.getCompanyName(),
                    newKAHEmailAddress, null, true, null, null);
        } else {//ww w  .j  a  v  a  2  s.com
            if (STOXXConstants.STOXX_STAFF_USER.equals(userProfileDetails.getUserType())) {
                throw new STOXXException("KAHIsStaff",
                        "Key account holder staff, can't become key account holder");
            } else if (STOXXConstants.STOXX_VENDOR_USER.equals(userProfileDetails.getUserType())) {
                throw new STOXXException("KAHIsVendor",
                        "Key account holder vendor, can't become key account holder");
            } else if (userProfileDetails.getSalesEntryId() != null
                    && userProfileDetails.getSalesEntryId() != salesEntryId) {
                throw new STOXXException("KAHInAnotherSE",
                        "Key account holder already member of another sales entry.");
            } else if (Validator.equals(userProfileDetails.getStatus(), Integer.valueOf(4))) {
                processEmailAddress(themeDisplay, resultMap, salesEntryId, salesEntryEditVO.getCompanyName(),
                        newKAHEmailAddress, userProfileDetails, true, null, null);
            }
        }
    }
    List<String> domains = salesEntryEditVO.getDomains();
    if (domains == null) {
        domains = new ArrayList<String>(0);
    }

    boolean isDomainLicense = !isEmptyStringList(domains);

    Date startDate = STOXXDateUtil.convertStringToUtilDate(salesEntryEditVO.getLicenseStartDate());
    Date endDate = STOXXDateUtil.convertStringToUtilDate(salesEntryEditVO.getLicenseEndDate());
    SalesEntry updatedSalesEntry = SalesEntryLocalServiceUtil.updateSalesEntry(salesEntryId,
            salesEntryEditVO.getCompanyName(), salesEntryEditVO.getProfile(), salesEntryEditVO.getPackages(),
            startDate, endDate, salesEntryEditVO.getCountryId(), salesEntryEditVO.getUsersAllowed() > 0,
            salesEntryEditVO.getUsersAllowed(), newKAHEmailAddress, isDomainLicense);
    log.info("Sales entry id " + salesEntryId + "updated successfully!");
    Role keyAccountHolderRole = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(),
            STOXX_KEY_ACCOUNT_HOLDER_ROLE);
    if (Validator.isNotNull(existingKAHEmailAddress)) {
        try {
            User existingKAHUser = UserLocalServiceUtil.getUserByEmailAddress(themeDisplay.getCompanyId(),
                    existingKAHEmailAddress);
            RoleLocalServiceUtil.deleteUserRole(existingKAHUser.getUserId(), keyAccountHolderRole.getRoleId());
            log.info("Deleted key account holder role mapping with user " + existingKAHEmailAddress);
        } catch (NoSuchUserException ex) {
            log.error("Unable to remove key account holder role mapping for user. " + ex.getMessage());
        }
    }
    if (Validator.isNotNull(newKAHEmailAddress)) {
        try {
            User newKAHUser = UserLocalServiceUtil.getUserByEmailAddress(themeDisplay.getCompanyId(),
                    newKAHEmailAddress);
            RoleLocalServiceUtil.addUserRole(newKAHUser.getUserId(), keyAccountHolderRole.getRoleId());
            log.info("Added key account holder role mapping with user " + newKAHEmailAddress);
        } catch (NoSuchUserException ex) {
            log.debug("Key account holder not yet registered.");
        }
    }

    List<String> newPackageList = ListUtil.fromString(updatedSalesEntry.getPackageNames(), StringPool.COMMA);
    for (Iterator<String> iter = existingPagkageList.iterator(); iter.hasNext();) {
        String existingPackageName = iter.next();
        if (newPackageList.contains(existingPackageName)) {
            iter.remove();
        }
    }
    List<Long> roleIdsToRemove = getRoleIdsList(themeDisplay, existingPagkageList);
    List<Long> roleIdsToAdd = getRoleIdsList(themeDisplay, newPackageList);

    List<UserProfileDetails> existingUserProfiles = userProfileService.getLicensedUsers(salesEntryId);
    for (UserProfileDetails userProfileDetails : existingUserProfiles) {
        updateRoleAssignments(themeDisplay, roleIdsToRemove, roleIdsToAdd,
                userProfileDetails.getEmailAddress());
    }

    List<String> newEmailAddresses = salesEntryEditVO.getNewEmailAddresses();
    if (newEmailAddresses != null) {
        for (String emailAddress : newEmailAddresses) {
            if (Validator.isNotNull(emailAddress)) {
                processCustomerEmailAddress(themeDisplay, resultMap, updatedSalesEntry.getSalesEntryId(),
                        updatedSalesEntry.getCompanyName(), emailAddress, roleIdsToRemove, roleIdsToAdd);
            }
        }
    }
    List<EmailDomain> existingDomains = EmailDomainLocalServiceUtil.getEmailDomains(salesEntryId);
    for (String domain : domains) {
        if (Validator.isNotNull(domain)) {
            processDomain(resultMap, salesEntryId, domain);
        }
    }
    if (existingDomains != null) {
        for (EmailDomain existingEmailDomain : existingDomains) {
            String existingDomain = existingEmailDomain.getDomain();
            if (!domains.contains(existingDomain)) {
                log.info("Processing deletion of domain " + existingDomain);
                List<UserProfileDetails> domainUsers = userProfileService.getLicensedUsersOfDomain(salesEntryId,
                        existingDomain);
                if (domainUsers != null) {
                    log.info("Removing " + domainUsers.size() + " users of domain " + existingDomain);
                    for (UserProfileDetails userProfileToDelete : domainUsers) {
                        deleteUser(userProfileToDelete, themeDisplay);
                    }
                }
                log.info("Deleting existing domain " + existingEmailDomain.getEmailDomainId() + existingDomain);
                EmailDomainLocalServiceUtil.deleteEmailDomain(existingEmailDomain.getEmailDomainId());
            }
        }
    }

    return resultMap;
}

From source file:com.stoxx.service.business.registration.RegistrationServiceImpl.java

private void assignRolesForReRegisteredUser(UserProfileDetails userProfileDetails, ThemeDisplay themeDisplay,
        ServiceContext serviceContext, TranslatorAgency translatorAgency, User user) throws STOXXException {
    try {/*from  w  w w.  j  a va  2s .  co  m*/
        if (userProfileDetails.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_REGISTERED_USER)) {
            if (null != userProfileDetails.getSalesEntryId()) {

                List<Long> roleList = new ArrayList<Long>();
                Long salesEntryID = userProfileDetails.getSalesEntryId();
                SalesEntry salesEntry = SalesEntryLocalServiceUtil.getSalesEntry(salesEntryID);
                if (!(salesEntry.getPackageNames().contains(StringPool.COMMA))) {
                    Role packageRole = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(),
                            salesEntry.getPackageNames().trim());
                    long packageRoleId = packageRole.getRoleId();
                    roleList.add(packageRoleId);
                } else {
                    for (String packageName : salesEntry.getPackageNames().split(StringPool.COMMA)) {
                        Role packageRole = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(),
                                packageName.trim());
                        long packageRoleId = packageRole.getRoleId();
                        roleList.add(packageRoleId);
                    }
                }

                if (StringUtils.isNotBlank(salesEntry.getKeyEmailAddress()) && salesEntry.getKeyEmailAddress()
                        .trim().equalsIgnoreCase(userProfileDetails.getEmailAddress())) {
                    if (isLicensedUser(userProfileDetails.getEmailAddress())) {
                        Role keyAccntHolderUserRole = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(),
                                STOXXConstants.STOXX_KEY_ACCOUNT_HOLDER_ROLE);
                        long roleKeyAccntHolder = keyAccntHolderUserRole.getRoleId();
                        roleList.add(roleKeyAccntHolder);
                    }
                }

                long roleLicensed[] = ArrayUtils.toPrimitive(roleList.toArray(new Long[roleList.size()]));
                RoleLocalServiceUtil.addUserRoles(user.getUserId(), roleLicensed);
            }
        } else if (userProfileDetails.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_VENDOR_USER)) {
            if (translatorAgency != null) {

                StringBuilder userGroupNameTemp = new StringBuilder();
                String userGroupName = StringPool.BLANK;
                List<Long> translatorRoles = null;
                if (translatorAgency.getCompanyName().trim().contains(StringPool.SPACE)) {

                    for (String word : translatorAgency.getCompanyName().trim().split(StringPool.SPACE)) {
                        userGroupNameTemp.append(word).append(StringPool.UNDERLINE);
                    }
                    userGroupName = userGroupNameTemp.substring(0, userGroupNameTemp.length() - 1);
                    translatorRoles = assignTranslatorRole(userGroupName, translatorAgency, themeDisplay);
                } else {
                    userGroupName = translatorAgency.getCompanyName().trim();
                    translatorRoles = assignTranslatorRole(userGroupName, translatorAgency, themeDisplay);
                }
                UserGroup translatorGroup = UserGroupLocalServiceUtil.getUserGroup(themeDisplay.getCompanyId(),
                        userGroupName);
                long translatorGroupId[] = { translatorGroup.getUserGroupId() };
                long translatorRoleId[] = ArrayUtils
                        .toPrimitive(translatorRoles.toArray(new Long[translatorRoles.size()]));
                if (translatorAgency.getAgencyManagerEmailId()
                        .equalsIgnoreCase(userProfileDetails.getEmailAddress())) {
                    RoleLocalServiceUtil.addUserRoles(user.getUserId(), translatorRoleId);
                    UserGroupLocalServiceUtil.addUserUserGroups(user.getUserId(),
                            UserGroupLocalServiceUtil.getUserGroups(translatorGroupId));
                }

            }
        }

        Role powerUserRole = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(),
                RoleConstants.POWER_USER);
        if (Validator.isNotNull(powerUserRole)) {
            long rolePower[] = { powerUserRole.getRoleId() };
            if (Validator.isNotNull(user) && rolePower.length > 0) {
                RoleLocalServiceUtil.unsetUserRoles(user.getUserId(), rolePower);
            }
        }
    } catch (PortalException e) {
        logger.error(e.getMessage(), e);
        throw new STOXXException(e.getMessage(), e);
    } catch (SystemException e) {
        logger.error(e.getMessage(), e);
        throw new STOXXException(e.getMessage(), e);
    }

}