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.kernel.json.JSONArray;
28 import com.liferay.portal.kernel.util.ListUtil;
29 import com.liferay.portal.kernel.util.Validator;
30 import com.liferay.portal.security.permission.ActionKeys;
31 import com.liferay.portal.security.permission.PermissionChecker;
32 import com.liferay.portal.service.ServiceContext;
33 import com.liferay.portlet.tags.model.TagsEntry;
34 import com.liferay.portlet.tags.model.TagsEntryConstants;
35 import com.liferay.portlet.tags.model.TagsVocabulary;
36 import com.liferay.portlet.tags.service.base.TagsEntryServiceBaseImpl;
37 import com.liferay.portlet.tags.service.permission.TagsEntryPermission;
38
39 import java.util.Iterator;
40 import java.util.List;
41
42
52 public class TagsEntryServiceImpl extends TagsEntryServiceBaseImpl {
53
54 public TagsEntry addEntry(
55 String parentEntryName, String name, String vocabularyName,
56 String[] properties, ServiceContext serviceContext)
57 throws PortalException, SystemException {
58
59 long parentEntryId = TagsEntryConstants.DEFAULT_PARENT_ENTRY_ID;
60 long groupId = serviceContext.getScopeGroupId();
61
62 if (Validator.isNotNull(parentEntryName)) {
63 TagsVocabulary vocabulary = tagsVocabularyPersistence.findByG_N(
64 groupId, vocabularyName);
65
66 TagsEntry parentEntry = tagsEntryLocalService.getEntry(
67 groupId, parentEntryName, vocabulary.isFolksonomy());
68
69 parentEntryId = parentEntry.getEntryId();
70 }
71
72 TagsEntryPermission.check(
73 getPermissionChecker(), serviceContext.getScopeGroupId(),
74 parentEntryId, ActionKeys.ADD_ENTRY);
75
76 return tagsEntryLocalService.addEntry(
77 getUserId(), parentEntryName, name, vocabularyName, properties,
78 serviceContext);
79 }
80
81 public void deleteEntry(long entryId)
82 throws PortalException, SystemException {
83
84 TagsEntryPermission.check(
85 getPermissionChecker(), entryId, ActionKeys.DELETE);
86
87 tagsEntryLocalService.deleteEntry(entryId);
88 }
89
90 public List<TagsEntry> getEntries(String className, long classPK)
91 throws PortalException, SystemException {
92
93 return getEntries(tagsEntryLocalService.getEntries(className, classPK));
94 }
95
96 public List<TagsEntry> getEntries(
97 long groupId, long classNameId, String name)
98 throws PortalException, SystemException {
99
100 return getEntries(
101 tagsEntryLocalService.getEntries(groupId, classNameId, name));
102 }
103
104 public TagsEntry getEntry(long entryId)
105 throws PortalException, SystemException {
106
107 TagsEntryPermission.check(
108 getPermissionChecker(), entryId, ActionKeys.VIEW);
109
110 return tagsEntryLocalService.getEntry(entryId);
111 }
112
113 public List<TagsEntry> getGroupVocabularyEntries(
114 long groupId, String vocabularyName)
115 throws PortalException, SystemException {
116
117 return getEntries(
118 tagsEntryLocalService.getGroupVocabularyEntries(
119 groupId, vocabularyName));
120 }
121
122 public List<TagsEntry> getGroupVocabularyEntries(
123 long groupId, String parentEntryName, String vocabularyName)
124 throws PortalException, SystemException {
125
126 return getEntries(
127 tagsEntryLocalService.getGroupVocabularyEntries(
128 groupId, parentEntryName, vocabularyName));
129 }
130
131 public List<TagsEntry> getGroupVocabularyRootEntries(
132 long groupId, String vocabularyName)
133 throws PortalException, SystemException {
134
135 return getEntries(
136 tagsEntryLocalService.getGroupVocabularyRootEntries(
137 groupId, vocabularyName));
138 }
139
140 public void mergeEntries(long fromEntryId, long toEntryId)
141 throws PortalException, SystemException {
142
143 TagsEntryPermission.check(
144 getPermissionChecker(), fromEntryId, ActionKeys.VIEW);
145
146 TagsEntryPermission.check(
147 getPermissionChecker(), toEntryId, ActionKeys.UPDATE);
148
149 tagsEntryLocalService.mergeEntries(fromEntryId, toEntryId);
150 }
151
152 public JSONArray search(
153 long groupId, String name, String[] properties, int start, int end)
154 throws SystemException {
155
156 return tagsEntryLocalService.search(
157 groupId, name, properties, start, end);
158 }
159
160 public TagsEntry updateEntry(
161 long entryId, String parentEntryName, String name,
162 String vocabularyName, String[] properties)
163 throws PortalException, SystemException {
164
165 TagsEntryPermission.check(
166 getPermissionChecker(), entryId, ActionKeys.UPDATE);
167
168 return tagsEntryLocalService.updateEntry(
169 getUserId(), entryId, parentEntryName, name, vocabularyName,
170 properties);
171 }
172
173 protected List<TagsEntry> getEntries(List<TagsEntry> entries)
174 throws PortalException {
175
176 PermissionChecker permissionChecker = getPermissionChecker();
177
178 entries = ListUtil.copy(entries);
179
180 Iterator<TagsEntry> itr = entries.iterator();
181
182 while (itr.hasNext()) {
183 TagsEntry entry = itr.next();
184
185 if (!TagsEntryPermission.contains(
186 permissionChecker, entry, ActionKeys.VIEW)) {
187
188 itr.remove();
189 }
190 }
191
192 return entries;
193 }
194
195 }