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.portal.kernel.staging;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.json.JSONArray;
020    import com.liferay.portal.kernel.json.JSONObject;
021    import com.liferay.portal.kernel.lar.MissingReference;
022    import com.liferay.portal.kernel.lar.PortletDataContext;
023    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
024    import com.liferay.portal.kernel.util.UnicodeProperties;
025    import com.liferay.portal.kernel.workflow.WorkflowTask;
026    import com.liferay.portal.kernel.xml.Element;
027    import com.liferay.portal.model.Group;
028    import com.liferay.portal.model.Layout;
029    import com.liferay.portal.model.LayoutRevision;
030    import com.liferay.portal.model.Portlet;
031    import com.liferay.portal.model.User;
032    import com.liferay.portal.service.ServiceContext;
033    
034    import java.io.Serializable;
035    
036    import java.util.Date;
037    import java.util.List;
038    import java.util.Locale;
039    import java.util.Map;
040    
041    import javax.portlet.PortletPreferences;
042    import javax.portlet.PortletRequest;
043    
044    import javax.servlet.http.HttpServletRequest;
045    
046    /**
047     * @author Raymond Aug??
048     */
049    public class StagingUtil {
050    
051            public static String buildRemoteURL(
052                    String remoteAddress, int remotePort, String remotePathContext,
053                    boolean secureConnection, long remoteGroupId, boolean privateLayout) {
054    
055                    return getStaging().buildRemoteURL(
056                            remoteAddress, remotePort, remotePathContext, secureConnection,
057                            remoteGroupId, privateLayout);
058            }
059    
060            public static String buildRemoteURL(
061                    UnicodeProperties typeSettingsProperties) {
062    
063                    return getStaging().buildRemoteURL(typeSettingsProperties);
064            }
065    
066            public static void checkDefaultLayoutSetBranches(
067                            long userId, Group liveGroup, boolean branchingPublic,
068                            boolean branchingPrivate, boolean remote,
069                            ServiceContext serviceContext)
070                    throws PortalException, SystemException {
071    
072                    getStaging().checkDefaultLayoutSetBranches(
073                            userId, liveGroup, branchingPublic, branchingPrivate, remote,
074                            serviceContext);
075            }
076    
077            public static void copyFromLive(PortletRequest PortletRequest)
078                    throws Exception {
079    
080                    getStaging().copyFromLive(PortletRequest);
081            }
082    
083            public static void copyFromLive(
084                            PortletRequest PortletRequest, Portlet portlet)
085                    throws Exception {
086    
087                    getStaging().copyFromLive(PortletRequest, portlet);
088            }
089    
090            public static void copyPortlet(
091                            PortletRequest PortletRequest, long sourceGroupId,
092                            long targetGroupId, long sourcePlid, long targetPlid,
093                            String portletId)
094                    throws Exception {
095    
096                    getStaging().copyPortlet(
097                            PortletRequest, sourceGroupId, targetGroupId, sourcePlid,
098                            targetPlid, portletId);
099            }
100    
101            public static void copyRemoteLayouts(
102                            long sourceGroupId, boolean privateLayout,
103                            Map<Long, Boolean> layoutIdMap, Map<String, String[]> parameterMap,
104                            String remoteAddress, int remotePort, String remotePathContext,
105                            boolean secureConnection, long remoteGroupId,
106                            boolean remotePrivateLayout, Date startDate, Date endDate)
107                    throws Exception {
108    
109                    getStaging().copyRemoteLayouts(
110                            sourceGroupId, privateLayout, layoutIdMap, parameterMap,
111                            remoteAddress, remotePort, remotePathContext, secureConnection,
112                            remoteGroupId, remotePrivateLayout, startDate, endDate);
113            }
114    
115            public static void deleteLastImportSettings(
116                            Group liveGroup, boolean privateLayout)
117                    throws PortalException, SystemException {
118    
119                    getStaging().deleteLastImportSettings(liveGroup, privateLayout);
120            }
121    
122            public static void deleteRecentLayoutRevisionId(
123                            HttpServletRequest request, long layoutSetBranchId, long plid)
124                    throws SystemException {
125    
126                    getStaging().deleteRecentLayoutRevisionId(
127                            request, layoutSetBranchId, plid);
128            }
129    
130            public static void deleteRecentLayoutRevisionId(
131                            User user, long layoutSetBranchId, long plid)
132                    throws SystemException {
133    
134                    getStaging().deleteRecentLayoutRevisionId(
135                            user, layoutSetBranchId, plid);
136            }
137    
138            /**
139             * @deprecated As of 6.2.0, replaced by {@link
140             *             com.liferay.portal.service.StagingLocalService#disableStaging(
141             *             Group, ServiceContext)}
142             */
143            public static void disableStaging(
144                            Group scopeGroup, Group liveGroup, ServiceContext serviceContext)
145                    throws Exception {
146    
147                    getStaging().disableStaging(scopeGroup, liveGroup, serviceContext);
148            }
149    
150            /**
151             * @deprecated As of 6.2.0, replaced by {@link
152             *             com.liferay.portal.service.StagingLocalService#disableStaging(
153             *             Group, ServiceContext)}
154             */
155            public static void disableStaging(
156                            Group liveGroup, ServiceContext serviceContext)
157                    throws Exception {
158    
159                    getStaging().disableStaging(liveGroup, serviceContext);
160            }
161    
162            /**
163             * @deprecated As of 6.2.0, replaced by {@link
164             *             com.liferay.portal.service.StagingLocalService#disableStaging(
165             *             PortletRequest, Group, ServiceContext)}
166             */
167            public static void disableStaging(
168                            PortletRequest portletRequest, Group scopeGroup, Group liveGroup,
169                            ServiceContext serviceContext)
170                    throws Exception {
171    
172                    getStaging().disableStaging(
173                            portletRequest, scopeGroup, liveGroup, serviceContext);
174            }
175    
176            /**
177             * @deprecated As of 6.2.0, replaced by {@link
178             *             com.liferay.portal.service.StagingLocalService#disableStaging(
179             *             PortletRequest, Group, ServiceContext)}
180             */
181            public static void disableStaging(
182                            PortletRequest portletRequest, Group liveGroup,
183                            ServiceContext serviceContext)
184                    throws Exception {
185    
186                    getStaging().disableStaging(portletRequest, liveGroup, serviceContext);
187            }
188    
189            /**
190             * @deprecated As of 6.2.0, replaced by {@link
191             *             com.liferay.portal.service.StagingLocalService#enableLocalStaging(
192             *             long, Group, boolean, boolean, ServiceContext)}
193             */
194            public static void enableLocalStaging(
195                            long userId, Group scopeGroup, Group liveGroup,
196                            boolean branchingPublic, boolean branchingPrivate,
197                            ServiceContext serviceContext)
198                    throws Exception {
199    
200                    getStaging().enableLocalStaging(
201                            userId, scopeGroup, liveGroup, branchingPublic, branchingPrivate,
202                            serviceContext);
203            }
204    
205            /**
206             * @deprecated As of 6.2.0, replaced by {@link
207             *             com.liferay.portal.service.StagingLocalService#enableRemoteStaging(
208             *             long, Group, boolean, boolean, String, int, String, boolean,
209             *             long, ServiceContext)}
210             */
211            public static void enableRemoteStaging(
212                            long userId, Group scopeGroup, Group liveGroup,
213                            boolean branchingPublic, boolean branchingPrivate,
214                            String remoteAddress, int remotePort, String remotePathContext,
215                            boolean secureConnection, long remoteGroupId,
216                            ServiceContext serviceContext)
217                    throws Exception {
218    
219                    getStaging().enableRemoteStaging(
220                            userId, scopeGroup, liveGroup, branchingPublic, branchingPrivate,
221                            remoteAddress, remotePort, remotePathContext, secureConnection,
222                            remoteGroupId, serviceContext);
223            }
224    
225            public static JSONArray getErrorMessagesJSONArray(
226                    Locale locale, Map<String, MissingReference> missingReferences,
227                    Map<String, Serializable> contextMap) {
228    
229                    return getStaging().getErrorMessagesJSONArray(
230                            locale, missingReferences, contextMap);
231            }
232    
233            public static JSONObject getExceptionMessagesJSONObject(
234                    Locale locale, Exception e, Map<String, Serializable> contextMap) {
235    
236                    return getStaging().getExceptionMessagesJSONObject(
237                            locale, e, contextMap);
238            }
239    
240            public static Group getLiveGroup(long groupId)
241                    throws PortalException, SystemException {
242    
243                    return getStaging().getLiveGroup(groupId);
244            }
245    
246            public static long getLiveGroupId(long groupId)
247                    throws PortalException, SystemException {
248    
249                    return getStaging().getLiveGroupId(groupId);
250            }
251    
252            public static List<Layout> getMissingParentLayouts(
253                            Layout layout, long liveGroupId)
254                    throws Exception {
255    
256                    return getStaging().getMissingParentLayouts(layout, liveGroupId);
257            }
258    
259            public static long getRecentLayoutRevisionId(
260                            HttpServletRequest request, long layoutSetBranchId, long plid)
261                    throws PortalException, SystemException {
262    
263                    return getStaging().getRecentLayoutRevisionId(
264                            request, layoutSetBranchId, plid);
265            }
266    
267            public static long getRecentLayoutRevisionId(
268                            User user, long layoutSetBranchId, long plid)
269                    throws PortalException, SystemException {
270    
271                    return getStaging().getRecentLayoutRevisionId(
272                            user, layoutSetBranchId, plid);
273            }
274    
275            public static long getRecentLayoutSetBranchId(
276                    HttpServletRequest request, long layoutSetId) {
277    
278                    return getStaging().getRecentLayoutSetBranchId(request, layoutSetId);
279            }
280    
281            public static long getRecentLayoutSetBranchId(User user, long layoutSetId)
282                    throws SystemException {
283    
284                    return getStaging().getRecentLayoutSetBranchId(user, layoutSetId);
285            }
286    
287            public static String getSchedulerGroupName(
288                    String destinationName, long groupId) {
289    
290                    return getStaging().getSchedulerGroupName(destinationName, groupId);
291            }
292    
293            public static String getStagedPortletId(String portletId) {
294                    return getStaging().getStagedPortletId(portletId);
295            }
296    
297            public static Staging getStaging() {
298                    PortalRuntimePermission.checkGetBeanProperty(StagingUtil.class);
299    
300                    return _staging;
301            }
302    
303            public static Map<String, String[]> getStagingParameters() {
304                    return getStaging().getStagingParameters();
305            }
306    
307            public static Map<String, String[]> getStagingParameters(
308                    PortletRequest PortletRequest) {
309    
310                    return getStaging().getStagingParameters(PortletRequest);
311            }
312    
313            public static JSONArray getWarningMessagesJSONArray(
314                    Locale locale, Map<String, MissingReference> missingReferences,
315                    Map<String, Serializable> contextMap) {
316    
317                    return getStaging().getWarningMessagesJSONArray(
318                            locale, missingReferences, contextMap);
319            }
320    
321            public static WorkflowTask getWorkflowTask(
322                            long userId, LayoutRevision layoutRevision)
323                    throws PortalException, SystemException {
324    
325                    return getStaging().getWorkflowTask(userId, layoutRevision);
326            }
327    
328            public static boolean hasWorkflowTask(
329                            long userId, LayoutRevision layoutRevision)
330                    throws PortalException, SystemException {
331    
332                    return getStaging().hasWorkflowTask(userId, layoutRevision);
333            }
334    
335            public static boolean isIncomplete(Layout layout, long layoutSetBranchId) {
336                    return getStaging().isIncomplete(layout, layoutSetBranchId);
337            }
338    
339            public static void lockGroup(long userId, long groupId) throws Exception {
340                    getStaging().lockGroup(userId, groupId);
341            }
342    
343            public static void publishLayout(
344                            long userId, long plid, long liveGroupId, boolean includeChildren)
345                    throws Exception {
346    
347                    getStaging().publishLayout(userId, plid, liveGroupId, includeChildren);
348            }
349    
350            public static void publishLayouts(
351                            long userId, long sourceGroupId, long targetGroupId,
352                            boolean privateLayout, long[] layoutIds,
353                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
354                    throws PortalException, SystemException {
355    
356                    getStaging().publishLayouts(
357                            userId, sourceGroupId, targetGroupId, privateLayout, layoutIds,
358                            parameterMap, startDate, endDate);
359            }
360    
361            public static void publishLayouts(
362                            long userId, long sourceGroupId, long targetGroupId,
363                            boolean privateLayout, Map<Long, Boolean> layoutIdMap,
364                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
365                    throws PortalException, SystemException {
366    
367                    getStaging().publishLayouts(
368                            userId, sourceGroupId, targetGroupId, privateLayout, layoutIdMap,
369                            parameterMap, startDate, endDate);
370            }
371    
372            public static void publishLayouts(
373                            long userId, long sourceGroupId, long targetGroupId,
374                            boolean privateLayout, Map<String, String[]> parameterMap,
375                            Date startDate, Date endDate)
376                    throws PortalException, SystemException {
377    
378                    getStaging().publishLayouts(
379                            userId, sourceGroupId, targetGroupId, privateLayout, parameterMap,
380                            startDate, endDate);
381            }
382    
383            public static void publishToLive(PortletRequest PortletRequest)
384                    throws Exception {
385    
386                    getStaging().publishToLive(PortletRequest);
387            }
388    
389            public static void publishToLive(
390                            PortletRequest PortletRequest, Portlet portlet)
391                    throws Exception {
392    
393                    getStaging().publishToLive(PortletRequest, portlet);
394            }
395    
396            public static void publishToRemote(PortletRequest PortletRequest)
397                    throws Exception {
398    
399                    getStaging().publishToRemote(PortletRequest);
400            }
401    
402            public static void scheduleCopyFromLive(PortletRequest PortletRequest)
403                    throws Exception {
404    
405                    getStaging().scheduleCopyFromLive(PortletRequest);
406            }
407    
408            public static void schedulePublishToLive(PortletRequest PortletRequest)
409                    throws Exception {
410    
411                    getStaging().schedulePublishToLive(PortletRequest);
412            }
413    
414            public static void schedulePublishToRemote(PortletRequest PortletRequest)
415                    throws Exception {
416    
417                    getStaging().schedulePublishToRemote(PortletRequest);
418            }
419    
420            public static void setRecentLayoutBranchId(
421                            HttpServletRequest request, long layoutSetBranchId, long plid,
422                            long layoutBranchId)
423                    throws SystemException {
424    
425                    getStaging().setRecentLayoutBranchId(
426                            request, layoutSetBranchId, plid, layoutBranchId);
427            }
428    
429            public static void setRecentLayoutBranchId(
430                            User user, long layoutSetBranchId, long plid, long layoutBranchId)
431                    throws SystemException {
432    
433                    getStaging().setRecentLayoutBranchId(
434                            user, layoutSetBranchId, plid, layoutBranchId);
435            }
436    
437            public static void setRecentLayoutRevisionId(
438                            HttpServletRequest request, long layoutSetBranchId, long plid,
439                            long layoutRevisionId)
440                    throws SystemException {
441    
442                    getStaging().setRecentLayoutRevisionId(
443                            request, layoutSetBranchId, plid, layoutRevisionId);
444            }
445    
446            public static void setRecentLayoutRevisionId(
447                            User user, long layoutSetBranchId, long plid, long layoutRevisionId)
448                    throws SystemException {
449    
450                    getStaging().setRecentLayoutRevisionId(
451                            user, layoutSetBranchId, plid, layoutRevisionId);
452            }
453    
454            public static void setRecentLayoutSetBranchId(
455                    HttpServletRequest request, long layoutSetId, long layoutSetBranchId) {
456    
457                    getStaging().setRecentLayoutSetBranchId(
458                            request, layoutSetId, layoutSetBranchId);
459            }
460    
461            public static void setRecentLayoutSetBranchId(
462                            User user, long layoutSetId, long layoutSetBranchId)
463                    throws SystemException {
464    
465                    getStaging().setRecentLayoutSetBranchId(
466                            user, layoutSetId, layoutSetBranchId);
467            }
468    
469            public static void unlockGroup(long groupId) throws SystemException {
470                    getStaging().unlockGroup(groupId);
471            }
472    
473            public static void unscheduleCopyFromLive(PortletRequest PortletRequest)
474                    throws Exception {
475    
476                    getStaging().unscheduleCopyFromLive(PortletRequest);
477            }
478    
479            public static void unschedulePublishToLive(PortletRequest PortletRequest)
480                    throws Exception {
481    
482                    getStaging().unschedulePublishToLive(PortletRequest);
483            }
484    
485            public static void unschedulePublishToRemote(PortletRequest PortletRequest)
486                    throws Exception {
487    
488                    getStaging().unschedulePublishToRemote(PortletRequest);
489            }
490    
491            public static void updateLastImportSettings(
492                            Element layoutElement, Layout layout,
493                            PortletDataContext portletDataContext)
494                    throws Exception {
495    
496                    getStaging().updateLastImportSettings(
497                            layoutElement, layout, portletDataContext);
498            }
499    
500            public static void updateLastPublishDate(
501                            long sourceGroupId, boolean privateLayout, Date lastPublishDate)
502                    throws Exception {
503    
504                    getStaging().updateLastPublishDate(
505                            sourceGroupId, privateLayout, lastPublishDate);
506            }
507    
508            public static void updateLastPublishDate(
509                            String portletId, PortletPreferences portletPreferences,
510                            Date lastPublishDate)
511                    throws Exception {
512    
513                    getStaging().updateLastPublishDate(
514                            portletId, portletPreferences, lastPublishDate);
515            }
516    
517            public static void updateStaging(
518                            PortletRequest PortletRequest, Group liveGroup)
519                    throws Exception {
520    
521                    getStaging().updateStaging(PortletRequest, liveGroup);
522            }
523    
524            public static void validateRemote(
525                            String remoteAddress, int remotePort, String remotePathContext,
526                            boolean secureConnection, long remoteGroupId)
527                    throws PortalException {
528    
529                    getStaging().validateRemote(
530                            remoteAddress, remotePort, remotePathContext, secureConnection,
531                            remoteGroupId);
532            }
533    
534            public void setStaging(Staging staging) {
535                    PortalRuntimePermission.checkSetBeanProperty(getClass());
536    
537                    _staging = staging;
538            }
539    
540            private static Staging _staging;
541    
542    }