001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.assetpublisher.util;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
020    import com.liferay.portal.model.Group;
021    import com.liferay.portal.model.Layout;
022    import com.liferay.portal.model.User;
023    import com.liferay.portal.security.permission.PermissionChecker;
024    import com.liferay.portal.theme.ThemeDisplay;
025    import com.liferay.portlet.asset.model.AssetEntry;
026    import com.liferay.portlet.asset.model.AssetRendererFactory;
027    import com.liferay.portlet.asset.service.persistence.AssetEntryQuery;
028    
029    import java.util.List;
030    import java.util.Locale;
031    import java.util.Map;
032    
033    import javax.portlet.PortletPreferences;
034    import javax.portlet.PortletRequest;
035    
036    /**
037     * @author Eudaldo Alonso
038     */
039    public class AssetPublisherUtil {
040    
041            public static void addAndStoreSelection(
042                            PortletRequest portletRequest, String className, long classPK,
043                            int assetEntryOrder)
044                    throws Exception {
045    
046                    getAssetPublisher().addAndStoreSelection(
047                            portletRequest, className, classPK, assetEntryOrder);
048            }
049    
050            public static void addRecentFolderId(
051                    PortletRequest portletRequest, String className, long classPK) {
052    
053                    getAssetPublisher().addRecentFolderId(
054                            portletRequest, className, classPK);
055            }
056    
057            public static void addSelection(
058                            PortletRequest portletRequest,
059                            PortletPreferences portletPreferences, String portletId)
060                    throws Exception {
061    
062                    getAssetPublisher().addSelection(
063                            portletRequest, portletPreferences, portletId);
064            }
065    
066            public static void addSelection(
067                            ThemeDisplay themeDisplay, PortletPreferences portletPreferences,
068                            String portletId, long assetEntryId, int assetEntryOrder,
069                            String assetEntryType)
070                    throws Exception {
071    
072                    getAssetPublisher().addSelection(
073                            themeDisplay, portletPreferences, portletId, assetEntryId,
074                            assetEntryOrder, assetEntryType);
075            }
076    
077            public static void addUserAttributes(
078                            User user, String[] customUserAttributeNames,
079                            AssetEntryQuery assetEntryQuery)
080                    throws Exception {
081    
082                    getAssetPublisher().addUserAttributes(
083                            user, customUserAttributeNames, assetEntryQuery);
084            }
085    
086            public static void checkAssetEntries() throws Exception {
087                    getAssetPublisher().checkAssetEntries();
088            }
089    
090            public static List<AssetEntry> getAssetEntries(
091                            PortletPreferences preferences, Layout layout, long scopeGroupId,
092                            int max, boolean checkPermission)
093                    throws PortalException, SystemException {
094    
095                    return getAssetPublisher().getAssetEntries(
096                            preferences, layout, scopeGroupId, max, checkPermission);
097            }
098    
099            public static List<AssetEntry> getAssetEntries(
100                            PortletRequest portletRequest,
101                            PortletPreferences portletPreferences,
102                            PermissionChecker permissionChecker, long[] groupIds,
103                            long[] assetCategoryIds, String[] assetEntryXmls,
104                            String[] assetTagNames, boolean deleteMissingAssetEntries,
105                            boolean checkPermission)
106                    throws Exception {
107    
108                    return getAssetPublisher().getAssetEntries(
109                            portletRequest, portletPreferences, permissionChecker, groupIds,
110                            assetCategoryIds, assetEntryXmls, assetTagNames,
111                            deleteMissingAssetEntries, checkPermission);
112            }
113    
114            public static List<AssetEntry> getAssetEntries(
115                            PortletRequest portletRequest,
116                            PortletPreferences portletPreferences,
117                            PermissionChecker permissionChecker, long[] groupIds,
118                            String[] assetEntryXmls, boolean deleteMissingAssetEntries,
119                            boolean checkPermission)
120                    throws Exception {
121    
122                    return getAssetPublisher().getAssetEntries(
123                            portletRequest, portletPreferences, permissionChecker, groupIds,
124                            assetEntryXmls, deleteMissingAssetEntries, checkPermission);
125            }
126    
127            public static AssetEntryQuery getAssetEntryQuery(
128                            PortletPreferences portletPreferences, long[] scopeGroupIds)
129                    throws PortalException, SystemException {
130    
131                    return getAssetPublisher().getAssetEntryQuery(
132                            portletPreferences, scopeGroupIds);
133            }
134    
135            public static AssetPublisher getAssetPublisher() {
136                    PortalRuntimePermission.checkGetBeanProperty(AssetPublisherUtil.class);
137    
138                    return _assetPublisher;
139            }
140    
141            public static String[] getAssetTagNames(
142                            PortletPreferences portletPreferences, long scopeGroupId)
143                    throws Exception {
144    
145                    return getAssetPublisher().getAssetTagNames(
146                            portletPreferences, scopeGroupId);
147            }
148    
149            public static String getClassName(
150                    AssetRendererFactory assetRendererFactory) {
151    
152                    return getAssetPublisher().getClassName(assetRendererFactory);
153            }
154    
155            public static long[] getClassNameIds(
156                    PortletPreferences portletPreferences, long[] availableClassNameIds) {
157    
158                    return getAssetPublisher().getClassNameIds(
159                            portletPreferences, availableClassNameIds);
160            }
161    
162            public static Long[] getClassTypeIds(
163                    PortletPreferences portletPreferences, String className,
164                    Long[] availableClassTypeIds) {
165    
166                    return getAssetPublisher().getClassTypeIds(
167                            portletPreferences, className, availableClassTypeIds);
168            }
169    
170            public static Map<Locale, String> getEmailAssetEntryAddedBodyMap(
171                    PortletPreferences preferences) {
172    
173                    return getAssetPublisher().getEmailAssetEntryAddedBodyMap(preferences);
174            }
175    
176            public static boolean getEmailAssetEntryAddedEnabled(
177                    PortletPreferences preferences) {
178    
179                    return getAssetPublisher().getEmailAssetEntryAddedEnabled(preferences);
180            }
181    
182            public static Map<Locale, String> getEmailAssetEntryAddedSubjectMap(
183                    PortletPreferences preferences) {
184    
185                    return getAssetPublisher().getEmailAssetEntryAddedSubjectMap(
186                            preferences);
187            }
188    
189            public static String getEmailFromAddress(
190                            PortletPreferences preferences, long companyId)
191                    throws SystemException {
192    
193                    return getAssetPublisher().getEmailFromAddress(preferences, companyId);
194            }
195    
196            public static String getEmailFromName(
197                            PortletPreferences preferences, long companyId)
198                    throws SystemException {
199    
200                    return getAssetPublisher().getEmailFromName(preferences, companyId);
201            }
202    
203            public static long getGroupIdFromScopeId(
204                            String scopeId, long siteGroupId, boolean privateLayout)
205                    throws PortalException, SystemException {
206    
207                    return getAssetPublisher().getGroupIdFromScopeId(
208                            scopeId, siteGroupId, privateLayout);
209            }
210    
211            public static long[] getGroupIds(
212                    PortletPreferences portletPreferences, long scopeGroupId,
213                    Layout layout) {
214    
215                    return getAssetPublisher().getGroupIds(
216                            portletPreferences, scopeGroupId, layout);
217            }
218    
219            public static long getRecentFolderId(
220                    PortletRequest portletRequest, String className) {
221    
222                    return getAssetPublisher().getRecentFolderId(portletRequest, className);
223            }
224    
225            public static String getScopeId(Group group, long scopeGroupId)
226                    throws PortalException, SystemException {
227    
228                    return getAssetPublisher().getScopeId(group, scopeGroupId);
229            }
230    
231            public static boolean isScopeIdSelectable(
232                            PermissionChecker permissionChecker, String scopeId,
233                            long companyGroupId, Layout layout)
234                    throws PortalException, SystemException {
235    
236                    return getAssetPublisher().isScopeIdSelectable(
237                            permissionChecker, scopeId, companyGroupId, layout);
238            }
239    
240            public static boolean isSubscribed(
241                            long companyId, long userId, long plid, String portletId)
242                    throws PortalException, SystemException {
243    
244                    return getAssetPublisher().isSubscribed(
245                            companyId, userId, plid, portletId);
246            }
247    
248            public static void notifySubscribers(
249                            PortletPreferences preferences, long plid, String portletId,
250                            List<AssetEntry> assetEntries)
251                    throws PortalException, SystemException {
252    
253                    getAssetPublisher().notifySubscribers(
254                            preferences, plid, portletId, assetEntries);
255            }
256    
257            public static void removeAndStoreSelection(
258                            List<String> assetEntryUuids, PortletPreferences portletPreferences)
259                    throws Exception {
260    
261                    getAssetPublisher().removeAndStoreSelection(
262                            assetEntryUuids, portletPreferences);
263            }
264    
265            public static void removeRecentFolderId(
266                    PortletRequest portletRequest, String className, long classPK) {
267    
268                    getAssetPublisher().removeRecentFolderId(
269                            portletRequest, className, classPK);
270            }
271    
272            public static void subscribe(
273                            PermissionChecker permissionChecker, long groupId, long plid,
274                            String portletId)
275                    throws PortalException, SystemException {
276    
277                    getAssetPublisher().subscribe(
278                            permissionChecker, groupId, plid, portletId);
279            }
280    
281            public static void unsubscribe(
282                            PermissionChecker permissionChecker, long plid, String portletId)
283                    throws PortalException, SystemException {
284    
285                    getAssetPublisher().unsubscribe(permissionChecker, plid, portletId);
286            }
287    
288            public void setAssetPublisher(AssetPublisher assetPublisher) {
289                    PortalRuntimePermission.checkSetBeanProperty(getClass());
290    
291                    _assetPublisher = assetPublisher;
292            }
293    
294            private static AssetPublisher _assetPublisher;
295    
296    }