001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.asset.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.ListUtil;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.security.permission.ActionKeys;
022    import com.liferay.portal.security.permission.PermissionChecker;
023    import com.liferay.portal.service.ServiceContext;
024    import com.liferay.portlet.asset.model.AssetVocabulary;
025    import com.liferay.portlet.asset.service.base.AssetVocabularyServiceBaseImpl;
026    import com.liferay.portlet.asset.service.permission.AssetPermission;
027    import com.liferay.portlet.asset.service.permission.AssetVocabularyPermission;
028    
029    import java.util.Iterator;
030    import java.util.List;
031    import java.util.Locale;
032    import java.util.Map;
033    
034    /**
035     * @author Alvaro del Castillo
036     * @author Eduardo Lundgren
037     * @author Jorge Ferrer
038     */
039    public class AssetVocabularyServiceImpl
040            extends AssetVocabularyServiceBaseImpl {
041    
042            /**
043             * @deprecated
044             */
045            public AssetVocabulary addVocabulary(
046                            Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
047                            String settings, ServiceContext serviceContext)
048                    throws PortalException, SystemException {
049    
050                    return addVocabulary(
051                            StringPool.BLANK, titleMap, descriptionMap, settings,
052                            serviceContext);
053            }
054    
055            public AssetVocabulary addVocabulary(
056                            String title, Map<Locale, String> titleMap,
057                            Map<Locale, String> descriptionMap, String settings,
058                            ServiceContext serviceContext)
059                    throws PortalException, SystemException {
060    
061                    AssetPermission.check(
062                            getPermissionChecker(), serviceContext.getScopeGroupId(),
063                            ActionKeys.ADD_VOCABULARY);
064    
065                    return assetVocabularyLocalService.addVocabulary(
066                            getUserId(), title, titleMap, descriptionMap, settings,
067                            serviceContext);
068            }
069    
070            public void deleteVocabulary(long vocabularyId)
071                    throws PortalException, SystemException {
072    
073                    AssetVocabularyPermission.check(
074                            getPermissionChecker(), vocabularyId, ActionKeys.DELETE);
075    
076                    assetVocabularyLocalService.deleteVocabulary(vocabularyId);
077            }
078    
079            public List<AssetVocabulary> getCompanyVocabularies(long companyId)
080                    throws PortalException, SystemException {
081    
082                    return filterVocabularies(
083                            assetVocabularyLocalService.getCompanyVocabularies(companyId));
084            }
085    
086            public List<AssetVocabulary> getGroupsVocabularies(long[] groupIds)
087                    throws PortalException, SystemException {
088    
089                    return filterVocabularies(
090                            assetVocabularyLocalService.getGroupsVocabularies(groupIds));
091            }
092    
093            public List<AssetVocabulary> getGroupVocabularies(long groupId)
094                    throws PortalException, SystemException {
095    
096                    return filterVocabularies(
097                            assetVocabularyLocalService.getGroupVocabularies(groupId));
098            }
099    
100            public AssetVocabulary getVocabulary(long vocabularyId)
101                    throws PortalException, SystemException {
102    
103                    AssetVocabularyPermission.check(
104                            getPermissionChecker(), vocabularyId, ActionKeys.VIEW);
105    
106                    return assetVocabularyLocalService.getVocabulary(vocabularyId);
107            }
108    
109            /**
110             * @deprecated
111             */
112            public AssetVocabulary updateVocabulary(
113                            long vocabularyId, Map<Locale, String> titleMap,
114                            Map<Locale, String> descriptionMap, String settings,
115                            ServiceContext serviceContext)
116                    throws PortalException, SystemException {
117    
118                    return updateVocabulary(
119                            vocabularyId, StringPool.BLANK, titleMap, descriptionMap, settings,
120                            serviceContext);
121            }
122    
123            public AssetVocabulary updateVocabulary(
124                            long vocabularyId, String title, Map<Locale, String> titleMap,
125                            Map<Locale, String> descriptionMap, String settings,
126                            ServiceContext serviceContext)
127                    throws PortalException, SystemException {
128    
129                    AssetVocabularyPermission.check(
130                            getPermissionChecker(), vocabularyId, ActionKeys.UPDATE);
131    
132                    return assetVocabularyLocalService.updateVocabulary(
133                            vocabularyId, title, titleMap, descriptionMap, settings,
134                            serviceContext);
135            }
136    
137            protected List<AssetVocabulary> filterVocabularies(
138                            List<AssetVocabulary> vocabularies)
139                    throws PortalException {
140    
141                    PermissionChecker permissionChecker = getPermissionChecker();
142    
143                    vocabularies = ListUtil.copy(vocabularies);
144    
145                    Iterator<AssetVocabulary> itr = vocabularies.iterator();
146    
147                    while (itr.hasNext()) {
148                            AssetVocabulary vocabulary = itr.next();
149    
150                            if (!AssetVocabularyPermission.contains(
151                                            permissionChecker, vocabulary, ActionKeys.VIEW)) {
152    
153                                    itr.remove();
154                            }
155                    }
156    
157                    return vocabularies;
158            }
159    
160    }