001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.SchedulerEngineUtil;
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             *         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                    SchedulerEngineUtil.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  secureConnection whether the connection is secure
803             * @param  remoteGroupId the primary key of the remote group
804             * @param  remotePrivateLayout whether remote group's layout is private
805             * @param  startDate the start date
806             * @param  endDate the end date
807             * @param  groupName the group name. Optionally {@link
808             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
809             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
810             * @param  cronText the cron text. See {@link
811             *         com.liferay.portal.kernel.cal.RecurrenceSerializer #toCronText}
812             * @param  schedulerStartDate the scheduler start date
813             * @param  schedulerEndDate the scheduler end date
814             * @param  description the scheduler description
815             * @throws PortalException if a group with the source group primary key was
816             *         not found or if the group did not have permission to publish
817             * @throws SystemException if a system exception occurred
818             */
819            public void schedulePublishToRemote(
820                            long sourceGroupId, boolean privateLayout,
821                            Map<Long, Boolean> layoutIdMap, Map<String, String[]> parameterMap,
822                            String remoteAddress, int remotePort, String remotePathContext,
823                            boolean secureConnection, long remoteGroupId,
824                            boolean remotePrivateLayout, Date startDate, Date endDate,
825                            String groupName, String cronText, Date schedulerStartDate,
826                            Date schedulerEndDate, String description)
827                    throws PortalException, SystemException {
828    
829                    GroupPermissionUtil.check(
830                            getPermissionChecker(), sourceGroupId, ActionKeys.PUBLISH_STAGING);
831    
832                    LayoutsRemotePublisherRequest publisherRequest =
833                            new LayoutsRemotePublisherRequest(
834                                    getUserId(), sourceGroupId, privateLayout, layoutIdMap,
835                                    parameterMap, remoteAddress, remotePort, remotePathContext,
836                                    secureConnection, remoteGroupId, remotePrivateLayout, startDate,
837                                    endDate);
838    
839                    String jobName = PortalUUIDUtil.generate();
840    
841                    Trigger trigger = new CronTrigger(
842                            jobName, groupName, schedulerStartDate, schedulerEndDate, cronText);
843    
844                    SchedulerEngineUtil.schedule(
845                            trigger, StorageType.PERSISTED, description,
846                            DestinationNames.LAYOUTS_REMOTE_PUBLISHER, publisherRequest, 0);
847            }
848    
849            /**
850             * Sets the layouts for the group, replacing and prioritizing all layouts of
851             * the parent layout.
852             *
853             * @param  groupId the primary key of the group
854             * @param  privateLayout whether the layout is private to the group
855             * @param  parentLayoutId the primary key of the parent layout
856             * @param  layoutIds the primary keys of the layouts
857             * @param  serviceContext the service context
858             * @throws PortalException if a group or layout with the primary key could
859             *         not be found, if the group did not have permission to manage the
860             *         layouts, if no layouts were specified, if the first layout was
861             *         not page-able, if the first layout was hidden, or if some other
862             *         portal exception occurred
863             * @throws SystemException if a system exception occurred
864             */
865            public void setLayouts(
866                            long groupId, boolean privateLayout, long parentLayoutId,
867                            long[] layoutIds, ServiceContext serviceContext)
868                    throws PortalException, SystemException {
869    
870                    GroupPermissionUtil.check(
871                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
872    
873                    layoutLocalService.setLayouts(
874                            groupId, privateLayout, parentLayoutId, layoutIds, serviceContext);
875            }
876    
877            /**
878             * Deletes the job from the scheduler's queue.
879             *
880             * @param  groupId the primary key of the group
881             * @param  jobName the job name
882             * @param  groupName the group name (optionally {@link
883             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
884             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
885             * @throws PortalException if the group did not permission to manage staging
886             *         and publish
887             * @throws SystemException if a system exception occurred
888             */
889            public void unschedulePublishToLive(
890                            long groupId, String jobName, String groupName)
891                    throws PortalException, SystemException {
892    
893                    GroupPermissionUtil.check(
894                            getPermissionChecker(), groupId, ActionKeys.PUBLISH_STAGING);
895    
896                    SchedulerEngineUtil.delete(jobName, groupName, StorageType.PERSISTED);
897            }
898    
899            /**
900             * Deletes the job from the scheduler's persistent queue.
901             *
902             * @param  groupId the primary key of the group
903             * @param  jobName the job name
904             * @param  groupName the group name (optionally {@link
905             *         com.liferay.portal.kernel.messaging.DestinationNames#LAYOUTS_LOCAL_PUBLISHER}).
906             *         See {@link com.liferay.portal.kernel.messaging.DestinationNames}.
907             * @throws PortalException if a group with the primary key could not be
908             *         found or if the group did not have permission to publish
909             * @throws SystemException if a system exception occurred
910             */
911            public void unschedulePublishToRemote(
912                            long groupId, String jobName, String groupName)
913                    throws PortalException, SystemException {
914    
915                    GroupPermissionUtil.check(
916                            getPermissionChecker(), groupId, ActionKeys.PUBLISH_STAGING);
917    
918                    SchedulerEngineUtil.delete(jobName, groupName, StorageType.PERSISTED);
919            }
920    
921            /**
922             * Updates the layout.
923             *
924             * @param  groupId the primary key of the group
925             * @param  privateLayout whether the layout is private to the group
926             * @param  layoutId the primary key of the layout
927             * @param  parentLayoutId the primary key of the layout's new parent layout
928             * @param  localeNamesMap the layout's locales and localized names
929             * @param  localeTitlesMap the layout's locales and localized titles
930             * @param  descriptionMap the locales and localized descriptions to merge
931             *         (optionally <code>null</code>)
932             * @param  keywordsMap the locales and localized keywords to merge
933             *         (optionally <code>null</code>)
934             * @param  robotsMap the locales and localized robots to merge (optionally
935             *         <code>null</code>)
936             * @param  type the layout's new type (optionally {@link
937             *         com.liferay.portal.model.LayoutConstants#TYPE_PORTLET})
938             * @param  hidden whether the layout is hidden
939             * @param  friendlyURL the layout's new friendly URL (optionally {@link
940             *         com.liferay.portal.util.PropsValues#DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL}
941             *         or {@link
942             *         com.liferay.portal.util.PropsValues#DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL}).
943             *         The default values can be overridden in
944             *         <code>portal-ext.properties</code> by specifying new values for
945             *         the corresponding properties defined in {@link
946             *         com.liferay.portal.util.PropsValues}. To see how the URL is
947             *         normalized when accessed see {@link
948             *         com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
949             *         String)}.
950             * @param  iconImage whether the icon image will be updated
951             * @param  iconBytes the byte array of the layout's new icon image
952             * @param  serviceContext the service context. Can set the modification date
953             *         and expando bridge attributes for the layout.
954             * @return the updated layout
955             * @throws PortalException if a group or layout with the primary key could
956             *         not be found, if the user did not have permission to update the
957             *         layout, if a unique friendly URL could not be generated, if a
958             *         valid parent layout ID to use could not be found, or if the
959             *         layout parameters were invalid
960             * @throws SystemException if a system exception occurred
961             */
962            public Layout updateLayout(
963                            long groupId, boolean privateLayout, long layoutId,
964                            long parentLayoutId, Map<Locale, String> localeNamesMap,
965                            Map<Locale, String> localeTitlesMap,
966                            Map<Locale, String> descriptionMap, Map<Locale, String> keywordsMap,
967                            Map<Locale, String> robotsMap, String type, boolean hidden,
968                            String friendlyURL, Boolean iconImage, byte[] iconBytes,
969                            ServiceContext serviceContext)
970                    throws PortalException, SystemException {
971    
972                    LayoutPermissionUtil.check(
973                            getPermissionChecker(), groupId, privateLayout, layoutId,
974                            ActionKeys.UPDATE);
975    
976                    return layoutLocalService.updateLayout(
977                            groupId, privateLayout, layoutId, parentLayoutId, localeNamesMap,
978                            localeTitlesMap, descriptionMap, keywordsMap, robotsMap, type,
979                            hidden, friendlyURL, iconImage, iconBytes, serviceContext);
980            }
981    
982            /**
983             * Updates the layout replacing its type settings.
984             *
985             * @param  groupId the primary key of the group
986             * @param  privateLayout whether the layout is private to the group
987             * @param  layoutId the primary key of the layout
988             * @param  typeSettings the settings to load the unicode properties object.
989             *         See {@link com.liferay.portal.kernel.util.UnicodeProperties
990             *         #fastLoad(String)}.
991             * @return the updated layout
992             * @throws PortalException if a matching layout could not be found or if the
993             *         user did not have permission to update the layout
994             * @throws SystemException if a system exception occurred
995             */
996            public Layout updateLayout(
997                            long groupId, boolean privateLayout, long layoutId,
998                            String typeSettings)
999                    throws PortalException, SystemException {
1000    
1001                    LayoutPermissionUtil.check(
1002                            getPermissionChecker(), groupId, privateLayout, layoutId,
1003                            ActionKeys.UPDATE);
1004    
1005                    return layoutLocalService.updateLayout(
1006                            groupId, privateLayout, layoutId, typeSettings);
1007            }
1008    
1009            /**
1010             * Updates the look and feel of the layout.
1011             *
1012             * @param  groupId the primary key of the group
1013             * @param  privateLayout whether the layout is private to the group
1014             * @param  layoutId the primary key of the layout
1015             * @param  themeId the primary key of the layout's new theme
1016             * @param  colorSchemeId the primary key of the layout's new color scheme
1017             * @param  css the layout's new CSS
1018             * @param  wapTheme whether the theme is for WAP browsers
1019             * @return the updated layout
1020             * @throws PortalException if a matching layout could not be found, or if
1021             *         the user did not have permission to update the layout and
1022             *         permission to apply the theme
1023             * @throws SystemException if a system exception occurred
1024             */
1025            public Layout updateLookAndFeel(
1026                            long groupId, boolean privateLayout, long layoutId, String themeId,
1027                            String colorSchemeId, String css, boolean wapTheme)
1028                    throws PortalException, SystemException {
1029    
1030                    LayoutPermissionUtil.check(
1031                            getPermissionChecker(), groupId, privateLayout, layoutId,
1032                            ActionKeys.UPDATE);
1033    
1034                    if (Validator.isNotNull(themeId)) {
1035                            pluginSettingLocalService.checkPermission(
1036                                    getUserId(), themeId, Plugin.TYPE_THEME);
1037                    }
1038    
1039                    return layoutLocalService.updateLookAndFeel(
1040                            groupId, privateLayout, layoutId, themeId, colorSchemeId, css,
1041                            wapTheme);
1042            }
1043    
1044            /**
1045             * Updates the name of the layout matching the group, layout ID, and
1046             * privacy.
1047             *
1048             * @param  groupId the primary key of the group
1049             * @param  privateLayout whether the layout is private to the group
1050             * @param  layoutId the primary key of the layout
1051             * @param  name the layout's new name
1052             * @param  languageId the primary key of the language. For more information
1053             *         see {@link java.util.Locale}.
1054             * @return the updated layout
1055             * @throws PortalException if a matching layout could not be found, if the
1056             *         user did not have permission to update the layout, or if the new
1057             *         name was <code>null</code>
1058             * @throws SystemException if a system exception occurred
1059             */
1060            public Layout updateName(
1061                            long groupId, boolean privateLayout, long layoutId, String name,
1062                            String languageId)
1063                    throws PortalException, SystemException {
1064    
1065                    LayoutPermissionUtil.check(
1066                            getPermissionChecker(), groupId, privateLayout, layoutId,
1067                            ActionKeys.UPDATE);
1068    
1069                    return layoutLocalService.updateName(
1070                            groupId, privateLayout, layoutId, name, languageId);
1071            }
1072    
1073            /**
1074             * Updates the name of the layout matching the primary key.
1075             *
1076             * @param  plid the primary key of the layout
1077             * @param  name the name to be assigned
1078             * @param  languageId the primary key of the language. For more information
1079             *         see {@link java.util.Locale}.
1080             * @return the updated layout
1081             * @throws PortalException if a layout with the primary key could not be
1082             *         found, or if the user did not have permission to update the
1083             *         layout, or if the name was <code>null</code>
1084             * @throws SystemException if a system exception occurred
1085             */
1086            public Layout updateName(long plid, String name, String languageId)
1087                    throws PortalException, SystemException {
1088    
1089                    LayoutPermissionUtil.check(
1090                            getPermissionChecker(), plid, ActionKeys.UPDATE);
1091    
1092                    return layoutLocalService.updateName(plid, name, languageId);
1093            }
1094    
1095            /**
1096             * Updates the parent layout ID of the layout matching the group, layout ID,
1097             * and privacy.
1098             *
1099             * @param  groupId the primary key of the group
1100             * @param  privateLayout whether the layout is private to the group
1101             * @param  layoutId the primary key of the layout
1102             * @param  parentLayoutId the primary key to be assigned to the parent
1103             *         layout
1104             * @return the matching layout
1105             * @throws PortalException if a valid parent layout ID to use could not be
1106             *         found, if a matching layout could not be found, or if the user
1107             *         did not have permission to update the layout
1108             * @throws SystemException if a system exception occurred
1109             */
1110            public Layout updateParentLayoutId(
1111                            long groupId, boolean privateLayout, long layoutId,
1112                            long parentLayoutId)
1113                    throws PortalException, SystemException {
1114    
1115                    LayoutPermissionUtil.check(
1116                            getPermissionChecker(), groupId, privateLayout, layoutId,
1117                            ActionKeys.UPDATE);
1118    
1119                    return layoutLocalService.updateParentLayoutId(
1120                            groupId, privateLayout, layoutId, parentLayoutId);
1121            }
1122    
1123            /**
1124             * Updates the parent layout ID of the layout matching the primary key. If a
1125             * layout matching the parent primary key is found, the layout ID of that
1126             * layout is assigned, otherwise {@link
1127             * com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID} is
1128             * assigned.
1129             *
1130             * @param  plid the primary key of the layout
1131             * @param  parentPlid the primary key of the parent layout
1132             * @return the layout matching the primary key
1133             * @throws PortalException if a layout with the primary key could not be
1134             *         found, if the user did not have permission to update the layout,
1135             *         or if a valid parent layout ID to use could not be found
1136             * @throws SystemException if a system exception occurred
1137             */
1138            public Layout updateParentLayoutId(long plid, long parentPlid)
1139                    throws PortalException, SystemException {
1140    
1141                    LayoutPermissionUtil.check(
1142                            getPermissionChecker(), plid, ActionKeys.UPDATE);
1143    
1144                    return layoutLocalService.updateParentLayoutId(plid, parentPlid);
1145            }
1146    
1147            /**
1148             * Updates the priority of the layout matching the group, layout ID, and
1149             * privacy.
1150             *
1151             * @param  groupId the primary key of the group
1152             * @param  privateLayout whether the layout is private to the group
1153             * @param  layoutId the primary key of the layout
1154             * @param  priority the layout's new priority
1155             * @return the updated layout
1156             * @throws PortalException if a matching layout could not be found or if the
1157             *         user did not have permission to update the layout
1158             * @throws SystemException if a system exception occurred
1159             */
1160            public Layout updatePriority(
1161                            long groupId, boolean privateLayout, long layoutId, int priority)
1162                    throws PortalException, SystemException {
1163    
1164                    LayoutPermissionUtil.check(
1165                            getPermissionChecker(), groupId, privateLayout, layoutId,
1166                            ActionKeys.UPDATE);
1167    
1168                    return layoutLocalService.updatePriority(
1169                            groupId, privateLayout, layoutId, priority);
1170            }
1171    
1172            /**
1173             * Updates the priority of the layout matching the primary key.
1174             *
1175             * @param  plid the primary key of the layout
1176             * @param  priority the layout's new priority
1177             * @return the updated layout
1178             * @throws PortalException if a layout with the primary key could not be
1179             *         found
1180             * @throws SystemException if a system exception occurred
1181             */
1182            public Layout updatePriority(long plid, int priority)
1183                    throws PortalException, SystemException {
1184    
1185                    LayoutPermissionUtil.check(
1186                            getPermissionChecker(), plid, ActionKeys.UPDATE);
1187    
1188                    return layoutLocalService.updatePriority(plid, priority);
1189            }
1190    
1191            protected List<Layout> filterLayouts(List<Layout> layouts)
1192                    throws PortalException, SystemException {
1193    
1194                    List<Layout> filteredLayouts = new ArrayList<Layout>();
1195    
1196                    for (Layout layout : layouts) {
1197                            if (LayoutPermissionUtil.contains(
1198                                            getPermissionChecker(), layout.getPlid(),
1199                                            ActionKeys.VIEW)) {
1200    
1201                                    filteredLayouts.add(layout);
1202                            }
1203                    }
1204    
1205                    return filteredLayouts;
1206            }
1207    
1208    }