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.rivetlogic.hangouts.portlet.HangoutsPortlet.java

License:Open Source License

private void updateGroup(PortletRequest request, PortletResponse response, JSONObject jsonResponse) {
    Long hangoutsGroupId = ParamUtil.getLong(request, Constants.HANGOUTS_GROUP_ID, Constants.UNDEFINED_ID);
    HangoutsGroup hangoutsGroup = null;//from w w w  . j a  v a 2s . c  o m
    if (Constants.UNDEFINED_ID != hangoutsGroupId) {
        try {
            List<String> errors = new ArrayList<String>();
            hangoutsGroup = HangoutsGroupLocalServiceUtil.getHangoutsGroup(hangoutsGroupId);
            JSONArray obj = contactsFromRequest(request);
            hangoutsGroup.setGroupName(ParamUtil.getString(request, Constants.HANGOUTS_GROUP_NAME));
            hangoutsGroup.setHangoutsContacts(obj.toString());

            if (HangoutsPortletValidator.validateUpdateGroup(hangoutsGroup, errors)) {
                HangoutsGroupLocalServiceUtil.updateHangoutsGroup(hangoutsGroup);
                jsonResponse.put(Constants.CMD_SUCCESS, true);
            } else {
                jsonResponse.put(Constants.ERRORS,
                        ListUtil.toString(errors, StringPool.BLANK, StringPool.COMMA));
                jsonResponse.put(Constants.CMD_SUCCESS, false);
            }

        } catch (JSONException e) {
            jsonResponse.put(Constants.CMD_SUCCESS, false);
            LOG.error("Wrong format in ids: ", e);
        } catch (Exception e) {
            jsonResponse.put(Constants.CMD_SUCCESS, false);
            LOG.error(e);
        }

    } else {
        jsonResponse.put(Constants.CMD_SUCCESS, false);
    }
}

From source file:com.rivetlogic.portal.search.elasticsearch.indexer.document.ElasticsearchDocumentJSONBuilder.java

License:Open Source License

/**
 * Init method.//from   ww  w.ja  v  a 2  s.c o m
 */
public void loadExcludedTypes() {
    String cslExcludedType = PortletProps.get(ElasticsearchIndexerConstants.ES_KEY_EXCLUDED_INDEXTYPE);
    if (Validator.isNotNull(cslExcludedType)) {
        excludedTypes = new HashSet<String>();
        for (String excludedType : cslExcludedType.split(StringPool.COMMA)) {
            excludedTypes.add(excludedType);
        }
        if (_log.isDebugEnabled()) {
            _log.debug("Loaded Excluded index types are:" + cslExcludedType);
        }
        _log.info("Loaded Excluded index types are:" + cslExcludedType);
    } else {
        if (_log.isDebugEnabled()) {
            _log.debug("Excluded index types are not defined");
        }
        _log.info("Excluded index types are not defined");
    }
}

From source file:com.rivetlogic.portal.search.elasticsearch.indexer.document.ElasticsearchDocumentJSONBuilder.java

License:Open Source License

/**
 * Convert to json.//from www .  j av a  2s  .  co  m
 * 
 * @param document
 *            the document
 * @return the string
 */
public ElasticserachJSONDocument convertToJSON(final Document document) {

    Map<String, Field> fields = document.getFields();
    ElasticserachJSONDocument elasticserachJSONDocument = new ElasticserachJSONDocument();

    try {
        XContentBuilder contentBuilder = XContentFactory.jsonBuilder().startObject();

        Field classnameField = document.getField(ElasticsearchIndexerConstants.ENTRY_CLASSNAME);
        String entryClassName = (classnameField == null) ? "" : classnameField.getValue();

        /**
         * Handle all error scenarios prior to conversion
         */
        if (isDocumentHidden(document)) {
            elasticserachJSONDocument.setError(true);
            elasticserachJSONDocument
                    .setErrorMessage(ElasticserachJSONDocument.DocumentError.HIDDEN_DOCUMENT.toString());
            return elasticserachJSONDocument;
        }
        if (entryClassName.isEmpty()) {
            elasticserachJSONDocument.setError(true);
            elasticserachJSONDocument
                    .setErrorMessage(ElasticserachJSONDocument.DocumentError.MISSING_ENTRYCLASSNAME.toString());
            return elasticserachJSONDocument;
        }
        if (isExcludedType(entryClassName)) {
            elasticserachJSONDocument.setError(true);
            elasticserachJSONDocument.setErrorMessage("Index Type:" + entryClassName + StringPool.COMMA
                    + ElasticserachJSONDocument.DocumentError.EXCLUDED_TYPE.toString());
            return elasticserachJSONDocument;
        }

        /**
         * To avoid multiple documents for versioned assets such as Journal articles, DL entry etc
         * the primary Id will be Indextype + Entry class PK. The primary Id is to maintain uniqueness
         * in ES server database and nothing to do with UID or is not used for any other purpose.
         */
        Field classPKField = document.getField(ElasticsearchIndexerConstants.ENTRY_CLASSPK);
        String entryClassPK = (classPKField == null) ? "" : classPKField.getValue();
        if (entryClassPK.isEmpty()) {
            elasticserachJSONDocument.setError(true);
            elasticserachJSONDocument
                    .setErrorMessage(ElasticserachJSONDocument.DocumentError.MISSING_CLASSPK.toString());
            return elasticserachJSONDocument;
        }

        /** Replace '.' by '_' in Entry class name,since '.' is not recommended by Elasticsearch in Index type */
        String indexType = entryClassName.replace(StringPool.PERIOD, StringPool.UNDERLINE);
        elasticserachJSONDocument.setIndexType(indexType);

        elasticserachJSONDocument.setId(indexType + entryClassPK);

        /** Create a JSON string for remaining fields of document */
        for (Iterator<Map.Entry<String, Field>> it = fields.entrySet().iterator(); it.hasNext();) {
            Map.Entry<String, Field> entry = it.next();
            Field field = entry.getValue();
            contentBuilder.field(entry.getKey(), field.getValue());
        }
        contentBuilder.endObject();

        elasticserachJSONDocument.setJsonDocument(contentBuilder.string());
        if (_log.isDebugEnabled()) {
            _log.debug("Liferay Document converted to ESJSON document successfully:" + contentBuilder.string());
        }
    } catch (IOException e) {
        _log.error("IO Error during converstion of Liferay Document to JSON format" + e.getMessage());
    }
    return elasticserachJSONDocument;
}

From source file:com.rivetlogic.portal.search.elasticsearch.util.ElasticsearchConnector.java

License:Open Source License

/**
 * Inits the transport client./* w  w  w .j av  a 2  s .  c o m*/
 */
public void initESSetup() {

    try {
        String esServerHome = PropsUtil.get(ElasticsearchIndexerConstants.ES_KEY_HOME_PATH);
        String esClusterName = PropsUtil.get(ElasticsearchIndexerConstants.ES_KEY_CLUSTERNAME);

        if (Validator.isNull(esServerHome) || esServerHome.isEmpty()) {
            throw new ElasticsearchException("Elasticsearch server home folder is not configured...");
        }

        /** Create a settings object with custom attributes and build */
        ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder()
                .classLoader(Settings.class.getClassLoader())
                .put(ElasticsearchIndexerConstants.ES_SETTING_PATH_HOME, esServerHome)
                .put(ElasticsearchIndexerConstants.ES_SETTING_CLIENT_SNIFF, true);

        if (Validator.isNotNull(esClusterName) && !esClusterName.isEmpty()
                && !ElasticsearchIndexerConstants.ELASTIC_SEARCH.equalsIgnoreCase(esClusterName)) {
            settingsBuilder.put(ElasticsearchIndexerConstants.ES_SETTING_CLUSTERNAME, esClusterName);

            if (_log.isDebugEnabled()) {
                _log.debug("Elasticsearch cluster name is not configured to default:" + esClusterName);
            }
        }

        String csElasticsearchNodes = PropsUtil.get(ElasticsearchIndexerConstants.ES_KEY_NODE);
        if (Validator.isNull(csElasticsearchNodes) || csElasticsearchNodes.isEmpty()) {
            throw new ElasticsearchException("Elasticsearch server node is not configured...");
        }

        String[] nodeList = csElasticsearchNodes.split(StringPool.COMMA);
        InetSocketTransportAddress[] transportAddresses = new InetSocketTransportAddress[nodeList.length];

        /** Prepare a list of Hosts */
        for (int i = 0; i < nodeList.length; i++) {
            String[] hostnames = nodeList[i].split(StringPool.COLON);
            InetSocketTransportAddress transportAddress = new InetSocketTransportAddress(hostnames[0],
                    Integer.parseInt(hostnames[1]));
            transportAddresses[i] = transportAddress;
        }

        client = new TransportClient(settingsBuilder.build()).addTransportAddresses(transportAddresses);
        _log.info("Successfully created Transport client........");
        /**
         * Check if Liferay index already exists, else create one with
         * default mapping The Index creation is one time setup, so it is
         * important to check if index already exists before creation
         */
        if (!isLiferayIndexExists()) {
            createLiferayIndexInESServer();
        }
    } catch (FailedToResolveConfigException configEx) {
        _log.error("Error while connecting to Elasticsearch server:" + configEx.getMessage());
    }
}

From source file:com.rivetlogic.portlet.AnnouncerTools.java

License:Open Source License

/**
 * Removes the article.//from ww w.j ava  2  s .  c  o  m
 *
 * @param pref the pref
 * @param themeDisplay the theme display
 * @param articleId the article id
 */
public static void removeArticle(PortletPreferences pref, ThemeDisplay themeDisplay, String articleId) {
    String articles = pref.getValue(ARTICLE_RAW, LR_EMPTY_VALUE);

    articles = articles.replace(String.valueOf(articleId), StringPool.BLANK); // remove id
    articles = articles.replaceAll("\\s+", StringPool.SPACE);

    String articleIds = articles.trim().replaceAll("\\s", StringPool.COMMA);

    String articleWithVersionPref = LR_EMPTY_VALUE;
    String articleConsecutive = LR_EMPTY_VALUE;
    String articleWithVersion = LR_EMPTY_VALUE;

    articleWithVersionPref = pref.getValue(ARTICLE_ID_WITH_VERSION, LR_EMPTY_VALUE); // articleId1:version
    // ...
    articleConsecutive = pref.getValue(ARTICLE_ID_CONSECUTIVE, LR_EMPTY_VALUE);

    boolean updatedArticleIds = false, updatedArticleVersions = false;

    updatedArticleIds = !pref.getValue(ARTICLE_ID, LR_EMPTY_VALUE).equals(articleIds);

    long groupId = themeDisplay.getScopeGroupId();

    articleWithVersion = getArticleIdsWithVersion(groupId, articleIds);
    // Check if the articles version is still the same
    updatedArticleVersions = !articleWithVersion.equals(articleWithVersionPref);
    if (updatedArticleIds || updatedArticleVersions) {
        articleConsecutive = String.valueOf((int) (Double.valueOf(articleConsecutive) + 1));
    }

    try {
        pref.setValue(ARTICLES_RAW, articles);
        pref.setValue(ARTICLE_ID, articleIds);
        pref.setValue(ARTICLE_ID_WITH_VERSION, articleWithVersion);
        pref.setValue(ARTICLE_ID_CONSECUTIVE, articleConsecutive);
        pref.store();
    } catch (ReadOnlyException e) {
        LOG.error(e);
    } catch (ValidatorException e) {
        LOG.error(e);
    } catch (IOException e) {
        LOG.error(e);
    }
}

From source file:com.rivetlogic.portlet.AnnouncerTools.java

License:Open Source License

/**
 * Gets a string in the form of articleId1:version,articleId2:version ...
 *
 * @param groupId the group id//ww  w  . jav a 2 s  .c  om
 * @param articleIds the article ids
 * @return the article ids with version
 */
public static String getArticleIdsWithVersion(long groupId, String articleIds) {
    StringBuilder articleWithVersionBuilder = new StringBuilder();
    for (String articleId : articleIds.split(StringPool.COMMA)) {
        double version;
        try {
            version = JournalArticleLocalServiceUtil.getLatestVersion(groupId, articleId);
            articleWithVersionBuilder.append(StringPool.COMMA);
            articleWithVersionBuilder.append(articleId);
            articleWithVersionBuilder.append(StringPool.COLON);
            articleWithVersionBuilder.append(version);
        } catch (PortalException e) {
            LOG.error(e);
        } catch (SystemException e) {
            LOG.error(e);
        }

    }
    articleWithVersionBuilder.deleteCharAt(0); // remove the initial comma
    return articleWithVersionBuilder.toString();
}

From source file:com.rivetlogic.portlet.service.persistence.CompletedPK.java

License:Open Source License

@Override
public String toString() {
    StringBundler sb = new StringBundler(10);

    sb.append(StringPool.OPEN_CURLY_BRACE);

    sb.append("USER_ID");
    sb.append(StringPool.EQUAL);//from  w ww . j a v  a  2s  . c  om
    sb.append(USER_ID);

    sb.append(StringPool.COMMA);
    sb.append(StringPool.SPACE);
    sb.append("LAYOUT_PK");
    sb.append(StringPool.EQUAL);
    sb.append(LAYOUT_PK);

    sb.append(StringPool.CLOSE_CURLY_BRACE);

    return sb.toString();
}

From source file:com.rivetlogic.portlet.service.persistence.DriveLinksPK.java

License:Open Source License

@Override
public String toString() {
    StringBundler sb = new StringBundler(10);

    sb.append(StringPool.OPEN_CURLY_BRACE);

    sb.append("USER_ID");
    sb.append(StringPool.EQUAL);//from  w  ww  .  j ava 2s.  c om
    sb.append(USER_ID);

    sb.append(StringPool.COMMA);
    sb.append(StringPool.SPACE);
    sb.append("DOCUMENT_ID");
    sb.append(StringPool.EQUAL);
    sb.append(DOCUMENT_ID);

    sb.append(StringPool.CLOSE_CURLY_BRACE);

    return sb.toString();
}

From source file:com.rivetlogic.portlet.TipOfTheDayDockbarPortlet.java

License:Open Source License

/**
 * Select tip.//from www  .  j a v a2  s  .c om
 *
 * @param request the request
 * @param articleIds the article ids
 * @param currentArticleId the current article id
 */
private void selectTip(RenderRequest request, String[] articleIds, String currentArticleId) {

    String attVisited = ParamUtil.getString(request, WebKeys.VISITED);

    String[] visited = StringUtil.split(attVisited);

    List<String> visitedList = Arrays.asList(visited);

    int actualArticlePosition = visitedList.indexOf(currentArticleId);

    choosePreviousSelectedTip(request, visitedList, actualArticlePosition);

    if ((actualArticlePosition == -1) || (actualArticlePosition == (visitedList.size() - 1))) {

        if (visited.length >= (articleIds.length - 1)) {
            request.setAttribute(WebKeys.DISABLE_NEXT, true);

        } else {
            chooseRandomTip(request, articleIds, visited, visitedList, currentArticleId);
        }

    } else {
        String nextArticleId = visitedList.get(actualArticlePosition + 1);

        if (logger.isDebugEnabled())
            logger.debug("nextArticleId: " + nextArticleId);

        request.setAttribute(WebKeys.NEXT_ARTICLE_ID, nextArticleId);
    }

    if ((visited.length == 0) || (actualArticlePosition == 0)) {
        request.setAttribute(WebKeys.DISABLE_PREV, true);
    }

    if (actualArticlePosition == -1) {

        if (visited.length > 0) {
            request.setAttribute(WebKeys.VISITED, attVisited + StringPool.COMMA + currentArticleId);

        } else {
            request.setAttribute(WebKeys.VISITED, currentArticleId);
        }

    } else {
        request.setAttribute(WebKeys.VISITED, attVisited);
    }
}

From source file:com.rivetlogic.service.persistence.TipsOfTheDayVisitedPK.java

License:Open Source License

@Override
public String toString() {
    StringBundler sb = new StringBundler(20);

    sb.append(StringPool.OPEN_CURLY_BRACE);

    sb.append("userId");
    sb.append(StringPool.EQUAL);//from  ww w  . ja va 2  s  .  c o m
    sb.append(userId);

    sb.append(StringPool.COMMA);
    sb.append(StringPool.SPACE);
    sb.append("companyId");
    sb.append(StringPool.EQUAL);
    sb.append(companyId);

    sb.append(StringPool.COMMA);
    sb.append(StringPool.SPACE);
    sb.append("groupId");
    sb.append(StringPool.EQUAL);
    sb.append(groupId);

    sb.append(StringPool.COMMA);
    sb.append(StringPool.SPACE);
    sb.append("tipId");
    sb.append(StringPool.EQUAL);
    sb.append(tipId);

    sb.append(StringPool.CLOSE_CURLY_BRACE);

    return sb.toString();
}