1
22
23 package com.liferay.portlet.tags.service.impl;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.model.User;
28 import com.liferay.portlet.tags.PropertyKeyException;
29 import com.liferay.portlet.tags.PropertyValueException;
30 import com.liferay.portlet.tags.model.TagsProperty;
31 import com.liferay.portlet.tags.service.base.TagsPropertyLocalServiceBaseImpl;
32 import com.liferay.portlet.tags.util.TagsUtil;
33
34 import java.util.Date;
35 import java.util.List;
36
37
43 public class TagsPropertyLocalServiceImpl
44 extends TagsPropertyLocalServiceBaseImpl {
45
46 public TagsProperty addProperty(
47 long userId, long entryId, String key, String value)
48 throws PortalException, SystemException {
49
50 User user = userPersistence.findByPrimaryKey(userId);
51 Date now = new Date();
52
53 validate(key, value);
54
55 long propertyId = counterLocalService.increment();
56
57 TagsProperty property = tagsPropertyPersistence.create(propertyId);
58
59 property.setCompanyId(user.getCompanyId());
60 property.setUserId(user.getUserId());
61 property.setUserName(user.getFullName());
62 property.setCreateDate(now);
63 property.setModifiedDate(now);
64 property.setEntryId(entryId);
65 property.setKey(key);
66 property.setValue(value);
67
68 tagsPropertyPersistence.update(property, false);
69
70 return property;
71 }
72
73 public void deleteProperties(long entryId) throws SystemException {
74 List<TagsProperty> properties = tagsPropertyPersistence.findByEntryId(
75 entryId);
76
77 for (TagsProperty property : properties) {
78 deleteProperty(property);
79 }
80 }
81
82 public void deleteProperty(long propertyId)
83 throws PortalException, SystemException {
84
85 TagsProperty property = tagsPropertyPersistence.findByPrimaryKey(
86 propertyId);
87
88 deleteProperty(property);
89 }
90
91 public void deleteProperty(TagsProperty property) throws SystemException {
92 tagsPropertyPersistence.remove(property);
93 }
94
95 public List<TagsProperty> getProperties() throws SystemException {
96 return tagsPropertyPersistence.findAll();
97 }
98
99 public List<TagsProperty> getProperties(long entryId)
100 throws SystemException {
101
102 return tagsPropertyPersistence.findByEntryId(entryId);
103 }
104
105 public TagsProperty getProperty(long propertyId)
106 throws PortalException, SystemException {
107
108 return tagsPropertyPersistence.findByPrimaryKey(propertyId);
109 }
110
111 public TagsProperty getProperty(long entryId, String key)
112 throws PortalException, SystemException {
113
114 return tagsPropertyPersistence.findByE_K(entryId, key);
115 }
116
117 public String[] getPropertyKeys(long groupId) throws SystemException {
118 return tagsPropertyKeyFinder.findByGroupId(groupId);
119 }
120
121 public List<TagsProperty> getPropertyValues(long groupId, String key)
122 throws SystemException {
123
124 return tagsPropertyFinder.findByG_K(groupId, key);
125 }
126
127 public TagsProperty updateProperty(
128 long propertyId, String key, String value)
129 throws PortalException, SystemException {
130
131 validate(key, value);
132
133 TagsProperty property = tagsPropertyPersistence.findByPrimaryKey(
134 propertyId);
135
136 property.setModifiedDate(new Date());
137 property.setKey(key);
138 property.setValue(value);
139
140 tagsPropertyPersistence.update(property, false);
141
142 return property;
143 }
144
145 protected void validate(String key, String value) throws PortalException {
146 if (!TagsUtil.isValidWord(key)) {
147 throw new PropertyKeyException();
148 }
149
150 if (!TagsUtil.isValidWord(value)) {
151 throw new PropertyValueException();
152 }
153 }
154
155 }