001    /**
002     * Copyright (c) 2000-present 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 aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
021    import com.liferay.portal.model.Group;
022    import com.liferay.portal.model.Layout;
023    import com.liferay.portal.model.User;
024    import com.liferay.portal.security.permission.PermissionChecker;
025    import com.liferay.portal.theme.ThemeDisplay;
026    import com.liferay.portlet.asset.model.AssetEntry;
027    import com.liferay.portlet.asset.model.AssetRendererFactory;
028    import com.liferay.portlet.asset.model.ClassType;
029    import com.liferay.portlet.asset.service.persistence.AssetEntryQuery;
030    
031    import java.util.List;
032    import java.util.Locale;
033    import java.util.Map;
034    
035    import javax.portlet.PortletPreferences;
036    import javax.portlet.PortletRequest;
037    
038    /**
039     * @author Eudaldo Alonso
040     */
041    @ProviderType
042    public class AssetPublisherUtil {
043    
044            public static void addAndStoreSelection(
045                            PortletRequest portletRequest, String className, long classPK,
046                            int assetEntryOrder)
047                    throws Exception {
048    
049                    getAssetPublisher().addAndStoreSelection(
050                            portletRequest, className, classPK, assetEntryOrder);
051            }
052    
053            public static void addRecentFolderId(
054                    PortletRequest portletRequest, String className, long classPK) {
055    
056                    getAssetPublisher().addRecentFolderId(
057                            portletRequest, className, classPK);
058            }
059    
060            public static void addSelection(
061                            PortletRequest portletRequest,
062                            PortletPreferences portletPreferences, String portletId)
063                    throws Exception {
064    
065                    getAssetPublisher().addSelection(
066                            portletRequest, portletPreferences, portletId);
067            }
068    
069            public static void addSelection(
070                            ThemeDisplay themeDisplay, PortletPreferences portletPreferences,
071                            String portletId, long assetEntryId, int assetEntryOrder,
072                            String assetEntryType)
073                    throws Exception {
074    
075                    getAssetPublisher().addSelection(
076                            themeDisplay, portletPreferences, portletId, assetEntryId,
077                            assetEntryOrder, assetEntryType);
078            }
079    
080            public static void addUserAttributes(
081                            User user, String[] customUserAttributeNames,
082                            AssetEntryQuery assetEntryQuery)
083                    throws Exception {
084    
085                    getAssetPublisher().addUserAttributes(
086                            user, customUserAttributeNames, assetEntryQuery);
087            }
088    
089            public static void checkAssetEntries() throws Exception {
090                    getAssetPublisher().checkAssetEntries();
091            }
092    
093            public static long[] getAssetCategoryIds(
094                            PortletPreferences portletPreferences)
095                    throws Exception {
096    
097                    return getAssetPublisher().getAssetCategoryIds(portletPreferences);
098            }
099    
100            public static List<AssetEntry> getAssetEntries(
101                            PortletPreferences portletPreferences, Layout layout,
102                            long scopeGroupId, int max, boolean checkPermission)
103                    throws PortalException {
104    
105                    return getAssetPublisher().getAssetEntries(
106                            portletPreferences, layout, scopeGroupId, max, checkPermission);
107            }
108    
109            public static List<AssetEntry> getAssetEntries(
110                            PortletRequest portletRequest,
111                            PortletPreferences portletPreferences,
112                            PermissionChecker permissionChecker, long[] groupIds,
113                            boolean deleteMissingAssetEntries, boolean checkPermission)
114                    throws Exception {
115    
116                    return getAssetPublisher().getAssetEntries(
117                            portletRequest, portletPreferences, permissionChecker, groupIds,
118                            deleteMissingAssetEntries, checkPermission);
119            }
120    
121            public static List<AssetEntry> getAssetEntries(
122                            PortletRequest portletRequest,
123                            PortletPreferences portletPreferences,
124                            PermissionChecker permissionChecker, long[] groupIds,
125                            long[] allCategoryIds, String[] allTagNames,
126                            boolean deleteMissingAssetEntries, boolean checkPermission)
127                    throws Exception {
128    
129                    return getAssetPublisher().getAssetEntries(
130                            portletRequest, portletPreferences, permissionChecker, groupIds,
131                            allCategoryIds, allTagNames, deleteMissingAssetEntries,
132                            checkPermission);
133            }
134    
135            /**
136             * @deprecated As of 7.0.0, replaced by {@link
137             *             AssetPublisherUtil#getAssetEntries( PortletRequest,
138             *             PortletPreferences, PermissionChecker, long[], long[],
139             *             String[], boolean , boolean)}
140             */
141            @Deprecated
142            public static List<AssetEntry> getAssetEntries(
143                            PortletRequest portletRequest,
144                            PortletPreferences portletPreferences,
145                            PermissionChecker permissionChecker, long[] groupIds,
146                            long[] assetCategoryIds, String[] assetEntryXmls,
147                            String[] assetTagNames, boolean deleteMissingAssetEntries,
148                            boolean checkPermission)
149                    throws Exception {
150    
151                    return getAssetPublisher().getAssetEntries(
152                            portletRequest, portletPreferences, permissionChecker, groupIds,
153                            assetCategoryIds, assetEntryXmls, assetTagNames,
154                            deleteMissingAssetEntries, checkPermission);
155            }
156    
157            /**
158             * @deprecated As of 7.0.0, replaced by {@link
159             *             AssetPublisherUtil#getAssetEntries( PortletRequest,
160             *             PortletPreferences, PermissionChecker, long[], boolean,
161             *             boolean)}
162             */
163            @Deprecated
164            public static List<AssetEntry> getAssetEntries(
165                            PortletRequest portletRequest,
166                            PortletPreferences portletPreferences,
167                            PermissionChecker permissionChecker, long[] groupIds,
168                            String[] assetEntryXmls, boolean deleteMissingAssetEntries,
169                            boolean checkPermission)
170                    throws Exception {
171    
172                    return getAssetPublisher().getAssetEntries(
173                            portletRequest, portletPreferences, permissionChecker, groupIds,
174                            assetEntryXmls, deleteMissingAssetEntries, checkPermission);
175            }
176    
177            /**
178             * @deprecated As of 7.0.0, replaced by {@link
179             *             AssetPublisherUtil#getAssetEntryQuery(PortletPreferences,
180             *             long[], long[], String[])}
181             */
182            @Deprecated
183            public static AssetEntryQuery getAssetEntryQuery(
184                            PortletPreferences portletPreferences, long[] siteGroupIds)
185                    throws PortalException {
186    
187                    return getAssetPublisher().getAssetEntryQuery(
188                            portletPreferences, siteGroupIds);
189            }
190    
191            public static AssetEntryQuery getAssetEntryQuery(
192                            PortletPreferences portletPreferences, long[] scopeGroupIds,
193                            long[] overrideAllAssetCategoryIds,
194                            String[] overrideAllAssetTagNames)
195                    throws PortalException {
196    
197                    return getAssetPublisher().getAssetEntryQuery(
198                            portletPreferences, scopeGroupIds, overrideAllAssetCategoryIds,
199                            overrideAllAssetTagNames);
200            }
201    
202            public static AssetPublisher getAssetPublisher() {
203                    PortalRuntimePermission.checkGetBeanProperty(AssetPublisherUtil.class);
204    
205                    return _assetPublisher;
206            }
207    
208            public static String[] getAssetTagNames(
209                            PortletPreferences portletPreferences)
210                    throws Exception {
211    
212                    return getAssetPublisher().getAssetTagNames(portletPreferences);
213            }
214    
215            /**
216             * @deprecated As of 7.0.0, replaced by {@link
217             *             AssetPublisherUtil#getAssetTagNames(PortletPreferences)}
218             */
219            @Deprecated
220            public static String[] getAssetTagNames(
221                            PortletPreferences portletPreferences, long scopeGroupId)
222                    throws Exception {
223    
224                    return getAssetPublisher().getAssetTagNames(
225                            portletPreferences, scopeGroupId);
226            }
227    
228            public static String getClassName(
229                    AssetRendererFactory assetRendererFactory) {
230    
231                    return getAssetPublisher().getClassName(assetRendererFactory);
232            }
233    
234            public static long[] getClassNameIds(
235                    PortletPreferences portletPreferences, long[] availableClassNameIds) {
236    
237                    return getAssetPublisher().getClassNameIds(
238                            portletPreferences, availableClassNameIds);
239            }
240    
241            public static Long[] getClassTypeIds(
242                    PortletPreferences portletPreferences, String className,
243                    List<ClassType> availableClassTypes) {
244    
245                    return getAssetPublisher().getClassTypeIds(
246                            portletPreferences, className, availableClassTypes);
247            }
248    
249            public static Long[] getClassTypeIds(
250                    PortletPreferences portletPreferences, String className,
251                    Long[] availableClassTypeIds) {
252    
253                    return getAssetPublisher().getClassTypeIds(
254                            portletPreferences, className, availableClassTypeIds);
255            }
256    
257            public static Map<Locale, String> getEmailAssetEntryAddedBodyMap(
258                    PortletPreferences portletPreferences) {
259    
260                    return getAssetPublisher().getEmailAssetEntryAddedBodyMap(
261                            portletPreferences);
262            }
263    
264            public static boolean getEmailAssetEntryAddedEnabled(
265                    PortletPreferences portletPreferences) {
266    
267                    return getAssetPublisher().getEmailAssetEntryAddedEnabled(
268                            portletPreferences);
269            }
270    
271            public static Map<Locale, String> getEmailAssetEntryAddedSubjectMap(
272                    PortletPreferences portletPreferences) {
273    
274                    return getAssetPublisher().getEmailAssetEntryAddedSubjectMap(
275                            portletPreferences);
276            }
277    
278            public static Map<String, String> getEmailDefinitionTerms(
279                    PortletRequest portletRequest, String emailFromAddress,
280                    String emailFromName) {
281    
282                    return getAssetPublisher().getEmailDefinitionTerms(
283                            portletRequest, emailFromAddress, emailFromName);
284            }
285    
286            public static String getEmailFromAddress(
287                    PortletPreferences portletPreferences, long companyId) {
288    
289                    return getAssetPublisher().getEmailFromAddress(
290                            portletPreferences, companyId);
291            }
292    
293            public static String getEmailFromName(
294                    PortletPreferences portletPreferences, long companyId) {
295    
296                    return getAssetPublisher().getEmailFromName(
297                            portletPreferences, companyId);
298            }
299    
300            public static long getGroupIdFromScopeId(
301                            String scopeId, long siteGroupId, boolean privateLayout)
302                    throws PortalException {
303    
304                    return getAssetPublisher().getGroupIdFromScopeId(
305                            scopeId, siteGroupId, privateLayout);
306            }
307    
308            public static long[] getGroupIds(
309                    PortletPreferences portletPreferences, long scopeGroupId,
310                    Layout layout) {
311    
312                    return getAssetPublisher().getGroupIds(
313                            portletPreferences, scopeGroupId, layout);
314            }
315    
316            public static long getRecentFolderId(
317                    PortletRequest portletRequest, String className) {
318    
319                    return getAssetPublisher().getRecentFolderId(portletRequest, className);
320            }
321    
322            public static String getScopeId(Group group, long scopeGroupId)
323                    throws PortalException {
324    
325                    return getAssetPublisher().getScopeId(group, scopeGroupId);
326            }
327    
328            public static long getSubscriptionClassPK(long plid, String portletId)
329                    throws PortalException {
330    
331                    return getAssetPublisher().getSubscriptionClassPK(plid, portletId);
332            }
333    
334            public static boolean isScopeIdSelectable(
335                            PermissionChecker permissionChecker, String scopeId,
336                            long companyGroupId, Layout layout)
337                    throws PortalException {
338    
339                    return getAssetPublisher().isScopeIdSelectable(
340                            permissionChecker, scopeId, companyGroupId, layout);
341            }
342    
343            public static boolean isSubscribed(
344                            long companyId, long userId, long plid, String portletId)
345                    throws PortalException {
346    
347                    return getAssetPublisher().isSubscribed(
348                            companyId, userId, plid, portletId);
349            }
350    
351            public static void notifySubscribers(
352                            PortletPreferences portletPreferences, long plid, String portletId,
353                            List<AssetEntry> assetEntries)
354                    throws PortalException {
355    
356                    getAssetPublisher().notifySubscribers(
357                            portletPreferences, plid, portletId, assetEntries);
358            }
359    
360            public static void processAssetEntryQuery(
361                            User user, PortletPreferences portletPreferences,
362                            AssetEntryQuery assetEntryQuery)
363                    throws Exception {
364    
365                    getAssetPublisher().processAssetEntryQuery(
366                            user, portletPreferences, assetEntryQuery);
367            }
368    
369            public static void registerAssetQueryProcessor(
370                    String name, AssetEntryQueryProcessor assetQueryProcessor) {
371    
372                    getAssetPublisher().registerAssetQueryProcessor(
373                            name, assetQueryProcessor);
374            }
375    
376            public static void removeAndStoreSelection(
377                            List<String> assetEntryUuids, PortletPreferences portletPreferences)
378                    throws Exception {
379    
380                    getAssetPublisher().removeAndStoreSelection(
381                            assetEntryUuids, portletPreferences);
382            }
383    
384            public static void removeRecentFolderId(
385                    PortletRequest portletRequest, String className, long classPK) {
386    
387                    getAssetPublisher().removeRecentFolderId(
388                            portletRequest, className, classPK);
389            }
390    
391            public static void subscribe(
392                            PermissionChecker permissionChecker, long groupId, long plid,
393                            String portletId)
394                    throws PortalException {
395    
396                    getAssetPublisher().subscribe(
397                            permissionChecker, groupId, plid, portletId);
398            }
399    
400            public static void unregisterAssetQueryProcessor(
401                    String assetQueryProcessorClassName) {
402    
403                    getAssetPublisher().unregisterAssetQueryProcessor(
404                            assetQueryProcessorClassName);
405            }
406    
407            public static void unsubscribe(
408                            PermissionChecker permissionChecker, long plid, String portletId)
409                    throws PortalException {
410    
411                    getAssetPublisher().unsubscribe(permissionChecker, plid, portletId);
412            }
413    
414            public void setAssetPublisher(AssetPublisher assetPublisher) {
415                    PortalRuntimePermission.checkSetBeanProperty(getClass());
416    
417                    _assetPublisher = assetPublisher;
418            }
419    
420            private static AssetPublisher _assetPublisher;
421    
422    }