コード例 #1
0
  protected void checkPopulatedServiceContext(
      ServiceContext serviceContext, WikiPage page, boolean hasExpandoValues) throws Exception {

    long[] assetCategoryIds =
        AssetCategoryLocalServiceUtil.getCategoryIds(
            WikiPage.class.getName(), page.getResourcePrimKey());

    Assert.assertArrayEquals(serviceContext.getAssetCategoryIds(), assetCategoryIds);

    AssetEntry assetEntry =
        AssetEntryLocalServiceUtil.getEntry(WikiPage.class.getName(), page.getResourcePrimKey());

    List<AssetLink> assetLinks = AssetLinkLocalServiceUtil.getLinks(assetEntry.getEntryId());

    long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);

    Assert.assertArrayEquals(serviceContext.getAssetLinkEntryIds(), assetLinkEntryIds);

    String[] assetTagNames =
        AssetTagLocalServiceUtil.getTagNames(WikiPage.class.getName(), page.getResourcePrimKey());

    Assert.assertArrayEquals(serviceContext.getAssetTagNames(), assetTagNames);

    if (hasExpandoValues) {
      ExpandoBridge expandoBridge = page.getExpandoBridge();

      AssertUtils.assertEquals(
          expandoBridge.getAttributes(), serviceContext.getExpandoBridgeAttributes());
    }
  }
コード例 #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());
    }
  }
コード例 #3
0
  public void addAssetLinks(Class<?> clazz, long classPK) throws PortalException, SystemException {

    AssetEntry assetEntry = null;

    try {
      assetEntry = AssetEntryLocalServiceUtil.getEntry(clazz.getName(), classPK);
    } catch (NoSuchEntryException nsee) {
      return;
    }

    List<AssetLink> directAssetLinks =
        AssetLinkLocalServiceUtil.getDirectLinks(assetEntry.getEntryId());

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

    Map<Integer, List<AssetLink>> assetLinksMap = new HashMap<Integer, List<AssetLink>>();

    for (AssetLink assetLink : directAssetLinks) {
      List<AssetLink> assetLinks = assetLinksMap.get(assetLink.getType());

      if (assetLinks == null) {
        assetLinks = new ArrayList<AssetLink>();

        assetLinksMap.put(assetLink.getType(), assetLinks);
      }

      assetLinks.add(assetLink);
    }

    for (Map.Entry<Integer, List<AssetLink>> entry : assetLinksMap.entrySet()) {

      int assetLinkType = entry.getKey();
      List<AssetLink> assetLinks = entry.getValue();

      List<String> assetLinkUuids = new ArrayList<String>(directAssetLinks.size());

      for (AssetLink assetLink : assetLinks) {
        try {
          AssetEntry assetLinkEntry = AssetEntryLocalServiceUtil.getEntry(assetLink.getEntryId2());

          assetLinkUuids.add(assetLinkEntry.getClassUuid());
        } catch (NoSuchEntryException nsee) {
        }
      }

      _assetLinkUuidsMap.put(
          getPrimaryKeyString(assetEntry.getClassUuid(), String.valueOf(assetLinkType)),
          assetLinkUuids.toArray(new String[assetLinkUuids.size()]));
    }
  }
コード例 #4
0
  protected void readAssetLinks(PortletDataContext portletDataContext) throws Exception {

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

    if (xml == null) {
      return;
    }

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

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

    for (Element assetLinkElement : assetLinkElements) {
      String sourceUuid = GetterUtil.getString(assetLinkElement.attributeValue("source-uuid"));
      String[] assetEntryUuidArray =
          StringUtil.split(GetterUtil.getString(assetLinkElement.attributeValue("target-uuids")));
      int assetLinkType = GetterUtil.getInteger(assetLinkElement.attributeValue("type"));

      List<Long> assetEntryIds = new ArrayList<Long>();

      for (String assetEntryUuid : assetEntryUuidArray) {
        try {
          AssetEntry assetEntry =
              AssetEntryLocalServiceUtil.getEntry(
                  portletDataContext.getScopeGroupId(), assetEntryUuid);

          assetEntryIds.add(assetEntry.getEntryId());
        } catch (NoSuchEntryException nsee) {
        }
      }

      if (assetEntryIds.isEmpty()) {
        continue;
      }

      long[] assetEntryIdsArray =
          ArrayUtil.toArray(assetEntryIds.toArray(new Long[assetEntryIds.size()]));

      try {
        AssetEntry assetEntry =
            AssetEntryLocalServiceUtil.getEntry(portletDataContext.getScopeGroupId(), sourceUuid);

        AssetLinkLocalServiceUtil.updateLinks(
            assetEntry.getUserId(), assetEntry.getEntryId(), assetEntryIdsArray, assetLinkType);
      } catch (NoSuchEntryException nsee) {
      }
    }
  }
コード例 #5
0
  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());
      }
    }
  }