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