/** * 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; }
@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; }
@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; }