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