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.service.impl;
016    
017    import com.liferay.portal.NoSuchLayoutException;
018    import com.liferay.portal.kernel.cache.ThreadLocalCachable;
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.exception.SystemException;
021    import com.liferay.portal.kernel.lar.MissingReferences;
022    import com.liferay.portal.kernel.messaging.DestinationNames;
023    import com.liferay.portal.kernel.repository.model.FileEntry;
024    import com.liferay.portal.kernel.scheduler.CronTrigger;
025    import com.liferay.portal.kernel.scheduler.SchedulerEngineHelperUtil;
026    import com.liferay.portal.kernel.scheduler.StorageType;
027    import com.liferay.portal.kernel.scheduler.Trigger;
028    import com.liferay.portal.kernel.util.GetterUtil;
029    import com.liferay.portal.kernel.util.StringPool;
030    import com.liferay.portal.kernel.util.TempFileUtil;
031    import com.liferay.portal.kernel.util.Validator;
032    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
033    import com.liferay.portal.messaging.LayoutsLocalPublisherRequest;
034    import com.liferay.portal.messaging.LayoutsRemotePublisherRequest;
035    import com.liferay.portal.model.Group;
036    import com.liferay.portal.model.Layout;
037    import com.liferay.portal.model.LayoutConstants;
038    import com.liferay.portal.model.LayoutReference;
039    import com.liferay.portal.model.LayoutTypePortlet;
040    import com.liferay.portal.model.Plugin;
041    import com.liferay.portal.model.User;
042    import com.liferay.portal.security.permission.ActionKeys;
043    import com.liferay.portal.security.permission.PermissionChecker;
044    import com.liferay.portal.service.ServiceContext;
045    import com.liferay.portal.service.base.LayoutServiceBaseImpl;
046    import com.liferay.portal.service.permission.GroupPermissionUtil;
047    import com.liferay.portal.service.permission.LayoutPermissionUtil;
048    import com.liferay.portal.service.permission.PortletPermissionUtil;
049    import com.liferay.portal.util.PortletKeys;
050    import com.liferay.portlet.PortletPreferencesFactoryUtil;
051    
052    import java.io.File;
053    import java.io.InputStream;
054    
055    import java.util.ArrayList;
056    import java.util.Date;
057    import java.util.List;
058    import java.util.Locale;
059    import java.util.Map;
060    
061    /**
062     * Provides the remote service for accessing, adding, deleting, exporting,
063     * importing, scheduling publishing of, and updating layouts. Its methods
064     * include permission checks.
065     *
066     * @author Brian Wing Shun Chan
067     * @author Wesley Gong
068     * @author Tibor Lipusz
069     */
070    public class LayoutServiceImpl extends LayoutServiceBaseImpl {
071    
072            /**
073             * Adds a layout with additional parameters.
074             *
075             * <p>
076             * This method handles the creation of the layout including its resources,
077             * metadata, and internal data structures. It is not necessary to make
078             * subsequent calls to any methods to setup default groups, resources, ...
079             * etc.
080             * </p>
081             *
082             * @param      groupId the primary key of the group
083             * @param      privateLayout whether the layout is private to the group
084             * @param      parentLayoutId the primary key of the parent layout
085             *             (optionally {@link
086             *             com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID})
087             * @param      localeNamesMap the layout's locales and localized names
088             * @param      localeTitlesMap the layout's locales and localized titles
089             * @param      descriptionMap the layout's locales and localized
090             *             descriptions
091             * @param      keywordsMap the layout's locales and localized keywords
092             * @param      robotsMap the layout's locales and localized robots
093             * @param      type the layout's type (optionally {@link
094             *             com.liferay.portal.model.LayoutConstants#TYPE_PORTLET}). The
095             *             possible types can be found in {@link
096             *             com.liferay.portal.model.LayoutConstants}.
097             * @param      hidden whether the layout is hidden
098             * @param      friendlyURL the layout's locales and localized friendly URLs.
099             *             To see how the URL is normalized when accessed, see {@link
100             *             com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
101             *             String)}.
102             * @param      serviceContext the service context to be applied. Must set
103             *             the UUID for the layout. Can set the creation date,
104             *             modification date, and expando bridge attributes for the
105             *             layout. For layouts that belong to a layout set prototype, an
106             *             attribute named <code>layoutUpdateable</code> can be used to
107             *             specify whether site administrators can modify this page
108             *             within their site.
109             * @return     the layout
110             * @throws     PortalException if a group with the primary key could not be
111             *             found, if the group did not have permission to manage the
112             *             layouts involved, if layout values were invalid, or if a
113             *             portal exception occurred
114             * @throws     SystemException if a system exception occurred
115             * @deprecated As of 6.2.0, replaced by {@link #addLayout(long, boolean,
116             *             long, Map, Map, Map, Map, Map, String, String, boolean, Map,
117             *             ServiceContext)}
118             */
119            @Override
120            public Layout addLayout(
121                            long groupId, boolean privateLayout, long parentLayoutId,
122                            Map<Locale, String> localeNamesMap,
123                            Map<Locale, String> localeTitlesMap,
124                            Map<Locale, String> descriptionMap, Map<Locale, String> keywordsMap,
125                            Map<Locale, String> robotsMap, String type, boolean hidden,
126                            String friendlyURL, ServiceContext serviceContext)
127                    throws PortalException, SystemException {
128    
129                    PermissionChecker permissionChecker = getPermissionChecker();
130    
131                    if (parentLayoutId == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
132                            GroupPermissionUtil.check(
133                                    permissionChecker, groupId, ActionKeys.ADD_LAYOUT);
134                    }
135                    else {
136                            LayoutPermissionUtil.check(
137                                    permissionChecker, groupId, privateLayout, parentLayoutId,
138                                    ActionKeys.ADD_LAYOUT);
139                    }
140    
141                    return layoutLocalService.addLayout(
142                            getUserId(), groupId, privateLayout, parentLayoutId, localeNamesMap,
143                            localeTitlesMap, descriptionMap, keywordsMap, robotsMap, type,
144                            hidden, friendlyURL, serviceContext);
145            }
146    
147            /**
148             * Adds a layout with additional parameters.
149             *
150             * <p>
151             * This method handles the creation of the layout including its resources,
152             * metadata, and internal data structures. It is not necessary to make
153             * subsequent calls to any methods to setup default groups, resources, ...
154             * etc.
155             * </p>
156             *
157             * @param  groupId the primary key of the group
158             * @param  privateLayout whether the layout is private to the group
159             * @param  parentLayoutId the primary key of the parent layout (optionally
160             *         {@link
161             *         com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID})
162             * @param  localeNamesMap the layout's locales and localized names
163             * @param  localeTitlesMap the layout's locales and localized titles
164             * @param  descriptionMap the layout's locales and localized descriptions
165             * @param  keywordsMap the layout's locales and localized keywords
166             * @param  robotsMap the layout's locales and localized robots
167             * @param  type the layout's type (optionally {@link
168             *         com.liferay.portal.model.LayoutConstants#TYPE_PORTLET}). The
169             *         possible types can be found in {@link
170             *         com.liferay.portal.model.LayoutConstants}.
171             * @param  typeSettings the settings to load the unicode properties object.
172             *         See {@link com.liferay.portal.kernel.util.UnicodeProperties
173             *         #fastLoad(String)}.
174             * @param  hidden whether the layout is hidden
175             * @param  friendlyURLMap the layout's locales and localized friendly URLs.
176             *         To see how the URL is normalized when accessed, see {@link
177             *         com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
178             *         String)}.
179             * @param  serviceContext the service context to be applied. Must set the
180             *         UUID for the layout. Can set the creation date, modification
181             *         date, and expando bridge attributes for the layout. For layouts
182             *         that belong to a layout set prototype, an attribute named
183             *         <code>layoutUpdateable</code> can be used to specify whether site
184             *         administrators can modify this page within their site.
185             * @return the layout
186             * @throws PortalException if a group with the primary key could not be
187             *         found, if the group did not have permission to manage the layouts
188             *         involved, if layout values were invalid, or if a portal exception
189             *         occurred
190             * @throws SystemException if a system exception occurred
191             */
192            @Override
193            public Layout addLayout(
194                            long groupId, boolean privateLayout, long parentLayoutId,
195                            Map<Locale, String> localeNamesMap,
196                            Map<Locale, String> localeTitlesMap,
197                            Map<Locale, String> descriptionMap, Map<Locale, String> keywordsMap,
198                            Map<Locale, String> robotsMap, String type, String typeSettings,
199                            boolean hidden, Map<Locale, String> friendlyURLMap,
200                            ServiceContext serviceContext)
201                    throws PortalException, SystemException {
202    
203                    PermissionChecker permissionChecker = getPermissionChecker();
204    
205                    if (parentLayoutId == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
206                            GroupPermissionUtil.check(
207                                    permissionChecker, groupId, ActionKeys.ADD_LAYOUT);
208                    }
209                    else {
210                            LayoutPermissionUtil.check(
211                                    permissionChecker, groupId, privateLayout, parentLayoutId,
212                                    ActionKeys.ADD_LAYOUT);
213                    }
214    
215                    return layoutLocalService.addLayout(
216                            getUserId(), groupId, privateLayout, parentLayoutId, localeNamesMap,
217                            localeTitlesMap, descriptionMap, keywordsMap, robotsMap, type,
218                            typeSettings, hidden, friendlyURLMap, serviceContext);
219            }
220    
221            /**
222             * Adds a layout with single entry maps for name, title, and description to
223             * the default locale.
224             *
225             * <p>
226             * This method handles the creation of the layout including its resources,
227             * metadata, and internal data structures. It is not necessary to make
228             * subsequent calls to any methods to setup default groups, resources, ...
229             * etc.
230             * </p>
231             *
232             * @param  groupId the primary key of the group
233             * @param  privateLayout whether the layout is private to the group
234             * @param  parentLayoutId the primary key of the parent layout (optionally
235             *         {@link
236             *         com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID})
237             * @param  name Map the layout's locales and localized names
238             * @param  title Map the layout's locales and localized titles
239             * @param  description Map the layout's locales and localized descriptions
240             * @param  type the layout's type (optionally {@link
241             *         com.liferay.portal.model.LayoutConstants#TYPE_PORTLET}). The
242             *         possible types can be found in {@link
243             *         com.liferay.portal.model.LayoutConstants}.
244             * @param  hidden whether the layout is hidden
245             * @param  friendlyURL the layout's locales and localized friendly URLs. To
246             *         see how the URL is normalized when accessed, see {@link
247             *         com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
248             *         String)}.
249             * @param  serviceContext the service context to be applied. Must set the
250             *         UUID for the layout. Can specify the creation date, modification
251             *         date, and expando bridge attributes for the layout. For layouts
252             *         that belong to a layout set prototype, an attribute named
253             *         <code>layoutUpdateable</code> can be used to specify whether site
254             *         administrators can modify this page within their site.
255             * @return the layout
256             * @throws PortalException if a group with the primary key could not be
257             *         found, if the group did not have permission to manage the layouts
258             *         involved, if layout values were invalid, or if a portal exception
259             *         occurred
260             * @throws SystemException if a system exception occurred
261             */
262            @Override
263            public Layout addLayout(
264                            long groupId, boolean privateLayout, long parentLayoutId,
265                            String name, String title, String description, String type,
266                            boolean hidden, String friendlyURL, ServiceContext serviceContext)
267                    throws PortalException, SystemException {
268    
269                    PermissionChecker permissionChecker = getPermissionChecker();
270    
271                    if (parentLayoutId == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
272                            GroupPermissionUtil.check(
273                                    permissionChecker, groupId, ActionKeys.ADD_LAYOUT);
274                    }
275                    else {
276                            LayoutPermissionUtil.check(
277                                    permissionChecker, groupId, privateLayout, parentLayoutId,
278                                    ActionKeys.ADD_LAYOUT);
279                    }
280    
281                    return layoutLocalService.addLayout(
282                            getUserId(), groupId, privateLayout, parentLayoutId, name, title,
283                            description, type, hidden, friendlyURL, serviceContext);
284            }
285    
286            @Override
287            public FileEntry addTempFileEntry(
288                            long groupId, String fileName, String tempFolderName,
289                            InputStream inputStream, String mimeType)
290                    throws PortalException, SystemException {
291    
292                    GroupPermissionUtil.check(
293                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
294    
295                    return TempFileUtil.addTempFile(
296                            groupId, getUserId(), fileName, tempFolderName, inputStream,
297                            mimeType);
298            }
299    
300            /**
301             * Deletes the layout with the primary key, also deleting the layout's child
302             * layouts, and associated resources.
303             *
304             * @param  groupId the primary key of the group
305             * @param  privateLayout whether the layout is private to the group
306             * @param  layoutId the primary key of the layout
307             * @param  serviceContext the service context to be applied
308             * @throws PortalException if the user did not have permission to delete the
309             *         layout, if a matching layout could not be found , or if some
310             *         other portal exception occurred
311             * @throws SystemException if a system exception occurred
312             */
313            @Override
314            public void deleteLayout(
315                            long groupId, boolean privateLayout, long layoutId,
316                            ServiceContext serviceContext)
317                    throws PortalException, SystemException {
318    
319                    LayoutPermissionUtil.check(
320                            getPermissionChecker(), groupId, privateLayout, layoutId,
321                            ActionKeys.DELETE);
322    
323                    layoutLocalService.deleteLayout(
324                            groupId, privateLayout, layoutId, serviceContext);
325            }
326    
327            /**
328             * Deletes the layout with the plid, also deleting the layout's child
329             * layouts, and associated resources.
330             *
331             * @param  plid the primary key of the layout
332             * @param  serviceContext the service context to be applied
333             * @throws PortalException if the user did not have permission to delete the
334             *         layout, if a layout with the primary key could not be found , or
335             *         if some other portal exception occurred
336             * @throws SystemException if a system exception occurred
337             */
338            @Override
339            public void deleteLayout(long plid, ServiceContext serviceContext)
340                    throws PortalException, SystemException {
341    
342                    LayoutPermissionUtil.check(
343                            getPermissionChecker(), plid, ActionKeys.DELETE);
344    
345                    layoutLocalService.deleteLayout(plid, serviceContext);
346            }
347    
348            @Override
349            public void deleteTempFileEntry(
350                            long groupId, String fileName, String tempFolderName)
351                    throws PortalException, SystemException {
352    
353                    GroupPermissionUtil.check(
354                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
355    
356                    TempFileUtil.deleteTempFile(
357                            groupId, getUserId(), fileName, tempFolderName);
358            }
359    
360            /**
361             * Exports the layouts that match the primary keys and the criteria as a
362             * byte array.
363             *
364             * @param  groupId the primary key of the group
365             * @param  privateLayout whether the layout is private to the group
366             * @param  layoutIds the primary keys of the layouts to be exported
367             * @param  parameterMap the mapping of parameters indicating which
368             *         information to export. For information on the keys used in the
369             *         map see {@link
370             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
371             * @param  startDate the export's start date
372             * @param  endDate the export's end date
373             * @return the layouts as a byte array
374             * @throws PortalException if a group or any layout with the primary key
375             *         could not be found, if the group did not have permission to
376             *         manage the layouts, or if some other portal exception occurred
377             * @throws SystemException if a system exception occurred
378             */
379            @Override
380            public byte[] exportLayouts(
381                            long groupId, boolean privateLayout, long[] layoutIds,
382                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
383                    throws PortalException, SystemException {
384    
385                    GroupPermissionUtil.check(
386                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
387    
388                    return layoutLocalService.exportLayouts(
389                            groupId, privateLayout, layoutIds, parameterMap, startDate,
390                            endDate);
391            }
392    
393            /**
394             * Exports all layouts that match the criteria as a byte array.
395             *
396             * @param  groupId the primary key of the group
397             * @param  privateLayout whether the layout is private to the group
398             * @param  parameterMap the mapping of parameters indicating which
399             *         information to export. For information on the keys used in the
400             *         map see {@link
401             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
402             * @param  startDate the export's start date
403             * @param  endDate the export's end date
404             * @return the layout as a byte array
405             * @throws PortalException if a group with the primary key could not be
406             *         found, if the group did not have permission to manage the
407             *         layouts, or if some other portal exception occurred
408             * @throws SystemException if a system exception occurred
409             */
410            @Override
411            public byte[] exportLayouts(
412                            long groupId, boolean privateLayout,
413                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
414                    throws PortalException, SystemException {
415    
416                    GroupPermissionUtil.check(
417                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
418    
419                    return layoutLocalService.exportLayouts(
420                            groupId, privateLayout, parameterMap, startDate, endDate);
421            }
422    
423            /**
424             * Exports all layouts that match the primary keys and criteria as a file.
425             *
426             * @param  groupId the primary key of the group
427             * @param  privateLayout whether the layout is private to the group
428             * @param  layoutIds the primary keys of the layouts to be exported
429             *         (optionally <code>null</code>)
430             * @param  parameterMap the mapping of parameters indicating which
431             *         information to export. For information on the keys used in the
432             *         map see {@link
433             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
434             * @param  startDate the export's start date
435             * @param  endDate the export's end date
436             * @return the layouts as a File
437             * @throws PortalException if a group or any layout with the primary key
438             *         could not be found, it the group did not have permission to
439             *         manage the layouts, or if some other portal exception occurred
440             * @throws SystemException if a system exception occurred
441             */
442            @Override
443            public File exportLayoutsAsFile(
444                            long groupId, boolean privateLayout, long[] layoutIds,
445                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
446                    throws PortalException, SystemException {
447    
448                    GroupPermissionUtil.check(
449                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
450    
451                    return layoutLocalService.exportLayoutsAsFile(
452                            groupId, privateLayout, layoutIds, parameterMap, startDate,
453                            endDate);
454            }
455    
456            @Override
457            public long exportLayoutsAsFileInBackground(
458                            String taskName, long groupId, boolean privateLayout,
459                            long[] layoutIds, Map<String, String[]> parameterMap,
460                            Date startDate, Date endDate, String fileName)
461                    throws PortalException, SystemException {
462    
463                    GroupPermissionUtil.check(
464                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
465    
466                    return layoutLocalService.exportLayoutsAsFileInBackground(
467                            getUserId(), taskName, groupId, privateLayout, layoutIds,
468                            parameterMap, startDate, endDate, fileName);
469            }
470    
471            /**
472             * Exports the portlet information (categories, permissions, ... etc.) as a
473             * byte array.
474             *
475             * @param  plid the primary key of the layout
476             * @param  groupId the primary key of the group
477             * @param  portletId the primary key of the portlet
478             * @param  parameterMap the mapping of parameters indicating which
479             *         information to export. For information on the keys used in the
480             *         map see {@link
481             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
482             * @param  startDate the export's start date
483             * @param  endDate the export's end date
484             * @return the portlet information as a byte array
485             * @throws PortalException if a layout, group, or portlet with the primary
486             *         key could not be found, if the group did not have permission to
487             *         manage the layouts involved, or if some other portal exception
488             *         occurred
489             * @throws SystemException if a system exception occurred
490             */
491            @Override
492            public byte[] exportPortletInfo(
493                            long plid, long groupId, String portletId,
494                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
495                    throws PortalException, SystemException {
496    
497                    Layout layout = layoutLocalService.getLayout(plid);
498    
499                    GroupPermissionUtil.check(
500                            getPermissionChecker(), layout.getGroupId(),
501                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
502    
503                    return layoutLocalService.exportPortletInfo(
504                            plid, groupId, portletId, parameterMap, startDate, endDate);
505            }
506    
507            @Override
508            public byte[] exportPortletInfo(
509                            long companyId, String portletId,
510                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
511                    throws PortalException, SystemException {
512    
513                    Group companyGroup = groupLocalService.getCompanyGroup(companyId);
514    
515                    GroupPermissionUtil.check(
516                            getPermissionChecker(), companyGroup.getGroupId(),
517                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
518    
519                    return layoutLocalService.exportPortletInfo(
520                            companyId, portletId, parameterMap, startDate, endDate);
521            }
522    
523            /**
524             * Exports the portlet information (categories, permissions, ... etc.) as a
525             * file.
526             *
527             * @param  plid the primary key of the layout
528             * @param  groupId the primary key of the group
529             * @param  portletId the primary key of the portlet
530             * @param  parameterMap the mapping of parameters indicating which
531             *         information to export. For information on the keys used in the
532             *         map see {@link
533             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
534             * @param  startDate the export's start date
535             * @param  endDate the export's end date
536             * @return the portlet information as a file
537             * @throws PortalException if a layout, group, or portlet with the primary
538             *         key could not be found, it the group did not have permission to
539             *         manage the layouts involved, or if some other portal exception
540             *         occurred
541             * @throws SystemException if a system exception occurred
542             */
543            @Override
544            public File exportPortletInfoAsFile(
545                            long plid, long groupId, String portletId,
546                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
547                    throws PortalException, SystemException {
548    
549                    Layout layout = layoutLocalService.getLayout(plid);
550    
551                    GroupPermissionUtil.check(
552                            getPermissionChecker(), layout.getGroupId(),
553                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
554    
555                    return layoutLocalService.exportPortletInfoAsFile(
556                            plid, groupId, portletId, parameterMap, startDate, endDate);
557            }
558    
559            @Override
560            public File exportPortletInfoAsFile(
561                            String portletId, Map<String, String[]> parameterMap,
562                            Date startDate, Date endDate)
563                    throws PortalException, SystemException {
564    
565                    User user = userPersistence.findByPrimaryKey(getUserId());
566    
567                    Group companyGroup = groupLocalService.getCompanyGroup(
568                            user.getCompanyId());
569    
570                    GroupPermissionUtil.check(
571                            getPermissionChecker(), companyGroup.getGroupId(),
572                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
573    
574                    return layoutLocalService.exportPortletInfoAsFile(
575                            user.getCompanyId(), portletId, parameterMap, startDate, endDate);
576            }
577    
578            @Override
579            public long exportPortletInfoAsFileInBackground(
580                            String taskName, long plid, long groupId, String portletId,
581                            Map<String, String[]> parameterMap, Date startDate, Date endDate,
582                            String fileName)
583                    throws PortalException, SystemException {
584    
585                    Layout layout = layoutLocalService.getLayout(plid);
586    
587                    GroupPermissionUtil.check(
588                            getPermissionChecker(), layout.getGroupId(),
589                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
590    
591                    return layoutLocalService.exportPortletInfoAsFileInBackground(
592                            getUserId(), taskName, plid, groupId, portletId, parameterMap,
593                            startDate, endDate, fileName);
594            }
595    
596            @Override
597            public long exportPortletInfoAsFileInBackground(
598                            String taskName, String portletId,
599                            Map<String, String[]> parameterMap, Date startDate, Date endDate,
600                            String fileName)
601                    throws PortalException, SystemException {
602    
603                    User user = userPersistence.findByPrimaryKey(getUserId());
604    
605                    Group companyGroup = groupLocalService.getCompanyGroup(
606                            user.getCompanyId());
607    
608                    GroupPermissionUtil.check(
609                            getPermissionChecker(), companyGroup.getGroupId(),
610                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
611    
612                    return layoutLocalService.exportPortletInfoAsFileInBackground(
613                            getUserId(), taskName, portletId, parameterMap, startDate, endDate,
614                            fileName);
615            }
616    
617            /**
618             * Returns all the ancestor layouts of the layout.
619             *
620             * @param  plid the primary key of the layout
621             * @return the ancestor layouts of the layout
622             * @throws PortalException if a matching layout could not be found or if a
623             *         portal exception occurred
624             * @throws SystemException if a system exception occurred
625             */
626            @Override
627            public List<Layout> getAncestorLayouts(long plid)
628                    throws PortalException, SystemException {
629    
630                    Layout layout = layoutLocalService.getLayout(plid);
631    
632                    List<Layout> ancestors = layout.getAncestors();
633    
634                    return filterLayouts(ancestors);
635            }
636    
637            /**
638             * Returns the primary key of the default layout for the group.
639             *
640             * @param  groupId the primary key of the group
641             * @param  scopeGroupId the primary key of the scope group. See {@link
642             *         com.liferay.portal.service.ServiceContext#getScopeGroupId()}.
643             * @param  privateLayout whether the layout is private to the group
644             * @param  portletId the primary key of the portlet
645             * @return Returns the primary key of the default layout group; {@link
646             *         com.liferay.portal.model.LayoutConstants#DEFAULT_PLID} otherwise
647             * @throws PortalException if a group, layout, or portlet with the primary
648             *         key could not be found
649             * @throws SystemException if a system exception occurred
650             */
651            @Override
652            public long getDefaultPlid(
653                            long groupId, long scopeGroupId, boolean privateLayout,
654                            String portletId)
655                    throws PortalException, SystemException {
656    
657                    if (groupId <= 0) {
658                            return LayoutConstants.DEFAULT_PLID;
659                    }
660    
661                    PermissionChecker permissionChecker = getPermissionChecker();
662    
663                    String scopeGroupLayoutUuid = null;
664    
665                    Group scopeGroup = groupLocalService.getGroup(scopeGroupId);
666    
667                    if (scopeGroup.isLayout()) {
668                            Layout scopeGroupLayout = layoutLocalService.getLayout(
669                                    scopeGroup.getClassPK());
670    
671                            scopeGroupLayoutUuid = scopeGroupLayout.getUuid();
672                    }
673    
674                    Map<Long, javax.portlet.PortletPreferences> jxPortletPreferencesMap =
675                            PortletPreferencesFactoryUtil.getPortletSetupMap(
676                                    scopeGroup.getCompanyId(), groupId,
677                                    PortletKeys.PREFS_OWNER_ID_DEFAULT,
678                                    PortletKeys.PREFS_OWNER_TYPE_LAYOUT, portletId, privateLayout);
679    
680                    for (Map.Entry<Long, javax.portlet.PortletPreferences> entry :
681                                    jxPortletPreferencesMap.entrySet()) {
682    
683                            long plid = entry.getKey();
684    
685                            Layout layout = null;
686    
687                            try {
688                                    layout = layoutLocalService.getLayout(plid);
689                            }
690                            catch (NoSuchLayoutException nsle) {
691                                    continue;
692                            }
693    
694                            if (!LayoutPermissionUtil.contains(
695                                            permissionChecker, layout, ActionKeys.VIEW)) {
696    
697                                    continue;
698                            }
699    
700                            if (!layout.isTypePortlet()) {
701                                    continue;
702                            }
703    
704                            LayoutTypePortlet layoutTypePortlet =
705                                    (LayoutTypePortlet)layout.getLayoutType();
706    
707                            if (!layoutTypePortlet.hasPortletId(portletId)) {
708                                    continue;
709                            }
710    
711                            javax.portlet.PortletPreferences jxPortletPreferences =
712                                    entry.getValue();
713    
714                            String scopeType = GetterUtil.getString(
715                                    jxPortletPreferences.getValue("lfrScopeType", null));
716    
717                            if (scopeGroup.isLayout()) {
718                                    String scopeLayoutUuid = GetterUtil.getString(
719                                            jxPortletPreferences.getValue("lfrScopeLayoutUuid", null));
720    
721                                    if (Validator.isNotNull(scopeType) &&
722                                            Validator.isNotNull(scopeLayoutUuid) &&
723                                            scopeLayoutUuid.equals(scopeGroupLayoutUuid)) {
724    
725                                            return layout.getPlid();
726                                    }
727                            }
728                            else if (scopeGroup.isCompany()) {
729                                    if (Validator.isNotNull(scopeType) &&
730                                            scopeType.equals("company")) {
731    
732                                            return layout.getPlid();
733                                    }
734                            }
735                            else {
736                                    if (Validator.isNull(scopeType)) {
737                                            return layout.getPlid();
738                                    }
739                            }
740                    }
741    
742                    return LayoutConstants.DEFAULT_PLID;
743            }
744    
745            @Override
746            @ThreadLocalCachable
747            public long getDefaultPlid(
748                            long groupId, long scopeGroupId, String portletId)
749                    throws PortalException, SystemException {
750    
751                    long plid = getDefaultPlid(groupId, scopeGroupId, false, portletId);
752    
753                    if (plid == 0) {
754                            plid = getDefaultPlid(groupId, scopeGroupId, true, portletId);
755                    }
756    
757                    return plid;
758            }
759    
760            /**
761             * Returns the layout matching the UUID, group, and privacy.
762             *
763             * @param  uuid the layout's UUID
764             * @param  groupId the primary key of the group
765             * @param  privateLayout whether the layout is private to the group
766             * @return the matching layout
767             * @throws PortalException if a matching layout could not be found, if the
768             *         user did not have permission to view the layout, or if some other
769             *         portal exception occurred
770             * @throws SystemException if a system exception occurred
771             */
772            @Override
773            public Layout getLayoutByUuidAndGroupId(
774                            String uuid, long groupId, boolean privateLayout)
775                    throws PortalException, SystemException {
776    
777                    Layout layout = layoutLocalService.getLayoutByUuidAndGroupId(
778                            uuid, groupId, privateLayout);
779    
780                    LayoutPermissionUtil.check(
781                            getPermissionChecker(), layout, ActionKeys.VIEW);
782    
783                    return layout;
784            }
785    
786            /**
787             * Returns the name of the layout.
788             *
789             * @param  groupId the primary key of the group
790             * @param  privateLayout whether the layout is private to the group
791             * @param  layoutId the primary key of the layout
792             * @param  languageId the primary key of the language. For more information
793             *         See {@link java.util.Locale}.
794             * @return the layout's name
795             * @throws PortalException if a matching layout could not be found
796             * @throws SystemException if a system exception occurred
797             */
798            @Override
799            public String getLayoutName(
800                            long groupId, boolean privateLayout, long layoutId,
801                            String languageId)
802                    throws PortalException, SystemException {
803    
804                    Layout layout = layoutLocalService.getLayout(
805                            groupId, privateLayout, layoutId);
806    
807                    return layout.getName(languageId);
808            }
809    
810            /**
811             * Returns the layout references for all the layouts that belong to the
812             * company and belong to the portlet that matches the preferences.
813             *
814             * @param  companyId the primary key of the company
815             * @param  portletId the primary key of the portlet
816             * @param  preferencesKey the portlet's preference key
817             * @param  preferencesValue the portlet's preference value
818             * @return the layout references of the matching layouts
819             * @throws SystemException if a system exception occurred
820             */
821            @Override
822            public LayoutReference[] getLayoutReferences(
823                            long companyId, String portletId, String preferencesKey,
824                            String preferencesValue)
825                    throws SystemException {
826    
827                    return layoutLocalService.getLayouts(
828                            companyId, portletId, preferencesKey, preferencesValue);
829            }
830    
831            @Override
832            public List<Layout> getLayouts(long groupId, boolean privateLayout)
833                    throws SystemException {
834    
835                    return layoutPersistence.filterFindByG_P(groupId, privateLayout);
836            }
837    
838            @Override
839            public List<Layout> getLayouts(
840                            long groupId, boolean privateLayout, long parentLayoutId)
841                    throws SystemException {
842    
843                    return layoutPersistence.filterFindByG_P_P(
844                            groupId, privateLayout, parentLayoutId);
845            }
846    
847            @Override
848            public List<Layout> getLayouts(
849                            long groupId, boolean privateLayout, long parentLayoutId,
850                            boolean incomplete, int start, int end)
851                    throws PortalException, SystemException {
852    
853                    List<Layout> layouts = layoutLocalService.getLayouts(
854                            groupId, privateLayout, parentLayoutId, incomplete, start, end);
855    
856                    return filterLayouts(layouts);
857            }
858    
859            @Override
860            public String[] getTempFileEntryNames(long groupId, String tempFolderName)
861                    throws PortalException, SystemException {
862    
863                    GroupPermissionUtil.check(
864                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
865    
866                    return TempFileUtil.getTempFileEntryNames(
867                            groupId, getUserId(), tempFolderName);
868            }
869    
870            /**
871             * Imports the layouts from the byte array.
872             *
873             * @param  groupId the primary key of the group
874             * @param  privateLayout whether the layout is private to the group
875             * @param  parameterMap the mapping of parameters indicating which
876             *         information will be imported. For information on the keys used in
877             *         the map see {@link
878             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
879             * @param  bytes the byte array with the data
880             * @throws PortalException if a group with the primary key could not be
881             *         found, if the group did not have permission to manage the
882             *         layouts, or if some other portal exception occurred
883             * @throws SystemException if a system exception occurred
884             * @see    com.liferay.portal.lar.LayoutImporter
885             */
886            @Override
887            public void importLayouts(
888                            long groupId, boolean privateLayout,
889                            Map<String, String[]> parameterMap, byte[] bytes)
890                    throws PortalException, SystemException {
891    
892                    GroupPermissionUtil.check(
893                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
894    
895                    layoutLocalService.importLayouts(
896                            getUserId(), groupId, privateLayout, parameterMap, bytes);
897            }
898    
899            /**
900             * Imports the layouts from the file.
901             *
902             * @param  groupId the primary key of the group
903             * @param  privateLayout whether the layout is private to the group
904             * @param  parameterMap the mapping of parameters indicating which
905             *         information will be imported. For information on the keys used in
906             *         the map see {@link
907             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
908             * @param  file the LAR file with the data
909             * @throws PortalException if a group with the primary key could not be
910             *         found, if the group did not have permission to manage the layouts
911             *         and publish, or if some other portal exception occurred
912             * @throws SystemException if a system exception occurred
913             * @see    com.liferay.portal.lar.LayoutImporter
914             */
915            @Override
916            public void importLayouts(
917                            long groupId, boolean privateLayout,
918                            Map<String, String[]> parameterMap, File file)
919                    throws PortalException, SystemException {
920    
921                    GroupPermissionUtil.check(
922                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
923    
924                    layoutLocalService.importLayouts(
925                            getUserId(), groupId, privateLayout, parameterMap, file);
926            }
927    
928            /**
929             * Imports the layouts from the input stream.
930             *
931             * @param  groupId the primary key of the group
932             * @param  privateLayout whether the layout is private to the group
933             * @param  parameterMap the mapping of parameters indicating which
934             *         information will be imported. For information on the keys used in
935             *         the map see {@link
936             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
937             * @param  is the input stream
938             * @throws PortalException if a group with the primary key could not be
939             *         found, if the group did not have permission to manage the
940             *         layouts, or if some other portal exception occurred
941             * @throws SystemException if a system exception occurred
942             * @see    com.liferay.portal.lar.LayoutImporter
943             */
944            @Override
945            public void importLayouts(
946                            long groupId, boolean privateLayout,
947                            Map<String, String[]> parameterMap, InputStream is)
948                    throws PortalException, SystemException {
949    
950                    GroupPermissionUtil.check(
951                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
952    
953                    layoutLocalService.importLayouts(
954                            getUserId(), groupId, privateLayout, parameterMap, is);
955            }
956    
957            @Override
958            public long importLayoutsInBackground(
959                            String taskName, long groupId, boolean privateLayout,
960                            Map<String, String[]> parameterMap, File file)
961                    throws PortalException, SystemException {
962    
963                    GroupPermissionUtil.check(
964                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
965    
966                    return layoutLocalService.importLayoutsInBackground(
967                            getUserId(), taskName, groupId, privateLayout, parameterMap, file);
968            }
969    
970            @Override
971            public long importLayoutsInBackground(
972                            String taskName, long groupId, boolean privateLayout,
973                            Map<String, String[]> parameterMap, InputStream inputStream)
974                    throws PortalException, SystemException {
975    
976                    GroupPermissionUtil.check(
977                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
978    
979                    return layoutLocalService.importLayoutsInBackground(
980                            getUserId(), taskName, groupId, privateLayout, parameterMap,
981                            inputStream);
982            }
983    
984            /**
985             * Imports the portlet information (categories, permissions, ... etc.) from
986             * the file.
987             *
988             * @param  plid the primary key of the layout
989             * @param  groupId the primary key of the group
990             * @param  portletId the primary key of the portlet
991             * @param  parameterMap the mapping of parameters indicating which
992             *         information will be imported. For information on the keys used in
993             *         the map see {@link
994             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
995             * @param  file the LAR file with the data
996             * @throws PortalException if a group, layout, or portlet with the primary
997             *         key could not be found, or if the group did not have permission
998             *         to manage the layouts
999             * @throws SystemException if a system exception occurred
1000             */
1001            @Override
1002            public void importPortletInfo(
1003                            long plid, long groupId, String portletId,
1004                            Map<String, String[]> parameterMap, File file)
1005                    throws PortalException, SystemException {
1006    
1007                    GroupPermissionUtil.check(
1008                            getPermissionChecker(), groupId,
1009                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1010    
1011                    layoutLocalService.importPortletInfo(
1012                            getUserId(), plid, groupId, portletId, parameterMap, file);
1013            }
1014    
1015            /**
1016             * Imports the portlet information (categories, permissions, ... etc.) from
1017             * the input stream.
1018             *
1019             * @param  plid the primary key of the layout
1020             * @param  groupId the primary key of the group
1021             * @param  portletId the primary key of the portlet
1022             * @param  parameterMap the mapping of parameters indicating which
1023             *         information will be imported. For information on the keys used in
1024             *         the map see {@link
1025             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
1026             * @param  is the input stream
1027             * @throws PortalException if a group, portlet, or layout with the primary
1028             *         key could not be found or if the group did not have permission to
1029             *         manage the layouts
1030             * @throws SystemException if a system exception occurred
1031             */
1032            @Override
1033            public void importPortletInfo(
1034                            long plid, long groupId, String portletId,
1035                            Map<String, String[]> parameterMap, InputStream is)
1036                    throws PortalException, SystemException {
1037    
1038                    GroupPermissionUtil.check(
1039                            getPermissionChecker(), groupId,
1040                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1041    
1042                    layoutLocalService.importPortletInfo(
1043                            getUserId(), plid, groupId, portletId, parameterMap, is);
1044            }
1045    
1046            @Override
1047            public void importPortletInfo(
1048                            String portletId, Map<String, String[]> parameterMap, File file)
1049                    throws PortalException, SystemException {
1050    
1051                    User user = userPersistence.findByPrimaryKey(getUserId());
1052    
1053                    Group companyGroup = groupLocalService.getCompanyGroup(
1054                            user.getCompanyId());
1055    
1056                    GroupPermissionUtil.check(
1057                            getPermissionChecker(), companyGroup.getGroupId(),
1058                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1059    
1060                    layoutLocalService.importPortletInfo(
1061                            getUserId(), portletId, parameterMap, file);
1062            }
1063    
1064            @Override
1065            public void importPortletInfo(
1066                            String portletId, Map<String, String[]> parameterMap,
1067                            InputStream is)
1068                    throws PortalException, SystemException {
1069    
1070                    User user = userPersistence.findByPrimaryKey(getUserId());
1071    
1072                    Group companyGroup = groupLocalService.getCompanyGroup(
1073                            user.getCompanyId());
1074    
1075                    GroupPermissionUtil.check(
1076                            getPermissionChecker(), companyGroup.getGroupId(),
1077                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1078    
1079                    layoutLocalService.importPortletInfo(
1080                            getUserId(), portletId, parameterMap, is);
1081            }
1082    
1083            @Override
1084            public long importPortletInfoInBackground(
1085                            String taskName, long plid, long groupId, String portletId,
1086                            Map<String, String[]> parameterMap, File file)
1087                    throws PortalException, SystemException {
1088    
1089                    GroupPermissionUtil.check(
1090                            getPermissionChecker(), groupId,
1091                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1092    
1093                    return layoutLocalService.importPortletInfoInBackground(
1094                            getUserId(), taskName, plid, groupId, portletId, parameterMap,
1095                            file);
1096            }
1097    
1098            @Override
1099            public long importPortletInfoInBackground(
1100                            String taskName, long plid, long groupId, String portletId,
1101                            Map<String, String[]> parameterMap, InputStream is)
1102                    throws PortalException, SystemException {
1103    
1104                    GroupPermissionUtil.check(
1105                            getPermissionChecker(), groupId,
1106                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1107    
1108                    return layoutLocalService.importPortletInfoInBackground(
1109                            getUserId(), taskName, plid, groupId, portletId, parameterMap, is);
1110            }
1111    
1112            @Override
1113            public void importPortletInfoInBackground(
1114                            String taskName, String portletId,
1115                            Map<String, String[]> parameterMap, File file)
1116                    throws PortalException, SystemException {
1117    
1118                    User user = userPersistence.findByPrimaryKey(getUserId());
1119    
1120                    Group companyGroup = groupLocalService.getCompanyGroup(
1121                            user.getCompanyId());
1122    
1123                    GroupPermissionUtil.check(
1124                            getPermissionChecker(), companyGroup.getGroupId(),
1125                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1126    
1127                    layoutLocalService.importPortletInfoInBackground(
1128                            getUserId(), taskName, portletId, parameterMap, file);
1129            }
1130    
1131            @Override
1132            public void importPortletInfoInBackground(
1133                            String taskName, String portletId,
1134                            Map<String, String[]> parameterMap, InputStream is)
1135                    throws PortalException, SystemException {
1136    
1137                    User user = userPersistence.findByPrimaryKey(getUserId());
1138    
1139                    Group companyGroup = groupLocalService.getCompanyGroup(
1140                            user.getCompanyId());
1141    
1142                    GroupPermissionUtil.check(
1143                            getPermissionChecker(), companyGroup.getGroupId(),
1144                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1145    
1146                    layoutLocalService.importPortletInfoInBackground(
1147                            getUserId(), taskName, portletId, parameterMap, is);
1148            }
1149    
1150            /**
1151             * Schedules a range of layouts to be published.
1152             *
1153             * @param  sourceGroupId the primary key of the source group
1154             * @param  targetGroupId the primary key of the target group
1155             * @param  privateLayout whether the layout is private to the group
1156             * @param  layoutIdMap the layouts considered for publishing, specified by
1157             *         the layout IDs and booleans indicating whether they have children
1158             * @param  parameterMap the mapping of parameters indicating which
1159             *         information will be used. See {@link
1160             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}
1161             * @param  scope the scope of the pages. It can be <code>all-pages</code> or
1162             *         <code>selected-pages</code>.
1163             * @param  startDate the start date
1164             * @param  endDate the end date
1165             * @param  groupName the group name (optionally {@link
1166             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
1167             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
1168             * @param  cronText the cron text. See {@link
1169             *         com.liferay.portal.kernel.cal.RecurrenceSerializer #toCronText}
1170             * @param  schedulerStartDate the scheduler start date
1171             * @param  schedulerEndDate the scheduler end date
1172             * @param  description the scheduler description
1173             * @throws PortalException if the group did not have permission to manage
1174             *         and publish
1175             * @throws SystemException if a system exception occurred
1176             */
1177            @Override
1178            public void schedulePublishToLive(
1179                            long sourceGroupId, long targetGroupId, boolean privateLayout,
1180                            Map<Long, Boolean> layoutIdMap, Map<String, String[]> parameterMap,
1181                            String scope, Date startDate, Date endDate, String groupName,
1182                            String cronText, Date schedulerStartDate, Date schedulerEndDate,
1183                            String description)
1184                    throws PortalException, SystemException {
1185    
1186                    GroupPermissionUtil.check(
1187                            getPermissionChecker(), targetGroupId, ActionKeys.PUBLISH_STAGING);
1188    
1189                    String jobName = PortalUUIDUtil.generate();
1190    
1191                    Trigger trigger = new CronTrigger(
1192                            jobName, groupName, schedulerStartDate, schedulerEndDate, cronText);
1193    
1194                    String command = StringPool.BLANK;
1195    
1196                    if (scope.equals("all-pages")) {
1197                            command = LayoutsLocalPublisherRequest.COMMAND_ALL_PAGES;
1198                    }
1199                    else if (scope.equals("selected-pages")) {
1200                            command = LayoutsLocalPublisherRequest.COMMAND_SELECTED_PAGES;
1201                    }
1202    
1203                    LayoutsLocalPublisherRequest publisherRequest =
1204                            new LayoutsLocalPublisherRequest(
1205                                    command, getUserId(), sourceGroupId, targetGroupId,
1206                                    privateLayout, layoutIdMap, parameterMap, startDate, endDate);
1207    
1208                    SchedulerEngineHelperUtil.schedule(
1209                            trigger, StorageType.PERSISTED, description,
1210                            DestinationNames.LAYOUTS_LOCAL_PUBLISHER, publisherRequest, 0);
1211            }
1212    
1213            /**
1214             * Schedules a range of layouts to be stored.
1215             *
1216             * @param  sourceGroupId the primary key of the source group
1217             * @param  privateLayout whether the layout is private to the group
1218             * @param  layoutIdMap the layouts considered for publishing, specified by
1219             *         the layout IDs and booleans indicating whether they have children
1220             * @param  parameterMap the mapping of parameters indicating which
1221             *         information will be used. See {@link
1222             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}
1223             * @param  remoteAddress the remote address
1224             * @param  remotePort the remote port
1225             * @param  remotePathContext the remote path context
1226             * @param  secureConnection whether the connection is secure
1227             * @param  remoteGroupId the primary key of the remote group
1228             * @param  remotePrivateLayout whether remote group's layout is private
1229             * @param  startDate the start date
1230             * @param  endDate the end date
1231             * @param  groupName the group name. Optionally {@link
1232             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
1233             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
1234             * @param  cronText the cron text. See {@link
1235             *         com.liferay.portal.kernel.cal.RecurrenceSerializer #toCronText}
1236             * @param  schedulerStartDate the scheduler start date
1237             * @param  schedulerEndDate the scheduler end date
1238             * @param  description the scheduler description
1239             * @throws PortalException if a group with the source group primary key was
1240             *         not found or if the group did not have permission to publish
1241             * @throws SystemException if a system exception occurred
1242             */
1243            @Override
1244            public void schedulePublishToRemote(
1245                            long sourceGroupId, boolean privateLayout,
1246                            Map<Long, Boolean> layoutIdMap, Map<String, String[]> parameterMap,
1247                            String remoteAddress, int remotePort, String remotePathContext,
1248                            boolean secureConnection, long remoteGroupId,
1249                            boolean remotePrivateLayout, Date startDate, Date endDate,
1250                            String groupName, String cronText, Date schedulerStartDate,
1251                            Date schedulerEndDate, String description)
1252                    throws PortalException, SystemException {
1253    
1254                    GroupPermissionUtil.check(
1255                            getPermissionChecker(), sourceGroupId, ActionKeys.PUBLISH_STAGING);
1256    
1257                    LayoutsRemotePublisherRequest publisherRequest =
1258                            new LayoutsRemotePublisherRequest(
1259                                    getUserId(), sourceGroupId, privateLayout, layoutIdMap,
1260                                    parameterMap, remoteAddress, remotePort, remotePathContext,
1261                                    secureConnection, remoteGroupId, remotePrivateLayout, startDate,
1262                                    endDate);
1263    
1264                    String jobName = PortalUUIDUtil.generate();
1265    
1266                    Trigger trigger = new CronTrigger(
1267                            jobName, groupName, schedulerStartDate, schedulerEndDate, cronText);
1268    
1269                    SchedulerEngineHelperUtil.schedule(
1270                            trigger, StorageType.PERSISTED, description,
1271                            DestinationNames.LAYOUTS_REMOTE_PUBLISHER, publisherRequest, 0);
1272            }
1273    
1274            /**
1275             * Sets the layouts for the group, replacing and prioritizing all layouts of
1276             * the parent layout.
1277             *
1278             * @param  groupId the primary key of the group
1279             * @param  privateLayout whether the layout is private to the group
1280             * @param  parentLayoutId the primary key of the parent layout
1281             * @param  layoutIds the primary keys of the layouts
1282             * @param  serviceContext the service context to be applied
1283             * @throws PortalException if a group or layout with the primary key could
1284             *         not be found, if the group did not have permission to manage the
1285             *         layouts, if no layouts were specified, if the first layout was
1286             *         not page-able, if the first layout was hidden, or if some other
1287             *         portal exception occurred
1288             * @throws SystemException if a system exception occurred
1289             */
1290            @Override
1291            public void setLayouts(
1292                            long groupId, boolean privateLayout, long parentLayoutId,
1293                            long[] layoutIds, ServiceContext serviceContext)
1294                    throws PortalException, SystemException {
1295    
1296                    GroupPermissionUtil.check(
1297                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
1298    
1299                    layoutLocalService.setLayouts(
1300                            groupId, privateLayout, parentLayoutId, layoutIds, serviceContext);
1301            }
1302    
1303            /**
1304             * Deletes the job from the scheduler's queue.
1305             *
1306             * @param  groupId the primary key of the group
1307             * @param  jobName the job name
1308             * @param  groupName the group name (optionally {@link
1309             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
1310             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
1311             * @throws PortalException if the group did not permission to manage staging
1312             *         and publish
1313             * @throws SystemException if a system exception occurred
1314             */
1315            @Override
1316            public void unschedulePublishToLive(
1317                            long groupId, String jobName, String groupName)
1318                    throws PortalException, SystemException {
1319    
1320                    GroupPermissionUtil.check(
1321                            getPermissionChecker(), groupId, ActionKeys.PUBLISH_STAGING);
1322    
1323                    SchedulerEngineHelperUtil.delete(
1324                            jobName, groupName, StorageType.PERSISTED);
1325            }
1326    
1327            /**
1328             * Deletes the job from the scheduler's persistent queue.
1329             *
1330             * @param  groupId the primary key of the group
1331             * @param  jobName the job name
1332             * @param  groupName the group name (optionally {@link
1333             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
1334             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
1335             * @throws PortalException if a group with the primary key could not be
1336             *         found or if the group did not have permission to publish
1337             * @throws SystemException if a system exception occurred
1338             */
1339            @Override
1340            public void unschedulePublishToRemote(
1341                            long groupId, String jobName, String groupName)
1342                    throws PortalException, SystemException {
1343    
1344                    GroupPermissionUtil.check(
1345                            getPermissionChecker(), groupId, ActionKeys.PUBLISH_STAGING);
1346    
1347                    SchedulerEngineHelperUtil.delete(
1348                            jobName, groupName, StorageType.PERSISTED);
1349            }
1350    
1351            /**
1352             * Updates the layout with additional parameters.
1353             *
1354             * @param  groupId the primary key of the group
1355             * @param  privateLayout whether the layout is private to the group
1356             * @param  layoutId the primary key of the layout
1357             * @param  parentLayoutId the primary key of the layout's new parent layout
1358             * @param  localeNamesMap the layout's locales and localized names
1359             * @param  localeTitlesMap the layout's locales and localized titles
1360             * @param  descriptionMap the locales and localized descriptions to merge
1361             *         (optionally <code>null</code>)
1362             * @param  keywordsMap the locales and localized keywords to merge
1363             *         (optionally <code>null</code>)
1364             * @param  robotsMap the locales and localized robots to merge (optionally
1365             *         <code>null</code>)
1366             * @param  type the layout's new type (optionally {@link
1367             *         com.liferay.portal.model.LayoutConstants#TYPE_PORTLET})
1368             * @param  hidden whether the layout is hidden
1369             * @param  friendlyURLMap the layout's locales and localized friendly URLs.
1370             *         To see how the URL is normalized when accessed see {@link
1371             *         com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
1372             *         String)}.
1373             * @param  iconImage whether the icon image will be updated
1374             * @param  iconBytes the byte array of the layout's new icon image
1375             * @param  serviceContext the service context to be applied. Can set the
1376             *         modification date and expando bridge attributes for the layout.
1377             * @return the updated layout
1378             * @throws PortalException if a group or layout with the primary key could
1379             *         not be found, if the user did not have permission to update the
1380             *         layout, if a unique friendly URL could not be generated, if a
1381             *         valid parent layout ID to use could not be found, or if the
1382             *         layout parameters were invalid
1383             * @throws SystemException if a system exception occurred
1384             */
1385            @Override
1386            public Layout updateLayout(
1387                            long groupId, boolean privateLayout, long layoutId,
1388                            long parentLayoutId, Map<Locale, String> localeNamesMap,
1389                            Map<Locale, String> localeTitlesMap,
1390                            Map<Locale, String> descriptionMap, Map<Locale, String> keywordsMap,
1391                            Map<Locale, String> robotsMap, String type, boolean hidden,
1392                            Map<Locale, String> friendlyURLMap, Boolean iconImage,
1393                            byte[] iconBytes, ServiceContext serviceContext)
1394                    throws PortalException, SystemException {
1395    
1396                    LayoutPermissionUtil.check(
1397                            getPermissionChecker(), groupId, privateLayout, layoutId,
1398                            ActionKeys.UPDATE);
1399    
1400                    return layoutLocalService.updateLayout(
1401                            groupId, privateLayout, layoutId, parentLayoutId, localeNamesMap,
1402                            localeTitlesMap, descriptionMap, keywordsMap, robotsMap, type,
1403                            hidden, friendlyURLMap, iconImage, iconBytes, serviceContext);
1404            }
1405    
1406            /**
1407             * Updates the layout with additional parameters.
1408             *
1409             * @param      groupId the primary key of the group
1410             * @param      privateLayout whether the layout is private to the group
1411             * @param      layoutId the primary key of the layout
1412             * @param      parentLayoutId the primary key of the layout's new parent
1413             *             layout
1414             * @param      localeNamesMap the layout's locales and localized names
1415             * @param      localeTitlesMap the layout's locales and localized titles
1416             * @param      descriptionMap the locales and localized descriptions to
1417             *             merge (optionally <code>null</code>)
1418             * @param      keywordsMap the locales and localized keywords to merge
1419             *             (optionally <code>null</code>)
1420             * @param      robotsMap the locales and localized robots to merge
1421             *             (optionally <code>null</code>)
1422             * @param      type the layout's new type (optionally {@link
1423             *             com.liferay.portal.model.LayoutConstants#TYPE_PORTLET})
1424             * @param      hidden whether the layout is hidden
1425             * @param      friendlyURL the layout's locales and new friendly URLs. To
1426             *             see how the URL is normalized when accessed, see {@link
1427             *             com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
1428             *             String)}.
1429             * @param      iconImage whether the icon image will be updated
1430             * @param      iconBytes the byte array of the layout's new icon image
1431             * @param      serviceContext the service context to be applied. Can set the
1432             *             modification date and expando bridge attributes for the
1433             *             layout.
1434             * @return     the updated layout
1435             * @throws     PortalException if a group or layout with the primary key
1436             *             could not be found, if the user did not have permission to
1437             *             update the layout, if a unique friendly URL could not be
1438             *             generated, if a valid parent layout ID to use could not be
1439             *             found, or if the layout parameters were invalid
1440             * @throws     SystemException if a system exception occurred
1441             * @deprecated As of 6.2.0, replaced by {@link #updateLayout(long, boolean,
1442             *             long, long, Map, Map, Map, Map, Map, String, boolean, Map,
1443             *             Boolean, byte[], ServiceContext)}
1444             */
1445            @Override
1446            public Layout updateLayout(
1447                            long groupId, boolean privateLayout, long layoutId,
1448                            long parentLayoutId, Map<Locale, String> localeNamesMap,
1449                            Map<Locale, String> localeTitlesMap,
1450                            Map<Locale, String> descriptionMap, Map<Locale, String> keywordsMap,
1451                            Map<Locale, String> robotsMap, String type, boolean hidden,
1452                            String friendlyURL, Boolean iconImage, byte[] iconBytes,
1453                            ServiceContext serviceContext)
1454                    throws PortalException, SystemException {
1455    
1456                    LayoutPermissionUtil.check(
1457                            getPermissionChecker(), groupId, privateLayout, layoutId,
1458                            ActionKeys.UPDATE);
1459    
1460                    return layoutLocalService.updateLayout(
1461                            groupId, privateLayout, layoutId, parentLayoutId, localeNamesMap,
1462                            localeTitlesMap, descriptionMap, keywordsMap, robotsMap, type,
1463                            hidden, friendlyURL, iconImage, iconBytes, serviceContext);
1464            }
1465    
1466            /**
1467             * Updates the layout replacing its type settings.
1468             *
1469             * @param  groupId the primary key of the group
1470             * @param  privateLayout whether the layout is private to the group
1471             * @param  layoutId the primary key of the layout
1472             * @param  typeSettings the settings to load the unicode properties object.
1473             *         See {@link com.liferay.portal.kernel.util.UnicodeProperties
1474             *         #fastLoad(String)}.
1475             * @return the updated layout
1476             * @throws PortalException if a matching layout could not be found or if the
1477             *         user did not have permission to update the layout
1478             * @throws SystemException if a system exception occurred
1479             */
1480            @Override
1481            public Layout updateLayout(
1482                            long groupId, boolean privateLayout, long layoutId,
1483                            String typeSettings)
1484                    throws PortalException, SystemException {
1485    
1486                    LayoutPermissionUtil.check(
1487                            getPermissionChecker(), groupId, privateLayout, layoutId,
1488                            ActionKeys.UPDATE);
1489    
1490                    return layoutLocalService.updateLayout(
1491                            groupId, privateLayout, layoutId, typeSettings);
1492            }
1493    
1494            /**
1495             * Updates the look and feel of the layout.
1496             *
1497             * @param  groupId the primary key of the group
1498             * @param  privateLayout whether the layout is private to the group
1499             * @param  layoutId the primary key of the layout
1500             * @param  themeId the primary key of the layout's new theme
1501             * @param  colorSchemeId the primary key of the layout's new color scheme
1502             * @param  css the layout's new CSS
1503             * @param  wapTheme whether the theme is for WAP browsers
1504             * @return the updated layout
1505             * @throws PortalException if a matching layout could not be found, or if
1506             *         the user did not have permission to update the layout and
1507             *         permission to apply the theme
1508             * @throws SystemException if a system exception occurred
1509             */
1510            @Override
1511            public Layout updateLookAndFeel(
1512                            long groupId, boolean privateLayout, long layoutId, String themeId,
1513                            String colorSchemeId, String css, boolean wapTheme)
1514                    throws PortalException, SystemException {
1515    
1516                    LayoutPermissionUtil.check(
1517                            getPermissionChecker(), groupId, privateLayout, layoutId,
1518                            ActionKeys.UPDATE);
1519    
1520                    if (Validator.isNotNull(themeId)) {
1521                            pluginSettingLocalService.checkPermission(
1522                                    getUserId(), themeId, Plugin.TYPE_THEME);
1523                    }
1524    
1525                    return layoutLocalService.updateLookAndFeel(
1526                            groupId, privateLayout, layoutId, themeId, colorSchemeId, css,
1527                            wapTheme);
1528            }
1529    
1530            /**
1531             * Updates the name of the layout matching the group, layout ID, and
1532             * privacy.
1533             *
1534             * @param  groupId the primary key of the group
1535             * @param  privateLayout whether the layout is private to the group
1536             * @param  layoutId the primary key of the layout
1537             * @param  name the layout's new name
1538             * @param  languageId the primary key of the language. For more information
1539             *         see {@link java.util.Locale}.
1540             * @return the updated layout
1541             * @throws PortalException if a matching layout could not be found, if the
1542             *         user did not have permission to update the layout, or if the new
1543             *         name was <code>null</code>
1544             * @throws SystemException if a system exception occurred
1545             */
1546            @Override
1547            public Layout updateName(
1548                            long groupId, boolean privateLayout, long layoutId, String name,
1549                            String languageId)
1550                    throws PortalException, SystemException {
1551    
1552                    LayoutPermissionUtil.check(
1553                            getPermissionChecker(), groupId, privateLayout, layoutId,
1554                            ActionKeys.UPDATE);
1555    
1556                    return layoutLocalService.updateName(
1557                            groupId, privateLayout, layoutId, name, languageId);
1558            }
1559    
1560            /**
1561             * Updates the name of the layout matching the primary key.
1562             *
1563             * @param  plid the primary key of the layout
1564             * @param  name the name to be assigned
1565             * @param  languageId the primary key of the language. For more information
1566             *         see {@link java.util.Locale}.
1567             * @return the updated layout
1568             * @throws PortalException if a layout with the primary key could not be
1569             *         found, or if the user did not have permission to update the
1570             *         layout, or if the name was <code>null</code>
1571             * @throws SystemException if a system exception occurred
1572             */
1573            @Override
1574            public Layout updateName(long plid, String name, String languageId)
1575                    throws PortalException, SystemException {
1576    
1577                    LayoutPermissionUtil.check(
1578                            getPermissionChecker(), plid, ActionKeys.UPDATE);
1579    
1580                    return layoutLocalService.updateName(plid, name, languageId);
1581            }
1582    
1583            /**
1584             * Updates the parent layout ID of the layout matching the group, layout ID,
1585             * and privacy.
1586             *
1587             * @param  groupId the primary key of the group
1588             * @param  privateLayout whether the layout is private to the group
1589             * @param  layoutId the primary key of the layout
1590             * @param  parentLayoutId the primary key to be assigned to the parent
1591             *         layout
1592             * @return the matching layout
1593             * @throws PortalException if a valid parent layout ID to use could not be
1594             *         found, if a matching layout could not be found, or if the user
1595             *         did not have permission to update the layout
1596             * @throws SystemException if a system exception occurred
1597             */
1598            @Override
1599            public Layout updateParentLayoutId(
1600                            long groupId, boolean privateLayout, long layoutId,
1601                            long parentLayoutId)
1602                    throws PortalException, SystemException {
1603    
1604                    LayoutPermissionUtil.check(
1605                            getPermissionChecker(), groupId, privateLayout, layoutId,
1606                            ActionKeys.UPDATE);
1607    
1608                    return layoutLocalService.updateParentLayoutId(
1609                            groupId, privateLayout, layoutId, parentLayoutId);
1610            }
1611    
1612            /**
1613             * Updates the parent layout ID of the layout matching the primary key. If a
1614             * layout matching the parent primary key is found, the layout ID of that
1615             * layout is assigned, otherwise {@link
1616             * com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID} is
1617             * assigned.
1618             *
1619             * @param  plid the primary key of the layout
1620             * @param  parentPlid the primary key of the parent layout
1621             * @return the layout matching the primary key
1622             * @throws PortalException if a layout with the primary key could not be
1623             *         found, if the user did not have permission to update the layout,
1624             *         or if a valid parent layout ID to use could not be found
1625             * @throws SystemException if a system exception occurred
1626             */
1627            @Override
1628            public Layout updateParentLayoutId(long plid, long parentPlid)
1629                    throws PortalException, SystemException {
1630    
1631                    LayoutPermissionUtil.check(
1632                            getPermissionChecker(), plid, ActionKeys.UPDATE);
1633    
1634                    return layoutLocalService.updateParentLayoutId(plid, parentPlid);
1635            }
1636    
1637            /**
1638             * Updates the priority of the layout matching the group, layout ID, and
1639             * privacy.
1640             *
1641             * @param  groupId the primary key of the group
1642             * @param  privateLayout whether the layout is private to the group
1643             * @param  layoutId the primary key of the layout
1644             * @param  priority the layout's new priority
1645             * @return the updated layout
1646             * @throws PortalException if a matching layout could not be found or if the
1647             *         user did not have permission to update the layout
1648             * @throws SystemException if a system exception occurred
1649             */
1650            @Override
1651            public Layout updatePriority(
1652                            long groupId, boolean privateLayout, long layoutId, int priority)
1653                    throws PortalException, SystemException {
1654    
1655                    LayoutPermissionUtil.check(
1656                            getPermissionChecker(), groupId, privateLayout, layoutId,
1657                            ActionKeys.UPDATE);
1658    
1659                    return layoutLocalService.updatePriority(
1660                            groupId, privateLayout, layoutId, priority);
1661            }
1662    
1663            /**
1664             * Updates the priority of the layout matching the group, layout ID, and
1665             * privacy, setting the layout's priority based on the priorities of the
1666             * next and previous layouts.
1667             *
1668             * @param  groupId the primary key of the group
1669             * @param  privateLayout whether the layout is private to the group
1670             * @param  layoutId the primary key of the layout
1671             * @param  nextLayoutId the primary key of the next layout
1672             * @param  previousLayoutId the primary key of the previous layout
1673             * @return the updated layout
1674             * @throws PortalException if a matching layout could not be found or if the
1675             *         user did not have permission to update the layout
1676             * @throws SystemException if a system exception occurred
1677             */
1678            @Override
1679            public Layout updatePriority(
1680                            long groupId, boolean privateLayout, long layoutId,
1681                            long nextLayoutId, long previousLayoutId)
1682                    throws PortalException, SystemException {
1683    
1684                    LayoutPermissionUtil.check(
1685                            getPermissionChecker(), groupId, privateLayout, layoutId,
1686                            ActionKeys.UPDATE);
1687    
1688                    return layoutLocalService.updatePriority(
1689                            groupId, privateLayout, layoutId, nextLayoutId, previousLayoutId);
1690            }
1691    
1692            /**
1693             * Updates the priority of the layout matching the primary key.
1694             *
1695             * @param  plid the primary key of the layout
1696             * @param  priority the layout's new priority
1697             * @return the updated layout
1698             * @throws PortalException if a layout with the primary key could not be
1699             *         found
1700             * @throws SystemException if a system exception occurred
1701             */
1702            @Override
1703            public Layout updatePriority(long plid, int priority)
1704                    throws PortalException, SystemException {
1705    
1706                    LayoutPermissionUtil.check(
1707                            getPermissionChecker(), plid, ActionKeys.UPDATE);
1708    
1709                    return layoutLocalService.updatePriority(plid, priority);
1710            }
1711    
1712            @Override
1713            public MissingReferences validateImportLayoutsFile(
1714                            long groupId, boolean privateLayout,
1715                            Map<String, String[]> parameterMap, File file)
1716                    throws PortalException, SystemException {
1717    
1718                    GroupPermissionUtil.check(
1719                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
1720    
1721                    return layoutLocalService.validateImportLayoutsFile(
1722                            getUserId(), groupId, privateLayout, parameterMap, file);
1723            }
1724    
1725            @Override
1726            public MissingReferences validateImportLayoutsFile(
1727                            long groupId, boolean privateLayout,
1728                            Map<String, String[]> parameterMap, InputStream inputStream)
1729                    throws PortalException, SystemException {
1730    
1731                    GroupPermissionUtil.check(
1732                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
1733    
1734                    return layoutLocalService.validateImportLayoutsFile(
1735                            getUserId(), groupId, privateLayout, parameterMap, inputStream);
1736            }
1737    
1738            @Override
1739            public MissingReferences validateImportPortletInfo(
1740                            long plid, long groupId, String portletId,
1741                            Map<String, String[]> parameterMap, File file)
1742                    throws PortalException, SystemException {
1743    
1744                    PortletPermissionUtil.check(
1745                            getPermissionChecker(), plid, portletId, ActionKeys.CONFIGURATION);
1746    
1747                    return layoutLocalService.validateImportPortletInfo(
1748                            getUserId(), plid, groupId, portletId, parameterMap, file);
1749            }
1750    
1751            @Override
1752            public MissingReferences validateImportPortletInfo(
1753                            long plid, long groupId, String portletId,
1754                            Map<String, String[]> parameterMap, InputStream inputStream)
1755                    throws PortalException, SystemException {
1756    
1757                    PortletPermissionUtil.check(
1758                            getPermissionChecker(), plid, portletId, ActionKeys.CONFIGURATION);
1759    
1760                    return layoutLocalService.validateImportPortletInfo(
1761                            getUserId(), plid, groupId, portletId, parameterMap, inputStream);
1762            }
1763    
1764            protected List<Layout> filterLayouts(List<Layout> layouts)
1765                    throws PortalException, SystemException {
1766    
1767                    List<Layout> filteredLayouts = new ArrayList<Layout>();
1768    
1769                    for (Layout layout : layouts) {
1770                            if (LayoutPermissionUtil.contains(
1771                                            getPermissionChecker(), layout.getPlid(),
1772                                            ActionKeys.VIEW)) {
1773    
1774                                    filteredLayouts.add(layout);
1775                            }
1776                    }
1777    
1778                    return filteredLayouts;
1779            }
1780    
1781    }