Example usage for com.liferay.portal.kernel.util ListUtil fromString

List of usage examples for com.liferay.portal.kernel.util ListUtil fromString

Introduction

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

Prototype

public static List<String> fromString(String s, String delimiter) 

Source Link

Usage

From source file:com.liferay.expando.taglib.servlet.taglib.CustomAttributesAvailableTag.java

License:Open Source License

@Override
public int doStartTag() throws JspException {
    try {/*from  ww  w .  ja  v a2 s  . c  o  m*/
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

        long companyId = _companyId;

        if (companyId == 0) {
            companyId = themeDisplay.getCompanyId();
        }

        ExpandoBridge expandoBridge = null;

        if (_classPK == 0) {
            expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(companyId, _className);
        } else {
            expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(companyId, _className, _classPK);
        }

        List<String> attributeNames = ListUtil.remove(Collections.list(expandoBridge.getAttributeNames()),
                ListUtil.fromString(_ignoreAttributeNames, StringPool.COMMA));

        if (attributeNames.isEmpty()) {
            return SKIP_BODY;
        }

        if (_classPK == 0) {
            return EVAL_BODY_INCLUDE;
        }

        PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

        for (String attributeName : attributeNames) {
            Serializable value = expandoBridge.getAttribute(attributeName);

            if (Validator.isNull(value)) {
                continue;
            }

            UnicodeProperties properties = expandoBridge.getAttributeProperties(attributeName);

            boolean propertyHidden = GetterUtil
                    .getBoolean(properties.get(ExpandoColumnConstants.PROPERTY_HIDDEN));
            boolean propertyVisibleWithUpdatePermission = GetterUtil
                    .getBoolean(properties.get(ExpandoColumnConstants.PROPERTY_VISIBLE_WITH_UPDATE_PERMISSION));

            if (_editable && propertyVisibleWithUpdatePermission) {
                if (ExpandoColumnPermissionUtil.contains(permissionChecker, companyId, _className,
                        ExpandoTableConstants.DEFAULT_TABLE_NAME, attributeName, ActionKeys.UPDATE)) {

                    propertyHidden = false;
                } else {
                    propertyHidden = true;
                }
            }

            if (!propertyHidden && ExpandoColumnPermissionUtil.contains(permissionChecker, companyId,
                    _className, ExpandoTableConstants.DEFAULT_TABLE_NAME, attributeName, ActionKeys.VIEW)) {

                return EVAL_BODY_INCLUDE;
            }
        }

        return SKIP_BODY;
    } catch (Exception e) {
        throw new JspException(e);
    } finally {
        if (!ServerDetector.isResin()) {
            _className = null;
            _classPK = 0;
            _companyId = 0;
            _editable = false;
            _ignoreAttributeNames = null;
        }
    }
}

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java

License:Open Source License

protected List<String> getPropertyList(String key) {
    return ListUtil.fromString(GetterUtil.getString(getProperty(key)), StringPool.COMMA);
}

From source file:com.liferay.tools.sourceformatter.PropertiesSourceProcessor.java

License:Open Source License

protected void formatSourceFormatterProperties(String fileName, String content) throws Exception {

    String path = StringPool.BLANK;

    int pos = fileName.lastIndexOf(StringPool.SLASH);

    if (pos != -1) {
        path = fileName.substring(0, pos + 1);
    }//from   ww  w.  j a va2s. c  o m

    Properties properties = new Properties();

    InputStream inputStream = new FileInputStream(fileName);

    properties.load(inputStream);

    Enumeration<String> enu = (Enumeration<String>) properties.propertyNames();

    while (enu.hasMoreElements()) {
        String key = enu.nextElement();

        if (!key.endsWith("excludes.files")) {
            continue;
        }

        String value = properties.getProperty(key);

        if (Validator.isNull(value)) {
            continue;
        }

        List<String> propertyFileNames = ListUtil.fromString(value, StringPool.COMMA);

        for (String propertyFileName : propertyFileNames) {
            pos = propertyFileName.indexOf(StringPool.AT);

            if (pos != -1) {
                propertyFileName = propertyFileName.substring(0, pos);
            }

            if (!fileUtil.exists(path + propertyFileName)) {
                processErrorMessage(fileName, "Incorrect property value: " + propertyFileName + " " + fileName);
            }
        }
    }
}

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 {/*from w w w  .  j  av  a 2  s  . co m*/
        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.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);/*  w  w  w .  j  a  v  a  2s. c o m*/
    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 {
            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;
}