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