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