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