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                            String[] assetEntryXmls, boolean deleteMissingAssetEntries,
104                            boolean checkPermission)
105                    throws Exception {
106    
107                    return getAssetPublisher().getAssetEntries(
108                            portletRequest, portletPreferences, permissionChecker, groupIds,
109                            assetEntryXmls, deleteMissingAssetEntries, checkPermission);
110            }
111    
112            public static AssetEntryQuery getAssetEntryQuery(
113                            PortletPreferences portletPreferences, long[] scopeGroupIds)
114                    throws PortalException, SystemException {
115    
116                    return getAssetPublisher().getAssetEntryQuery(
117                            portletPreferences, scopeGroupIds);
118            }
119    
120            public static AssetPublisher getAssetPublisher() {
121                    PortalRuntimePermission.checkGetBeanProperty(AssetPublisherUtil.class);
122    
123                    return _assetPublisher;
124            }
125    
126            public static String[] getAssetTagNames(
127                            PortletPreferences portletPreferences, long scopeGroupId)
128                    throws Exception {
129    
130                    return getAssetPublisher().getAssetTagNames(
131                            portletPreferences, scopeGroupId);
132            }
133    
134            public static String getClassName(
135                    AssetRendererFactory assetRendererFactory) {
136    
137                    return getAssetPublisher().getClassName(assetRendererFactory);
138            }
139    
140            public static long[] getClassNameIds(
141                    PortletPreferences portletPreferences, long[] availableClassNameIds) {
142    
143                    return getAssetPublisher().getClassNameIds(
144                            portletPreferences, availableClassNameIds);
145            }
146    
147            public static Long[] getClassTypeIds(
148                    PortletPreferences portletPreferences, String className,
149                    Long[] availableClassTypeIds) {
150    
151                    return getAssetPublisher().getClassTypeIds(
152                            portletPreferences, className, availableClassTypeIds);
153            }
154    
155            public static Map<Locale, String> getEmailAssetEntryAddedBodyMap(
156                    PortletPreferences preferences) {
157    
158                    return getAssetPublisher().getEmailAssetEntryAddedBodyMap(preferences);
159            }
160    
161            public static boolean getEmailAssetEntryAddedEnabled(
162                    PortletPreferences preferences) {
163    
164                    return getAssetPublisher().getEmailAssetEntryAddedEnabled(preferences);
165            }
166    
167            public static Map<Locale, String> getEmailAssetEntryAddedSubjectMap(
168                    PortletPreferences preferences) {
169    
170                    return getAssetPublisher().getEmailAssetEntryAddedSubjectMap(
171                            preferences);
172            }
173    
174            public static String getEmailFromAddress(
175                            PortletPreferences preferences, long companyId)
176                    throws SystemException {
177    
178                    return getAssetPublisher().getEmailFromAddress(preferences, companyId);
179            }
180    
181            public static String getEmailFromName(
182                            PortletPreferences preferences, long companyId)
183                    throws SystemException {
184    
185                    return getAssetPublisher().getEmailFromName(preferences, companyId);
186            }
187    
188            public static long getGroupIdFromScopeId(
189                            String scopeId, long siteGroupId, boolean privateLayout)
190                    throws PortalException, SystemException {
191    
192                    return getAssetPublisher().getGroupIdFromScopeId(
193                            scopeId, siteGroupId, privateLayout);
194            }
195    
196            public static long[] getGroupIds(
197                    PortletPreferences portletPreferences, long scopeGroupId,
198                    Layout layout) {
199    
200                    return getAssetPublisher().getGroupIds(
201                            portletPreferences, scopeGroupId, layout);
202            }
203    
204            public static long getRecentFolderId(
205                    PortletRequest portletRequest, String className) {
206    
207                    return getAssetPublisher().getRecentFolderId(portletRequest, className);
208            }
209    
210            public static String getScopeId(Group group, long scopeGroupId)
211                    throws PortalException, SystemException {
212    
213                    return getAssetPublisher().getScopeId(group, scopeGroupId);
214            }
215    
216            public static boolean isScopeIdSelectable(
217                            PermissionChecker permissionChecker, String scopeId,
218                            long companyGroupId, Layout layout)
219                    throws PortalException, SystemException {
220    
221                    return getAssetPublisher().isScopeIdSelectable(
222                            permissionChecker, scopeId, companyGroupId, layout);
223            }
224    
225            public static boolean isSubscribed(
226                            long companyId, long userId, long plid, String portletId)
227                    throws PortalException, SystemException {
228    
229                    return getAssetPublisher().isSubscribed(
230                            companyId, userId, plid, portletId);
231            }
232    
233            public static void notifySubscribers(
234                            PortletPreferences preferences, long plid, String portletId,
235                            List<AssetEntry> assetEntries)
236                    throws PortalException, SystemException {
237    
238                    getAssetPublisher().notifySubscribers(
239                            preferences, plid, portletId, assetEntries);
240            }
241    
242            public static void removeAndStoreSelection(
243                            List<String> assetEntryUuids, PortletPreferences portletPreferences)
244                    throws Exception {
245    
246                    getAssetPublisher().removeAndStoreSelection(
247                            assetEntryUuids, portletPreferences);
248            }
249    
250            public static void removeRecentFolderId(
251                    PortletRequest portletRequest, String className, long classPK) {
252    
253                    getAssetPublisher().removeRecentFolderId(
254                            portletRequest, className, classPK);
255            }
256    
257            public static void subscribe(
258                            PermissionChecker permissionChecker, long groupId, long plid,
259                            String portletId)
260                    throws PortalException, SystemException {
261    
262                    getAssetPublisher().subscribe(
263                            permissionChecker, groupId, plid, portletId);
264            }
265    
266            public static void unsubscribe(
267                            PermissionChecker permissionChecker, long plid, String portletId)
268                    throws PortalException, SystemException {
269    
270                    getAssetPublisher().unsubscribe(permissionChecker, plid, portletId);
271            }
272    
273            public void setAssetPublisher(AssetPublisher assetPublisher) {
274                    PortalRuntimePermission.checkSetBeanProperty(getClass());
275    
276                    _assetPublisher = assetPublisher;
277            }
278    
279            private static AssetPublisher _assetPublisher;
280    
281    }