Exemplo n.º 1
0
  protected void verifyContentSearch(long groupId, String portletId) throws Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getUpgradeOptimizedConnection();

      ps =
          con.prepareStatement(
              "select preferences from PortletPreferences inner join "
                  + "Layout on PortletPreferences.plid = Layout.plid where "
                  + "groupId = ? and portletId = ?");

      ps.setLong(1, groupId);
      ps.setString(2, portletId);

      rs = ps.executeQuery();

      while (rs.next()) {
        String xml = rs.getString("preferences");

        PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromDefaultXML(xml);

        String articleId = portletPreferences.getValue("articleId", null);

        List<JournalContentSearch> contentSearches =
            JournalContentSearchLocalServiceUtil.getArticleContentSearches(groupId, articleId);

        if (contentSearches.isEmpty()) {
          continue;
        }

        JournalContentSearch contentSearch = contentSearches.get(0);

        JournalContentSearchLocalServiceUtil.updateContentSearch(
            contentSearch.getGroupId(),
            contentSearch.isPrivateLayout(),
            contentSearch.getLayoutId(),
            contentSearch.getPortletId(),
            articleId,
            true);
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
  /**
   * Updates the journal content search in the database or adds it if it does not yet exist. Also
   * notifies the appropriate model listeners.
   *
   * @param journalContentSearch the journal content search
   * @param merge whether to merge the journal content search with the current session. See {@link
   *     com.liferay.portal.service.persistence.BatchSession#update(com.liferay.portal.kernel.dao.orm.Session,
   *     com.liferay.portal.model.BaseModel, boolean)} for an explanation.
   * @return the journal content search that was updated
   * @throws SystemException if a system exception occurred
   */
  public JournalContentSearch updateJournalContentSearch(
      JournalContentSearch journalContentSearch, boolean merge) throws SystemException {
    journalContentSearch.setNew(false);

    journalContentSearch = journalContentSearchPersistence.update(journalContentSearch, merge);

    Indexer indexer = IndexerRegistryUtil.getIndexer(getModelClassName());

    if (indexer != null) {
      try {
        indexer.reindex(journalContentSearch);
      } catch (SearchException se) {
        if (_log.isWarnEnabled()) {
          _log.warn(se, se);
        }
      }
    }

    return journalContentSearch;
  }