Ejemplo n.º 1
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);
    }
  }
  @Test
  public void testGetNoAssetThreads() throws Exception {
    MBTestUtil.addMessage(_group.getGroupId());

    MBMessage message = MBTestUtil.addMessage(_group.getGroupId());

    MBThread thread = message.getThread();

    AssetEntry assetEntry =
        AssetEntryLocalServiceUtil.fetchEntry(MBThread.class.getName(), thread.getThreadId());

    Assert.assertNotNull(assetEntry);

    AssetEntryLocalServiceUtil.deleteAssetEntry(assetEntry);

    List<MBThread> threads = MBThreadLocalServiceUtil.getNoAssetThreads();

    Assert.assertEquals(1, threads.size());
    Assert.assertEquals(thread, threads.get(0));
  }
  @Test
  public void testAsstTags() throws Exception {
    long folderId = parentFolder.getFolderId();
    String name = "TestTags.txt";
    String description = StringPool.BLANK;
    String changeLog = StringPool.BLANK;
    byte[] bytes = CONTENT.getBytes();

    ServiceContext serviceContext = new ServiceContext();

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

    String[] assetTagNames = new String[] {"hello", "world"};

    serviceContext.setAssetTagNames(assetTagNames);

    FileEntry fileEntry =
        DLAppServiceUtil.addFileEntry(
            group.getGroupId(),
            folderId,
            name,
            ContentTypes.TEXT_PLAIN,
            name,
            description,
            changeLog,
            bytes,
            serviceContext);

    AssetEntry assetEntry =
        AssetEntryLocalServiceUtil.fetchEntry(
            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());

    AssertUtils.assertEqualsSorted(assetTagNames, assetEntry.getTagNames());

    Thread.sleep(1000 * TestPropsValues.JUNIT_DELAY_FACTOR);

    _fileEntry = fileEntry;

    search(_fileEntry, false, "hello", true);
    search(_fileEntry, false, "world", true);
    search(_fileEntry, false, "liferay", false);

    assetTagNames = new String[] {"hello", "world", "liferay"};

    serviceContext.setAssetTagNames(assetTagNames);

    fileEntry =
        DLAppServiceUtil.updateFileEntry(
            fileEntry.getFileEntryId(),
            name,
            ContentTypes.TEXT_PLAIN,
            name,
            description,
            changeLog,
            false,
            bytes,
            serviceContext);

    assetEntry =
        AssetEntryLocalServiceUtil.fetchEntry(
            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());

    AssertUtils.assertEqualsSorted(assetTagNames, assetEntry.getTagNames());

    Thread.sleep(1000 * TestPropsValues.JUNIT_DELAY_FACTOR);

    _fileEntry = fileEntry;

    search(_fileEntry, false, "hello", true);
    search(_fileEntry, false, "world", true);
    search(_fileEntry, false, "liferay", true);

    DLAppServiceUtil.deleteFileEntry(_fileEntry.getFileEntryId());

    _fileEntry = null;
  }
  protected void readAssetLinks(PortletDataContext portletDataContext) throws Exception {

    String xml =
        portletDataContext.getZipEntryAsString(
            ExportImportPathUtil.getSourceRootPath(portletDataContext) + "/links.xml");

    if (xml == null) {
      return;
    }

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

    List<Element> assetLinkGroupElements = rootElement.elements("asset-link-group");

    for (Element assetLinkGroupElement : assetLinkGroupElements) {
      String sourceUuid = assetLinkGroupElement.attributeValue("source-uuid");

      AssetEntry sourceAssetEntry =
          AssetEntryLocalServiceUtil.fetchEntry(portletDataContext.getScopeGroupId(), sourceUuid);

      if (sourceAssetEntry == null) {
        sourceAssetEntry =
            AssetEntryLocalServiceUtil.fetchEntry(
                portletDataContext.getCompanyGroupId(), sourceUuid);
      }

      if (sourceAssetEntry == null) {
        if (_log.isWarnEnabled()) {
          _log.warn("Unable to find asset entry with uuid " + sourceUuid);
        }

        continue;
      }

      List<Element> assetLinksElements = assetLinkGroupElement.elements("asset-link");

      for (Element assetLinkElement : assetLinksElements) {
        String path = assetLinkElement.attributeValue("path");

        if (!portletDataContext.isPathNotProcessed(path)) {
          continue;
        }

        String targetUuid = assetLinkElement.attributeValue("target-uuid");

        AssetEntry targetAssetEntry =
            AssetEntryLocalServiceUtil.fetchEntry(portletDataContext.getScopeGroupId(), targetUuid);

        if (targetAssetEntry == null) {
          targetAssetEntry =
              AssetEntryLocalServiceUtil.fetchEntry(
                  portletDataContext.getCompanyGroupId(), targetUuid);
        }

        if (targetAssetEntry == null) {
          if (_log.isWarnEnabled()) {
            _log.warn("Unable to find asset entry with uuid " + targetUuid);
          }

          continue;
        }

        AssetLink assetLink = (AssetLink) portletDataContext.getZipEntryAsObject(path);

        long userId = portletDataContext.getUserId(assetLink.getUserUuid());

        AssetLinkLocalServiceUtil.updateLink(
            userId,
            sourceAssetEntry.getEntryId(),
            targetAssetEntry.getEntryId(),
            assetLink.getType(),
            assetLink.getWeight());
      }
    }
  }