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            /**
967             * Imports the portlet information (categories, permissions, ... etc.) from
968             * the file.
969             *
970             * @param  plid the primary key of the layout
971             * @param  groupId the primary key of the group
972             * @param  portletId the primary key of the portlet
973             * @param  parameterMap the mapping of parameters indicating which
974             *         information will be imported. For information on the keys used in
975             *         the map see {@link
976             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
977             * @param  file the LAR file with the data
978             * @throws PortalException if a group, layout, or portlet with the primary
979             *         key could not be found, or if the group did not have permission
980             *         to manage the layouts
981             * @throws SystemException if a system exception occurred
982             */
983            @Override
984            public void importPortletInfo(
985                            long plid, long groupId, String portletId,
986                            Map<String, String[]> parameterMap, File file)
987                    throws PortalException, SystemException {
988    
989                    GroupPermissionUtil.check(
990                            getPermissionChecker(), groupId,
991                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
992    
993                    layoutLocalService.importPortletInfo(
994                            getUserId(), plid, groupId, portletId, parameterMap, file);
995            }
996    
997            /**
998             * Imports the portlet information (categories, permissions, ... etc.) from
999             * the input stream.
1000             *
1001             * @param  plid the primary key of the layout
1002             * @param  groupId the primary key of the group
1003             * @param  portletId the primary key of the portlet
1004             * @param  parameterMap the mapping of parameters indicating which
1005             *         information will be imported. For information on the keys used in
1006             *         the map see {@link
1007             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}.
1008             * @param  is the input stream
1009             * @throws PortalException if a group, portlet, or layout with the primary
1010             *         key could not be found or if the group did not have permission to
1011             *         manage the layouts
1012             * @throws SystemException if a system exception occurred
1013             */
1014            @Override
1015            public void importPortletInfo(
1016                            long plid, long groupId, String portletId,
1017                            Map<String, String[]> parameterMap, InputStream is)
1018                    throws PortalException, SystemException {
1019    
1020                    GroupPermissionUtil.check(
1021                            getPermissionChecker(), groupId,
1022                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1023    
1024                    layoutLocalService.importPortletInfo(
1025                            getUserId(), plid, groupId, portletId, parameterMap, is);
1026            }
1027    
1028            @Override
1029            public long importPortletInfoInBackground(
1030                            String taskName, long plid, long groupId, String portletId,
1031                            Map<String, String[]> parameterMap, File file)
1032                    throws PortalException, SystemException {
1033    
1034                    GroupPermissionUtil.check(
1035                            getPermissionChecker(), groupId,
1036                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1037    
1038                    return layoutLocalService.importPortletInfoInBackground(
1039                            getUserId(), taskName, plid, groupId, portletId, parameterMap,
1040                            file);
1041            }
1042    
1043            @Override
1044            public long importPortletInfoInBackground(
1045                            String taskName, long plid, long groupId, String portletId,
1046                            Map<String, String[]> parameterMap, InputStream is)
1047                    throws PortalException, SystemException {
1048    
1049                    GroupPermissionUtil.check(
1050                            getPermissionChecker(), groupId,
1051                            ActionKeys.EXPORT_IMPORT_PORTLET_INFO);
1052    
1053                    return layoutLocalService.importPortletInfoInBackground(
1054                            getUserId(), taskName, plid, groupId, portletId, parameterMap, is);
1055            }
1056    
1057            /**
1058             * Schedules a range of layouts to be published.
1059             *
1060             * @param  sourceGroupId the primary key of the source group
1061             * @param  targetGroupId the primary key of the target group
1062             * @param  privateLayout whether the layout is private to the group
1063             * @param  layoutIdMap the layouts considered for publishing, specified by
1064             *         the layout IDs and booleans indicating whether they have children
1065             * @param  parameterMap the mapping of parameters indicating which
1066             *         information will be used. See {@link
1067             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}
1068             * @param  scope the scope of the pages. It can be <code>all-pages</code> or
1069             *         <code>selected-pages</code>.
1070             * @param  startDate the start date
1071             * @param  endDate the end date
1072             * @param  groupName the group name (optionally {@link
1073             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
1074             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
1075             * @param  cronText the cron text. See {@link
1076             *         com.liferay.portal.kernel.cal.RecurrenceSerializer #toCronText}
1077             * @param  schedulerStartDate the scheduler start date
1078             * @param  schedulerEndDate the scheduler end date
1079             * @param  description the scheduler description
1080             * @throws PortalException if the group did not have permission to manage
1081             *         and publish
1082             * @throws SystemException if a system exception occurred
1083             */
1084            @Override
1085            public void schedulePublishToLive(
1086                            long sourceGroupId, long targetGroupId, boolean privateLayout,
1087                            Map<Long, Boolean> layoutIdMap, Map<String, String[]> parameterMap,
1088                            String scope, Date startDate, Date endDate, String groupName,
1089                            String cronText, Date schedulerStartDate, Date schedulerEndDate,
1090                            String description)
1091                    throws PortalException, SystemException {
1092    
1093                    GroupPermissionUtil.check(
1094                            getPermissionChecker(), targetGroupId, ActionKeys.PUBLISH_STAGING);
1095    
1096                    String jobName = PortalUUIDUtil.generate();
1097    
1098                    Trigger trigger = new CronTrigger(
1099                            jobName, groupName, schedulerStartDate, schedulerEndDate, cronText);
1100    
1101                    String command = StringPool.BLANK;
1102    
1103                    if (scope.equals("all-pages")) {
1104                            command = LayoutsLocalPublisherRequest.COMMAND_ALL_PAGES;
1105                    }
1106                    else if (scope.equals("selected-pages")) {
1107                            command = LayoutsLocalPublisherRequest.COMMAND_SELECTED_PAGES;
1108                    }
1109    
1110                    LayoutsLocalPublisherRequest publisherRequest =
1111                            new LayoutsLocalPublisherRequest(
1112                                    command, getUserId(), sourceGroupId, targetGroupId,
1113                                    privateLayout, layoutIdMap, parameterMap, startDate, endDate);
1114    
1115                    SchedulerEngineHelperUtil.schedule(
1116                            trigger, StorageType.PERSISTED, description,
1117                            DestinationNames.LAYOUTS_LOCAL_PUBLISHER, publisherRequest, 0);
1118            }
1119    
1120            /**
1121             * Schedules a range of layouts to be stored.
1122             *
1123             * @param  sourceGroupId the primary key of the source group
1124             * @param  privateLayout whether the layout is private to the group
1125             * @param  layoutIdMap the layouts considered for publishing, specified by
1126             *         the layout IDs and booleans indicating whether they have children
1127             * @param  parameterMap the mapping of parameters indicating which
1128             *         information will be used. See {@link
1129             *         com.liferay.portal.kernel.lar.PortletDataHandlerKeys}
1130             * @param  remoteAddress the remote address
1131             * @param  remotePort the remote port
1132             * @param  remotePathContext the remote path context
1133             * @param  secureConnection whether the connection is secure
1134             * @param  remoteGroupId the primary key of the remote group
1135             * @param  remotePrivateLayout whether remote group's layout is private
1136             * @param  startDate the start date
1137             * @param  endDate the end date
1138             * @param  groupName the group name. Optionally {@link
1139             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
1140             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
1141             * @param  cronText the cron text. See {@link
1142             *         com.liferay.portal.kernel.cal.RecurrenceSerializer #toCronText}
1143             * @param  schedulerStartDate the scheduler start date
1144             * @param  schedulerEndDate the scheduler end date
1145             * @param  description the scheduler description
1146             * @throws PortalException if a group with the source group primary key was
1147             *         not found or if the group did not have permission to publish
1148             * @throws SystemException if a system exception occurred
1149             */
1150            @Override
1151            public void schedulePublishToRemote(
1152                            long sourceGroupId, boolean privateLayout,
1153                            Map<Long, Boolean> layoutIdMap, Map<String, String[]> parameterMap,
1154                            String remoteAddress, int remotePort, String remotePathContext,
1155                            boolean secureConnection, long remoteGroupId,
1156                            boolean remotePrivateLayout, Date startDate, Date endDate,
1157                            String groupName, String cronText, Date schedulerStartDate,
1158                            Date schedulerEndDate, String description)
1159                    throws PortalException, SystemException {
1160    
1161                    GroupPermissionUtil.check(
1162                            getPermissionChecker(), sourceGroupId, ActionKeys.PUBLISH_STAGING);
1163    
1164                    LayoutsRemotePublisherRequest publisherRequest =
1165                            new LayoutsRemotePublisherRequest(
1166                                    getUserId(), sourceGroupId, privateLayout, layoutIdMap,
1167                                    parameterMap, remoteAddress, remotePort, remotePathContext,
1168                                    secureConnection, remoteGroupId, remotePrivateLayout, startDate,
1169                                    endDate);
1170    
1171                    String jobName = PortalUUIDUtil.generate();
1172    
1173                    Trigger trigger = new CronTrigger(
1174                            jobName, groupName, schedulerStartDate, schedulerEndDate, cronText);
1175    
1176                    SchedulerEngineHelperUtil.schedule(
1177                            trigger, StorageType.PERSISTED, description,
1178                            DestinationNames.LAYOUTS_REMOTE_PUBLISHER, publisherRequest, 0);
1179            }
1180    
1181            /**
1182             * Sets the layouts for the group, replacing and prioritizing all layouts of
1183             * the parent layout.
1184             *
1185             * @param  groupId the primary key of the group
1186             * @param  privateLayout whether the layout is private to the group
1187             * @param  parentLayoutId the primary key of the parent layout
1188             * @param  layoutIds the primary keys of the layouts
1189             * @param  serviceContext the service context to be applied
1190             * @throws PortalException if a group or layout with the primary key could
1191             *         not be found, if the group did not have permission to manage the
1192             *         layouts, if no layouts were specified, if the first layout was
1193             *         not page-able, if the first layout was hidden, or if some other
1194             *         portal exception occurred
1195             * @throws SystemException if a system exception occurred
1196             */
1197            @Override
1198            public void setLayouts(
1199                            long groupId, boolean privateLayout, long parentLayoutId,
1200                            long[] layoutIds, ServiceContext serviceContext)
1201                    throws PortalException, SystemException {
1202    
1203                    GroupPermissionUtil.check(
1204                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
1205    
1206                    layoutLocalService.setLayouts(
1207                            groupId, privateLayout, parentLayoutId, layoutIds, serviceContext);
1208            }
1209    
1210            /**
1211             * Deletes the job from the scheduler's queue.
1212             *
1213             * @param  groupId the primary key of the group
1214             * @param  jobName the job name
1215             * @param  groupName the group name (optionally {@link
1216             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
1217             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
1218             * @throws PortalException if the group did not permission to manage staging
1219             *         and publish
1220             * @throws SystemException if a system exception occurred
1221             */
1222            @Override
1223            public void unschedulePublishToLive(
1224                            long groupId, String jobName, String groupName)
1225                    throws PortalException, SystemException {
1226    
1227                    GroupPermissionUtil.check(
1228                            getPermissionChecker(), groupId, ActionKeys.PUBLISH_STAGING);
1229    
1230                    SchedulerEngineHelperUtil.delete(
1231                            jobName, groupName, StorageType.PERSISTED);
1232            }
1233    
1234            /**
1235             * Deletes the job from the scheduler's persistent queue.
1236             *
1237             * @param  groupId the primary key of the group
1238             * @param  jobName the job name
1239             * @param  groupName the group name (optionally {@link
1240             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
1241             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
1242             * @throws PortalException if a group with the primary key could not be
1243             *         found or if the group did not have permission to publish
1244             * @throws SystemException if a system exception occurred
1245             */
1246            @Override
1247            public void unschedulePublishToRemote(
1248                            long groupId, String jobName, String groupName)
1249                    throws PortalException, SystemException {
1250    
1251                    GroupPermissionUtil.check(
1252                            getPermissionChecker(), groupId, ActionKeys.PUBLISH_STAGING);
1253    
1254                    SchedulerEngineHelperUtil.delete(
1255                            jobName, groupName, StorageType.PERSISTED);
1256            }
1257    
1258            /**
1259             * Updates the layout with additional parameters.
1260             *
1261             * @param  groupId the primary key of the group
1262             * @param  privateLayout whether the layout is private to the group
1263             * @param  layoutId the primary key of the layout
1264             * @param  parentLayoutId the primary key of the layout's new parent layout
1265             * @param  localeNamesMap the layout's locales and localized names
1266             * @param  localeTitlesMap the layout's locales and localized titles
1267             * @param  descriptionMap the locales and localized descriptions to merge
1268             *         (optionally <code>null</code>)
1269             * @param  keywordsMap the locales and localized keywords to merge
1270             *         (optionally <code>null</code>)
1271             * @param  robotsMap the locales and localized robots to merge (optionally
1272             *         <code>null</code>)
1273             * @param  type the layout's new type (optionally {@link
1274             *         com.liferay.portal.model.LayoutConstants#TYPE_PORTLET})
1275             * @param  hidden whether the layout is hidden
1276             * @param  friendlyURLMap the layout's locales and localized friendly URLs.
1277             *         To see how the URL is normalized when accessed see {@link
1278             *         com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
1279             *         String)}.
1280             * @param  iconImage whether the icon image will be updated
1281             * @param  iconBytes the byte array of the layout's new icon image
1282             * @param  serviceContext the service context to be applied. Can set the
1283             *         modification date and expando bridge attributes for the layout.
1284             * @return the updated layout
1285             * @throws PortalException if a group or layout with the primary key could
1286             *         not be found, if the user did not have permission to update the
1287             *         layout, if a unique friendly URL could not be generated, if a
1288             *         valid parent layout ID to use could not be found, or if the
1289             *         layout parameters were invalid
1290             * @throws SystemException if a system exception occurred
1291             */
1292            @Override
1293            public Layout updateLayout(
1294                            long groupId, boolean privateLayout, long layoutId,
1295                            long parentLayoutId, Map<Locale, String> localeNamesMap,
1296                            Map<Locale, String> localeTitlesMap,
1297                            Map<Locale, String> descriptionMap, Map<Locale, String> keywordsMap,
1298                            Map<Locale, String> robotsMap, String type, boolean hidden,
1299                            Map<Locale, String> friendlyURLMap, Boolean iconImage,
1300                            byte[] iconBytes, ServiceContext serviceContext)
1301                    throws PortalException, SystemException {
1302    
1303                    LayoutPermissionUtil.check(
1304                            getPermissionChecker(), groupId, privateLayout, layoutId,
1305                            ActionKeys.UPDATE);
1306    
1307                    return layoutLocalService.updateLayout(
1308                            groupId, privateLayout, layoutId, parentLayoutId, localeNamesMap,
1309                            localeTitlesMap, descriptionMap, keywordsMap, robotsMap, type,
1310                            hidden, friendlyURLMap, iconImage, iconBytes, serviceContext);
1311            }
1312    
1313            /**
1314             * Updates the layout with additional parameters.
1315             *
1316             * @param      groupId the primary key of the group
1317             * @param      privateLayout whether the layout is private to the group
1318             * @param      layoutId the primary key of the layout
1319             * @param      parentLayoutId the primary key of the layout's new parent
1320             *             layout
1321             * @param      localeNamesMap the layout's locales and localized names
1322             * @param      localeTitlesMap the layout's locales and localized titles
1323             * @param      descriptionMap the locales and localized descriptions to
1324             *             merge (optionally <code>null</code>)
1325             * @param      keywordsMap the locales and localized keywords to merge
1326             *             (optionally <code>null</code>)
1327             * @param      robotsMap the locales and localized robots to merge
1328             *             (optionally <code>null</code>)
1329             * @param      type the layout's new type (optionally {@link
1330             *             com.liferay.portal.model.LayoutConstants#TYPE_PORTLET})
1331             * @param      hidden whether the layout is hidden
1332             * @param      friendlyURL the layout's locales and new friendly URLs. To
1333             *             see how the URL is normalized when accessed, see {@link
1334             *             com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
1335             *             String)}.
1336             * @param      iconImage whether the icon image will be updated
1337             * @param      iconBytes the byte array of the layout's new icon image
1338             * @param      serviceContext the service context to be applied. Can set the
1339             *             modification date and expando bridge attributes for the
1340             *             layout.
1341             * @return     the updated layout
1342             * @throws     PortalException if a group or layout with the primary key
1343             *             could not be found, if the user did not have permission to
1344             *             update the layout, if a unique friendly URL could not be
1345             *             generated, if a valid parent layout ID to use could not be
1346             *             found, or if the layout parameters were invalid
1347             * @throws     SystemException if a system exception occurred
1348             * @deprecated As of 6.2.0, replaced by {@link #updateLayout(long, boolean,
1349             *             long, long, Map, Map, Map, Map, Map, String, boolean, Map,
1350             *             Boolean, byte[], ServiceContext)}
1351             */
1352            @Override
1353            public Layout updateLayout(
1354                            long groupId, boolean privateLayout, long layoutId,
1355                            long parentLayoutId, Map<Locale, String> localeNamesMap,
1356                            Map<Locale, String> localeTitlesMap,
1357                            Map<Locale, String> descriptionMap, Map<Locale, String> keywordsMap,
1358                            Map<Locale, String> robotsMap, String type, boolean hidden,
1359                            String friendlyURL, Boolean iconImage, byte[] iconBytes,
1360                            ServiceContext serviceContext)
1361                    throws PortalException, SystemException {
1362    
1363                    LayoutPermissionUtil.check(
1364                            getPermissionChecker(), groupId, privateLayout, layoutId,
1365                            ActionKeys.UPDATE);
1366    
1367                    return layoutLocalService.updateLayout(
1368                            groupId, privateLayout, layoutId, parentLayoutId, localeNamesMap,
1369                            localeTitlesMap, descriptionMap, keywordsMap, robotsMap, type,
1370                            hidden, friendlyURL, iconImage, iconBytes, serviceContext);
1371            }
1372    
1373            /**
1374             * Updates the layout replacing its type settings.
1375             *
1376             * @param  groupId the primary key of the group
1377             * @param  privateLayout whether the layout is private to the group
1378             * @param  layoutId the primary key of the layout
1379             * @param  typeSettings the settings to load the unicode properties object.
1380             *         See {@link com.liferay.portal.kernel.util.UnicodeProperties
1381             *         #fastLoad(String)}.
1382             * @return the updated layout
1383             * @throws PortalException if a matching layout could not be found or if the
1384             *         user did not have permission to update the layout
1385             * @throws SystemException if a system exception occurred
1386             */
1387            @Override
1388            public Layout updateLayout(
1389                            long groupId, boolean privateLayout, long layoutId,
1390                            String typeSettings)
1391                    throws PortalException, SystemException {
1392    
1393                    LayoutPermissionUtil.check(
1394                            getPermissionChecker(), groupId, privateLayout, layoutId,
1395                            ActionKeys.UPDATE);
1396    
1397                    return layoutLocalService.updateLayout(
1398                            groupId, privateLayout, layoutId, typeSettings);
1399            }
1400    
1401            /**
1402             * Updates the look and feel of the layout.
1403             *
1404             * @param  groupId the primary key of the group
1405             * @param  privateLayout whether the layout is private to the group
1406             * @param  layoutId the primary key of the layout
1407             * @param  themeId the primary key of the layout's new theme
1408             * @param  colorSchemeId the primary key of the layout's new color scheme
1409             * @param  css the layout's new CSS
1410             * @param  wapTheme whether the theme is for WAP browsers
1411             * @return the updated layout
1412             * @throws PortalException if a matching layout could not be found, or if
1413             *         the user did not have permission to update the layout and
1414             *         permission to apply the theme
1415             * @throws SystemException if a system exception occurred
1416             */
1417            @Override
1418            public Layout updateLookAndFeel(
1419                            long groupId, boolean privateLayout, long layoutId, String themeId,
1420                            String colorSchemeId, String css, boolean wapTheme)
1421                    throws PortalException, SystemException {
1422    
1423                    LayoutPermissionUtil.check(
1424                            getPermissionChecker(), groupId, privateLayout, layoutId,
1425                            ActionKeys.UPDATE);
1426    
1427                    if (Validator.isNotNull(themeId)) {
1428                            pluginSettingLocalService.checkPermission(
1429                                    getUserId(), themeId, Plugin.TYPE_THEME);
1430                    }
1431    
1432                    return layoutLocalService.updateLookAndFeel(
1433                            groupId, privateLayout, layoutId, themeId, colorSchemeId, css,
1434                            wapTheme);
1435            }
1436    
1437            /**
1438             * Updates the name of the layout matching the group, layout ID, and
1439             * privacy.
1440             *
1441             * @param  groupId the primary key of the group
1442             * @param  privateLayout whether the layout is private to the group
1443             * @param  layoutId the primary key of the layout
1444             * @param  name the layout's new name
1445             * @param  languageId the primary key of the language. For more information
1446             *         see {@link java.util.Locale}.
1447             * @return the updated layout
1448             * @throws PortalException if a matching layout could not be found, if the
1449             *         user did not have permission to update the layout, or if the new
1450             *         name was <code>null</code>
1451             * @throws SystemException if a system exception occurred
1452             */
1453            @Override
1454            public Layout updateName(
1455                            long groupId, boolean privateLayout, long layoutId, String name,
1456                            String languageId)
1457                    throws PortalException, SystemException {
1458    
1459                    LayoutPermissionUtil.check(
1460                            getPermissionChecker(), groupId, privateLayout, layoutId,
1461                            ActionKeys.UPDATE);
1462    
1463                    return layoutLocalService.updateName(
1464                            groupId, privateLayout, layoutId, name, languageId);
1465            }
1466    
1467            /**
1468             * Updates the name of the layout matching the primary key.
1469             *
1470             * @param  plid the primary key of the layout
1471             * @param  name the name to be assigned
1472             * @param  languageId the primary key of the language. For more information
1473             *         see {@link java.util.Locale}.
1474             * @return the updated layout
1475             * @throws PortalException if a layout with the primary key could not be
1476             *         found, or if the user did not have permission to update the
1477             *         layout, or if the name was <code>null</code>
1478             * @throws SystemException if a system exception occurred
1479             */
1480            @Override
1481            public Layout updateName(long plid, String name, String languageId)
1482                    throws PortalException, SystemException {
1483    
1484                    LayoutPermissionUtil.check(
1485                            getPermissionChecker(), plid, ActionKeys.UPDATE);
1486    
1487                    return layoutLocalService.updateName(plid, name, languageId);
1488            }
1489    
1490            /**
1491             * Updates the parent layout ID of the layout matching the group, layout ID,
1492             * and privacy.
1493             *
1494             * @param  groupId the primary key of the group
1495             * @param  privateLayout whether the layout is private to the group
1496             * @param  layoutId the primary key of the layout
1497             * @param  parentLayoutId the primary key to be assigned to the parent
1498             *         layout
1499             * @return the matching layout
1500             * @throws PortalException if a valid parent layout ID to use could not be
1501             *         found, if a matching layout could not be found, or if the user
1502             *         did not have permission to update the layout
1503             * @throws SystemException if a system exception occurred
1504             */
1505            @Override
1506            public Layout updateParentLayoutId(
1507                            long groupId, boolean privateLayout, long layoutId,
1508                            long parentLayoutId)
1509                    throws PortalException, SystemException {
1510    
1511                    LayoutPermissionUtil.check(
1512                            getPermissionChecker(), groupId, privateLayout, layoutId,
1513                            ActionKeys.UPDATE);
1514    
1515                    return layoutLocalService.updateParentLayoutId(
1516                            groupId, privateLayout, layoutId, parentLayoutId);
1517            }
1518    
1519            /**
1520             * Updates the parent layout ID of the layout matching the primary key. If a
1521             * layout matching the parent primary key is found, the layout ID of that
1522             * layout is assigned, otherwise {@link
1523             * com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID} is
1524             * assigned.
1525             *
1526             * @param  plid the primary key of the layout
1527             * @param  parentPlid the primary key of the parent layout
1528             * @return the layout matching the primary key
1529             * @throws PortalException if a layout with the primary key could not be
1530             *         found, if the user did not have permission to update the layout,
1531             *         or if a valid parent layout ID to use could not be found
1532             * @throws SystemException if a system exception occurred
1533             */
1534            @Override
1535            public Layout updateParentLayoutId(long plid, long parentPlid)
1536                    throws PortalException, SystemException {
1537    
1538                    LayoutPermissionUtil.check(
1539                            getPermissionChecker(), plid, ActionKeys.UPDATE);
1540    
1541                    return layoutLocalService.updateParentLayoutId(plid, parentPlid);
1542            }
1543    
1544            /**
1545             * Updates the priority of the layout matching the group, layout ID, and
1546             * privacy.
1547             *
1548             * @param  groupId the primary key of the group
1549             * @param  privateLayout whether the layout is private to the group
1550             * @param  layoutId the primary key of the layout
1551             * @param  priority the layout's new priority
1552             * @return the updated layout
1553             * @throws PortalException if a matching layout could not be found or if the
1554             *         user did not have permission to update the layout
1555             * @throws SystemException if a system exception occurred
1556             */
1557            @Override
1558            public Layout updatePriority(
1559                            long groupId, boolean privateLayout, long layoutId, int priority)
1560                    throws PortalException, SystemException {
1561    
1562                    LayoutPermissionUtil.check(
1563                            getPermissionChecker(), groupId, privateLayout, layoutId,
1564                            ActionKeys.UPDATE);
1565    
1566                    return layoutLocalService.updatePriority(
1567                            groupId, privateLayout, layoutId, priority);
1568            }
1569    
1570            /**
1571             * Updates the priority of the layout matching the primary key.
1572             *
1573             * @param  plid the primary key of the layout
1574             * @param  priority the layout's new priority
1575             * @return the updated layout
1576             * @throws PortalException if a layout with the primary key could not be
1577             *         found
1578             * @throws SystemException if a system exception occurred
1579             */
1580            @Override
1581            public Layout updatePriority(long plid, int priority)
1582                    throws PortalException, SystemException {
1583    
1584                    LayoutPermissionUtil.check(
1585                            getPermissionChecker(), plid, ActionKeys.UPDATE);
1586    
1587                    return layoutLocalService.updatePriority(plid, priority);
1588            }
1589    
1590            @Override
1591            public MissingReferences validateImportLayoutsFile(
1592                            long groupId, boolean privateLayout,
1593                            Map<String, String[]> parameterMap, File file)
1594                    throws PortalException, SystemException {
1595    
1596                    GroupPermissionUtil.check(
1597                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
1598    
1599                    return layoutLocalService.validateImportLayoutsFile(
1600                            getUserId(), groupId, privateLayout, parameterMap, file);
1601            }
1602    
1603            @Override
1604            public MissingReferences validateImportPortletInfo(
1605                            long plid, long groupId, String portletId,
1606                            Map<String, String[]> parameterMap, File file)
1607                    throws PortalException, SystemException {
1608    
1609                    PortletPermissionUtil.check(
1610                            getPermissionChecker(), plid, portletId, ActionKeys.CONFIGURATION);
1611    
1612                    return layoutLocalService.validateImportPortletInfo(
1613                            getUserId(), plid, groupId, portletId, parameterMap, file);
1614            }
1615    
1616            protected List<Layout> filterLayouts(List<Layout> layouts)
1617                    throws PortalException, SystemException {
1618    
1619                    List<Layout> filteredLayouts = new ArrayList<Layout>();
1620    
1621                    for (Layout layout : layouts) {
1622                            if (LayoutPermissionUtil.contains(
1623                                            getPermissionChecker(), layout.getPlid(),
1624                                            ActionKeys.VIEW)) {
1625    
1626                                    filteredLayouts.add(layout);
1627                            }
1628                    }
1629    
1630                    return filteredLayouts;
1631            }
1632    
1633    }