1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
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  /**
32   * <a href="TagsVocabularyServiceImpl.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Alvaro del Castillo
35   * @author Eduardo Lundgren
36   */
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 }