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                    throws PortalException {
884    
885                    List<Layout> layouts = layoutLocalService.getLayouts(
886                            groupId, privateLayout, parentLayoutId, incomplete, start, end);
887    
888                    return filterLayouts(layouts);
889            }
890    
891            @Override
892            public int getLayoutsCount(
893                    long groupId, boolean privateLayout, long parentLayoutId) {
894    
895                    return layoutPersistence.filterCountByG_P_P(
896                            groupId, privateLayout, parentLayoutId);
897            }
898    
899            @Override
900            public String[] getTempFileNames(long groupId, String folderName)
901                    throws PortalException {
902    
903                    GroupPermissionUtil.check(
904                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
905    
906                    return TempFileEntryUtil.getTempFileNames(
907                            groupId, getUserId(), folderName);
908            }
909    
910            /**
911             * Imports the layouts from the byte array.
912             *
913             * @param  groupId the primary key of the group
914             * @param  privateLayout whether the layout is private to the group
915             * @param  parameterMap the mapping of parameters indicating which
916             *         information will be imported. For information on the keys used in
917             *         the map see {@link
918             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
919             * @param  bytes the byte array with the data
920             * @throws PortalException if a group with the primary key could not be
921             *         found, if the group did not have permission to manage the
922             *         layouts, or if some other portal exception occurred
923             * @see    com.liferay.portal.lar.LayoutImporter
924             */
925            @Override
926            public void importLayouts(
927                            long groupId, boolean privateLayout,
928                            Map<String, String[]> parameterMap, byte[] bytes)
929                    throws PortalException {
930    
931                    GroupPermissionUtil.check(
932                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
933    
934                    layoutLocalService.importLayouts(
935                            getUserId(), groupId, privateLayout, parameterMap, bytes);
936            }
937    
938            /**
939             * Imports the layouts from the file.
940             *
941             * @param  groupId the primary key of the group
942             * @param  privateLayout whether the layout is private to the group
943             * @param  parameterMap the mapping of parameters indicating which
944             *         information will be imported. For information on the keys used in
945             *         the map see {@link
946             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
947             * @param  file the LAR file with the data
948             * @throws PortalException if a group with the primary key could not be
949             *         found, if the group did not have permission to manage the layouts
950             *         and publish, or if some other portal exception occurred
951             * @see    com.liferay.portal.lar.LayoutImporter
952             */
953            @Override
954            public void importLayouts(
955                            long groupId, boolean privateLayout,
956                            Map<String, String[]> parameterMap, File file)
957                    throws PortalException {
958    
959                    GroupPermissionUtil.check(
960                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
961    
962                    layoutLocalService.importLayouts(
963                            getUserId(), groupId, privateLayout, parameterMap, file);
964            }
965    
966            /**
967             * Imports the layouts from the input stream.
968             *
969             * @param  groupId the primary key of the group
970             * @param  privateLayout whether the layout is private to the group
971             * @param  parameterMap the mapping of parameters indicating which
972             *         information will be imported. For information on the keys used in
973             *         the map see {@link
974             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
975             * @param  is the input stream
976             * @throws PortalException if a group with the primary key could not be
977             *         found, if the group did not have permission to manage the
978             *         layouts, or if some other portal exception occurred
979             * @see    com.liferay.portal.lar.LayoutImporter
980             */
981            @Override
982            public void importLayouts(
983                            long groupId, boolean privateLayout,
984                            Map<String, String[]> parameterMap, InputStream is)
985                    throws PortalException {
986    
987                    GroupPermissionUtil.check(
988                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
989    
990                    layoutLocalService.importLayouts(
991                            getUserId(), groupId, privateLayout, parameterMap, is);
992            }
993    
994            @Override
995            public long importLayoutsInBackground(
996                            String taskName, long groupId, boolean privateLayout,
997                            Map<String, String[]> parameterMap, File file)
998                    throws PortalException {
999    
1000                    GroupPermissionUtil.check(
1001                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
1002    
1003                    return layoutLocalService.importLayoutsInBackground(
1004                            getUserId(), taskName, groupId, privateLayout, parameterMap, file);
1005            }
1006    
1007            @Override
1008            public long importLayoutsInBackground(
1009                            String taskName, long groupId, boolean privateLayout,
1010                            Map<String, String[]> parameterMap, InputStream inputStream)
1011                    throws PortalException {
1012    
1013                    GroupPermissionUtil.check(
1014                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
1015    
1016                    return layoutLocalService.importLayoutsInBackground(
1017                            getUserId(), taskName, groupId, privateLayout, parameterMap,
1018                            inputStream);
1019            }
1020    
1021            /**
1022             * Imports the portlet information (categories, permissions, ... etc.) from
1023             * the file.
1024             *
1025             * @param  plid the primary key of the layout
1026             * @param  groupId the primary key of the group
1027             * @param  portletId the primary key of the portlet
1028             * @param  parameterMap the mapping of parameters indicating which
1029             *         information will be imported. For information on the keys used in
1030             *         the map see {@link
1031             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
1032             * @param  file the LAR file with the data
1033             * @throws PortalException if a group, layout, or portlet with the primary
1034             *         key could not be found, or if the group did not have permission
1035             *         to manage the layouts
1036             */
1037            @Override
1038            public void importPortletInfo(
1039                            long plid, long groupId, String portletId,
1040                            Map<String, String[]> parameterMap, File file)
1041                    throws PortalException {
1042    
1043                    GroupPermissionUtil.check(
1044                            getPermissionChecker(), groupId,
1045                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1046    
1047                    layoutLocalService.importPortletInfo(
1048                            getUserId(), plid, groupId, portletId, parameterMap, file);
1049            }
1050    
1051            /**
1052             * Imports the portlet information (categories, permissions, ... etc.) from
1053             * the input stream.
1054             *
1055             * @param  plid the primary key of the layout
1056             * @param  groupId the primary key of the group
1057             * @param  portletId the primary key of the portlet
1058             * @param  parameterMap the mapping of parameters indicating which
1059             *         information will be imported. For information on the keys used in
1060             *         the map see {@link
1061             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
1062             * @param  is the input stream
1063             * @throws PortalException if a group, portlet, or layout with the primary
1064             *         key could not be found or if the group did not have permission to
1065             *         manage the layouts
1066             */
1067            @Override
1068            public void importPortletInfo(
1069                            long plid, long groupId, String portletId,
1070                            Map<String, String[]> parameterMap, InputStream is)
1071                    throws PortalException {
1072    
1073                    GroupPermissionUtil.check(
1074                            getPermissionChecker(), groupId,
1075                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1076    
1077                    layoutLocalService.importPortletInfo(
1078                            getUserId(), plid, groupId, portletId, parameterMap, is);
1079            }
1080    
1081            @Override
1082            public void importPortletInfo(
1083                            String portletId, Map<String, String[]> parameterMap, File file)
1084                    throws PortalException {
1085    
1086                    User user = userPersistence.findByPrimaryKey(getUserId());
1087    
1088                    Group companyGroup = groupLocalService.getCompanyGroup(
1089                            user.getCompanyId());
1090    
1091                    GroupPermissionUtil.check(
1092                            getPermissionChecker(), companyGroup,
1093                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1094    
1095                    layoutLocalService.importPortletInfo(
1096                            getUserId(), portletId, parameterMap, file);
1097            }
1098    
1099            @Override
1100            public void importPortletInfo(
1101                            String portletId, Map<String, String[]> parameterMap,
1102                            InputStream is)
1103                    throws PortalException {
1104    
1105                    User user = userPersistence.findByPrimaryKey(getUserId());
1106    
1107                    Group companyGroup = groupLocalService.getCompanyGroup(
1108                            user.getCompanyId());
1109    
1110                    GroupPermissionUtil.check(
1111                            getPermissionChecker(), companyGroup,
1112                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1113    
1114                    layoutLocalService.importPortletInfo(
1115                            getUserId(), portletId, parameterMap, is);
1116            }
1117    
1118            @Override
1119            public long importPortletInfoInBackground(
1120                            String taskName, long plid, long groupId, String portletId,
1121                            Map<String, String[]> parameterMap, File file)
1122                    throws PortalException {
1123    
1124                    GroupPermissionUtil.check(
1125                            getPermissionChecker(), groupId,
1126                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1127    
1128                    return layoutLocalService.importPortletInfoInBackground(
1129                            getUserId(), taskName, plid, groupId, portletId, parameterMap,
1130                            file);
1131            }
1132    
1133            @Override
1134            public long importPortletInfoInBackground(
1135                            String taskName, long plid, long groupId, String portletId,
1136                            Map<String, String[]> parameterMap, InputStream is)
1137                    throws PortalException {
1138    
1139                    GroupPermissionUtil.check(
1140                            getPermissionChecker(), groupId,
1141                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1142    
1143                    return layoutLocalService.importPortletInfoInBackground(
1144                            getUserId(), taskName, plid, groupId, portletId, parameterMap, is);
1145            }
1146    
1147            @Override
1148            public void importPortletInfoInBackground(
1149                            String taskName, String portletId,
1150                            Map<String, String[]> parameterMap, File file)
1151                    throws PortalException {
1152    
1153                    User user = userPersistence.findByPrimaryKey(getUserId());
1154    
1155                    Group companyGroup = groupLocalService.getCompanyGroup(
1156                            user.getCompanyId());
1157    
1158                    GroupPermissionUtil.check(
1159                            getPermissionChecker(), companyGroup,
1160                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1161    
1162                    layoutLocalService.importPortletInfoInBackground(
1163                            getUserId(), taskName, portletId, parameterMap, file);
1164            }
1165    
1166            @Override
1167            public void importPortletInfoInBackground(
1168                            String taskName, String portletId,
1169                            Map<String, String[]> parameterMap, InputStream is)
1170                    throws PortalException {
1171    
1172                    User user = userPersistence.findByPrimaryKey(getUserId());
1173    
1174                    Group companyGroup = groupLocalService.getCompanyGroup(
1175                            user.getCompanyId());
1176    
1177                    GroupPermissionUtil.check(
1178                            getPermissionChecker(), companyGroup,
1179                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1180    
1181                    layoutLocalService.importPortletInfoInBackground(
1182                            getUserId(), taskName, portletId, parameterMap, is);
1183            }
1184    
1185            /**
1186             * Schedules a range of layouts to be published.
1187             *
1188             * @param  sourceGroupId the primary key of the source group
1189             * @param  targetGroupId the primary key of the target group
1190             * @param  privateLayout whether the layout is private to the group
1191             * @param  layoutIds the layouts considered for publishing, specified by the
1192             *         layout IDs
1193             * @param  parameterMap the mapping of parameters indicating which
1194             *         information will be used. See {@link
1195             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}
1196             * @param  scope the scope of the pages. It can be <code>all-pages</code> or
1197             *         <code>selected-pages</code>.
1198             * @param  startDate the start date
1199             * @param  endDate the end date
1200             * @param  groupName the group name (optionally {@link
1201             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
1202             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
1203             * @param  cronText the cron text. See {@link
1204             *         com.liferay.portal.kernel.cal.RecurrenceSerializer #toCronText}
1205             * @param  schedulerStartDate the scheduler start date
1206             * @param  schedulerEndDate the scheduler end date
1207             * @param  description the scheduler description
1208             * @throws PortalException if the group did not have permission to manage
1209             *         and publish
1210             */
1211            @Override
1212            public void schedulePublishToLive(
1213                            long sourceGroupId, long targetGroupId, boolean privateLayout,
1214                            long[] layoutIds, Map<String, String[]> parameterMap, String scope,
1215                            Date startDate, Date endDate, String groupName, String cronText,
1216                            Date schedulerStartDate, Date schedulerEndDate, String description)
1217                    throws PortalException {
1218    
1219                    GroupPermissionUtil.check(
1220                            getPermissionChecker(), targetGroupId, ActionKeys.PUBLISH_STAGING);
1221    
1222                    Trigger trigger = new CronTrigger(
1223                            PortalUUIDUtil.generate(), groupName, schedulerStartDate,
1224                            schedulerEndDate, cronText);
1225    
1226                    User user = userPersistence.findByPrimaryKey(getUserId());
1227    
1228                    Map<String, Serializable> settingsMap =
1229                            ExportImportConfigurationSettingsMapFactory.buildSettingsMap(
1230                                    getUserId(), sourceGroupId, targetGroupId, privateLayout,
1231                                    layoutIds, parameterMap, startDate, endDate, user.getLocale(),
1232                                    user.getTimeZone());
1233    
1234                    ExportImportConfiguration exportImportConfiguration =
1235                            exportImportConfigurationLocalService.addExportImportConfiguration(
1236                                    getUserId(), sourceGroupId, trigger.getJobName(), description,
1237                                    ExportImportConfigurationConstants.
1238                                            TYPE_SCHEDULED_PUBLISH_LAYOUT_LOCAL,
1239                                    settingsMap, WorkflowConstants.STATUS_DRAFT,
1240                                    new ServiceContext());
1241    
1242                    SchedulerEngineHelperUtil.schedule(
1243                            trigger, StorageType.PERSISTED, description,
1244                            DestinationNames.LAYOUTS_LOCAL_PUBLISHER,
1245                            exportImportConfiguration.getExportImportConfigurationId(), 0);
1246            }
1247    
1248            /**
1249             * Schedules a range of layouts to be published.
1250             *
1251             * @param      sourceGroupId the primary key of the source group
1252             * @param      targetGroupId the primary key of the target group
1253             * @param      privateLayout whether the layout is private to the group
1254             * @param      layoutIdMap the layouts considered for publishing, specified
1255             *             by the layout IDs and booleans indicating whether they have
1256             *             children
1257             * @param      parameterMap the mapping of parameters indicating which
1258             *             information will be used. See {@link
1259             *             com.liferay.portal.kernel.lar.PortletDataHandlerKeys}
1260             * @param      scope the scope of the pages. It can be
1261             *             <code>all-pages</code> or <code>selected-pages</code>.
1262             * @param      startDate the start date
1263             * @param      endDate the end date
1264             * @param      groupName the group name (optionally {@link
1265             *             com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
1266             *             See {@link
1267             *             com.liferay.portal.kernel.messaging.DestinationNames}.
1268             * @param      cronText the cron text. See {@link
1269             *             com.liferay.portal.kernel.cal.RecurrenceSerializer
1270             *             #toCronText}
1271             * @param      schedulerStartDate the scheduler start date
1272             * @param      schedulerEndDate the scheduler end date
1273             * @param      description the scheduler description
1274             * @throws     PortalException if the group did not have permission to
1275             *             manage and publish
1276             * @deprecated As of 7.0.0, replaced by {@link #schedulePublishToLive(long,
1277             *             long, boolean, long[], Map, String, Date, Date, String,
1278             *             String, Date, Date, String)}
1279             */
1280            @Deprecated
1281            @Override
1282            public void schedulePublishToLive(
1283                            long sourceGroupId, long targetGroupId, boolean privateLayout,
1284                            Map<Long, Boolean> layoutIdMap, Map<String, String[]> parameterMap,
1285                            String scope, Date startDate, Date endDate, String groupName,
1286                            String cronText, Date schedulerStartDate, Date schedulerEndDate,
1287                            String description)
1288                    throws PortalException {
1289    
1290                    schedulePublishToLive(
1291                            sourceGroupId, targetGroupId, privateLayout,
1292                            ExportImportHelperUtil.getLayoutIds(layoutIdMap, targetGroupId),
1293                            parameterMap, scope, startDate, endDate, groupName, cronText,
1294                            schedulerStartDate, schedulerEndDate, description);
1295            }
1296    
1297            /**
1298             * Schedules a range of layouts to be stored.
1299             *
1300             * @param  sourceGroupId the primary key of the source group
1301             * @param  privateLayout whether the layout is private to the group
1302             * @param  layoutIdMap the layouts considered for publishing, specified by
1303             *         the layout IDs and booleans indicating whether they have children
1304             * @param  parameterMap the mapping of parameters indicating which
1305             *         information will be used. See {@link
1306             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}
1307             * @param  remoteAddress the remote address
1308             * @param  remotePort the remote port
1309             * @param  remotePathContext the remote path context
1310             * @param  secureConnection whether the connection is secure
1311             * @param  remoteGroupId the primary key of the remote group
1312             * @param  remotePrivateLayout whether remote group's layout is private
1313             * @param  startDate the start date
1314             * @param  endDate the end date
1315             * @param  groupName the group name. Optionally {@link
1316             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
1317             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
1318             * @param  cronText the cron text. See {@link
1319             *         com.liferay.portal.kernel.cal.RecurrenceSerializer #toCronText}
1320             * @param  schedulerStartDate the scheduler start date
1321             * @param  schedulerEndDate the scheduler end date
1322             * @param  description the scheduler description
1323             * @throws PortalException if a group with the source group primary key was
1324             *         not found or if the group did not have permission to publish
1325             */
1326            @Override
1327            public void schedulePublishToRemote(
1328                            long sourceGroupId, boolean privateLayout,
1329                            Map<Long, Boolean> layoutIdMap, Map<String, String[]> parameterMap,
1330                            String remoteAddress, int remotePort, String remotePathContext,
1331                            boolean secureConnection, long remoteGroupId,
1332                            boolean remotePrivateLayout, Date startDate, Date endDate,
1333                            String groupName, String cronText, Date schedulerStartDate,
1334                            Date schedulerEndDate, String description)
1335                    throws PortalException {
1336    
1337                    GroupPermissionUtil.check(
1338                            getPermissionChecker(), sourceGroupId, ActionKeys.PUBLISH_STAGING);
1339    
1340                    Trigger trigger = new CronTrigger(
1341                            PortalUUIDUtil.generate(), groupName, schedulerStartDate,
1342                            schedulerEndDate, cronText);
1343    
1344                    User user = userPersistence.findByPrimaryKey(getUserId());
1345    
1346                    Map<String, Serializable> settingsMap =
1347                            ExportImportConfigurationSettingsMapFactory.buildSettingsMap(
1348                                    getUserId(), sourceGroupId, privateLayout, layoutIdMap,
1349                                    parameterMap, remoteAddress, remotePort, remotePathContext,
1350                                    secureConnection, remoteGroupId, remotePrivateLayout, startDate,
1351                                    endDate, user.getLocale(), user.getTimeZone());
1352    
1353                    ExportImportConfiguration exportImportConfiguration =
1354                            exportImportConfigurationLocalService.addExportImportConfiguration(
1355                                    getUserId(), sourceGroupId, trigger.getJobName(), description,
1356                                    ExportImportConfigurationConstants.
1357                                            TYPE_SCHEDULED_PUBLISH_LAYOUT_REMOTE,
1358                                    settingsMap, WorkflowConstants.STATUS_DRAFT,
1359                                    new ServiceContext());
1360    
1361                    SchedulerEngineHelperUtil.schedule(
1362                            trigger, StorageType.PERSISTED, description,
1363                            DestinationNames.LAYOUTS_REMOTE_PUBLISHER,
1364                            exportImportConfiguration.getExportImportConfigurationId(), 0);
1365            }
1366    
1367            /**
1368             * Sets the layouts for the group, replacing and prioritizing all layouts of
1369             * the parent layout.
1370             *
1371             * @param  groupId the primary key of the group
1372             * @param  privateLayout whether the layout is private to the group
1373             * @param  parentLayoutId the primary key of the parent layout
1374             * @param  layoutIds the primary keys of the layouts
1375             * @param  serviceContext the service context to be applied
1376             * @throws PortalException if a group or layout with the primary key could
1377             *         not be found, if the group did not have permission to manage the
1378             *         layouts, if no layouts were specified, if the first layout was
1379             *         not page-able, if the first layout was hidden, or if some other
1380             *         portal exception occurred
1381             */
1382            @Override
1383            public void setLayouts(
1384                            long groupId, boolean privateLayout, long parentLayoutId,
1385                            long[] layoutIds, ServiceContext serviceContext)
1386                    throws PortalException {
1387    
1388                    GroupPermissionUtil.check(
1389                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
1390    
1391                    layoutLocalService.setLayouts(
1392                            groupId, privateLayout, parentLayoutId, layoutIds, serviceContext);
1393            }
1394    
1395            /**
1396             * Deletes the job from the scheduler's queue.
1397             *
1398             * @param  groupId the primary key of the group
1399             * @param  jobName the job name
1400             * @param  groupName the group name (optionally {@link
1401             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
1402             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
1403             * @throws PortalException if the group did not permission to manage staging
1404             *         and publish
1405             */
1406            @Override
1407            public void unschedulePublishToLive(
1408                            long groupId, String jobName, String groupName)
1409                    throws PortalException {
1410    
1411                    GroupPermissionUtil.check(
1412                            getPermissionChecker(), groupId, ActionKeys.PUBLISH_STAGING);
1413    
1414                    SchedulerEngineHelperUtil.delete(
1415                            jobName, groupName, StorageType.PERSISTED);
1416            }
1417    
1418            /**
1419             * Deletes the job from the scheduler's persistent queue.
1420             *
1421             * @param  groupId the primary key of the group
1422             * @param  jobName the job name
1423             * @param  groupName the group name (optionally {@link
1424             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
1425             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
1426             * @throws PortalException if a group with the primary key could not be
1427             *         found or if the group did not have permission to publish
1428             */
1429            @Override
1430            public void unschedulePublishToRemote(
1431                            long groupId, String jobName, String groupName)
1432                    throws PortalException {
1433    
1434                    GroupPermissionUtil.check(
1435                            getPermissionChecker(), groupId, ActionKeys.PUBLISH_STAGING);
1436    
1437                    SchedulerEngineHelperUtil.delete(
1438                            jobName, groupName, StorageType.PERSISTED);
1439            }
1440    
1441            @Override
1442            public Layout updateIconImage(long plid, byte[] bytes)
1443                    throws PortalException {
1444    
1445                    LayoutPermissionUtil.check(
1446                            getPermissionChecker(), plid, ActionKeys.UPDATE);
1447    
1448                    return layoutLocalService.updateIconImage(plid, bytes);
1449            }
1450    
1451            /**
1452             * Updates the layout with additional parameters.
1453             *
1454             * @param  groupId the primary key of the group
1455             * @param  privateLayout whether the layout is private to the group
1456             * @param  layoutId the primary key of the layout
1457             * @param  parentLayoutId the primary key of the layout's new parent layout
1458             * @param  localeNamesMap the layout's locales and localized names
1459             * @param  localeTitlesMap the layout's locales and localized titles
1460             * @param  descriptionMap the locales and localized descriptions to merge
1461             *         (optionally <code>null</code>)
1462             * @param  keywordsMap the locales and localized keywords to merge
1463             *         (optionally <code>null</code>)
1464             * @param  robotsMap the locales and localized robots to merge (optionally
1465             *         <code>null</code>)
1466             * @param  type the layout's new type (optionally {@link
1467             *         com.liferay.portal.model.LayoutConstants#TYPE_PORTLET})
1468             * @param  hidden whether the layout is hidden
1469             * @param  friendlyURLMap the layout's locales and localized friendly URLs.
1470             *         To see how the URL is normalized when accessed see {@link
1471             *         com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
1472             *         String)}.
1473             * @param  iconImage whether the icon image will be updated
1474             * @param  iconBytes the byte array of the layout's new icon image
1475             * @param  serviceContext the service context to be applied. Can set the
1476             *         modification date and expando bridge attributes for the layout.
1477             * @return the updated layout
1478             * @throws PortalException if a group or layout with the primary key could
1479             *         not be found, if the user did not have permission to update the
1480             *         layout, if a unique friendly URL could not be generated, if a
1481             *         valid parent layout ID to use could not be found, or if the
1482             *         layout parameters were invalid
1483             */
1484            @Override
1485            public Layout updateLayout(
1486                            long groupId, boolean privateLayout, long layoutId,
1487                            long parentLayoutId, Map<Locale, String> localeNamesMap,
1488                            Map<Locale, String> localeTitlesMap,
1489                            Map<Locale, String> descriptionMap, Map<Locale, String> keywordsMap,
1490                            Map<Locale, String> robotsMap, String type, boolean hidden,
1491                            Map<Locale, String> friendlyURLMap, boolean iconImage,
1492                            byte[] iconBytes, ServiceContext serviceContext)
1493                    throws PortalException {
1494    
1495                    LayoutPermissionUtil.check(
1496                            getPermissionChecker(), groupId, privateLayout, layoutId,
1497                            ActionKeys.UPDATE);
1498    
1499                    return layoutLocalService.updateLayout(
1500                            groupId, privateLayout, layoutId, parentLayoutId, localeNamesMap,
1501                            localeTitlesMap, descriptionMap, keywordsMap, robotsMap, type,
1502                            hidden, friendlyURLMap, iconImage, iconBytes, serviceContext);
1503            }
1504    
1505            /**
1506             * Updates the layout with additional parameters.
1507             *
1508             * @param      groupId the primary key of the group
1509             * @param      privateLayout whether the layout is private to the group
1510             * @param      layoutId the primary key of the layout
1511             * @param      parentLayoutId the primary key of the layout's new parent
1512             *             layout
1513             * @param      localeNamesMap the layout's locales and localized names
1514             * @param      localeTitlesMap the layout's locales and localized titles
1515             * @param      descriptionMap the locales and localized descriptions to
1516             *             merge (optionally <code>null</code>)
1517             * @param      keywordsMap the locales and localized keywords to merge
1518             *             (optionally <code>null</code>)
1519             * @param      robotsMap the locales and localized robots to merge
1520             *             (optionally <code>null</code>)
1521             * @param      type the layout's new type (optionally {@link
1522             *             com.liferay.portal.model.LayoutConstants#TYPE_PORTLET})
1523             * @param      hidden whether the layout is hidden
1524             * @param      friendlyURL the layout's locales and new friendly URLs. To
1525             *             see how the URL is normalized when accessed, see {@link
1526             *             com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
1527             *             String)}.
1528             * @param      iconImage whether the icon image will be updated
1529             * @param      iconBytes the byte array of the layout's new icon image
1530             * @param      serviceContext the service context to be applied. Can set the
1531             *             modification date and expando bridge attributes for the
1532             *             layout.
1533             * @return     the updated layout
1534             * @throws     PortalException if a group or layout with the primary key
1535             *             could not be found, if the user did not have permission to
1536             *             update the layout, if a unique friendly URL could not be
1537             *             generated, if a valid parent layout ID to use could not be
1538             *             found, or if the layout parameters were invalid
1539             * @deprecated As of 6.2.0, replaced by {@link #updateLayout(long, boolean,
1540             *             long, long, Map, Map, Map, Map, Map, String, boolean, Map,
1541             *             Boolean, byte[], ServiceContext)}
1542             */
1543            @Deprecated
1544            @Override
1545            public Layout updateLayout(
1546                            long groupId, boolean privateLayout, long layoutId,
1547                            long parentLayoutId, Map<Locale, String> localeNamesMap,
1548                            Map<Locale, String> localeTitlesMap,
1549                            Map<Locale, String> descriptionMap, Map<Locale, String> keywordsMap,
1550                            Map<Locale, String> robotsMap, String type, boolean hidden,
1551                            String friendlyURL, Boolean iconImage, byte[] iconBytes,
1552                            ServiceContext serviceContext)
1553                    throws PortalException {
1554    
1555                    LayoutPermissionUtil.check(
1556                            getPermissionChecker(), groupId, privateLayout, layoutId,
1557                            ActionKeys.UPDATE);
1558    
1559                    return layoutLocalService.updateLayout(
1560                            groupId, privateLayout, layoutId, parentLayoutId, localeNamesMap,
1561                            localeTitlesMap, descriptionMap, keywordsMap, robotsMap, type,
1562                            hidden, friendlyURL, iconImage, iconBytes, serviceContext);
1563            }
1564    
1565            /**
1566             * Updates the layout replacing its type settings.
1567             *
1568             * @param  groupId the primary key of the group
1569             * @param  privateLayout whether the layout is private to the group
1570             * @param  layoutId the primary key of the layout
1571             * @param  typeSettings the settings to load the unicode properties object.
1572             *         See {@link com.liferay.portal.kernel.util.UnicodeProperties
1573             *         #fastLoad(String)}.
1574             * @return the updated layout
1575             * @throws PortalException if a matching layout could not be found or if the
1576             *         user did not have permission to update the layout
1577             */
1578            @Override
1579            public Layout updateLayout(
1580                            long groupId, boolean privateLayout, long layoutId,
1581                            String typeSettings)
1582                    throws PortalException {
1583    
1584                    LayoutPermissionUtil.check(
1585                            getPermissionChecker(), groupId, privateLayout, layoutId,
1586                            ActionKeys.UPDATE);
1587    
1588                    return layoutLocalService.updateLayout(
1589                            groupId, privateLayout, layoutId, typeSettings);
1590            }
1591    
1592            /**
1593             * Updates the look and feel of the layout.
1594             *
1595             * @param  groupId the primary key of the group
1596             * @param  privateLayout whether the layout is private to the group
1597             * @param  layoutId the primary key of the layout
1598             * @param  themeId the primary key of the layout's new theme
1599             * @param  colorSchemeId the primary key of the layout's new color scheme
1600             * @param  css the layout's new CSS
1601             * @param  wapTheme whether the theme is for WAP browsers
1602             * @return the updated layout
1603             * @throws PortalException if a matching layout could not be found, or if
1604             *         the user did not have permission to update the layout and
1605             *         permission to apply the theme
1606             */
1607            @Override
1608            public Layout updateLookAndFeel(
1609                            long groupId, boolean privateLayout, long layoutId, String themeId,
1610                            String colorSchemeId, String css, boolean wapTheme)
1611                    throws PortalException {
1612    
1613                    LayoutPermissionUtil.check(
1614                            getPermissionChecker(), groupId, privateLayout, layoutId,
1615                            ActionKeys.UPDATE);
1616    
1617                    if (Validator.isNotNull(themeId)) {
1618                            pluginSettingLocalService.checkPermission(
1619                                    getUserId(), themeId, Plugin.TYPE_THEME);
1620                    }
1621    
1622                    return layoutLocalService.updateLookAndFeel(
1623                            groupId, privateLayout, layoutId, themeId, colorSchemeId, css,
1624                            wapTheme);
1625            }
1626    
1627            /**
1628             * Updates the name of the layout matching the group, layout ID, and
1629             * privacy.
1630             *
1631             * @param  groupId the primary key of the group
1632             * @param  privateLayout whether the layout is private to the group
1633             * @param  layoutId the primary key of the layout
1634             * @param  name the layout's new name
1635             * @param  languageId the primary key of the language. For more information
1636             *         see {@link java.util.Locale}.
1637             * @return the updated layout
1638             * @throws PortalException if a matching layout could not be found, if the
1639             *         user did not have permission to update the layout, or if the new
1640             *         name was <code>null</code>
1641             */
1642            @Override
1643            public Layout updateName(
1644                            long groupId, boolean privateLayout, long layoutId, String name,
1645                            String languageId)
1646                    throws PortalException {
1647    
1648                    LayoutPermissionUtil.check(
1649                            getPermissionChecker(), groupId, privateLayout, layoutId,
1650                            ActionKeys.UPDATE);
1651    
1652                    return layoutLocalService.updateName(
1653                            groupId, privateLayout, layoutId, name, languageId);
1654            }
1655    
1656            /**
1657             * Updates the name of the layout matching the primary key.
1658             *
1659             * @param  plid the primary key of the layout
1660             * @param  name the name to be assigned
1661             * @param  languageId the primary key of the language. For more information
1662             *         see {@link java.util.Locale}.
1663             * @return the updated layout
1664             * @throws PortalException if a layout with the primary key could not be
1665             *         found, or if the user did not have permission to update the
1666             *         layout, or if the name was <code>null</code>
1667             */
1668            @Override
1669            public Layout updateName(long plid, String name, String languageId)
1670                    throws PortalException {
1671    
1672                    LayoutPermissionUtil.check(
1673                            getPermissionChecker(), plid, ActionKeys.UPDATE);
1674    
1675                    return layoutLocalService.updateName(plid, name, languageId);
1676            }
1677    
1678            /**
1679             * Updates the parent layout ID of the layout matching the group, layout ID,
1680             * and privacy.
1681             *
1682             * @param  groupId the primary key of the group
1683             * @param  privateLayout whether the layout is private to the group
1684             * @param  layoutId the primary key of the layout
1685             * @param  parentLayoutId the primary key to be assigned to the parent
1686             *         layout
1687             * @return the matching layout
1688             * @throws PortalException if a valid parent layout ID to use could not be
1689             *         found, if a matching layout could not be found, or if the user
1690             *         did not have permission to update the layout
1691             */
1692            @Override
1693            public Layout updateParentLayoutId(
1694                            long groupId, boolean privateLayout, long layoutId,
1695                            long parentLayoutId)
1696                    throws PortalException {
1697    
1698                    LayoutPermissionUtil.check(
1699                            getPermissionChecker(), groupId, privateLayout, layoutId,
1700                            ActionKeys.UPDATE);
1701    
1702                    return layoutLocalService.updateParentLayoutId(
1703                            groupId, privateLayout, layoutId, parentLayoutId);
1704            }
1705    
1706            /**
1707             * Updates the parent layout ID of the layout matching the primary key. If a
1708             * layout matching the parent primary key is found, the layout ID of that
1709             * layout is assigned, otherwise {@link
1710             * com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID} is
1711             * assigned.
1712             *
1713             * @param  plid the primary key of the layout
1714             * @param  parentPlid the primary key of the parent layout
1715             * @return the layout matching the primary key
1716             * @throws PortalException if a layout with the primary key could not be
1717             *         found, if the user did not have permission to update the layout,
1718             *         or if a valid parent layout ID to use could not be found
1719             */
1720            @Override
1721            public Layout updateParentLayoutId(long plid, long parentPlid)
1722                    throws PortalException {
1723    
1724                    LayoutPermissionUtil.check(
1725                            getPermissionChecker(), plid, ActionKeys.UPDATE);
1726    
1727                    return layoutLocalService.updateParentLayoutId(plid, parentPlid);
1728            }
1729    
1730            /**
1731             * Updates the parent layout ID and priority of the layout.
1732             *
1733             * @param  plid the primary key of the layout
1734             * @param  parentPlid the primary key of the parent layout
1735             * @param  priority the layout's new priority
1736             * @return the layout matching the primary key
1737             * @throws PortalException if a portal exception occurred
1738             */
1739            @Override
1740            public Layout updateParentLayoutIdAndPriority(
1741                            long plid, long parentPlid, int priority)
1742                    throws PortalException {
1743    
1744                    return layoutLocalService.updateParentLayoutIdAndPriority(
1745                            plid, parentPlid, priority);
1746            }
1747    
1748            /**
1749             * Updates the priority of the layout matching the group, layout ID, and
1750             * privacy.
1751             *
1752             * @param  groupId the primary key of the group
1753             * @param  privateLayout whether the layout is private to the group
1754             * @param  layoutId the primary key of the layout
1755             * @param  priority the layout's new priority
1756             * @return the updated layout
1757             * @throws PortalException if a matching layout could not be found or if the
1758             *         user did not have permission to update the layout
1759             */
1760            @Override
1761            public Layout updatePriority(
1762                            long groupId, boolean privateLayout, long layoutId, int priority)
1763                    throws PortalException {
1764    
1765                    LayoutPermissionUtil.check(
1766                            getPermissionChecker(), groupId, privateLayout, layoutId,
1767                            ActionKeys.UPDATE);
1768    
1769                    return layoutLocalService.updatePriority(
1770                            groupId, privateLayout, layoutId, priority);
1771            }
1772    
1773            /**
1774             * Updates the priority of the layout matching the group, layout ID, and
1775             * privacy, setting the layout's priority based on the priorities of the
1776             * next and previous layouts.
1777             *
1778             * @param  groupId the primary key of the group
1779             * @param  privateLayout whether the layout is private to the group
1780             * @param  layoutId the primary key of the layout
1781             * @param  nextLayoutId the primary key of the next layout
1782             * @param  previousLayoutId the primary key of the previous layout
1783             * @return the updated layout
1784             * @throws PortalException if a matching layout could not be found or if the
1785             *         user did not have permission to update the layout
1786             */
1787            @Override
1788            public Layout updatePriority(
1789                            long groupId, boolean privateLayout, long layoutId,
1790                            long nextLayoutId, long previousLayoutId)
1791                    throws PortalException {
1792    
1793                    LayoutPermissionUtil.check(
1794                            getPermissionChecker(), groupId, privateLayout, layoutId,
1795                            ActionKeys.UPDATE);
1796    
1797                    return layoutLocalService.updatePriority(
1798                            groupId, privateLayout, layoutId, nextLayoutId, previousLayoutId);
1799            }
1800    
1801            /**
1802             * Updates the priority of the layout matching the primary key.
1803             *
1804             * @param  plid the primary key of the layout
1805             * @param  priority the layout's new priority
1806             * @return the updated layout
1807             * @throws PortalException if a layout with the primary key could not be
1808             *         found
1809             */
1810            @Override
1811            public Layout updatePriority(long plid, int priority)
1812                    throws PortalException {
1813    
1814                    LayoutPermissionUtil.check(
1815                            getPermissionChecker(), plid, ActionKeys.UPDATE);
1816    
1817                    return layoutLocalService.updatePriority(plid, priority);
1818            }
1819    
1820            @Override
1821            public MissingReferences validateImportLayoutsFile(
1822                            long groupId, boolean privateLayout,
1823                            Map<String, String[]> parameterMap, File file)
1824                    throws PortalException {
1825    
1826                    GroupPermissionUtil.check(
1827                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
1828    
1829                    return layoutLocalService.validateImportLayoutsFile(
1830                            getUserId(), groupId, privateLayout, parameterMap, file);
1831            }
1832    
1833            @Override
1834            public MissingReferences validateImportLayoutsFile(
1835                            long groupId, boolean privateLayout,
1836                            Map<String, String[]> parameterMap, InputStream inputStream)
1837                    throws PortalException {
1838    
1839                    GroupPermissionUtil.check(
1840                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
1841    
1842                    return layoutLocalService.validateImportLayoutsFile(
1843                            getUserId(), groupId, privateLayout, parameterMap, inputStream);
1844            }
1845    
1846            @Override
1847            public MissingReferences validateImportPortletInfo(
1848                            long plid, long groupId, String portletId,
1849                            Map<String, String[]> parameterMap, File file)
1850                    throws PortalException {
1851    
1852                    PortletPermissionUtil.check(
1853                            getPermissionChecker(), plid, portletId, ActionKeys.CONFIGURATION);
1854    
1855                    return layoutLocalService.validateImportPortletInfo(
1856                            getUserId(), plid, groupId, portletId, parameterMap, file);
1857            }
1858    
1859            @Override
1860            public MissingReferences validateImportPortletInfo(
1861                            long plid, long groupId, String portletId,
1862                            Map<String, String[]> parameterMap, InputStream inputStream)
1863                    throws PortalException {
1864    
1865                    PortletPermissionUtil.check(
1866                            getPermissionChecker(), plid, portletId, ActionKeys.CONFIGURATION);
1867    
1868                    return layoutLocalService.validateImportPortletInfo(
1869                            getUserId(), plid, groupId, portletId, parameterMap, inputStream);
1870            }
1871    
1872            protected List<Layout> filterLayouts(List<Layout> layouts)
1873                    throws PortalException {
1874    
1875                    List<Layout> filteredLayouts = new ArrayList<Layout>();
1876    
1877                    for (Layout layout : layouts) {
1878                            if (LayoutPermissionUtil.contains(
1879                                            getPermissionChecker(), layout, ActionKeys.VIEW)) {
1880    
1881                                    filteredLayouts.add(layout);
1882                            }
1883                    }
1884    
1885                    return filteredLayouts;
1886            }
1887    
1888    }