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