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