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