/**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static AssetTag toModel(AssetTagSoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    AssetTag model = new AssetTagImpl();

    model.setUuid(soapModel.getUuid());
    model.setTagId(soapModel.getTagId());
    model.setGroupId(soapModel.getGroupId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setName(soapModel.getName());
    model.setAssetCount(soapModel.getAssetCount());
    model.setLastPublishDate(soapModel.getLastPublishDate());

    return model;
  }
示例#2
0
  @Override
  public AssetTag addTag(
      long userId, String name, String[] tagProperties, ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Tag

    User user = userPersistence.findByPrimaryKey(userId);
    long groupId = serviceContext.getScopeGroupId();

    if (tagProperties == null) {
      tagProperties = new String[0];
    }

    Date now = new Date();

    long tagId = counterLocalService.increment();

    AssetTag tag = assetTagPersistence.create(tagId);

    tag.setGroupId(groupId);
    tag.setCompanyId(user.getCompanyId());
    tag.setUserId(user.getUserId());
    tag.setUserName(user.getFullName());
    tag.setCreateDate(now);
    tag.setModifiedDate(now);

    name = name.trim();
    name = StringUtil.toLowerCase(name);

    if (hasTag(groupId, name)) {
      throw new DuplicateTagException("A tag with the name " + name + " already exists");
    }

    validate(name);

    tag.setName(name);

    assetTagPersistence.update(tag);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

      addTagResources(
          tag, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
      addTagResources(
          tag, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    // Properties

    for (int i = 0; i < tagProperties.length; i++) {
      String[] tagProperty =
          StringUtil.split(tagProperties[i], AssetTagConstants.PROPERTY_KEY_VALUE_SEPARATOR);

      if (tagProperty.length <= 1) {
        tagProperty = StringUtil.split(tagProperties[i], CharPool.COLON);
      }

      String key = StringPool.BLANK;

      if (tagProperty.length > 0) {
        key = GetterUtil.getString(tagProperty[0]);
      }

      String value = StringPool.BLANK;

      if (tagProperty.length > 1) {
        value = GetterUtil.getString(tagProperty[1]);
      }

      if (Validator.isNotNull(key)) {
        assetTagPropertyLocalService.addTagProperty(userId, tagId, key, value);
      }
    }

    return tag;
  }