protected void exportAssetTag(
      PortletDataContext portletDataContext, AssetTag assetTag, Element assetTagsElement)
      throws SystemException, PortalException {

    String path = getAssetTagPath(portletDataContext, assetTag.getTagId());

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

    Element assetTagElement = assetTagsElement.addElement("tag");

    assetTagElement.addAttribute("path", path);

    assetTag.setUserUuid(assetTag.getUserUuid());

    portletDataContext.addZipEntry(path, assetTag);

    List<AssetTagProperty> assetTagProperties =
        AssetTagPropertyLocalServiceUtil.getTagProperties(assetTag.getTagId());

    for (AssetTagProperty assetTagProperty : assetTagProperties) {
      Element propertyElement = assetTagElement.addElement("property");

      propertyElement.addAttribute("key", assetTagProperty.getKey());
      propertyElement.addAttribute("value", assetTagProperty.getValue());
    }

    portletDataContext.addPermissions(AssetTag.class, assetTag.getTagId());
  }
Example #2
0
  /**
   * Returns the tags matching the group and names, creating new tags with the names if the group
   * doesn't already have them.
   *
   * <p>For each name, if a tag with that name doesn't already exist for the group, this method
   * creates a new tag with that name for the group. If a tag with that name already exists in the
   * company group, this method copies that company group's tag's properties to the group's new tag.
   *
   * @param userId the primary key of the user
   * @param group ID the primary key of the tag's group
   * @param names the tag names
   * @return the tags matching the group and names and new tags matching the names that don't
   *     already exist for the group
   * @throws PortalException if a matching group could not be found, if the tag's key or value were
   *     invalid, or if a portal exception occurred
   * @throws SystemException if a system exception occurred
   */
  @Override
  public List<AssetTag> checkTags(long userId, Group group, String[] names)
      throws PortalException, SystemException {

    List<AssetTag> tags = new ArrayList<AssetTag>();

    for (String name : names) {
      AssetTag tag = null;

      try {
        tag = getTag(group.getGroupId(), name);
      } catch (NoSuchTagException nste1) {
        ServiceContext serviceContext = new ServiceContext();

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

        tag = addTag(userId, name, PropsValues.ASSET_TAG_PROPERTIES_DEFAULT, serviceContext);

        Group companyGroup = groupLocalService.getCompanyGroup(group.getCompanyId());

        try {
          AssetTag companyGroupTag = getTag(companyGroup.getGroupId(), name);

          List<AssetTagProperty> tagProperties =
              assetTagPropertyLocalService.getTagProperties(companyGroupTag.getTagId());

          for (AssetTagProperty tagProperty : tagProperties) {
            assetTagPropertyLocalService.addTagProperty(
                userId, tag.getTagId(), tagProperty.getKey(), tagProperty.getValue());
          }
        } catch (NoSuchTagException nste2) {
        }
      }

      if (tag != null) {
        tags.add(tag);
      }
    }

    return tags;
  }
Example #3
0
  @Override
  public void mergeTags(long fromTagId, long toTagId, boolean overrideProperties)
      throws PortalException, SystemException {

    List<AssetEntry> entries = assetTagPersistence.getAssetEntries(fromTagId);

    assetTagPersistence.addAssetEntries(toTagId, entries);

    List<AssetTagProperty> tagProperties = assetTagPropertyPersistence.findByTagId(fromTagId);

    for (AssetTagProperty fromTagProperty : tagProperties) {
      AssetTagProperty toTagProperty =
          assetTagPropertyPersistence.fetchByT_K(toTagId, fromTagProperty.getKey());

      if (overrideProperties && (toTagProperty != null)) {
        toTagProperty.setValue(fromTagProperty.getValue());

        assetTagPropertyPersistence.update(toTagProperty);
      } else if (toTagProperty == null) {
        fromTagProperty.setTagId(toTagId);

        assetTagPropertyPersistence.update(fromTagProperty);
      }
    }

    deleteTag(fromTagId);
  }