示例#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);
    }
  }
  protected void importJournalArticle(
      PortletDataContext portletDataContext, Layout layout, Element layoutElement)
      throws Exception {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    String articleId = typeSettingsProperties.getProperty("article-id", StringPool.BLANK);

    if (Validator.isNull(articleId)) {
      return;
    }

    JournalPortletDataHandlerImpl.importReferencedData(portletDataContext, layoutElement);

    Element structureElement = layoutElement.element("structure");

    if (structureElement != null) {
      JournalPortletDataHandlerImpl.importStructure(portletDataContext, structureElement);
    }

    Element templateElement = layoutElement.element("template");

    if (templateElement != null) {
      JournalPortletDataHandlerImpl.importTemplate(portletDataContext, templateElement);
    }

    Element articleElement = layoutElement.element("article");

    if (articleElement != null) {
      JournalPortletDataHandlerImpl.importArticle(portletDataContext, articleElement);
    }

    Map<String, String> articleIds =
        (Map<String, String>)
            portletDataContext.getNewPrimaryKeysMap(JournalArticle.class + ".articleId");

    articleId = MapUtil.getString(articleIds, articleId, articleId);

    typeSettingsProperties.setProperty("article-id", articleId);

    JournalContentSearchLocalServiceUtil.updateContentSearch(
        portletDataContext.getScopeGroupId(),
        layout.isPrivateLayout(),
        layout.getLayoutId(),
        StringPool.BLANK,
        articleId,
        true);
  }
  @Override
  public void setAddToPagePreferences(
      PortletPreferences preferences, String portletId, ThemeDisplay themeDisplay)
      throws Exception {

    preferences.setValue("articleId", _article.getArticleId());
    preferences.setValue("groupId", String.valueOf(_article.getGroupId()));

    Layout layout = themeDisplay.getLayout();

    JournalContentSearchLocalServiceUtil.updateContentSearch(
        layout.getGroupId(),
        layout.isPrivateLayout(),
        layout.getLayoutId(),
        portletId,
        _article.getArticleId(),
        true);
  }
  protected PortletPreferences doImportData(
      PortletDataContext context, String portletId, PortletPreferences preferences, String data)
      throws Exception {

    context.importPermissions(
        "com.liferay.portlet.journal", context.getSourceGroupId(), context.getScopeGroupId());

    if (Validator.isNull(data)) {
      return null;
    }

    Document document = SAXReaderUtil.read(data);

    Element rootElement = document.getRootElement();

    Element dlFoldersElement = rootElement.element("dl-folders");

    List<Element> dlFolderElements = Collections.EMPTY_LIST;

    if (dlFoldersElement != null) {
      dlFolderElements = dlFoldersElement.elements("folder");
    }

    for (Element folderElement : dlFolderElements) {
      DLPortletDataHandlerImpl.importFolder(context, folderElement);
    }

    Element dlFileEntriesElement = rootElement.element("dl-file-entries");

    List<Element> dlFileEntryElements = Collections.EMPTY_LIST;

    if (dlFileEntriesElement != null) {
      dlFileEntryElements = dlFileEntriesElement.elements("file-entry");
    }

    for (Element fileEntryElement : dlFileEntryElements) {
      DLPortletDataHandlerImpl.importFileEntry(context, fileEntryElement);
    }

    Element dlFileRanksElement = rootElement.element("dl-file-ranks");

    List<Element> dlFileRankElements = Collections.EMPTY_LIST;

    if (dlFileRanksElement != null) {
      dlFileRankElements = dlFileRanksElement.elements("file-rank");
    }

    for (Element fileRankElement : dlFileRankElements) {
      DLPortletDataHandlerImpl.importFileRank(context, fileRankElement);
    }

    Element igFoldersElement = rootElement.element("ig-folders");

    List<Element> igFolderElements = Collections.EMPTY_LIST;

    if (igFoldersElement != null) {
      igFolderElements = igFoldersElement.elements("folder");
    }

    for (Element folderElement : igFolderElements) {
      IGPortletDataHandlerImpl.importFolder(context, folderElement);
    }

    Element igImagesElement = rootElement.element("ig-images");

    List<Element> igImageElements = Collections.EMPTY_LIST;

    if (igImagesElement != null) {
      igImageElements = igImagesElement.elements("image");
    }

    for (Element imageElement : igImageElements) {
      IGPortletDataHandlerImpl.importImage(context, imageElement);
    }

    Element structureElement = rootElement.element("structure");

    if (structureElement != null) {
      JournalPortletDataHandlerImpl.importStructure(context, structureElement);
    }

    Element templateElement = rootElement.element("template");

    if (templateElement != null) {
      JournalPortletDataHandlerImpl.importTemplate(context, templateElement);
    }

    Element articleElement = rootElement.element("article");

    if (articleElement != null) {
      JournalPortletDataHandlerImpl.importArticle(context, articleElement);
    }

    String articleId = preferences.getValue("article-id", StringPool.BLANK);

    if (Validator.isNotNull(articleId)) {
      Map<String, String> articleIds =
          (Map<String, String>) context.getNewPrimaryKeysMap(JournalArticle.class);

      articleId = MapUtil.getString(articleIds, articleId, articleId);

      preferences.setValue("group-id", String.valueOf(context.getScopeGroupId()));
      preferences.setValue("article-id", articleId);

      Layout layout = LayoutLocalServiceUtil.getLayout(context.getPlid());

      JournalContentSearchLocalServiceUtil.updateContentSearch(
          context.getScopeGroupId(),
          layout.isPrivateLayout(),
          layout.getLayoutId(),
          portletId,
          articleId,
          true);
    }

    return preferences;
  }