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