001
014
015 package com.liferay.portlet.asset.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.model.User;
019 import com.liferay.portlet.asset.TagPropertyKeyException;
020 import com.liferay.portlet.asset.TagPropertyValueException;
021 import com.liferay.portlet.asset.model.AssetTagProperty;
022 import com.liferay.portlet.asset.service.base.AssetTagPropertyLocalServiceBaseImpl;
023 import com.liferay.portlet.asset.util.AssetUtil;
024
025 import java.util.Date;
026 import java.util.List;
027
028
034 public class AssetTagPropertyLocalServiceImpl
035 extends AssetTagPropertyLocalServiceBaseImpl {
036
037
048 @Override
049 public AssetTagProperty addTagProperty(
050 long userId, long tagId, String key, String value)
051 throws PortalException {
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);
073
074 return tagProperty;
075 }
076
077
082 @Override
083 public void deleteTagProperties(long tagId) {
084 List<AssetTagProperty> tagProperties =
085 assetTagPropertyPersistence.findByTagId(tagId);
086
087 for (AssetTagProperty tagProperty : tagProperties) {
088 deleteTagProperty(tagProperty);
089 }
090 }
091
092
097 @Override
098 public void deleteTagProperty(AssetTagProperty tagProperty) {
099 assetTagPropertyPersistence.remove(tagProperty);
100 }
101
102
109 @Override
110 public void deleteTagProperty(long tagPropertyId) throws PortalException {
111 AssetTagProperty tagProperty =
112 assetTagPropertyPersistence.findByPrimaryKey(tagPropertyId);
113
114 deleteTagProperty(tagProperty);
115 }
116
117
122 @Override
123 public List<AssetTagProperty> getTagProperties() {
124 return assetTagPropertyPersistence.findAll();
125 }
126
127
133 @Override
134 public List<AssetTagProperty> getTagProperties(long tagId) {
135 return assetTagPropertyPersistence.findByTagId(tagId);
136 }
137
138
146 @Override
147 public AssetTagProperty getTagProperty(long tagPropertyId)
148 throws PortalException {
149
150 return assetTagPropertyPersistence.findByPrimaryKey(tagPropertyId);
151 }
152
153
162 @Override
163 public AssetTagProperty getTagProperty(long tagId, String key)
164 throws PortalException {
165
166 return assetTagPropertyPersistence.findByT_K(tagId, key);
167 }
168
169
175 @Override
176 public String[] getTagPropertyKeys(long groupId) {
177 return assetTagPropertyKeyFinder.findByGroupId(groupId);
178 }
179
180
187 @Override
188 public List<AssetTagProperty> getTagPropertyValues(
189 long groupId, String key) {
190
191 return assetTagPropertyFinder.findByG_K(groupId, key);
192 }
193
194
204 @Override
205 public AssetTagProperty updateTagProperty(
206 long tagPropertyId, String key, String value)
207 throws PortalException {
208
209 validate(key, value);
210
211 AssetTagProperty tagProperty =
212 assetTagPropertyPersistence.findByPrimaryKey(tagPropertyId);
213
214 tagProperty.setModifiedDate(new Date());
215 tagProperty.setKey(key);
216 tagProperty.setValue(value);
217
218 assetTagPropertyPersistence.update(tagProperty);
219
220 return tagProperty;
221 }
222
223 protected void validate(String key, String value) throws PortalException {
224 if (!AssetUtil.isValidWord(key)) {
225 throw new TagPropertyKeyException();
226 }
227
228 if (!AssetUtil.isValidWord(value)) {
229 throw new TagPropertyValueException();
230 }
231 }
232
233 }