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