Exemplo n.º 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);
      }
    }
  }
Exemplo n.º 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);
    }
  }