Example usage for com.liferay.portal.kernel.util ArrayUtil isNotEmpty

List of usage examples for com.liferay.portal.kernel.util ArrayUtil isNotEmpty

Introduction

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

Prototype

public static boolean isNotEmpty(short[] array) 

Source Link

Usage

From source file:com.cd.learning.hook.MBUtil.java

License:Open Source License

public static String getParentMessageIdString(Message message) throws Exception {

    // If the previous block failed, try to get the parent message ID from
    // the "References" header as explained in
    // http://cr.yp.to/immhf/thread.html. Some mail clients such as Yahoo!
    // Mail use the "In-Reply-To" header, so we check that as well.

    String parentHeader = null;/*w ww . ja v  a  2  s. co m*/

    String[] references = message.getHeader("References");

    if (ArrayUtil.isNotEmpty(references)) {
        String reference = references[0];

        int x = reference.lastIndexOf("<mb.");

        if (x > -1) {
            int y = reference.indexOf(">", x);

            parentHeader = reference.substring(x, y);
        }
    }

    if (parentHeader == null) {
        String[] inReplyToHeaders = message.getHeader("In-Reply-To");

        if (ArrayUtil.isNotEmpty(inReplyToHeaders)) {
            parentHeader = inReplyToHeaders[0];
        }
    }

    if (Validator.isNull(parentHeader) || !parentHeader.startsWith(MESSAGE_POP_PORTLET_PREFIX, 1)) {

        parentHeader = _getParentMessageIdFromSubject(message);
    }

    return parentHeader;
}

From source file:com.custom.portal.security.ldap.CustomPortalLDAPImporterImpl.java

License:Open Source License

protected User updateUser(long companyId, CustomLDAPUser ldapUser, User user, Properties userMappings,
        Properties contactMappings, String password, String modifiedDate, boolean isNew) throws Exception {

    Date ldapUserModifiedDate = null;

    boolean passwordReset = ldapUser.isPasswordReset();

    if (PrefsPropsUtil.getBoolean(companyId, PropsKeys.LDAP_EXPORT_ENABLED, PropsValues.LDAP_EXPORT_ENABLED)) {

        passwordReset = user.isPasswordReset();
    }/*from w  ww . ja v  a  2 s .c  o m*/

    try {
        if (Validator.isNotNull(modifiedDate)) {
            ldapUserModifiedDate = LDAPUtil.parseDate(modifiedDate);

            if (ldapUserModifiedDate.equals(user.getModifiedDate())) {
                if (ldapUser.isAutoPassword()) {
                    if (_log.isDebugEnabled()) {
                        _log.debug("Skipping user " + user.getEmailAddress()
                                + " because he is already synchronized");
                    }

                    return user;
                }

                UserLocalServiceUtil.updatePassword(user.getUserId(), password, password, passwordReset, true);

                if (_log.isDebugEnabled()) {
                    _log.debug("User " + user.getEmailAddress() + " is already synchronized, but updated "
                            + "password to avoid a blank value");
                }

                return user;
            }
        } else if (!isNew) {
            if (_log.isInfoEnabled()) {
                _log.info("Skipping user " + user.getEmailAddress()
                        + " because the LDAP entry was never modified");
            }

            return user;
        }
    } catch (ParseException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug("Unable to parse LDAP modify timestamp " + modifiedDate, pe);
        }
    }

    if (!PropsValues.LDAP_IMPORT_USER_PASSWORD_ENABLED) {
        password = PropsValues.LDAP_IMPORT_USER_PASSWORD_DEFAULT;

        if (StringUtil.equalsIgnoreCase(password, _USER_PASSWORD_SCREEN_NAME)) {

            password = ldapUser.getScreenName();
        }
    }

    if (Validator.isNull(ldapUser.getScreenName())) {
        ldapUser.setAutoScreenName(true);
    }

    if (ldapUser.isAutoScreenName()) {
        ScreenNameGenerator screenNameGenerator = ScreenNameGeneratorFactory.getInstance();

        ldapUser.setScreenName(
                screenNameGenerator.generate(companyId, user.getUserId(), ldapUser.getEmailAddress()));
    }

    Calendar birthdayCal = CalendarFactoryUtil.getCalendar();

    Contact ldapContact = ldapUser.getContact();

    birthdayCal.setTime(ldapContact.getBirthday());

    int birthdayMonth = birthdayCal.get(Calendar.MONTH);
    int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH);
    int birthdayYear = birthdayCal.get(Calendar.YEAR);

    if (ldapUser.isUpdatePassword()) {
        UserLocalServiceUtil.updatePassword(user.getUserId(), password, password, passwordReset, true);
    }

    updateLDAPUser(ldapUser.getUser(), ldapContact, user, userMappings, contactMappings);

    user = UserLocalServiceUtil.updateUser(user.getUserId(), password, StringPool.BLANK, StringPool.BLANK,
            passwordReset, ldapUser.getReminderQueryQuestion(), ldapUser.getReminderQueryAnswer(),
            ldapUser.getScreenName(), ldapUser.getEmailAddress(), ldapUser.getFacebookId(),
            ldapUser.getOpenId(), ldapUser.getLanguageId(), ldapUser.getTimeZoneId(), ldapUser.getGreeting(),
            ldapUser.getComments(), ldapUser.getFirstName(), ldapUser.getMiddleName(), ldapUser.getLastName(),
            ldapUser.getPrefixId(), ldapUser.getSuffixId(), ldapUser.isMale(), birthdayMonth, birthdayDay,
            birthdayYear, ldapUser.getSmsSn(), ldapUser.getAimSn(), ldapUser.getFacebookSn(),
            ldapUser.getIcqSn(), ldapUser.getJabberSn(), ldapUser.getMsnSn(), ldapUser.getMySpaceSn(),
            ldapUser.getSkypeSn(), ldapUser.getTwitterSn(), ldapUser.getYmSn(), ldapUser.getJobTitle(),
            ldapUser.getGroupIds(), ldapUser.getOrganizationIds(), ldapUser.getRoleIds(),
            ldapUser.getUserGroupRoles(), ldapUser.getUserGroupIds(), ldapUser.getServiceContext());

    boolean hasBusinessPhone = false;

    for (Phone phone : user.getPhones()) {
        if (phone.getTypeId() == 11006) {
            hasBusinessPhone = true;
            break;
        }
    }

    if (!hasBusinessPhone && !ldapUser.getPhone().isEmpty()) {
        if (_log.isDebugEnabled()) {
            _log.debug("Adding Business phone: " + ldapUser.getPhone());
        }
        PhoneLocalServiceUtil.addPhone(user.getUserId(), Contact.class.getName(), user.getContactId(),
                ldapUser.getPhone(), "", 11006, true, ldapUser.getServiceContext());
    }

    boolean hasBusinessAddress = false;

    for (Address address : user.getAddresses()) {
        if (address.getTypeId() == 11000) {
            hasBusinessAddress = true;
            break;
        }
    }

    if (!hasBusinessAddress && !ldapUser.getStreet().isEmpty() && !ldapUser.getCity().isEmpty()) {
        if (_log.isDebugEnabled()) {
            _log.debug("Adding Business Address: " + ldapUser.getStreet() + " " + ldapUser.getCity() + " "
                    + ldapUser.getZip());

        }
        AddressLocalServiceUtil.addAddress(user.getUserId(), Contact.class.getName(), user.getContactId(),
                ldapUser.getStreet(), "", "", ldapUser.getCity(), ldapUser.getZip(), 0, 0, 11000, true, true,
                ldapUser.getServiceContext());
    }

    user = UserLocalServiceUtil.updateStatus(user.getUserId(), ldapUser.getStatus());

    if (ldapUserModifiedDate != null) {
        user = UserLocalServiceUtil.updateModifiedDate(user.getUserId(), ldapUserModifiedDate);
    }

    if (ldapUser.isUpdatePortrait()) {
        byte[] portraitBytes = ldapUser.getPortraitBytes();

        if (ArrayUtil.isNotEmpty(portraitBytes)) {
            UserLocalServiceUtil.updatePortrait(user.getUserId(), portraitBytes);
        } else {
            UserLocalServiceUtil.deletePortrait(user.getUserId());
        }
    }

    return user;
}

From source file:com.liferay.alloy.mvc.BaseAlloyControllerImpl.java

License:Open Source License

protected AlloySearchResult search(Indexer indexer, AlloyServiceInvoker alloyServiceInvoker,
        HttpServletRequest request, PortletRequest portletRequest,
        SearchContainer<? extends BaseModel<?>> searchContainer, Map<String, Serializable> attributes,
        String keywords, Sort[] sorts) throws Exception {

    if (indexer == null) {
        throw new Exception("No indexer found for " + controllerPath);
    }//from   w ww.j av a  2s  . co m

    AlloySearchResult alloySearchResult = new AlloySearchResult();

    alloySearchResult.setAlloyServiceInvoker(alloyServiceInvoker);

    if (searchContainer == null) {
        searchContainer = new SearchContainer<BaseModel<?>>(portletRequest, portletURL, null, null);
    }

    SearchContext searchContext = SearchContextFactory.getInstance(request);

    boolean andOperator = ParamUtil.getBoolean(request, "andOperator");

    searchContext.setAndSearch(andOperator);

    if ((attributes != null) && !attributes.isEmpty()) {
        searchContext.setAttributes(attributes);
    }

    searchContext.setEnd(searchContainer.getEnd());

    Class<?> indexerClass = Class.forName(indexer.getClassNames()[0]);

    if (!GroupedModel.class.isAssignableFrom(indexerClass)) {
        searchContext.setGroupIds(null);
    } else if (searchContext.getAttribute(Field.GROUP_ID) != null) {
        long groupId = GetterUtil.getLong(searchContext.getAttribute(Field.GROUP_ID));

        searchContext.setGroupIds(new long[] { groupId });
    }

    if (Validator.isNotNull(keywords)) {
        searchContext.setKeywords(keywords);
    }

    if (ArrayUtil.isNotEmpty(sorts)) {
        searchContext.setSorts(sorts);
    }

    searchContext.setStart(searchContainer.getStart());

    Hits hits = indexer.search(searchContext);

    alloySearchResult.setHits(hits);

    alloySearchResult.setPortletURL(portletURL, searchContext.getAttributes());

    alloySearchResult.afterPropertiesSet();

    return alloySearchResult;
}

From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java

License:Open Source License

@Override
public long[] getClassNameIds(PortletPreferences portletPreferences, long[] availableClassNameIds) {

    boolean anyAssetType = GetterUtil
            .getBoolean(portletPreferences.getValue("anyAssetType", Boolean.TRUE.toString()));
    String selectionStyle = portletPreferences.getValue("selectionStyle", "dynamic");

    if (anyAssetType || selectionStyle.equals("manual")) {
        return availableClassNameIds;
    }/*from  w w w  . jav  a  2 s  . com*/

    long defaultClassNameId = GetterUtil.getLong(portletPreferences.getValue("anyAssetType", null));

    if (defaultClassNameId > 0) {
        return new long[] { defaultClassNameId };
    }

    long[] classNameIds = GetterUtil.getLongValues(portletPreferences.getValues("classNameIds", null));

    if (ArrayUtil.isNotEmpty(classNameIds)) {
        return classNameIds;
    } else {
        return availableClassNameIds;
    }
}

From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java

License:Open Source License

public Map<String, Serializable> getAttributes() {
    if (_attributes != null) {
        return _attributes;
    }//  w  w  w.  j a  v a  2 s . c o m

    _attributes = new HashMap<>();

    Map<String, String[]> parameters = _request.getParameterMap();

    for (Map.Entry<String, String[]> entry : parameters.entrySet()) {
        String name = entry.getKey();
        String[] values = entry.getValue();

        if (ArrayUtil.isNotEmpty(values)) {
            if (values.length == 1) {
                _attributes.put(name, values[0]);
            } else {
                _attributes.put(name, values);
            }
        }
    }

    return _attributes;
}

From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java

License:Open Source License

public Boolean isEnableConversions() throws Exception {
    if (_enableConversions != null) {
        return _enableConversions;
    }//from w  w w. j a  v a  2 s  . c om

    _enableConversions = isOpenOfficeServerEnabled() && ArrayUtil.isNotEmpty(getExtensions());

    return _enableConversions;
}

From source file:com.liferay.asset.publisher.web.portlet.action.AssetPublisherConfigurationAction.java

License:Open Source License

protected void updateDisplaySettings(ActionRequest actionRequest) throws Exception {

    String[] classNameIds = StringUtil.split(getParameter(actionRequest, "classNameIds"));

    String[] classTypeIds = getClassTypeIds(actionRequest, classNameIds);

    String[] extensions = actionRequest.getParameterValues("extensions");

    if (ArrayUtil.isNotEmpty(extensions) && (extensions.length == 1)
            && extensions[0].equals(Boolean.FALSE.toString())) {

        extensions = new String[0];
    }//from   w  w w. j  a  va 2s .  c o  m

    boolean subtypeFieldsFilterEnabled = getSubtypesFieldsFilterEnabled(actionRequest, classNameIds);

    setPreference(actionRequest, "classNameIds", classNameIds);
    setPreference(actionRequest, "classTypeIds", classTypeIds);
    setPreference(actionRequest, "extensions", extensions);
    setPreference(actionRequest, "subtypeFieldsFilterEnabled", String.valueOf(subtypeFieldsFilterEnabled));
}

From source file:com.liferay.asset.publisher.web.upgrade.v1_0_0.UpgradePortletPreferences.java

License:Open Source License

@Override
protected String upgradePreferences(long companyId, long ownerId, int ownerType, long plid, String portletId,
        String xml) throws Exception {

    PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromXML(companyId, ownerId, ownerType,
            plid, portletId, xml);//  w  ww .  j  a  va  2 s. com

    String[] assetEntryXmls = portletPreferences.getValues("asset-entry-xml", new String[0]);

    if (ArrayUtil.isNotEmpty(assetEntryXmls)) {
        upgradeUuids(assetEntryXmls);

        portletPreferences.setValues("assetEntryXml", assetEntryXmls);
    }

    boolean subtypeFieldsFilterEnabled = GetterUtil
            .getBoolean(portletPreferences.getValue("subtypeFieldsFilterEnabled", Boolean.FALSE.toString()));

    if (subtypeFieldsFilterEnabled) {
        boolean dlFilterByFieldEnable = isFilterByFieldEnable(portletPreferences,
                _DL_FILTER_BY_FIELD_ENABLED_KEY);
        boolean journalFilterByFieldEnable = isFilterByFieldEnable(portletPreferences,
                _JOURNAL_FILTER_BY_FIELD_ENABLED_KEY);

        if (dlFilterByFieldEnable) {
            upgradeDLDateFieldsValues(portletPreferences);
        } else if (journalFilterByFieldEnable) {
            upgradeJournalDateFieldValue(portletPreferences);
        }

        upgradeOrderByColumns(portletPreferences);
    }

    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

public static long[] getClassNameIds(PortletPreferences portletPreferences, long[] availableClassNameIds) {

    boolean anyAssetType = GetterUtil
            .getBoolean(portletPreferences.getValue("anyAssetType", Boolean.TRUE.toString()));
    String selectionStyle = portletPreferences.getValue("selectionStyle", "dynamic");

    if (anyAssetType || selectionStyle.equals("manual")) {
        return availableClassNameIds;
    }//from   w w w  . j a v  a 2  s  .co m

    long defaultClassNameId = GetterUtil.getLong(portletPreferences.getValue("anyAssetType", null));

    if (defaultClassNameId > 0) {
        return new long[] { defaultClassNameId };
    }

    long[] classNameIds = GetterUtil.getLongValues(portletPreferences.getValues("classNameIds", null));

    if (ArrayUtil.isNotEmpty(classNameIds)) {
        return classNameIds;
    } else {
        return availableClassNameIds;
    }
}

From source file:com.liferay.asset.tags.selector.web.internal.display.context.AssetTagsSelectorDisplayContext.java

License:Open Source License

public long[] getGroupIds() {
    if (ArrayUtil.isNotEmpty(_groupIds)) {
        return _groupIds;
    }/*from  w  w w . j  a  v a 2 s  . c om*/

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

    _groupIds = StringUtil.split(ParamUtil.getString(_request, "groupIds"), 0L);

    if (ArrayUtil.isEmpty(_groupIds)) {
        _groupIds = new long[] { themeDisplay.getScopeGroupId() };
    }

    return _groupIds;
}