コード例 #1
0
  public AssetEntry getParentEntry(long entryId) throws PortalException, SystemException {

    List<AssetLink> links =
        assetLinkLocalService.getReverseLinks(entryId, AssetLinkConstants.TYPE_CHILD);

    if (links.isEmpty()) {
      throw new NoSuchEntryException();
    }

    AssetLink link = links.get(0);

    return getEntry(link.getEntryId1());
  }
コード例 #2
0
  @Test
  public void testDeleteLinksByAssetEntryGroupId() throws Exception {

    // Add link between entries in group 1

    AssetEntry assetEntry1 = AssetTestUtil.addAssetEntry(_group1.getGroupId());
    AssetEntry assetEntry2 = AssetTestUtil.addAssetEntry(_group1.getGroupId());

    AssetLinkLocalServiceUtil.addLink(
        TestPropsValues.getUserId(), assetEntry1.getEntryId(), assetEntry2.getEntryId(), 0, 0);

    // Add link between entries in different groups

    assetEntry1 = AssetTestUtil.addAssetEntry(_group1.getGroupId());
    assetEntry2 = AssetTestUtil.addAssetEntry(_group2.getGroupId());

    AssetLinkLocalServiceUtil.addLink(
        TestPropsValues.getUserId(), assetEntry1.getEntryId(), assetEntry2.getEntryId(), 0, 0);

    // Add link between entries in group 2

    assetEntry1 = AssetTestUtil.addAssetEntry(_group2.getGroupId());
    assetEntry2 = AssetTestUtil.addAssetEntry(_group2.getGroupId());

    AssetLinkLocalServiceUtil.addLink(
        TestPropsValues.getUserId(), assetEntry1.getEntryId(), assetEntry2.getEntryId(), 0, 0);

    AssetLinkLocalServiceUtil.deleteGroupLinks(_group1.getGroupId());

    List<AssetLink> assetLinks =
        AssetLinkLocalServiceUtil.getAssetLinks(QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    Assert.assertNotNull(assetLinks);
    Assert.assertTrue(assetLinks.size() > 0);

    for (AssetLink assetLink : assetLinks) {
      AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(assetLink.getEntryId1());

      Assert.assertTrue(assetEntry.getGroupId() != _group1.getGroupId());

      assetEntry = AssetEntryLocalServiceUtil.getEntry(assetLink.getEntryId2());

      Assert.assertTrue(assetEntry.getGroupId() != _group1.getGroupId());
    }
  }