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 public AssetTagProperty addTagProperty(
050 long userId, long tagId, String key, String value)
051 throws PortalException, SystemException {
052
053 User user = userPersistence.findByPrimaryKey(userId);
054 Date now = new Date();
055
056 validate(key, value);
057
058 long tagPropertyId = counterLocalService.increment();
059
060 AssetTagProperty tagProperty = assetTagPropertyPersistence.create(
061 tagPropertyId);
062
063 tagProperty.setCompanyId(user.getCompanyId());
064 tagProperty.setUserId(user.getUserId());
065 tagProperty.setUserName(user.getFullName());
066 tagProperty.setCreateDate(now);
067 tagProperty.setModifiedDate(now);
068 tagProperty.setTagId(tagId);
069 tagProperty.setKey(key);
070 tagProperty.setValue(value);
071
072 assetTagPropertyPersistence.update(tagProperty, false);
073
074 return tagProperty;
075 }
076
077
083 public void deleteTagProperties(long tagId) throws SystemException {
084 List<AssetTagProperty> tagProperties =
085 assetTagPropertyPersistence.findByTagId(tagId);
086
087 for (AssetTagProperty tagProperty : tagProperties) {
088 deleteTagProperty(tagProperty);
089 }
090 }
091
092
098 public void deleteTagProperty(AssetTagProperty tagProperty)
099 throws SystemException {
100
101 assetTagPropertyPersistence.remove(tagProperty);
102 }
103
104
112 public void deleteTagProperty(long tagPropertyId)
113 throws PortalException, SystemException {
114
115 AssetTagProperty tagProperty =
116 assetTagPropertyPersistence.findByPrimaryKey(tagPropertyId);
117
118 deleteTagProperty(tagProperty);
119 }
120
121
127 public List<AssetTagProperty> getTagProperties() throws SystemException {
128 return assetTagPropertyPersistence.findAll();
129 }
130
131
138 public List<AssetTagProperty> getTagProperties(long tagId)
139 throws SystemException {
140
141 return assetTagPropertyPersistence.findByTagId(tagId);
142 }
143
144
153 public AssetTagProperty getTagProperty(long tagPropertyId)
154 throws PortalException, SystemException {
155
156 return assetTagPropertyPersistence.findByPrimaryKey(tagPropertyId);
157 }
158
159
169 public AssetTagProperty getTagProperty(long tagId, String key)
170 throws PortalException, SystemException {
171
172 return assetTagPropertyPersistence.findByT_K(tagId, key);
173 }
174
175
182 public String[] getTagPropertyKeys(long groupId) throws SystemException {
183 return assetTagPropertyKeyFinder.findByGroupId(groupId);
184 }
185
186
194 public List<AssetTagProperty> getTagPropertyValues(long groupId, String key)
195 throws SystemException {
196
197 return assetTagPropertyFinder.findByG_K(groupId, key);
198 }
199
200
211 public AssetTagProperty updateTagProperty(
212 long tagPropertyId, String key, String value)
213 throws PortalException, SystemException {
214
215 validate(key, value);
216
217 AssetTagProperty tagProperty =
218 assetTagPropertyPersistence.findByPrimaryKey(tagPropertyId);
219
220 tagProperty.setModifiedDate(new Date());
221 tagProperty.setKey(key);
222 tagProperty.setValue(value);
223
224 assetTagPropertyPersistence.update(tagProperty, false);
225
226 return tagProperty;
227 }
228
229 protected void validate(String key, String value) throws PortalException {
230 if (!AssetUtil.isValidWord(key)) {
231 throw new TagPropertyKeyException();
232 }
233
234 if (!AssetUtil.isValidWord(value)) {
235 throw new TagPropertyValueException();
236 }
237 }
238
239 }