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 long[] getAssetCategoryIds(
091                            PortletPreferences portletPreferences)
092                    throws Exception {
093    
094                    return getAssetPublisher().getAssetCategoryIds(portletPreferences);
095            }
096    
097            public static List<AssetEntry> getAssetEntries(
098                            PortletPreferences portletPreferences, Layout layout,
099                            long scopeGroupId, int max, boolean checkPermission)
100                    throws PortalException, SystemException {
101    
102                    return getAssetPublisher().getAssetEntries(
103                            portletPreferences, layout, scopeGroupId, max, checkPermission);
104            }
105    
106            public static List<AssetEntry> getAssetEntries(
107                            PortletRequest portletRequest,
108                            PortletPreferences portletPreferences,
109                            PermissionChecker permissionChecker, long[] groupIds,
110                            long[] assetCategoryIds, String[] assetEntryXmls,
111                            String[] assetTagNames, boolean deleteMissingAssetEntries,
112                            boolean checkPermission)
113                    throws Exception {
114    
115                    return getAssetPublisher().getAssetEntries(
116                            portletRequest, portletPreferences, permissionChecker, groupIds,
117                            assetCategoryIds, assetEntryXmls, assetTagNames,
118                            deleteMissingAssetEntries, checkPermission);
119            }
120    
121            public static List<AssetEntry> getAssetEntries(
122                            PortletRequest portletRequest,
123                            PortletPreferences portletPreferences,
124                            PermissionChecker permissionChecker, long[] groupIds,
125                            String[] assetEntryXmls, boolean deleteMissingAssetEntries,
126                            boolean checkPermission)
127                    throws Exception {
128    
129                    return getAssetPublisher().getAssetEntries(
130                            portletRequest, portletPreferences, permissionChecker, groupIds,
131                            assetEntryXmls, deleteMissingAssetEntries, checkPermission);
132            }
133    
134            public static AssetEntryQuery getAssetEntryQuery(
135                            PortletPreferences portletPreferences, long[] scopeGroupIds)
136                    throws PortalException, SystemException {
137    
138                    return getAssetPublisher().getAssetEntryQuery(
139                            portletPreferences, scopeGroupIds);
140            }
141    
142            public static AssetPublisher getAssetPublisher() {
143                    PortalRuntimePermission.checkGetBeanProperty(AssetPublisherUtil.class);
144    
145                    return _assetPublisher;
146            }
147    
148            public static String[] getAssetTagNames(
149                            PortletPreferences portletPreferences, long scopeGroupId)
150                    throws Exception {
151    
152                    return getAssetPublisher().getAssetTagNames(
153                            portletPreferences, scopeGroupId);
154            }
155    
156            public static String getClassName(
157                    AssetRendererFactory assetRendererFactory) {
158    
159                    return getAssetPublisher().getClassName(assetRendererFactory);
160            }
161    
162            public static long[] getClassNameIds(
163                    PortletPreferences portletPreferences, long[] availableClassNameIds) {
164    
165                    return getAssetPublisher().getClassNameIds(
166                            portletPreferences, availableClassNameIds);
167            }
168    
169            public static Long[] getClassTypeIds(
170                    PortletPreferences portletPreferences, String className,
171                    Long[] availableClassTypeIds) {
172    
173                    return getAssetPublisher().getClassTypeIds(
174                            portletPreferences, className, availableClassTypeIds);
175            }
176    
177            public static Map<Locale, String> getEmailAssetEntryAddedBodyMap(
178                    PortletPreferences portletPreferences) {
179    
180                    return getAssetPublisher().getEmailAssetEntryAddedBodyMap(
181                            portletPreferences);
182            }
183    
184            public static boolean getEmailAssetEntryAddedEnabled(
185                    PortletPreferences portletPreferences) {
186    
187                    return getAssetPublisher().getEmailAssetEntryAddedEnabled(
188                            portletPreferences);
189            }
190    
191            public static Map<Locale, String> getEmailAssetEntryAddedSubjectMap(
192                    PortletPreferences portletPreferences) {
193    
194                    return getAssetPublisher().getEmailAssetEntryAddedSubjectMap(
195                            portletPreferences);
196            }
197    
198            public static String getEmailFromAddress(
199                            PortletPreferences portletPreferences, long companyId)
200                    throws SystemException {
201    
202                    return getAssetPublisher().getEmailFromAddress(
203                            portletPreferences, companyId);
204            }
205    
206            public static String getEmailFromName(
207                            PortletPreferences portletPreferences, long companyId)
208                    throws SystemException {
209    
210                    return getAssetPublisher().getEmailFromName(
211                            portletPreferences, companyId);
212            }
213    
214            public static long getGroupIdFromScopeId(
215                            String scopeId, long siteGroupId, boolean privateLayout)
216                    throws PortalException, SystemException {
217    
218                    return getAssetPublisher().getGroupIdFromScopeId(
219                            scopeId, siteGroupId, privateLayout);
220            }
221    
222            public static long[] getGroupIds(
223                    PortletPreferences portletPreferences, long scopeGroupId,
224                    Layout layout) {
225    
226                    return getAssetPublisher().getGroupIds(
227                            portletPreferences, scopeGroupId, layout);
228            }
229    
230            public static long getRecentFolderId(
231                    PortletRequest portletRequest, String className) {
232    
233                    return getAssetPublisher().getRecentFolderId(portletRequest, className);
234            }
235    
236            public static String getScopeId(Group group, long scopeGroupId)
237                    throws PortalException, SystemException {
238    
239                    return getAssetPublisher().getScopeId(group, scopeGroupId);
240            }
241    
242            public static boolean isScopeIdSelectable(
243                            PermissionChecker permissionChecker, String scopeId,
244                            long companyGroupId, Layout layout)
245                    throws PortalException, SystemException {
246    
247                    return getAssetPublisher().isScopeIdSelectable(
248                            permissionChecker, scopeId, companyGroupId, layout);
249            }
250    
251            public static boolean isSubscribed(
252                            long companyId, long userId, long plid, String portletId)
253                    throws PortalException, SystemException {
254    
255                    return getAssetPublisher().isSubscribed(
256                            companyId, userId, plid, portletId);
257            }
258    
259            public static void notifySubscribers(
260                            PortletPreferences portletPreferences, long plid, String portletId,
261                            List<AssetEntry> assetEntries)
262                    throws PortalException, SystemException {
263    
264                    getAssetPublisher().notifySubscribers(
265                            portletPreferences, plid, portletId, assetEntries);
266            }
267    
268            public static void processAssetEntryQuery(
269                            User user, PortletPreferences portletPreferences,
270                            AssetEntryQuery assetEntryQuery)
271                    throws Exception {
272    
273                    getAssetPublisher().processAssetEntryQuery(
274                            user, portletPreferences, assetEntryQuery);
275            }
276    
277            public static void registerAssetQueryProcessor(
278                    String name, AssetEntryQueryProcessor assetQueryProcessor) {
279    
280                    getAssetPublisher().registerAssetQueryProcessor(
281                                    name, assetQueryProcessor);
282            }
283    
284            public static void removeAndStoreSelection(
285                            List<String> assetEntryUuids, PortletPreferences portletPreferences)
286                    throws Exception {
287    
288                    getAssetPublisher().removeAndStoreSelection(
289                            assetEntryUuids, portletPreferences);
290            }
291    
292            public static void removeRecentFolderId(
293                    PortletRequest portletRequest, String className, long classPK) {
294    
295                    getAssetPublisher().removeRecentFolderId(
296                            portletRequest, className, classPK);
297            }
298    
299            public static void subscribe(
300                            PermissionChecker permissionChecker, long groupId, long plid,
301                            String portletId)
302                    throws PortalException, SystemException {
303    
304                    getAssetPublisher().subscribe(
305                            permissionChecker, groupId, plid, portletId);
306            }
307    
308            public static void unregisterAssetQueryProcessor(
309                    String assetQueryProcessorClassName) {
310    
311                    getAssetPublisher().unregisterAssetQueryProcessor(
312                            assetQueryProcessorClassName);
313            }
314    
315            public static void unsubscribe(
316                            PermissionChecker permissionChecker, long plid, String portletId)
317                    throws PortalException, SystemException {
318    
319                    getAssetPublisher().unsubscribe(permissionChecker, plid, portletId);
320            }
321    
322            public void setAssetPublisher(AssetPublisher assetPublisher) {
323                    PortalRuntimePermission.checkSetBeanProperty(getClass());
324    
325                    _assetPublisher = assetPublisher;
326            }
327    
328            private static AssetPublisher _assetPublisher;
329    
330    }