1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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  /**
40   * <a href="TagsVocabularyServiceImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Alvaro del Castillo
43   * @author Eduardo Lundgren
44   *
45   */
46  public class TagsVocabularyServiceImpl extends TagsVocabularyServiceBaseImpl {
47  
48      public TagsVocabulary addVocabulary(
49              String name, boolean folksonomy, ServiceContext serviceContext)
50          throws PortalException, SystemException {
51  
52          TagsPermission.check(
53              getPermissionChecker(), serviceContext.getScopeGroupId(),
54              ActionKeys.ADD_VOCABULARY);
55  
56          return tagsVocabularyLocalService.addVocabulary(
57              getUserId(), name, folksonomy, serviceContext);
58      }
59  
60      public void deleteVocabulary(long vocabularyId)
61          throws PortalException, SystemException {
62  
63          TagsVocabularyPermission.check(
64              getPermissionChecker(), vocabularyId, ActionKeys.DELETE);
65  
66          tagsVocabularyLocalService.deleteVocabulary(vocabularyId);
67      }
68  
69      public List<TagsVocabulary> getCompanyVocabularies(
70              long companyId, boolean folksonomy)
71          throws PortalException, SystemException {
72  
73          return getVocabularies(
74              tagsVocabularyLocalService.getCompanyVocabularies(
75                  companyId, folksonomy));
76      }
77  
78      public List<TagsVocabulary> getGroupVocabularies(
79              long groupId, boolean folksonomy)
80          throws PortalException, SystemException {
81  
82          return getVocabularies(
83              tagsVocabularyLocalService.getGroupVocabularies(
84                  groupId, folksonomy));
85      }
86  
87      public TagsVocabulary getVocabulary(long vocabularyId)
88          throws PortalException, SystemException {
89  
90          TagsVocabularyPermission.check(
91              getPermissionChecker(), vocabularyId, ActionKeys.VIEW);
92  
93          return tagsVocabularyLocalService.getVocabulary(vocabularyId);
94      }
95  
96      public TagsVocabulary updateVocabulary(
97              long vocabularyId, String name, boolean folksonomy)
98          throws PortalException, SystemException {
99  
100         TagsVocabularyPermission.check(
101             getPermissionChecker(), vocabularyId, ActionKeys.UPDATE);
102 
103         return tagsVocabularyLocalService.updateVocabulary(
104             vocabularyId, name, folksonomy);
105     }
106 
107     protected List<TagsVocabulary> getVocabularies(
108             List<TagsVocabulary> vocabularies)
109         throws PortalException {
110 
111         PermissionChecker permissionChecker = getPermissionChecker();
112 
113         vocabularies = ListUtil.copy(vocabularies);
114 
115         Iterator<TagsVocabulary> itr = vocabularies.iterator();
116 
117         while (itr.hasNext()) {
118             TagsVocabulary vocabulary = itr.next();
119 
120             if (!TagsVocabularyPermission.contains(
121                     permissionChecker, vocabulary, ActionKeys.VIEW)) {
122 
123                 itr.remove();
124             }
125         }
126 
127         return vocabularies;
128     }
129 
130 }