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