001
014
015 package com.liferay.portlet.asset.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.model.User;
020 import com.liferay.portlet.asset.TagPropertyKeyException;
021 import com.liferay.portlet.asset.TagPropertyValueException;
022 import com.liferay.portlet.asset.model.AssetTagProperty;
023 import com.liferay.portlet.asset.service.base.AssetTagPropertyLocalServiceBaseImpl;
024 import com.liferay.portlet.asset.util.AssetUtil;
025
026 import java.util.Date;
027 import java.util.List;
028
029
035 public class AssetTagPropertyLocalServiceImpl
036 extends AssetTagPropertyLocalServiceBaseImpl {
037
038
050 @Override
051 public AssetTagProperty addTagProperty(
052 long userId, long tagId, String key, String value)
053 throws PortalException, SystemException {
054
055 User user = userPersistence.findByPrimaryKey(userId);
056 Date now = new Date();
057
058 validate(key, value);
059
060 long tagPropertyId = counterLocalService.increment();
061
062 AssetTagProperty tagProperty = assetTagPropertyPersistence.create(
063 tagPropertyId);
064
065 tagProperty.setCompanyId(user.getCompanyId());
066 tagProperty.setUserId(user.getUserId());
067 tagProperty.setUserName(user.getFullName());
068 tagProperty.setCreateDate(now);
069 tagProperty.setModifiedDate(now);
070 tagProperty.setTagId(tagId);
071 tagProperty.setKey(key);
072 tagProperty.setValue(value);
073
074 assetTagPropertyPersistence.update(tagProperty);
075
076 return tagProperty;
077 }
078
079
085 @Override
086 public void deleteTagProperties(long tagId) throws SystemException {
087 List<AssetTagProperty> tagProperties =
088 assetTagPropertyPersistence.findByTagId(tagId);
089
090 for (AssetTagProperty tagProperty : tagProperties) {
091 deleteTagProperty(tagProperty);
092 }
093 }
094
095
101 @Override
102 public void deleteTagProperty(AssetTagProperty tagProperty)
103 throws SystemException {
104
105 assetTagPropertyPersistence.remove(tagProperty);
106 }
107
108
116 @Override
117 public void deleteTagProperty(long tagPropertyId)
118 throws PortalException, SystemException {
119
120 AssetTagProperty tagProperty =
121 assetTagPropertyPersistence.findByPrimaryKey(tagPropertyId);
122
123 deleteTagProperty(tagProperty);
124 }
125
126
132 @Override
133 public List<AssetTagProperty> getTagProperties() throws SystemException {
134 return assetTagPropertyPersistence.findAll();
135 }
136
137
144 @Override
145 public List<AssetTagProperty> getTagProperties(long tagId)
146 throws SystemException {
147
148 return assetTagPropertyPersistence.findByTagId(tagId);
149 }
150
151
160 @Override
161 public AssetTagProperty getTagProperty(long tagPropertyId)
162 throws PortalException, SystemException {
163
164 return assetTagPropertyPersistence.findByPrimaryKey(tagPropertyId);
165 }
166
167
177 @Override
178 public AssetTagProperty getTagProperty(long tagId, String key)
179 throws PortalException, SystemException {
180
181 return assetTagPropertyPersistence.findByT_K(tagId, key);
182 }
183
184
191 @Override
192 public String[] getTagPropertyKeys(long groupId) throws SystemException {
193 return assetTagPropertyKeyFinder.findByGroupId(groupId);
194 }
195
196
204 @Override
205 public List<AssetTagProperty> getTagPropertyValues(long groupId, String key)
206 throws SystemException {
207
208 return assetTagPropertyFinder.findByG_K(groupId, key);
209 }
210
211
222 @Override
223 public AssetTagProperty updateTagProperty(
224 long tagPropertyId, String key, String value)
225 throws PortalException, SystemException {
226
227 validate(key, value);
228
229 AssetTagProperty tagProperty =
230 assetTagPropertyPersistence.findByPrimaryKey(tagPropertyId);
231
232 tagProperty.setModifiedDate(new Date());
233 tagProperty.setKey(key);
234 tagProperty.setValue(value);
235
236 assetTagPropertyPersistence.update(tagProperty);
237
238 return tagProperty;
239 }
240
241 protected void validate(String key, String value) throws PortalException {
242 if (!AssetUtil.isValidWord(key)) {
243 throw new TagPropertyKeyException();
244 }
245
246 if (!AssetUtil.isValidWord(value)) {
247 throw new TagPropertyValueException();
248 }
249 }
250
251 }