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.util.ListUtil;
28 import com.liferay.portal.security.permission.ActionKeys;
29 import com.liferay.portal.security.permission.PermissionChecker;
30 import com.liferay.portal.service.ServiceContext;
31 import com.liferay.portlet.tags.model.TagsVocabulary;
32 import com.liferay.portlet.tags.service.base.TagsVocabularyServiceBaseImpl;
33 import com.liferay.portlet.tags.service.permission.TagsPermission;
34 import com.liferay.portlet.tags.service.permission.TagsVocabularyPermission;
35
36 import java.util.Iterator;
37 import java.util.List;
38
39
45 public class TagsVocabularyServiceImpl extends TagsVocabularyServiceBaseImpl {
46
47 public TagsVocabulary addVocabulary(
48 String name, boolean folksonomy, ServiceContext serviceContext)
49 throws PortalException, SystemException {
50
51 TagsPermission.check(
52 getPermissionChecker(), serviceContext.getScopeGroupId(),
53 ActionKeys.ADD_VOCABULARY);
54
55 return tagsVocabularyLocalService.addVocabulary(
56 getUserId(), name, folksonomy, serviceContext);
57 }
58
59 public void deleteVocabulary(long vocabularyId)
60 throws PortalException, SystemException {
61
62 TagsVocabularyPermission.check(
63 getPermissionChecker(), vocabularyId, ActionKeys.DELETE);
64
65 tagsVocabularyLocalService.deleteVocabulary(vocabularyId);
66 }
67
68 public List<TagsVocabulary> getCompanyVocabularies(
69 long companyId, boolean folksonomy)
70 throws PortalException, SystemException {
71
72 return getVocabularies(
73 tagsVocabularyLocalService.getCompanyVocabularies(
74 companyId, folksonomy));
75 }
76
77 public List<TagsVocabulary> getGroupVocabularies(
78 long groupId, boolean folksonomy)
79 throws PortalException, SystemException {
80
81 return getVocabularies(
82 tagsVocabularyLocalService.getGroupVocabularies(
83 groupId, folksonomy));
84 }
85
86 public TagsVocabulary getVocabulary(long vocabularyId)
87 throws PortalException, SystemException {
88
89 TagsVocabularyPermission.check(
90 getPermissionChecker(), vocabularyId, ActionKeys.VIEW);
91
92 return tagsVocabularyLocalService.getVocabulary(vocabularyId);
93 }
94
95 public TagsVocabulary updateVocabulary(
96 long vocabularyId, String name, boolean folksonomy)
97 throws PortalException, SystemException {
98
99 TagsVocabularyPermission.check(
100 getPermissionChecker(), vocabularyId, ActionKeys.UPDATE);
101
102 return tagsVocabularyLocalService.updateVocabulary(
103 vocabularyId, name, folksonomy);
104 }
105
106 protected List<TagsVocabulary> getVocabularies(
107 List<TagsVocabulary> vocabularies)
108 throws PortalException {
109
110 PermissionChecker permissionChecker = getPermissionChecker();
111
112 vocabularies = ListUtil.copy(vocabularies);
113
114 Iterator<TagsVocabulary> itr = vocabularies.iterator();
115
116 while (itr.hasNext()) {
117 TagsVocabulary vocabulary = itr.next();
118
119 if (!TagsVocabularyPermission.contains(
120 permissionChecker, vocabulary, ActionKeys.VIEW)) {
121
122 itr.remove();
123 }
124 }
125
126 return vocabularies;
127 }
128
129 }