public static JSONObject toJSONObject(AssetTag model) {
    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("tagId", model.getTagId());
    jsonObject.put("groupId", model.getGroupId());
    jsonObject.put("companyId", model.getCompanyId());
    jsonObject.put("userId", model.getUserId());
    jsonObject.put("userName", model.getUserName());

    Date createDate = model.getCreateDate();

    String createDateJSON = StringPool.BLANK;

    if (createDate != null) {
      createDateJSON = String.valueOf(createDate.getTime());
    }

    jsonObject.put("createDate", createDateJSON);

    Date modifiedDate = model.getModifiedDate();

    String modifiedDateJSON = StringPool.BLANK;

    if (modifiedDate != null) {
      modifiedDateJSON = String.valueOf(modifiedDate.getTime());
    }

    jsonObject.put("modifiedDate", modifiedDateJSON);
    jsonObject.put("name", model.getName());
    jsonObject.put("assetCount", model.getAssetCount());

    return jsonObject;
  }
Пример #2
0
  @Override
  public void addTagResources(AssetTag tag, String[] groupPermissions, String[] guestPermissions)
      throws PortalException, SystemException {

    resourceLocalService.addModelResources(
        tag.getCompanyId(),
        tag.getGroupId(),
        tag.getUserId(),
        AssetTag.class.getName(),
        tag.getTagId(),
        groupPermissions,
        guestPermissions);
  }
Пример #3
0
  @Override
  public void addTagResources(
      AssetTag tag, boolean addGroupPermissions, boolean addGuestPermissions)
      throws PortalException, SystemException {

    resourceLocalService.addResources(
        tag.getCompanyId(),
        tag.getGroupId(),
        tag.getUserId(),
        AssetTag.class.getName(),
        tag.getTagId(),
        false,
        addGroupPermissions,
        addGuestPermissions);
  }
Пример #4
0
  @Override
  public AssetTag updateTag(
      long userId, long tagId, String name, String[] tagProperties, ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Tag

    AssetTag tag = assetTagPersistence.findByPrimaryKey(tagId);

    String oldName = tag.getName();

    tag.setModifiedDate(new Date());

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

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

    if (!name.equals(tag.getName()) && hasTag(tag.getGroupId(), name)) {
      throw new DuplicateTagException("A tag with the name " + name + " already exists");
    }

    if (!tag.getName().equals(name)) {
      try {
        AssetTag existingAssetTag = getTag(tag.getGroupId(), name);

        if (existingAssetTag.getTagId() != tagId) {
          throw new DuplicateTagException("A tag with the name " + name + " already exists");
        }
      } catch (NoSuchTagException nste) {
      }
    }

    validate(name);

    tag.setName(name);

    assetTagPersistence.update(tag);

    // Properties

    List<AssetTagProperty> oldTagProperties = assetTagPropertyPersistence.findByTagId(tagId);

    for (AssetTagProperty tagProperty : oldTagProperties) {
      assetTagPropertyLocalService.deleteTagProperty(tagProperty);
    }

    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);
      }
    }

    // Indexer

    if (!oldName.equals(name)) {
      List<AssetEntry> entries = assetTagPersistence.getAssetEntries(tag.getTagId());

      assetEntryLocalService.reindex(entries);
    }

    return tag;
  }