1
14
15 package com.liferay.portlet.tags.service.impl;
16
17 import com.liferay.portal.PortalException;
18 import com.liferay.portal.SystemException;
19 import com.liferay.portal.kernel.util.ListUtil;
20 import com.liferay.portal.security.permission.ActionKeys;
21 import com.liferay.portal.security.permission.PermissionChecker;
22 import com.liferay.portal.service.ServiceContext;
23 import com.liferay.portlet.tags.model.TagsVocabulary;
24 import com.liferay.portlet.tags.service.base.TagsVocabularyServiceBaseImpl;
25 import com.liferay.portlet.tags.service.permission.TagsPermission;
26 import com.liferay.portlet.tags.service.permission.TagsVocabularyPermission;
27
28 import java.util.Iterator;
29 import java.util.List;
30
31
37 public class TagsVocabularyServiceImpl extends TagsVocabularyServiceBaseImpl {
38
39 public TagsVocabulary addVocabulary(
40 String name, boolean folksonomy, ServiceContext serviceContext)
41 throws PortalException, SystemException {
42
43 TagsPermission.check(
44 getPermissionChecker(), serviceContext.getScopeGroupId(),
45 ActionKeys.ADD_VOCABULARY);
46
47 return tagsVocabularyLocalService.addVocabulary(
48 getUserId(), name, folksonomy, serviceContext);
49 }
50
51 public void deleteVocabulary(long vocabularyId)
52 throws PortalException, SystemException {
53
54 TagsVocabularyPermission.check(
55 getPermissionChecker(), vocabularyId, ActionKeys.DELETE);
56
57 tagsVocabularyLocalService.deleteVocabulary(vocabularyId);
58 }
59
60 public List<TagsVocabulary> getCompanyVocabularies(
61 long companyId, boolean folksonomy)
62 throws PortalException, SystemException {
63
64 return getVocabularies(
65 tagsVocabularyLocalService.getCompanyVocabularies(
66 companyId, folksonomy));
67 }
68
69 public List<TagsVocabulary> getGroupVocabularies(
70 long groupId, boolean folksonomy)
71 throws PortalException, SystemException {
72
73 return getVocabularies(
74 tagsVocabularyLocalService.getGroupVocabularies(
75 groupId, folksonomy));
76 }
77
78 public TagsVocabulary getVocabulary(long vocabularyId)
79 throws PortalException, SystemException {
80
81 TagsVocabularyPermission.check(
82 getPermissionChecker(), vocabularyId, ActionKeys.VIEW);
83
84 return tagsVocabularyLocalService.getVocabulary(vocabularyId);
85 }
86
87 public TagsVocabulary updateVocabulary(
88 long vocabularyId, String name, boolean folksonomy)
89 throws PortalException, SystemException {
90
91 TagsVocabularyPermission.check(
92 getPermissionChecker(), vocabularyId, ActionKeys.UPDATE);
93
94 return tagsVocabularyLocalService.updateVocabulary(
95 vocabularyId, name, folksonomy);
96 }
97
98 protected List<TagsVocabulary> getVocabularies(
99 List<TagsVocabulary> vocabularies)
100 throws PortalException {
101
102 PermissionChecker permissionChecker = getPermissionChecker();
103
104 vocabularies = ListUtil.copy(vocabularies);
105
106 Iterator<TagsVocabulary> itr = vocabularies.iterator();
107
108 while (itr.hasNext()) {
109 TagsVocabulary vocabulary = itr.next();
110
111 if (!TagsVocabularyPermission.contains(
112 permissionChecker, vocabulary, ActionKeys.VIEW)) {
113
114 itr.remove();
115 }
116 }
117
118 return vocabularies;
119 }
120
121 }