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
034 public class AssetTagPropertyLocalServiceImpl
035 extends AssetTagPropertyLocalServiceBaseImpl {
036
037
049 @Override
050 public AssetTagProperty addTagProperty(
051 long userId, long tagId, String key, String value)
052 throws PortalException, SystemException {
053
054 User user = userPersistence.findByPrimaryKey(userId);
055 Date now = new Date();
056
057 validate(key, value);
058
059 long tagPropertyId = counterLocalService.increment();
060
061 AssetTagProperty tagProperty = assetTagPropertyPersistence.create(
062 tagPropertyId);
063
064 tagProperty.setCompanyId(user.getCompanyId());
065 tagProperty.setUserId(user.getUserId());
066 tagProperty.setUserName(user.getFullName());
067 tagProperty.setCreateDate(now);
068 tagProperty.setModifiedDate(now);
069 tagProperty.setTagId(tagId);
070 tagProperty.setKey(key);
071 tagProperty.setValue(value);
072
073 assetTagPropertyPersistence.update(tagProperty, false);
074
075 return tagProperty;
076 }
077
078
084 @Override
085 public void deleteTagProperties(long tagId) throws SystemException {
086 List<AssetTagProperty> tagProperties =
087 assetTagPropertyPersistence.findByTagId(tagId);
088
089 for (AssetTagProperty tagProperty : tagProperties) {
090 deleteTagProperty(tagProperty);
091 }
092 }
093
094
100 @Override
101 public void deleteTagProperty(AssetTagProperty tagProperty)
102 throws SystemException {
103
104 assetTagPropertyPersistence.remove(tagProperty);
105 }
106
107
115 @Override
116 public void deleteTagProperty(long tagPropertyId)
117 throws PortalException, SystemException {
118
119 AssetTagProperty tagProperty =
120 assetTagPropertyPersistence.findByPrimaryKey(tagPropertyId);
121
122 deleteTagProperty(tagProperty);
123 }
124
125
131 @Override
132 public List<AssetTagProperty> getTagProperties() throws SystemException {
133 return assetTagPropertyPersistence.findAll();
134 }
135
136
143 @Override
144 public List<AssetTagProperty> getTagProperties(long tagId)
145 throws SystemException {
146
147 return assetTagPropertyPersistence.findByTagId(tagId);
148 }
149
150
159 @Override
160 public AssetTagProperty getTagProperty(long tagPropertyId)
161 throws PortalException, SystemException {
162
163 return assetTagPropertyPersistence.findByPrimaryKey(tagPropertyId);
164 }
165
166
176 @Override
177 public AssetTagProperty getTagProperty(long tagId, String key)
178 throws PortalException, SystemException {
179
180 return assetTagPropertyPersistence.findByT_K(tagId, key);
181 }
182
183
190 @Override
191 public String[] getTagPropertyKeys(long groupId) throws SystemException {
192 return assetTagPropertyKeyFinder.findByGroupId(groupId);
193 }
194
195
203 @Override
204 public List<AssetTagProperty> getTagPropertyValues(long groupId, String key)
205 throws SystemException {
206
207 return assetTagPropertyFinder.findByG_K(groupId, key);
208 }
209
210
221 @Override
222 public AssetTagProperty updateTagProperty(
223 long tagPropertyId, String key, String value)
224 throws PortalException, SystemException {
225
226 validate(key, value);
227
228 AssetTagProperty tagProperty =
229 assetTagPropertyPersistence.findByPrimaryKey(tagPropertyId);
230
231 tagProperty.setModifiedDate(new Date());
232 tagProperty.setKey(key);
233 tagProperty.setValue(value);
234
235 assetTagPropertyPersistence.update(tagProperty, false);
236
237 return tagProperty;
238 }
239
240 protected void validate(String key, String value) throws PortalException {
241 if (!AssetUtil.isValidWord(key)) {
242 throw new TagPropertyKeyException();
243 }
244
245 if (!AssetUtil.isValidWord(value)) {
246 throw new TagPropertyValueException();
247 }
248 }
249
250 }