예제 #1
0
  protected void verifyCreateDate(JournalArticleResource articleResource) {
    List<JournalArticle> articles =
        JournalArticleLocalServiceUtil.getArticles(
            articleResource.getGroupId(),
            articleResource.getArticleId(),
            QueryUtil.ALL_POS,
            QueryUtil.ALL_POS,
            new ArticleVersionComparator(true));

    if (articles.size() <= 1) {
      return;
    }

    JournalArticle firstArticle = articles.get(0);

    Date createDate = firstArticle.getCreateDate();

    for (JournalArticle article : articles) {
      if (!createDate.equals(article.getCreateDate())) {
        article.setCreateDate(createDate);

        JournalArticleLocalServiceUtil.updateJournalArticle(article);
      }
    }
  }
예제 #2
0
  protected void verifyPermissionsAndAssets(JournalArticle article) throws PortalException {

    long groupId = article.getGroupId();
    String articleId = article.getArticleId();
    double version = article.getVersion();

    if (article.getResourcePrimKey() <= 0) {
      article =
          JournalArticleLocalServiceUtil.checkArticleResourcePrimKey(groupId, articleId, version);
    }

    ResourceLocalServiceUtil.addResources(
        article.getCompanyId(),
        0,
        0,
        JournalArticle.class.getName(),
        article.getResourcePrimKey(),
        false,
        false,
        false);

    AssetEntry assetEntry =
        AssetEntryLocalServiceUtil.fetchEntry(
            JournalArticle.class.getName(), article.getResourcePrimKey());

    if (assetEntry == null) {
      try {
        JournalArticleLocalServiceUtil.updateAsset(article.getUserId(), article, null, null, null);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(
              "Unable to update asset for article " + article.getId() + ": " + e.getMessage());
        }
      }
    } else if ((article.getStatus() == WorkflowConstants.STATUS_DRAFT)
        && (article.getVersion() == JournalArticleConstants.VERSION_DEFAULT)) {

      AssetEntryLocalServiceUtil.updateEntry(
          assetEntry.getClassName(), assetEntry.getClassPK(), null, assetEntry.isVisible());
    }

    try {
      JournalArticleLocalServiceUtil.checkStructure(groupId, articleId, version);
    } catch (NoSuchStructureException nsse) {
      if (_log.isWarnEnabled()) {
        _log.warn("Removing reference to missing structure for article " + article.getId());
      }

      article.setStructureId(StringPool.BLANK);
      article.setTemplateId(StringPool.BLANK);

      JournalArticleLocalServiceUtil.updateJournalArticle(article);
    } catch (Exception e) {
      _log.error("Unable to check the structure for article " + article.getId(), e);
    }
  }
예제 #3
0
  protected void verifyOracleNewLine() throws Exception {
    DB db = DBFactoryUtil.getDB();

    String dbType = db.getType();

    if (!dbType.equals(DB.TYPE_ORACLE)) {
      return;
    }

    // This is a workaround for a limitation in Oracle sqlldr's inability
    // insert new line characters for long varchar columns. See
    // http://forums.liferay.com/index.php?showtopic=2761&hl=oracle for more
    // information. Check several articles because some articles may not
    // have new lines.

    boolean checkNewLine = false;

    List<JournalArticle> articles =
        JournalArticleLocalServiceUtil.getArticles(DEFAULT_GROUP_ID, 0, NUM_OF_ARTICLES);

    for (JournalArticle article : articles) {
      String content = article.getContent();

      if ((content != null) && content.contains("\\n")) {
        articles = JournalArticleLocalServiceUtil.getArticles(DEFAULT_GROUP_ID);

        for (int j = 0; j < articles.size(); j++) {
          article = articles.get(j);

          JournalArticleLocalServiceUtil.checkNewLine(
              article.getGroupId(), article.getArticleId(), article.getVersion());
        }

        checkNewLine = true;

        break;
      }
    }

    // Only process this once

    if (!checkNewLine) {
      if (_log.isInfoEnabled()) {
        _log.info("Do not fix oracle new line");
      }

      return;
    } else {
      if (_log.isInfoEnabled()) {
        _log.info("Fix oracle new line");
      }
    }
  }
  @Test
  public void testExportImportPortletData() throws Exception {

    // Check data after site creation

    String content = _layoutSetPrototypeJournalArticle.getContent();

    JournalArticle journalArticle =
        JournalArticleLocalServiceUtil.getArticleByUrlTitle(
            _group.getGroupId(), _layoutSetPrototypeJournalArticle.getUrlTitle());

    Assert.assertEquals(content, journalArticle.getContent());

    // Update site template data

    updateArticle(_layoutSetPrototypeJournalArticle, "New Test Content");

    // Check data after layout reset

    Layout layout =
        LayoutLocalServiceUtil.getFriendlyURLLayout(
            _group.getGroupId(), false, _layoutSetPrototypeLayout.getFriendlyURL());

    SitesUtil.resetPrototype(layout);

    Assert.assertEquals(content, journalArticle.getContent());
  }
예제 #5
0
  protected void reindexArticles(long companyId, long startId, long endId) throws Exception {

    List<JournalArticle> articles = new ArrayList<JournalArticle>();

    articles.addAll(getReindexApprovedArticles(companyId, startId, endId));
    articles.addAll(getReindexDraftArticles(companyId, startId, endId));

    if (articles.isEmpty()) {
      return;
    }

    Collection<Document> documents = new ArrayList<Document>(articles.size());

    for (JournalArticle article : articles) {
      if (!article.isIndexable()) {
        continue;
      }

      if (article.isApproved()) {
        JournalArticle latestArticle =
            JournalArticleLocalServiceUtil.getLatestArticle(
                article.getResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);

        if (!latestArticle.isIndexable()) {
          continue;
        }
      }

      Document document = getDocument(article);

      documents.add(document);
    }

    SearchEngineUtil.updateDocuments(getSearchEngineId(), companyId, documents);
  }
예제 #6
0
  @Override
  protected void doReindex(String className, long classPK) throws Exception {
    JournalArticle article =
        JournalArticleLocalServiceUtil.getLatestArticle(classPK, WorkflowConstants.STATUS_APPROVED);

    doReindex(article);
  }
  @Override
  public PortletURL getURLViewDiffs(
      LiferayPortletRequest liferayPortletRequest, LiferayPortletResponse liferayPortletResponse)
      throws Exception {

    PortletURL portletURL =
        liferayPortletResponse.createLiferayPortletURL(
            getControlPanelPlid(liferayPortletRequest),
            PortletKeys.JOURNAL,
            PortletRequest.RENDER_PHASE);

    JournalArticle previousApprovedArticle =
        JournalArticleLocalServiceUtil.getPreviousApprovedArticle(_article);

    if (previousApprovedArticle.getVersion() == _article.getVersion()) {
      return null;
    }

    portletURL.setParameter("struts_action", "/journal/compare_versions");
    portletURL.setParameter("groupId", String.valueOf(_article.getGroupId()));
    portletURL.setParameter("articleId", _article.getArticleId());
    portletURL.setParameter("sourceVersion", String.valueOf(previousApprovedArticle.getVersion()));
    portletURL.setParameter("targetVersion", String.valueOf(_article.getVersion()));

    return portletURL;
  }
예제 #8
0
  protected void updateURLTitle(long groupId, String articleId, String urlTitle) throws Exception {

    String normalizedURLTitle = FriendlyURLNormalizerUtil.normalize(urlTitle, _friendlyURLPattern);

    if (urlTitle.equals(normalizedURLTitle)) {
      return;
    }

    normalizedURLTitle =
        JournalArticleLocalServiceUtil.getUniqueUrlTitle(groupId, articleId, normalizedURLTitle);

    Connection con = null;
    PreparedStatement ps = null;

    try {
      con = DataAccess.getUpgradeOptimizedConnection();

      ps = con.prepareStatement("update JournalArticle set urlTitle = ? where urlTitle = ?");

      ps.setString(1, normalizedURLTitle);
      ps.setString(2, urlTitle);

      ps.executeUpdate();
    } finally {
      DataAccess.cleanUp(con, ps);
    }
  }
  protected void exportJournalArticle(
      PortletDataContext portletDataContext, Layout layout, Element layoutElement)
      throws Exception {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

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

    long articleGroupId = layout.getGroupId();

    if (Validator.isNull(articleId)) {
      if (_log.isWarnEnabled()) {
        _log.warn("No article id found in typeSettings of layout " + layout.getPlid());
      }
    }

    JournalArticle article = null;

    try {
      article =
          JournalArticleLocalServiceUtil.getLatestArticle(
              articleGroupId, articleId, WorkflowConstants.STATUS_APPROVED);
    } catch (NoSuchArticleException nsae) {
      if (_log.isWarnEnabled()) {
        _log.warn(
            "No approved article found with group id "
                + articleGroupId
                + " and article id "
                + articleId);
      }
    }

    if (article == null) {
      return;
    }

    String path = JournalPortletDataHandlerImpl.getArticlePath(portletDataContext, article);

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

    articleElement.addAttribute("path", path);

    Element dlFileEntryTypesElement = layoutElement.addElement("dl-file-entry-types");
    Element dlFoldersElement = layoutElement.addElement("dl-folders");
    Element dlFilesElement = layoutElement.addElement("dl-file-entries");
    Element dlFileRanksElement = layoutElement.addElement("dl-file-ranks");

    JournalPortletDataHandlerImpl.exportArticle(
        portletDataContext,
        layoutElement,
        layoutElement,
        layoutElement,
        dlFileEntryTypesElement,
        dlFoldersElement,
        dlFilesElement,
        dlFileRanksElement,
        article,
        false);
  }
  @Override
  public int getTrashContainedModelsCount(long classPK) throws PortalException, SystemException {

    JournalFolder folder = JournalFolderLocalServiceUtil.getFolder(classPK);

    return JournalArticleLocalServiceUtil.searchCount(
        folder.getGroupId(), classPK, WorkflowConstants.STATUS_IN_TRASH);
  }
  @Test
  public void testExportImportPortletPreferences() throws Exception {

    // Check preferences after site creation

    JournalArticle journalArticle =
        JournalArticleLocalServiceUtil.getArticleByUrlTitle(
            _group.getGroupId(), _layoutSetPrototypeJournalArticle.getUrlTitle());

    Layout layout =
        LayoutLocalServiceUtil.getFriendlyURLLayout(
            _group.getGroupId(), false, _layoutSetPrototypeLayout.getFriendlyURL());

    javax.portlet.PortletPreferences jxPreferences =
        getPortletPreferences(
            layout.getCompanyId(), layout.getPlid(), _layoutSetPrototypeJournalContentPortletId);

    Assert.assertEquals(
        journalArticle.getArticleId(), jxPreferences.getValue("articleId", StringPool.BLANK));

    Assert.assertEquals(
        String.valueOf(journalArticle.getGroupId()),
        jxPreferences.getValue("groupId", StringPool.BLANK));

    Assert.assertEquals(
        String.valueOf(true), jxPreferences.getValue("showAvailableLocales", StringPool.BLANK));

    // Update site template preferences

    javax.portlet.PortletPreferences layoutSetprototypeJxPreferences =
        getPortletPreferences(
            _layoutSetPrototypeLayout.getCompanyId(),
            _layoutSetPrototypeLayout.getPlid(),
            _layoutSetPrototypeJournalContentPortletId);

    layoutSetprototypeJxPreferences.setValue("showAvailableLocales", String.valueOf(false));

    updatePortletPreferences(
        _layoutSetPrototypeLayout.getPlid(),
        _layoutSetPrototypeJournalContentPortletId,
        layoutSetprototypeJxPreferences);

    // Check preferences after layout reset

    SitesUtil.resetPrototype(layout);

    jxPreferences =
        getPortletPreferences(
            _group.getCompanyId(), layout.getPlid(), _layoutSetPrototypeJournalContentPortletId);

    Assert.assertEquals(
        journalArticle.getArticleId(), jxPreferences.getValue("articleId", StringPool.BLANK));
    Assert.assertEquals(
        String.valueOf(journalArticle.getGroupId()),
        jxPreferences.getValue("groupId", StringPool.BLANK));
    Assert.assertEquals(
        Boolean.FALSE.toString(), jxPreferences.getValue("showAvailableLocales", StringPool.BLANK));
  }
  protected JournalArticle addJournalArticle(
      long groupId, long folderId, String name, String content) throws Exception {

    Map<Locale, String> titleMap = new HashMap<Locale, String>();

    Locale locale = LocaleUtil.getDefault();

    String localeId = locale.toString();

    titleMap.put(locale, name);

    Map<Locale, String> descriptionMap = new HashMap<Locale, String>();

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext();

    String xmlContent = getArticleContent(content, localeId);

    return JournalArticleLocalServiceUtil.addArticle(
        TestPropsValues.getUserId(),
        groupId,
        folderId,
        0,
        0,
        StringPool.BLANK,
        true,
        1,
        titleMap,
        descriptionMap,
        xmlContent,
        "general",
        null,
        null,
        null,
        1,
        1,
        1965,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        true,
        0,
        0,
        0,
        0,
        0,
        true,
        false,
        false,
        null,
        null,
        null,
        null,
        serviceContext);
  }
예제 #13
0
  protected List<JournalArticle> getReindexApprovedArticles(
      long companyId, long startId, long endId) throws Exception {

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            JournalArticle.class, PACLClassLoaderUtil.getPortalClassLoader());

    Property property = PropertyFactoryUtil.forName("id");

    dynamicQuery.add(property.ge(startId));
    dynamicQuery.add(property.lt(endId));

    addReindexCriteria(dynamicQuery, companyId, WorkflowConstants.STATUS_APPROVED);

    return JournalArticleLocalServiceUtil.dynamicQuery(dynamicQuery);
  }
  @Test
  public void testJournalArticleTreePathWithJournalArticleInTrash() throws Exception {

    JournalFolder parentFolder =
        JournalTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString());

    JournalArticle article =
        JournalTestUtil.addArticle(
            _group.getGroupId(), parentFolder.getFolderId(), "title", "content");

    JournalArticleLocalServiceUtil.moveArticleToTrash(
        TestPropsValues.getUserId(), _group.getGroupId(), article.getArticleId());

    JournalFolderLocalServiceUtil.deleteFolder(parentFolder.getFolderId(), false);

    doVerify();
  }
예제 #15
0
  protected JournalArticle updateJournalArticle(
      JournalArticle journalArticle, String name, String content) throws Exception {

    Map<Locale, String> titleMap = new HashMap<Locale, String>();

    for (Locale locale : _locales) {
      titleMap.put(locale, name.concat(LocaleUtil.toLanguageId(locale)));
    }

    return JournalArticleLocalServiceUtil.updateArticle(
        journalArticle.getUserId(),
        journalArticle.getGroupId(),
        journalArticle.getFolderId(),
        journalArticle.getArticleId(),
        journalArticle.getVersion(),
        titleMap,
        journalArticle.getDescriptionMap(),
        content,
        journalArticle.getLayoutUuid(),
        ServiceTestUtil.getServiceContext());
  }
예제 #16
0
  protected void verifyPermissionsAndAssets() throws Exception {
    ActionableDynamicQuery actionableDynamicQuery =
        JournalArticleLocalServiceUtil.getActionableDynamicQuery();

    actionableDynamicQuery.setPerformActionMethod(
        new ActionableDynamicQuery.PerformActionMethod() {

          @Override
          public void performAction(Object object) throws PortalException {

            JournalArticle article = (JournalArticle) object;

            verifyPermissionsAndAssets(article);
          }
        });

    actionableDynamicQuery.performActions();

    if (_log.isDebugEnabled()) {
      _log.debug("Permissions and assets verified for articles");
    }
  }
예제 #17
0
  protected void reindexArticles(long companyId) throws Exception {
    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            JournalArticle.class, PACLClassLoaderUtil.getPortalClassLoader());

    Projection minIdProjection = ProjectionFactoryUtil.min("id");
    Projection maxIdProjection = ProjectionFactoryUtil.max("id");

    ProjectionList projectionList = ProjectionFactoryUtil.projectionList();

    projectionList.add(minIdProjection);
    projectionList.add(maxIdProjection);

    dynamicQuery.setProjection(projectionList);

    addReindexCriteria(dynamicQuery, companyId, WorkflowConstants.STATUS_APPROVED);

    List<Object[]> results = JournalArticleLocalServiceUtil.dynamicQuery(dynamicQuery);

    Object[] minAndMaxIds = results.get(0);

    if ((minAndMaxIds[0] == null) || (minAndMaxIds[1] == null)) {
      return;
    }

    long minId = (Long) minAndMaxIds[0];
    long maxId = (Long) minAndMaxIds[1];

    long startId = minId;
    long endId = startId + DEFAULT_INTERVAL;

    while (startId <= maxId) {
      reindexArticles(companyId, startId, endId);

      startId = endId;
      endId += DEFAULT_INTERVAL;
    }
  }
  @Test
  public void testActionableDynamicQuery() throws Exception {
    final IntegerWrapper count = new IntegerWrapper();

    ActionableDynamicQuery actionableDynamicQuery =
        JournalArticleLocalServiceUtil.getActionableDynamicQuery();

    actionableDynamicQuery.setPerformActionMethod(
        new ActionableDynamicQuery.PerformActionMethod() {
          @Override
          public void performAction(Object object) {
            JournalArticle journalArticle = (JournalArticle) object;

            Assert.assertNotNull(journalArticle);

            count.increment();
          }
        });

    actionableDynamicQuery.performActions();

    Assert.assertEquals(count.getValue(), _persistence.countAll());
  }
  @Override
  public List<TrashRenderer> getTrashContainedModelTrashRenderers(long classPK, int start, int end)
      throws PortalException, SystemException {

    List<TrashRenderer> trashRenderers = new ArrayList<TrashRenderer>();

    JournalFolder folder = JournalFolderLocalServiceUtil.getFolder(classPK);

    List<JournalArticle> articles =
        JournalArticleLocalServiceUtil.search(
            folder.getGroupId(), classPK, WorkflowConstants.STATUS_IN_TRASH, start, end);

    for (JournalArticle article : articles) {
      TrashHandler trashHandler =
          TrashHandlerRegistryUtil.getTrashHandler(JournalArticle.class.getName());

      TrashRenderer trashRenderer = trashHandler.getTrashRenderer(article.getResourcePrimKey());

      trashRenderers.add(trashRenderer);
    }

    return trashRenderers;
  }
  @Override
  public String getSummary(PortletRequest portletRequest, PortletResponse portletResponse) {

    Locale locale = getLocale(portletRequest);

    String summary = _article.getDescription(locale);

    if (Validator.isNotNull(summary)) {
      return summary;
    }

    try {
      PortletRequestModel portletRequestModel = null;
      ThemeDisplay themeDisplay = null;

      if ((portletRequest != null) && (portletResponse != null)) {
        portletRequestModel = new PortletRequestModel(portletRequest, portletResponse);
        themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
      }

      JournalArticleDisplay articleDisplay =
          JournalArticleLocalServiceUtil.getArticleDisplay(
              _article,
              null,
              null,
              LanguageUtil.getLanguageId(locale),
              1,
              portletRequestModel,
              themeDisplay);

      summary = StringUtil.shorten(HtmlUtil.stripHtml(articleDisplay.getContent()), 200);
    } catch (Exception e) {
    }

    return summary;
  }
예제 #21
0
 @Override
 protected void doReceive(Message message) throws Exception {
   JournalArticleLocalServiceUtil.checkArticles();
 }
 @Override
 protected void deleteStagedModel(StagedModel stagedModel) throws Exception {
   JournalArticleLocalServiceUtil.deleteArticle((JournalArticle) stagedModel);
 }
예제 #23
0
  protected JournalArticle addJournalArticle(long groupId, String name, String content)
      throws Exception {

    Map<Locale, String> titleMap = new HashMap<Locale, String>();

    for (Locale locale : _locales) {
      titleMap.put(locale, name.concat(LocaleUtil.toLanguageId(locale)));
    }

    Map<Locale, String> descriptionMap = new HashMap<Locale, String>();

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext();

    StringBundler sb = new StringBundler(3 + 6 * _locales.length);

    sb.append("<?xml version=\"1.0\"?><root available-locales=");
    sb.append("\"en_US,es_ES,de_DE\" default-locale=\"en_US\">");

    for (Locale locale : _locales) {
      sb.append("<static-content language-id=\"");
      sb.append(LocaleUtil.toLanguageId(locale));
      sb.append("\"><![CDATA[<p>");
      sb.append(content);
      sb.append(LocaleUtil.toLanguageId(locale));
      sb.append("</p>]]></static-content>");
    }

    sb.append("</root>");

    return JournalArticleLocalServiceUtil.addArticle(
        TestPropsValues.getUserId(),
        groupId,
        JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
        0,
        0,
        StringPool.BLANK,
        true,
        1,
        titleMap,
        descriptionMap,
        sb.toString(),
        "general",
        null,
        null,
        null,
        1,
        1,
        1965,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        true,
        0,
        0,
        0,
        0,
        0,
        true,
        false,
        false,
        null,
        null,
        null,
        null,
        serviceContext);
  }
  protected void doAddJournalArticles(
      String journalStructureId, String journalTemplateId, String name, InputStream inputStream)
      throws Exception {

    String journalArticleId = getJournalArticleId(name);

    String title = getName(name);

    Map<Locale, String> titleMap = getNameMap(title);

    String content = StringUtil.read(inputStream);

    content = processJournalArticleContent(content);

    JournalArticle journalArticle =
        JournalArticleLocalServiceUtil.addArticle(
            userId,
            groupId,
            0,
            0,
            journalArticleId,
            false,
            JournalArticleConstants.VERSION_DEFAULT,
            titleMap,
            null,
            content,
            "general",
            journalStructureId,
            journalTemplateId,
            StringPool.BLANK,
            1,
            1,
            2010,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            true,
            0,
            0,
            0,
            0,
            0,
            true,
            true,
            false,
            StringPool.BLANK,
            null,
            new HashMap<String, byte[]>(),
            StringPool.BLANK,
            serviceContext);

    JournalArticleLocalServiceUtil.updateStatus(
        userId,
        groupId,
        journalArticle.getArticleId(),
        journalArticle.getVersion(),
        WorkflowConstants.STATUS_APPROVED,
        StringPool.BLANK,
        serviceContext);
  }
  protected void exportImportJournalArticle(boolean companyScopeDependencies) throws Exception {

    JournalArticle article = null;
    DDMStructure ddmStructure = null;
    DDMTemplate ddmTemplate = null;

    long groupId = group.getGroupId();

    Company company = CompanyLocalServiceUtil.fetchCompany(group.getCompanyId());

    Group companyGroup = company.getGroup();

    if (companyScopeDependencies) {
      groupId = companyGroup.getGroupId();
    }

    ddmStructure = DDMStructureTestUtil.addStructure(groupId, JournalArticle.class.getName());

    ddmTemplate = DDMTemplateTestUtil.addTemplate(groupId, ddmStructure.getStructureId());

    String content = DDMStructureTestUtil.getSampleStructuredContent();

    article =
        JournalTestUtil.addArticleWithXMLContent(
            group.getGroupId(),
            content,
            ddmStructure.getStructureKey(),
            ddmTemplate.getTemplateKey());

    exportImportPortlet(PortletKeys.JOURNAL);

    int articlesCount = JournalArticleLocalServiceUtil.getArticlesCount(importedGroup.getGroupId());

    Assert.assertEquals(1, articlesCount);

    JournalArticle groupArticle =
        JournalArticleLocalServiceUtil.fetchJournalArticleByUuidAndGroupId(
            article.getUuid(), importedGroup.getGroupId());

    Assert.assertNotNull(groupArticle);

    groupId = importedGroup.getGroupId();

    if (companyScopeDependencies) {
      DDMStructure importedDDMStructure =
          DDMStructureLocalServiceUtil.fetchDDMStructureByUuidAndGroupId(
              ddmStructure.getUuid(), groupId);

      Assert.assertNull(importedDDMStructure);

      DDMTemplate importedDDMTemplate =
          DDMTemplateLocalServiceUtil.fetchDDMTemplateByUuidAndGroupId(
              ddmTemplate.getUuid(), groupId);

      Assert.assertNull(importedDDMTemplate);

      groupId = companyGroup.getGroupId();
    }

    DDMStructure dependentDDMStructure =
        DDMStructureLocalServiceUtil.fetchDDMStructureByUuidAndGroupId(
            ddmStructure.getUuid(), groupId);

    Assert.assertNotNull(dependentDDMStructure);

    DDMTemplate dependentDDMTemplate =
        DDMTemplateLocalServiceUtil.fetchDDMTemplateByUuidAndGroupId(
            ddmTemplate.getUuid(), groupId);

    Assert.assertNotNull(dependentDDMTemplate);
    Assert.assertEquals(article.getDDMStructureKey(), dependentDDMStructure.getStructureKey());
    Assert.assertEquals(article.getDDMTemplateKey(), dependentDDMTemplate.getTemplateKey());
    Assert.assertEquals(dependentDDMTemplate.getClassPK(), dependentDDMStructure.getStructureId());
  }
  protected String doExportData(
      PortletDataContext context, String portletId, PortletPreferences preferences)
      throws Exception {

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

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

    if (articleId == null) {
      if (_log.isWarnEnabled()) {
        _log.warn("No article id found in preferences of portlet " + portletId);
      }

      return StringPool.BLANK;
    }

    long articleGroupId = GetterUtil.getLong(preferences.getValue("group-id", StringPool.BLANK));

    if (articleGroupId <= 0) {
      if (_log.isWarnEnabled()) {
        _log.warn("No group id found in preferences of portlet " + portletId);
      }

      return StringPool.BLANK;
    }

    JournalArticle article = null;

    try {
      article =
          JournalArticleLocalServiceUtil.getLatestArticle(
              articleGroupId, articleId, WorkflowConstants.STATUS_APPROVED);
    } catch (NoSuchArticleException nsae) {
      if (_log.isWarnEnabled()) {
        _log.warn(
            "No approved article found with group id "
                + articleGroupId
                + " and article id "
                + articleId);
      }
    }

    if (article == null) {
      return StringPool.BLANK;
    }

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("journal-content-data");

    String path = JournalPortletDataHandlerImpl.getArticlePath(context, article);

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

    articleElement.addAttribute("path", path);

    Element dlFoldersElement = rootElement.addElement("dl-folders");
    Element dlFilesElement = rootElement.addElement("dl-file-entries");
    Element dlFileRanksElement = rootElement.addElement("dl-file-ranks");
    Element igFoldersElement = rootElement.addElement("ig-folders");
    Element igImagesElement = rootElement.addElement("ig-images");

    JournalPortletDataHandlerImpl.exportArticle(
        context,
        rootElement,
        dlFoldersElement,
        dlFilesElement,
        dlFileRanksElement,
        igFoldersElement,
        igImagesElement,
        article,
        false);

    String structureId = article.getStructureId();

    if (Validator.isNotNull(structureId)) {
      JournalStructure structure =
          JournalStructureUtil.findByG_S(article.getGroupId(), structureId);

      JournalPortletDataHandlerImpl.exportStructure(context, rootElement, structure);
    }

    String templateId = article.getTemplateId();

    if (Validator.isNotNull(templateId)) {
      JournalTemplate template = JournalTemplateUtil.findByG_T(article.getGroupId(), templateId);

      JournalPortletDataHandlerImpl.exportTemplate(
          context,
          rootElement,
          dlFoldersElement,
          dlFilesElement,
          dlFileRanksElement,
          igFoldersElement,
          igImagesElement,
          template);
    }

    return document.formattedString();
  }
예제 #27
0
  @Override
  public ActionForward render(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      RenderRequest renderRequest,
      RenderResponse renderResponse)
      throws Exception {

    PortletPreferences preferences = renderRequest.getPreferences();

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

    long groupId = ParamUtil.getLong(renderRequest, "groupId");

    if (groupId <= 0) {
      groupId = GetterUtil.getLong(preferences.getValue("groupId", StringPool.BLANK));
    }

    String articleId = ParamUtil.getString(renderRequest, "articleId");
    String templateId = ParamUtil.getString(renderRequest, "templateId");

    if (Validator.isNull(articleId)) {
      articleId = GetterUtil.getString(preferences.getValue("articleId", StringPool.BLANK));
      templateId = GetterUtil.getString(preferences.getValue("templateId", StringPool.BLANK));
    }

    String viewMode = ParamUtil.getString(renderRequest, "viewMode");
    String languageId = LanguageUtil.getLanguageId(renderRequest);
    int page = ParamUtil.getInteger(renderRequest, "page", 1);
    String xmlRequest = PortletRequestUtil.toXML(renderRequest, renderResponse);

    JournalArticle article = null;
    JournalArticleDisplay articleDisplay = null;

    if ((groupId > 0) && Validator.isNotNull(articleId)) {
      try {
        article =
            JournalArticleLocalServiceUtil.getLatestArticle(
                groupId, articleId, WorkflowConstants.STATUS_ANY);

        double version = article.getVersion();

        articleDisplay =
            JournalContentUtil.getDisplay(
                groupId,
                articleId,
                version,
                templateId,
                viewMode,
                languageId,
                themeDisplay,
                page,
                xmlRequest);
      } catch (Exception e) {
        renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE);

        articleDisplay =
            JournalContentUtil.getDisplay(
                groupId,
                articleId,
                templateId,
                viewMode,
                languageId,
                themeDisplay,
                page,
                xmlRequest);
      }
    }

    if (article != null) {
      renderRequest.setAttribute(WebKeys.JOURNAL_ARTICLE, article);
    }

    if (articleDisplay != null) {
      renderRequest.setAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY, articleDisplay);
    } else {
      renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY);
    }

    return mapping.findForward("portlet.journal_content.view");
  }
 @Override
 protected StagedModel getStagedModel(String uuid, long groupId) {
   return JournalArticleLocalServiceUtil.fetchJournalArticleByUuidAndGroupId(uuid, groupId);
 }
  @Test
  public void testExportImportPortletPreferences() throws Exception {

    // Check preferences after site creation

    JournalArticle journalArticle =
        JournalArticleLocalServiceUtil.getArticleByUrlTitle(
            _group.getGroupId(), _layoutSetPrototypeJournalArticle.getUrlTitle());

    Layout layout =
        LayoutLocalServiceUtil.getFriendlyURLLayout(
            _group.getGroupId(), false, _layoutSetPrototypeLayout.getFriendlyURL());

    javax.portlet.PortletPreferences jxPreferences =
        getPortletPreferences(
            layout.getCompanyId(), layout.getPlid(), _layoutSetPrototypeJournalContentPortletId);

    Assert.assertEquals(
        journalArticle.getArticleId(), jxPreferences.getValue("articleId", StringPool.BLANK));

    Assert.assertEquals(
        String.valueOf(journalArticle.getGroupId()),
        jxPreferences.getValue("groupId", StringPool.BLANK));

    Assert.assertEquals(
        String.valueOf(true), jxPreferences.getValue("showAvailableLocales", StringPool.BLANK));

    // Update site template preferences

    javax.portlet.PortletPreferences layoutSetprototypeJxPreferences =
        getPortletPreferences(
            _layoutSetPrototypeLayout.getCompanyId(),
            _layoutSetPrototypeLayout.getPlid(),
            _layoutSetPrototypeJournalContentPortletId);

    layoutSetprototypeJxPreferences.setValue("showAvailableLocales", String.valueOf(false));

    updatePortletPreferences(
        _layoutSetPrototypeLayout.getPlid(),
        _layoutSetPrototypeJournalContentPortletId,
        layoutSetprototypeJxPreferences);

    // Check preferences after layout reset

    SitesUtil.resetPrototype(layout);

    jxPreferences =
        getPortletPreferences(
            _group.getCompanyId(), layout.getPlid(), _layoutSetPrototypeJournalContentPortletId);

    Assert.assertEquals(
        journalArticle.getArticleId(), jxPreferences.getValue("articleId", StringPool.BLANK));
    Assert.assertEquals(
        String.valueOf(journalArticle.getGroupId()),
        jxPreferences.getValue("groupId", StringPool.BLANK));
    Assert.assertEquals(
        Boolean.FALSE.toString(), jxPreferences.getValue("showAvailableLocales", StringPool.BLANK));

    // Update journal content portlet with a new globally scoped journal
    // article

    Company company = CompanyUtil.fetchByPrimaryKey(_layoutSetPrototypeLayout.getCompanyId());

    Group companyGroup = company.getGroup();

    JournalArticle globalScopeJournalArticle =
        addJournalArticle(companyGroup.getGroupId(), 0, "Global Article", "Global Content");

    layoutSetprototypeJxPreferences.setValue("articleId", globalScopeJournalArticle.getArticleId());
    layoutSetprototypeJxPreferences.setValue("groupId", Long.toString(companyGroup.getGroupId()));
    layoutSetprototypeJxPreferences.setValue("lfrScopeLayoutUuid", StringPool.BLANK);
    layoutSetprototypeJxPreferences.setValue("lfrScopeType", "company");

    updatePortletPreferences(
        _layoutSetPrototypeLayout.getPlid(),
        _layoutSetPrototypeJournalContentPortletId,
        layoutSetprototypeJxPreferences);

    jxPreferences =
        getPortletPreferences(
            _group.getCompanyId(), layout.getPlid(), _layoutSetPrototypeJournalContentPortletId);

    // Check preferences when journal article is from the global scope

    Assert.assertEquals(
        globalScopeJournalArticle.getArticleId(),
        jxPreferences.getValue("articleId", StringPool.BLANK));
    Assert.assertEquals(
        String.valueOf(companyGroup.getGroupId()),
        jxPreferences.getValue("groupId", StringPool.BLANK));
    Assert.assertEquals(
        StringPool.BLANK, jxPreferences.getValue("lfrScopeLayoutUuid", StringPool.BLANK));
    Assert.assertEquals("company", jxPreferences.getValue("lfrScopeType", StringPool.BLANK));
  }
예제 #30
0
  protected void enableLocalStaging(boolean stageJournal, boolean stagePolls) throws Exception {

    Group group = ServiceTestUtil.addGroup();

    ServiceTestUtil.addLayout(group.getGroupId(), "Page1");
    ServiceTestUtil.addLayout(group.getGroupId(), "Page2");

    int initialPagesCount = LayoutLocalServiceUtil.getLayoutsCount(group, false);

    // Create content

    JournalArticle journalArticle = addJournalArticle(group.getGroupId(), "Title", "content");

    PollsQuestion pollsQuestion = addPollsQuestion(group.getGroupId(), "Question", "Description");

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setScopeGroupId(group.getGroupId());

    Map<String, String[]> parameters = StagingUtil.getStagingParameters();

    parameters.put(PortletDataHandlerKeys.PORTLET_DATA_ALL, new String[] {String.valueOf(false)});

    parameters.put(
        PortletDataHandlerKeys.PORTLET_DATA + "_" + PortletKeys.JOURNAL,
        new String[] {String.valueOf(stageJournal)});

    parameters.put(
        PortletDataHandlerKeys.PORTLET_DATA + "_" + PortletKeys.POLLS,
        new String[] {String.valueOf(stagePolls)});

    for (String parameterName : parameters.keySet()) {
      serviceContext.setAttribute(parameterName, parameters.get(parameterName)[0]);
    }

    serviceContext.setAttribute(
        StagingConstants.STAGED_PORTLET + PortletKeys.JOURNAL, stageJournal);

    serviceContext.setAttribute(StagingConstants.STAGED_PORTLET + PortletKeys.POLLS, stagePolls);

    // Enable staging

    StagingUtil.enableLocalStaging(
        TestPropsValues.getUserId(), group, group, false, false, serviceContext);

    Group stagingGroup = group.getStagingGroup();

    Assert.assertNotNull(stagingGroup);

    Assert.assertEquals(
        LayoutLocalServiceUtil.getLayoutsCount(stagingGroup, false), initialPagesCount);

    // Update content in staging

    JournalArticle stagingJournalArticle =
        JournalArticleLocalServiceUtil.getArticleByUrlTitle(
            stagingGroup.getGroupId(), journalArticle.getUrlTitle());

    stagingJournalArticle =
        updateJournalArticle(stagingJournalArticle, "Title2", stagingJournalArticle.getContent());

    PollsQuestion stagingQuestion =
        PollsQuestionLocalServiceUtil.getPollsQuestionByUuidAndGroupId(
            pollsQuestion.getUuid(), stagingGroup.getGroupId());

    stagingQuestion = updatePollsQuestion(stagingQuestion, "Question2", "Description2");

    // Publish to live

    StagingUtil.publishLayouts(
        TestPropsValues.getUserId(),
        stagingGroup.getGroupId(),
        group.getGroupId(),
        false,
        parameters,
        null,
        null);

    // Retrieve content from live after publishing

    journalArticle = JournalArticleLocalServiceUtil.getArticle(journalArticle.getId());
    pollsQuestion = PollsQuestionLocalServiceUtil.getQuestion(pollsQuestion.getQuestionId());

    if (stagePolls) {
      for (Locale locale : _locales) {
        Assert.assertEquals(pollsQuestion.getTitle(locale), stagingQuestion.getTitle(locale));
      }
    } else {
      for (Locale locale : _locales) {
        Assert.assertFalse(pollsQuestion.getTitle(locale).equals(stagingQuestion.getTitle(locale)));
      }
    }

    if (stageJournal) {
      for (Locale locale : _locales) {
        Assert.assertEquals(
            journalArticle.getTitle(locale), stagingJournalArticle.getTitle(locale));
      }
    } else {
      for (Locale locale : _locales) {
        Assert.assertFalse(
            journalArticle.getTitle(locale).equals(stagingJournalArticle.getTitle(locale)));
      }
    }
  }