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