001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.NoSuchLayoutException;
018    import com.liferay.portal.RequiredLayoutException;
019    import com.liferay.portal.SitemapChangeFrequencyException;
020    import com.liferay.portal.SitemapIncludeException;
021    import com.liferay.portal.SitemapPagePriorityException;
022    import com.liferay.portal.kernel.bean.BeanReference;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.exception.PortalException;
025    import com.liferay.portal.kernel.exception.SystemException;
026    import com.liferay.portal.kernel.systemevent.SystemEvent;
027    import com.liferay.portal.kernel.systemevent.SystemEventHierarchyEntry;
028    import com.liferay.portal.kernel.systemevent.SystemEventHierarchyEntryThreadLocal;
029    import com.liferay.portal.kernel.util.ContentTypes;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.ListUtil;
032    import com.liferay.portal.kernel.util.LocaleUtil;
033    import com.liferay.portal.kernel.util.ParamUtil;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.UnicodeProperties;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.model.Group;
040    import com.liferay.portal.model.Layout;
041    import com.liferay.portal.model.LayoutConstants;
042    import com.liferay.portal.model.LayoutFriendlyURL;
043    import com.liferay.portal.model.LayoutPrototype;
044    import com.liferay.portal.model.LayoutReference;
045    import com.liferay.portal.model.LayoutSet;
046    import com.liferay.portal.model.LayoutSetPrototype;
047    import com.liferay.portal.model.LayoutType;
048    import com.liferay.portal.model.LayoutTypePortlet;
049    import com.liferay.portal.model.PortletConstants;
050    import com.liferay.portal.model.ResourceConstants;
051    import com.liferay.portal.model.ResourcePermission;
052    import com.liferay.portal.model.SystemEventConstants;
053    import com.liferay.portal.model.User;
054    import com.liferay.portal.model.UserGroup;
055    import com.liferay.portal.model.impl.VirtualLayout;
056    import com.liferay.portal.service.ServiceContext;
057    import com.liferay.portal.service.base.LayoutLocalServiceBaseImpl;
058    import com.liferay.portal.util.PortalUtil;
059    import com.liferay.portal.util.PropsValues;
060    import com.liferay.portal.util.comparator.LayoutComparator;
061    import com.liferay.portal.util.comparator.LayoutPriorityComparator;
062    import com.liferay.portlet.exportimport.lar.MissingReferences;
063    import com.liferay.portlet.exportimport.model.ExportImportConfiguration;
064    import com.liferay.portlet.sites.util.Sites;
065    import com.liferay.portlet.sites.util.SitesUtil;
066    
067    import java.io.File;
068    import java.io.InputStream;
069    
070    import java.util.ArrayList;
071    import java.util.Date;
072    import java.util.HashMap;
073    import java.util.HashSet;
074    import java.util.LinkedHashSet;
075    import java.util.List;
076    import java.util.Locale;
077    import java.util.Map;
078    import java.util.Set;
079    
080    /**
081     * Provides the local service for accessing, adding, deleting, exporting,
082     * importing, and updating layouts.
083     *
084     * @author Brian Wing Shun Chan
085     * @author Jorge Ferrer
086     * @author Joel Kozikowski
087     * @author Charles May
088     * @author Raymond Aug??
089     * @author Jorge Ferrer
090     * @author Bruno Farache
091     * @author Vilmos Papp
092     * @author James Lefeu
093     * @author Tibor Lipusz
094     */
095    public class LayoutLocalServiceImpl extends LayoutLocalServiceBaseImpl {
096    
097            /**
098             * Returns the object counter's name.
099             *
100             * @param  groupId the primary key of the group
101             * @param  privateLayout whether layout is private to the group
102             * @return the object counter's name
103             */
104            public static String getCounterName(long groupId, boolean privateLayout) {
105                    StringBundler sb = new StringBundler(5);
106    
107                    sb.append(Layout.class.getName());
108                    sb.append(StringPool.POUND);
109                    sb.append(groupId);
110                    sb.append(StringPool.POUND);
111                    sb.append(privateLayout);
112    
113                    return sb.toString();
114            }
115    
116            /**
117             * Adds a layout.
118             *
119             * <p>
120             * This method handles the creation of the layout including its resources,
121             * metadata, and internal data structures. It is not necessary to make
122             * subsequent calls to any methods to setup default groups, resources, ...
123             * etc.
124             * </p>
125             *
126             * @param      userId the primary key of the user
127             * @param      groupId the primary key of the group
128             * @param      privateLayout whether the layout is private to the group
129             * @param      parentLayoutId the primary key of the parent layout
130             *             (optionally {@link
131             *             com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID})
132             * @param      nameMap the layout's locales and localized names
133             * @param      titleMap the layout's locales and localized titles
134             * @param      descriptionMap the layout's locales and localized
135             *             descriptions
136             * @param      keywordsMap the layout's locales and localized keywords
137             * @param      robotsMap the layout's locales and localized robots
138             * @param      type the layout's type (optionally {@link
139             *             com.liferay.portal.model.LayoutConstants#TYPE_PORTLET}). The
140             *             possible types can be found in {@link
141             *             com.liferay.portal.model.LayoutConstants}.
142             * @param      hidden whether the layout is hidden
143             * @param      friendlyURL the layout's friendly URL (optionally {@link
144             *             com.liferay.portal.util.PropsValues#DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL}
145             *             or {@link
146             *             com.liferay.portal.util.PropsValues#DEFAULT_USER_PUBLIC_LAYOUT_FRIENDLY_URL}).
147             *             The default values can be overridden in
148             *             <code>portal-ext.properties</code> by specifying new values
149             *             for the corresponding properties defined in {@link
150             *             com.liferay.portal.util.PropsValues}. To see how the URL is
151             *             normalized when accessed, see {@link
152             *             com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
153             *             String)}.
154             * @param      serviceContext the service context to be applied. Must set
155             *             the UUID for the layout. Can set the creation date,
156             *             modification date and the expando bridge attributes for the
157             *             layout. For layouts that belong to a layout set prototype, an
158             *             attribute named <code>layoutUpdateable</code> can be set to
159             *             specify whether site administrators can modify this page
160             *             within their site. For layouts that are created from a layout
161             *             prototype, attributes named <code>layoutPrototypeUuid</code>
162             *             and <code>layoutPrototypeLinkedEnabled</code> can be
163             *             specified to provide the unique identifier of the source
164             *             prototype and a boolean to determine whether a link to it
165             *             should be enabled to activate propagation of changes made to
166             *             the linked page in the prototype.
167             * @return     the layout
168             * @throws     PortalException if a group or user with the primary key could
169             *             not be found, if layout values were invalid, or if a portal
170             *             exception occurred
171             * @deprecated As of 6.2.0, replaced by {@link #addLayout(long, long,
172             *             boolean, long, Map, Map, Map, Map, Map, String, String,
173             *             boolean, Map, ServiceContext)}
174             */
175            @Deprecated
176            @Override
177            public Layout addLayout(
178                            long userId, long groupId, boolean privateLayout,
179                            long parentLayoutId, Map<Locale, String> nameMap,
180                            Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
181                            Map<Locale, String> keywordsMap, Map<Locale, String> robotsMap,
182                            String type, boolean hidden, String friendlyURL,
183                            ServiceContext serviceContext)
184                    throws PortalException {
185    
186                    Map<Locale, String> friendlyURLMap = new HashMap<>();
187    
188                    friendlyURLMap.put(LocaleUtil.getSiteDefault(), friendlyURL);
189    
190                    return addLayout(
191                            userId, groupId, privateLayout, parentLayoutId, nameMap, titleMap,
192                            descriptionMap, keywordsMap, robotsMap, type, StringPool.BLANK,
193                            hidden, friendlyURLMap, serviceContext);
194            }
195    
196            /**
197             * Adds a layout with additional parameters.
198             *
199             * <p>
200             * This method handles the creation of the layout including its resources,
201             * metadata, and internal data structures. It is not necessary to make
202             * subsequent calls to any methods to setup default groups, resources, ...
203             * etc.
204             * </p>
205             *
206             * @param  userId the primary key of the user
207             * @param  groupId the primary key of the group
208             * @param  privateLayout whether the layout is private to the group
209             * @param  parentLayoutId the primary key of the parent layout (optionally
210             *         {@link
211             *         com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID})
212             * @param  nameMap the layout's locales and localized names
213             * @param  titleMap the layout's locales and localized titles
214             * @param  descriptionMap the layout's locales and localized descriptions
215             * @param  keywordsMap the layout's locales and localized keywords
216             * @param  robotsMap the layout's locales and localized robots
217             * @param  type the layout's type (optionally {@link
218             *         com.liferay.portal.model.LayoutConstants#TYPE_PORTLET}). The
219             *         possible types can be found in {@link
220             *         com.liferay.portal.model.LayoutConstants}.
221             * @param  typeSettings the settings to load the unicode properties object.
222             *         See {@link com.liferay.portal.kernel.util.UnicodeProperties
223             *         #fastLoad(String)}.
224             * @param  hidden whether the layout is hidden
225             * @param  friendlyURLMap the layout's locales and localized friendly URLs.
226             *         To see how the URL is normalized when accessed, see {@link
227             *         com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
228             *         String)}.
229             * @param  serviceContext the service context to be applied. Must set the
230             *         UUID for the layout. Can set the creation date, modification
231             *         date, and expando bridge attributes for the layout. For layouts
232             *         that belong to a layout set prototype, an attribute named
233             *         <code>layoutUpdateable</code> can be set to specify whether site
234             *         administrators can modify this page within their site. For
235             *         layouts that are created from a layout prototype, attributes
236             *         named <code>layoutPrototypeUuid</code> and
237             *         <code>layoutPrototypeLinkedEnabled</code> can be specified to
238             *         provide the unique identifier of the source prototype and a
239             *         boolean to determine whether a link to it should be enabled to
240             *         activate propagation of changes made to the linked page in the
241             *         prototype.
242             * @return the layout
243             * @throws PortalException if a group or user with the primary key could not
244             *         be found, if layout values were invalid, or if a portal exception
245             *         occurred
246             */
247            @Override
248            public Layout addLayout(
249                            long userId, long groupId, boolean privateLayout,
250                            long parentLayoutId, Map<Locale, String> nameMap,
251                            Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
252                            Map<Locale, String> keywordsMap, Map<Locale, String> robotsMap,
253                            String type, String typeSettings, boolean hidden,
254                            Map<Locale, String> friendlyURLMap, ServiceContext serviceContext)
255                    throws PortalException {
256    
257                    // Layout
258    
259                    User user = userPersistence.findByPrimaryKey(userId);
260                    long layoutId = getNextLayoutId(groupId, privateLayout);
261                    parentLayoutId = layoutLocalServiceHelper.getParentLayoutId(
262                            groupId, privateLayout, parentLayoutId);
263                    String name = nameMap.get(LocaleUtil.getSiteDefault());
264                    friendlyURLMap = layoutLocalServiceHelper.getFriendlyURLMap(
265                            groupId, privateLayout, layoutId, name, friendlyURLMap);
266    
267                    String friendlyURL = friendlyURLMap.get(LocaleUtil.getSiteDefault());
268    
269                    int priority = layoutLocalServiceHelper.getNextPriority(
270                            groupId, privateLayout, parentLayoutId, null, -1);
271    
272                    layoutLocalServiceHelper.validate(
273                            groupId, privateLayout, layoutId, parentLayoutId, name, type,
274                            hidden, friendlyURLMap);
275    
276                    Date now = new Date();
277    
278                    long plid = counterLocalService.increment();
279    
280                    Layout layout = layoutPersistence.create(plid);
281    
282                    layout.setUuid(serviceContext.getUuid());
283                    layout.setGroupId(groupId);
284                    layout.setCompanyId(user.getCompanyId());
285                    layout.setUserId(user.getUserId());
286                    layout.setUserName(user.getFullName());
287                    layout.setCreateDate(serviceContext.getCreateDate(now));
288                    layout.setModifiedDate(serviceContext.getModifiedDate(now));
289                    layout.setPrivateLayout(privateLayout);
290                    layout.setLayoutId(layoutId);
291                    layout.setParentLayoutId(parentLayoutId);
292                    layout.setNameMap(nameMap);
293                    layout.setTitleMap(titleMap);
294                    layout.setDescriptionMap(descriptionMap);
295                    layout.setKeywordsMap(keywordsMap);
296                    layout.setRobotsMap(robotsMap);
297                    layout.setType(type);
298                    layout.setHidden(hidden);
299                    layout.setFriendlyURL(friendlyURL);
300                    layout.setPriority(priority);
301    
302                    boolean layoutUpdateable = ParamUtil.getBoolean(
303                            serviceContext, Sites.LAYOUT_UPDATEABLE, true);
304    
305                    UnicodeProperties typeSettingsProperties = new UnicodeProperties();
306    
307                    typeSettingsProperties.fastLoad(typeSettings);
308    
309                    if (!layoutUpdateable) {
310                            typeSettingsProperties.put(
311                                    Sites.LAYOUT_UPDATEABLE, String.valueOf(layoutUpdateable));
312                    }
313    
314                    if (privateLayout) {
315                            typeSettingsProperties.put(
316                                    "privateLayout", String.valueOf(privateLayout));
317                    }
318    
319                    validateTypeSettingsProperties(typeSettingsProperties);
320    
321                    layout.setTypeSettingsProperties(typeSettingsProperties);
322    
323                    String layoutPrototypeUuid = ParamUtil.getString(
324                            serviceContext, "layoutPrototypeUuid");
325                    boolean layoutPrototypeLinkEnabled = ParamUtil.getBoolean(
326                            serviceContext, "layoutPrototypeLinkEnabled",
327                            PropsValues.LAYOUT_PROTOTYPE_LINK_ENABLED_DEFAULT);
328    
329                    if (Validator.isNotNull(layoutPrototypeUuid)) {
330                            layout.setLayoutPrototypeUuid(layoutPrototypeUuid);
331                            layout.setLayoutPrototypeLinkEnabled(layoutPrototypeLinkEnabled);
332                    }
333    
334                    if (type.equals(LayoutConstants.TYPE_PORTLET)) {
335                            LayoutTypePortlet layoutTypePortlet =
336                                    (LayoutTypePortlet)layout.getLayoutType();
337    
338                            if (Validator.isNull(layoutTypePortlet.getLayoutTemplateId())) {
339                                    layoutTypePortlet.setLayoutTemplateId(
340                                            0, PropsValues.LAYOUT_DEFAULT_TEMPLATE_ID, false);
341                            }
342                    }
343    
344                    layout.setExpandoBridgeAttributes(serviceContext);
345    
346                    layoutPersistence.update(layout);
347    
348                    // Layout friendly URLs
349    
350                    layoutFriendlyURLLocalService.updateLayoutFriendlyURLs(
351                            user.getUserId(), user.getCompanyId(), groupId, plid, privateLayout,
352                            friendlyURLMap, serviceContext);
353    
354                    // Layout prototype
355    
356                    if (Validator.isNotNull(layoutPrototypeUuid) &&
357                            !layoutPrototypeLinkEnabled) {
358    
359                            LayoutPrototype layoutPrototype =
360                                    layoutPrototypeLocalService.
361                                            getLayoutPrototypeByUuidAndCompanyId(
362                                                    layoutPrototypeUuid, layout.getCompanyId());
363    
364                            try {
365                                    SitesUtil.applyLayoutPrototype(
366                                            layoutPrototype, layout, layoutPrototypeLinkEnabled);
367                            }
368                            catch (PortalException pe) {
369                                    throw pe;
370                            }
371                            catch (SystemException se) {
372                                    throw se;
373                            }
374                            catch (Exception e) {
375                                    throw new SystemException(e);
376                            }
377                    }
378    
379                    // Resources
380    
381                    boolean addGroupPermissions = true;
382    
383                    Group group = groupLocalService.getGroup(groupId);
384    
385                    if (privateLayout && group.isUser()) {
386                            addGroupPermissions = false;
387                    }
388    
389                    boolean addGuestPermissions = false;
390    
391                    if (!privateLayout || type.equals(LayoutConstants.TYPE_CONTROL_PANEL) ||
392                            type.equals(LayoutConstants.TYPE_USER_PERSONAL_PANEL) ||
393                            group.isLayoutSetPrototype()) {
394    
395                            addGuestPermissions = true;
396                    }
397    
398                    resourceLocalService.addResources(
399                            user.getCompanyId(), groupId, user.getUserId(),
400                            Layout.class.getName(), layout.getPlid(), false,
401                            addGroupPermissions, addGuestPermissions);
402    
403                    // Group
404    
405                    groupLocalService.updateSite(groupId, true);
406    
407                    // Layout set
408    
409                    layoutSetLocalService.updatePageCount(groupId, privateLayout);
410    
411                    LayoutSet layoutSet = layoutSetPersistence.findByG_P(
412                            groupId, privateLayout);
413    
414                    layout.setLayoutSet(layoutSet);
415    
416                    // Asset
417    
418                    updateAsset(
419                            userId, layout, serviceContext.getAssetCategoryIds(),
420                            serviceContext.getAssetTagNames());
421    
422                    return layout;
423            }
424    
425            /**
426             * Adds a layout with single entry maps for name, title, and description to
427             * the default locale.
428             *
429             * <p>
430             * This method handles the creation of the layout including its resources,
431             * metadata, and internal data structures. It is not necessary to make
432             * subsequent calls to any methods to setup default groups, resources, ...
433             * etc.
434             * </p>
435             *
436             * @param  userId the primary key of the user
437             * @param  groupId the primary key of the group
438             * @param  privateLayout whether the layout is private to the group
439             * @param  parentLayoutId the primary key of the parent layout (optionally
440             *         {@link
441             *         com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID}).
442             *         The possible values can be found in {@link
443             *         com.liferay.portal.model.LayoutConstants}.
444             * @param  name the layout's name (optionally {@link
445             *         com.liferay.portal.util.PropsValues#DEFAULT_USER_PRIVATE_LAYOUT_NAME}
446             *         or {@link
447             *         com.liferay.portal.util.PropsValues#DEFAULT_USER_PUBLIC_LAYOUT_NAME}).
448             *         The default values can be overridden in
449             *         <code>portal-ext.properties</code> by specifying new values for
450             *         the corresponding properties defined in {@link
451             *         com.liferay.portal.util.PropsValues}
452             * @param  title the layout's title
453             * @param  description the layout's description
454             * @param  type the layout's type (optionally {@link
455             *         com.liferay.portal.model.LayoutConstants#TYPE_PORTLET}). The
456             *         possible types can be found in {@link
457             *         com.liferay.portal.model.LayoutConstants}.
458             * @param  hidden whether the layout is hidden
459             * @param  friendlyURL the friendly URL of the layout (optionally {@link
460             *         com.liferay.portal.util.PropsValues#DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL}
461             *         or {@link
462             *         com.liferay.portal.util.PropsValues#DEFAULT_USER_PUBLIC_LAYOUT_FRIENDLY_URL}).
463             *         The default values can be overridden in
464             *         <code>portal-ext.properties</code> by specifying new values for
465             *         the corresponding properties defined in {@link
466             *         com.liferay.portal.util.PropsValues}. To see how the URL is
467             *         normalized when accessed, see {@link
468             *         com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
469             *         String)}.
470             * @param  serviceContext the service context to be applied. Must set the
471             *         UUID for the layout. Can set the creation date and modification
472             *         date for the layout. For layouts that belong to a layout set
473             *         prototype, an attribute named <code>layoutUpdateable</code> can
474             *         be set to specify whether site administrators can modify this
475             *         page within their site.
476             * @return the layout
477             * @throws PortalException if a group or user with the primary key could not
478             *         be found, or if a portal exception occurred
479             */
480            @Override
481            public Layout addLayout(
482                            long userId, long groupId, boolean privateLayout,
483                            long parentLayoutId, String name, String title, String description,
484                            String type, boolean hidden, String friendlyURL,
485                            ServiceContext serviceContext)
486                    throws PortalException {
487    
488                    Locale locale = LocaleUtil.getSiteDefault();
489    
490                    Map<Locale, String> nameMap = new HashMap<>();
491    
492                    nameMap.put(locale, name);
493    
494                    Map<Locale, String> titleMap = new HashMap<>();
495    
496                    titleMap.put(locale, title);
497    
498                    Map<Locale, String> descriptionMap = new HashMap<>();
499    
500                    descriptionMap.put(locale, description);
501    
502                    Map<Locale, String> friendlyURLMap = new HashMap<>();
503    
504                    friendlyURLMap.put(LocaleUtil.getSiteDefault(), friendlyURL);
505    
506                    return addLayout(
507                            userId, groupId, privateLayout, parentLayoutId, nameMap, titleMap,
508                            descriptionMap, new HashMap<Locale, String>(),
509                            new HashMap<Locale, String>(), type, StringPool.BLANK, hidden,
510                            friendlyURLMap, serviceContext);
511            }
512    
513            /**
514             * Deletes the layout, its child layouts, and its associated resources.
515             *
516             * @param  layout the layout
517             * @param  updateLayoutSet whether the layout set's page counter needs to be
518             *         updated
519             * @param  serviceContext the service context to be applied
520             * @throws PortalException if a portal exception occurred
521             */
522            @Override
523            @SystemEvent(
524                    action = SystemEventConstants.ACTION_SKIP,
525                    type = SystemEventConstants.TYPE_DELETE
526            )
527            public void deleteLayout(
528                            Layout layout, boolean updateLayoutSet,
529                            ServiceContext serviceContext)
530                    throws PortalException {
531    
532                    // First layout validation
533    
534                    if (layout.getParentLayoutId() ==
535                                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
536    
537                            List<Layout> rootLayouts = layoutPersistence.findByG_P_P(
538                                    layout.getGroupId(), layout.isPrivateLayout(),
539                                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, 0, 2);
540    
541                            if (rootLayouts.size() > 1) {
542                                    Layout firstLayout = rootLayouts.get(0);
543    
544                                    if (firstLayout.getLayoutId() == layout.getLayoutId()) {
545                                            Layout secondLayout = rootLayouts.get(1);
546    
547                                            layoutLocalServiceHelper.validateFirstLayout(secondLayout);
548                                    }
549                            }
550                    }
551    
552                    // Child layouts
553    
554                    List<Layout> childLayouts = layoutPersistence.findByG_P_P(
555                            layout.getGroupId(), layout.isPrivateLayout(),
556                            layout.getLayoutId());
557    
558                    for (Layout childLayout : childLayouts) {
559                            layoutLocalService.deleteLayout(
560                                    childLayout, updateLayoutSet, serviceContext);
561                    }
562    
563                    // Layout friendly URLs
564    
565                    layoutFriendlyURLLocalService.deleteLayoutFriendlyURLs(
566                            layout.getPlid());
567    
568                    // Portlet preferences
569    
570                    portletPreferencesLocalService.deletePortletPreferencesByPlid(
571                            layout.getPlid());
572    
573                    // Subscriptions
574    
575                    subscriptionLocalService.deleteSubscriptions(
576                            layout.getCompanyId(), Layout.class.getName(), layout.getPlid());
577    
578                    // Asset
579    
580                    assetEntryLocalService.deleteEntry(
581                            Layout.class.getName(), layout.getPlid());
582    
583                    // Ratings
584    
585                    ratingsStatsLocalService.deleteStats(
586                            Layout.class.getName(), layout.getPlid());
587    
588                    // Expando
589    
590                    expandoRowLocalService.deleteRows(layout.getPlid());
591    
592                    // Icon
593    
594                    imageLocalService.deleteImage(layout.getIconImageId());
595    
596                    // Scope group
597    
598                    Group scopeGroup = layout.getScopeGroup();
599    
600                    if (scopeGroup != null) {
601                            groupLocalService.deleteGroup(scopeGroup.getGroupId());
602                    }
603    
604                    // Resources
605    
606                    String primKey =
607                            layout.getPlid() + PortletConstants.LAYOUT_SEPARATOR + "%";
608    
609                    List<ResourcePermission> resourcePermissions =
610                            resourcePermissionPersistence.findByC_LikeP(
611                                    layout.getCompanyId(), primKey);
612    
613                    for (ResourcePermission resourcePermission : resourcePermissions) {
614                            resourcePermissionLocalService.deleteResourcePermission(
615                                    resourcePermission);
616                    }
617    
618                    resourceLocalService.deleteResource(
619                            layout.getCompanyId(), Layout.class.getName(),
620                            ResourceConstants.SCOPE_INDIVIDUAL, layout.getPlid());
621    
622                    // Layout
623    
624                    layoutPersistence.remove(layout);
625    
626                    // Layout set
627    
628                    if (updateLayoutSet) {
629                            layoutSetLocalService.updatePageCount(
630                                    layout.getGroupId(), layout.isPrivateLayout());
631                    }
632    
633                    // System event
634    
635                    SystemEventHierarchyEntry systemEventHierarchyEntry =
636                            SystemEventHierarchyEntryThreadLocal.peek();
637    
638                    if ((systemEventHierarchyEntry != null) &&
639                            systemEventHierarchyEntry.hasTypedModel(
640                                    Layout.class.getName(), layout.getPlid())) {
641    
642                            systemEventHierarchyEntry.setExtraDataValue(
643                                    "privateLayout", StringUtil.valueOf(layout.isPrivateLayout()));
644                    }
645            }
646    
647            /**
648             * Deletes the layout with the primary key, also deleting the layout's child
649             * layouts, and associated resources.
650             *
651             * @param  groupId the primary key of the group
652             * @param  privateLayout whether the layout is private to the group
653             * @param  layoutId the primary key of the layout
654             * @param  serviceContext the service context to be applied
655             * @throws PortalException if a matching layout could not be found , or if
656             *         some other portal exception occurred
657             */
658            @Override
659            public void deleteLayout(
660                            long groupId, boolean privateLayout, long layoutId,
661                            ServiceContext serviceContext)
662                    throws PortalException {
663    
664                    Layout layout = layoutPersistence.findByG_P_L(
665                            groupId, privateLayout, layoutId);
666    
667                    layoutLocalService.deleteLayout(layout, true, serviceContext);
668            }
669    
670            /**
671             * Deletes the layout with the plid, also deleting the layout's child
672             * layouts, and associated resources.
673             *
674             * @param  plid the primary key of the layout
675             * @param  serviceContext the service context to be applied
676             * @throws PortalException if a layout with the primary key could not be
677             *         found , or if some other portal exception occurred
678             */
679            @Override
680            public void deleteLayout(long plid, ServiceContext serviceContext)
681                    throws PortalException {
682    
683                    Layout layout = layoutPersistence.findByPrimaryKey(plid);
684    
685                    layoutLocalService.deleteLayout(layout, true, serviceContext);
686            }
687    
688            /**
689             * Deletes the group's private or non-private layouts, also deleting the
690             * layouts' child layouts, and associated resources.
691             *
692             * @param  groupId the primary key of the group
693             * @param  privateLayout whether the layout is private to the group
694             * @param  serviceContext the service context to be applied. The parent
695             *         layout set's page count will be updated by default, unless an
696             *         attribute named <code>updatePageCount</code> is set to
697             *         <code>false</code>.
698             * @throws PortalException if a group with the primary key could not be
699             *         found or if a layout set for the group and privacy could not be
700             *         found
701             */
702            @Override
703            public void deleteLayouts(
704                            long groupId, boolean privateLayout, ServiceContext serviceContext)
705                    throws PortalException {
706    
707                    // Layouts
708    
709                    List<Layout> layouts = layoutPersistence.findByG_P_P(
710                            groupId, privateLayout, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID,
711                            QueryUtil.ALL_POS, QueryUtil.ALL_POS,
712                            new LayoutPriorityComparator(false));
713    
714                    for (Layout layout : layouts) {
715                            try {
716                                    layoutLocalService.deleteLayout(layout, false, serviceContext);
717                            }
718                            catch (NoSuchLayoutException nsle) {
719                            }
720                    }
721    
722                    // Layout set
723    
724                    if (GetterUtil.getBoolean(
725                                    serviceContext.getAttribute("updatePageCount"), true)) {
726    
727                            layoutSetLocalService.updatePageCount(groupId, privateLayout);
728                    }
729    
730                    // Counter
731    
732                    counterLocalService.reset(getCounterName(groupId, privateLayout));
733            }
734    
735            /**
736             * Exports layouts with the primary keys and criteria as a byte array.
737             *
738             * @param      groupId the primary key of the group
739             * @param      privateLayout whether the layout is private to the group
740             * @param      layoutIds the primary keys of the layouts to be exported
741             * @param      parameterMap the mapping of parameters indicating which
742             *             information to export. For information on the keys used in
743             *             the map see {@link
744             *             com.liferay.portlet.exportimport.lar.PortletDataHandlerKeys}.
745             * @param      startDate the export's start date
746             * @param      endDate the export's end date
747             * @return     the layouts as a byte array
748             * @throws     PortalException if a group or any layout with the primary key
749             *             could not be found, or if some other portal exception
750             *             occurred
751             * @deprecated As of 7.0.0, with no direct replacement
752             */
753            @Deprecated
754            @Override
755            public byte[] exportLayouts(
756                            long groupId, boolean privateLayout, long[] layoutIds,
757                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
758                    throws PortalException {
759    
760                    throw new UnsupportedOperationException();
761            }
762    
763            /**
764             * Exports all layouts that match the criteria as a byte array.
765             *
766             * @param      groupId the primary key of the group
767             * @param      privateLayout whether the layout is private to the group
768             * @param      parameterMap the mapping of parameters indicating which
769             *             information to export. For information on the keys used in
770             *             the map see {@link
771             *             com.liferay.portlet.exportimport.lar.PortletDataHandlerKeys}.
772             * @param      startDate the export's start date
773             * @param      endDate the export's end date
774             * @return     the layout as a byte array
775             * @throws     PortalException if a group with the primary key could not be
776             *             found or if some other portal exception occurred
777             * @deprecated As of 7.0.0, with no direct replacement
778             */
779            @Deprecated
780            @Override
781            public byte[] exportLayouts(
782                            long groupId, boolean privateLayout,
783                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
784                    throws PortalException {
785    
786                    throw new UnsupportedOperationException();
787            }
788    
789            /**
790             * @throws     PortalException
791             * @deprecated As of 7.0.0, replaced by {@link
792             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#exportLayoutsAsFile(
793             *             ExportImportConfiguration)}
794             */
795            @Deprecated
796            @Override
797            public File exportLayoutsAsFile(
798                            ExportImportConfiguration exportImportConfiguration)
799                    throws PortalException {
800    
801                    throw new UnsupportedOperationException();
802            }
803    
804            /**
805             * Exports the layouts that match the primary keys and criteria as a file.
806             *
807             * @param      groupId the primary key of the group
808             * @param      privateLayout whether the layout is private to the group
809             * @param      layoutIds the primary keys of the layouts to be exported
810             *             (optionally <code>null</code>)
811             * @param      parameterMap the mapping of parameters indicating which
812             *             information to export. For information on the keys used in
813             *             the map see {@link
814             *             com.liferay.portlet.exportimport.lar.PortletDataHandlerKeys}.
815             * @param      startDate the export's start date
816             * @param      endDate the export's end date
817             * @return     the layouts as a File
818             * @throws     PortalException if a group or any layout with the primary key
819             *             could not be found, or if some other portal exception
820             *             occurred
821             * @deprecated As of 7.0.0, with no direct replacement
822             */
823            @Deprecated
824            @Override
825            public File exportLayoutsAsFile(
826                            long groupId, boolean privateLayout, long[] layoutIds,
827                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
828                    throws PortalException {
829    
830                    throw new UnsupportedOperationException();
831            }
832    
833            /**
834             * @throws     PortalException
835             * @deprecated As of 7.0.0, replaced by {@link
836             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#exportLayoutsAsFileInBackground(
837             *             long, ExportImportConfiguration)}
838             */
839            @Deprecated
840            @Override
841            public long exportLayoutsAsFileInBackground(
842                            long userId, ExportImportConfiguration exportImportConfiguration)
843                    throws PortalException {
844    
845                    throw new UnsupportedOperationException();
846            }
847    
848            /**
849             * @throws     PortalException
850             * @deprecated As of 7.0.0, replaced by {@link
851             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#exportLayoutsAsFileInBackground(
852             *             long, long)}
853             */
854            @Deprecated
855            @Override
856            public long exportLayoutsAsFileInBackground(
857                            long userId, long exportImportConfigurationId)
858                    throws PortalException {
859    
860                    throw new UnsupportedOperationException();
861            }
862    
863            /**
864             * @throws     PortalException
865             * @deprecated As of 7.0.0, with no direct replacement
866             */
867            @Deprecated
868            @Override
869            public long exportLayoutsAsFileInBackground(
870                            long userId, String taskName, long groupId, boolean privateLayout,
871                            long[] layoutIds, Map<String, String[]> parameterMap,
872                            Date startDate, Date endDate)
873                    throws PortalException {
874    
875                    throw new UnsupportedOperationException();
876            }
877    
878            /**
879             * @throws     PortalException
880             * @deprecated As of 7.0.0, with no direct replacement
881             */
882            @Deprecated
883            @Override
884            public long exportLayoutsAsFileInBackground(
885                            long userId, String taskName, long groupId, boolean privateLayout,
886                            long[] layoutIds, Map<String, String[]> parameterMap,
887                            Date startDate, Date endDate, String fileName)
888                    throws PortalException {
889    
890                    throw new UnsupportedOperationException();
891            }
892    
893            /**
894             * Exports the portlet information (categories, permissions, ... etc.) as a
895             * byte array.
896             *
897             * @param      plid the primary key of the layout
898             * @param      groupId the primary key of the group
899             * @param      portletId the primary key of the portlet
900             * @param      parameterMap the mapping of parameters indicating which
901             *             information to export. For information on the keys used in
902             *             the map see {@link
903             *             com.liferay.portlet.exportimport.lar.PortletDataHandlerKeys}.
904             * @param      startDate the export's start date
905             * @param      endDate the export's end date
906             * @return     the portlet information as a byte array
907             * @throws     PortalException if a group or portlet with the primary key
908             *             could not be found, or if some other portal exception
909             *             occurred
910             * @deprecated As of 7.0.0, with no direct replacement
911             */
912            @Deprecated
913            @Override
914            public byte[] exportPortletInfo(
915                            long plid, long groupId, String portletId,
916                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
917                    throws PortalException {
918    
919                    throw new UnsupportedOperationException();
920            }
921    
922            /**
923             * @throws     PortalException
924             * @deprecated As of 7.0.0, with no direct replacement
925             */
926            @Deprecated
927            @Override
928            public byte[] exportPortletInfo(
929                            long companyId, String portletId,
930                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
931                    throws PortalException {
932    
933                    throw new UnsupportedOperationException();
934            }
935    
936            /**
937             * @throws     PortalException
938             * @deprecated As of 7.0.0, replaced by {@link
939             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#exportPortletInfoAsFile(
940             *             ExportImportConfiguration)}}
941             */
942            @Deprecated
943            @Override
944            public File exportPortletInfoAsFile(
945                            ExportImportConfiguration exportImportConfiguration)
946                    throws PortalException {
947    
948                    throw new UnsupportedOperationException();
949            }
950    
951            /**
952             * Exports the portlet information (categories, permissions, ... etc.) as a
953             * file.
954             *
955             * @param      plid the primary key of the layout
956             * @param      groupId the primary key of the group
957             * @param      portletId the primary key of the portlet
958             * @param      parameterMap the mapping of parameters indicating which
959             *             information to export. For information on the keys used in
960             *             the map see {@link
961             *             com.liferay.portlet.exportimport.lar.PortletDataHandlerKeys}.
962             * @param      startDate the export's start date
963             * @param      endDate the export's end date
964             * @return     the portlet information as a file
965             * @throws     PortalException if a group or portlet with the primary key
966             *             could not be found, or if some other portal exception
967             *             occurred
968             * @deprecated As of 7.0.0, with no direct replacement
969             */
970            @Deprecated
971            @Override
972            public File exportPortletInfoAsFile(
973                            long plid, long groupId, String portletId,
974                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
975                    throws PortalException {
976    
977                    throw new UnsupportedOperationException();
978            }
979    
980            /**
981             * @throws     PortalException
982             * @deprecated As of 7.0.0, with no direct replacement
983             */
984            @Deprecated
985            @Override
986            public File exportPortletInfoAsFile(
987                            long companyId, String portletId,
988                            Map<String, String[]> parameterMap, Date startDate, Date endDate)
989                    throws PortalException {
990    
991                    throw new UnsupportedOperationException();
992            }
993    
994            /**
995             * @throws     PortalException
996             * @deprecated As of 7.0.0, replaced by {@link
997             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#exportPortletInfoAsFileInBackground(
998             *             long, ExportImportConfiguration)}}
999             */
1000            @Deprecated
1001            @Override
1002            public long exportPortletInfoAsFileInBackground(
1003                            long userId, ExportImportConfiguration exportImportConfiguration)
1004                    throws PortalException {
1005    
1006                    throw new UnsupportedOperationException();
1007            }
1008    
1009            /**
1010             * @throws     PortalException
1011             * @deprecated As of 7.0.0, replaced by {@link
1012             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#exportPortletInfoAsFileInBackground(
1013             *             long, long)}}
1014             */
1015            @Deprecated
1016            @Override
1017            public long exportPortletInfoAsFileInBackground(
1018                            long userId, long exportImportConfigurationId)
1019                    throws PortalException {
1020    
1021                    throw new UnsupportedOperationException();
1022            }
1023    
1024            /**
1025             * @throws     PortalException
1026             * @deprecated As of 7.0.0, with no direct replacement
1027             */
1028            @Deprecated
1029            @Override
1030            public long exportPortletInfoAsFileInBackground(
1031                            long userId, String taskName, long plid, long groupId,
1032                            String portletId, Map<String, String[]> parameterMap,
1033                            Date startDate, Date endDate, String fileName)
1034                    throws PortalException {
1035    
1036                    throw new UnsupportedOperationException();
1037            }
1038    
1039            /**
1040             * @throws     PortalException
1041             * @deprecated As of 7.0.0, with no direct replacement
1042             */
1043            @Deprecated
1044            @Override
1045            public long exportPortletInfoAsFileInBackground(
1046                            long userId, String taskName, String portletId,
1047                            Map<String, String[]> parameterMap, Date startDate, Date endDate,
1048                            String fileName)
1049                    throws PortalException {
1050    
1051                    throw new UnsupportedOperationException();
1052            }
1053    
1054            @Override
1055            public Layout fetchFirstLayout(
1056                    long groupId, boolean privateLayout, long parentLayoutId) {
1057    
1058                    return layoutPersistence.fetchByG_P_P_First(
1059                            groupId, privateLayout, parentLayoutId,
1060                            new LayoutPriorityComparator());
1061            }
1062    
1063            @Override
1064            public Layout fetchLayout(
1065                    long groupId, boolean privateLayout, long layoutId) {
1066    
1067                    return layoutPersistence.fetchByG_P_L(groupId, privateLayout, layoutId);
1068            }
1069    
1070            @Override
1071            public Layout fetchLayoutByFriendlyURL(
1072                    long groupId, boolean privateLayout, String friendlyURL) {
1073    
1074                    return layoutPersistence.fetchByG_P_F(
1075                            groupId, privateLayout, friendlyURL);
1076            }
1077    
1078            /**
1079             * Returns the primary key of the default layout for the group
1080             *
1081             * @param  groupId the primary key of the group
1082             * @return the primary key of the default layout for the group (optionally
1083             *         {@link com.liferay.portal.model.LayoutConstants#DEFAULT_PLID})
1084             */
1085            @Override
1086            public long getDefaultPlid(long groupId) {
1087                    if (groupId > 0) {
1088                            List<Layout> layouts = layoutPersistence.findByGroupId(
1089                                    groupId, 0, 1);
1090    
1091                            if (!layouts.isEmpty()) {
1092                                    Layout layout = layouts.get(0);
1093    
1094                                    return layout.getPlid();
1095                            }
1096                    }
1097    
1098                    return LayoutConstants.DEFAULT_PLID;
1099            }
1100    
1101            /**
1102             * Returns primary key of the matching default layout for the group
1103             *
1104             * @param  groupId the primary key of the group
1105             * @param  privateLayout whether the layout is private to the group
1106             * @return the primary key of the default layout for the group; {@link
1107             *         com.liferay.portal.model.LayoutConstants#DEFAULT_PLID}) otherwise
1108             */
1109            @Override
1110            public long getDefaultPlid(long groupId, boolean privateLayout) {
1111                    if (groupId > 0) {
1112                            List<Layout> layouts = layoutPersistence.findByG_P(
1113                                    groupId, privateLayout, 0, 1);
1114    
1115                            if (!layouts.isEmpty()) {
1116                                    Layout layout = layouts.get(0);
1117    
1118                                    return layout.getPlid();
1119                            }
1120                    }
1121    
1122                    return LayoutConstants.DEFAULT_PLID;
1123            }
1124    
1125            /**
1126             * Returns primary key of the default portlet layout for the group
1127             *
1128             * @param  groupId the primary key of the group
1129             * @param  privateLayout whether the layout is private to the group
1130             * @param  portletId the primary key of the portlet
1131             * @return the primary key of the default portlet layout for the group;
1132             *         {@link com.liferay.portal.model.LayoutConstants#DEFAULT_PLID}
1133             *         otherwise
1134             * @throws PortalException if a portlet with the primary key could not be
1135             *         found
1136             */
1137            @Override
1138            public long getDefaultPlid(
1139                            long groupId, boolean privateLayout, String portletId)
1140                    throws PortalException {
1141    
1142                    if (groupId > 0) {
1143                            List<Layout> layouts = layoutPersistence.findByG_P(
1144                                    groupId, privateLayout);
1145    
1146                            for (Layout layout : layouts) {
1147                                    if (layout.isTypePortlet()) {
1148                                            LayoutTypePortlet layoutTypePortlet =
1149                                                    (LayoutTypePortlet)layout.getLayoutType();
1150    
1151                                            if (layoutTypePortlet.hasPortletId(portletId)) {
1152                                                    return layout.getPlid();
1153                                            }
1154                                    }
1155                            }
1156                    }
1157    
1158                    return LayoutConstants.DEFAULT_PLID;
1159            }
1160    
1161            /**
1162             * Returns the layout for the friendly URL
1163             *
1164             * @param  groupId the primary key of the group
1165             * @param  privateLayout whether the layout is private to the group
1166             * @param  friendlyURL the friendly URL of the layout
1167             * @return the layout for the friendly URL
1168             * @throws PortalException if the friendly URL is <code>null</code> or a
1169             *         matching layout could not be found
1170             */
1171            @Override
1172            public Layout getFriendlyURLLayout(
1173                            long groupId, boolean privateLayout, String friendlyURL)
1174                    throws PortalException {
1175    
1176                    if (Validator.isNull(friendlyURL)) {
1177                            StringBundler sb = new StringBundler(5);
1178    
1179                            sb.append("{groupId=");
1180                            sb.append(groupId);
1181                            sb.append(", privateLayout=");
1182                            sb.append(privateLayout);
1183                            sb.append("}");
1184    
1185                            throw new NoSuchLayoutException(sb.toString());
1186                    }
1187    
1188                    friendlyURL = layoutLocalServiceHelper.getFriendlyURL(friendlyURL);
1189    
1190                    Layout layout = null;
1191    
1192                    List<LayoutFriendlyURL> layoutFriendlyURLs =
1193                            layoutFriendlyURLPersistence.findByG_P_F(
1194                                    groupId, privateLayout, friendlyURL, 0, 1);
1195    
1196                    if (!layoutFriendlyURLs.isEmpty()) {
1197                            LayoutFriendlyURL layoutFriendlyURL = layoutFriendlyURLs.get(0);
1198    
1199                            layout = layoutPersistence.findByPrimaryKey(
1200                                    layoutFriendlyURL.getPlid());
1201                    }
1202    
1203                    if ((layout == null) && friendlyURL.startsWith(StringPool.SLASH) &&
1204                            Validator.isNumber(friendlyURL.substring(1))) {
1205    
1206                            long layoutId = GetterUtil.getLong(friendlyURL.substring(1));
1207    
1208                            layout = layoutPersistence.fetchByG_P_L(
1209                                    groupId, privateLayout, layoutId);
1210                    }
1211    
1212                    if (layout == null) {
1213                            StringBundler sb = new StringBundler(7);
1214    
1215                            sb.append("{groupId=");
1216                            sb.append(groupId);
1217                            sb.append(", privateLayout=");
1218                            sb.append(privateLayout);
1219                            sb.append(", friendlyURL=");
1220                            sb.append(friendlyURL);
1221                            sb.append("}");
1222    
1223                            throw new NoSuchLayoutException(sb.toString());
1224                    }
1225    
1226                    return layout;
1227            }
1228    
1229            /**
1230             * Returns the layout matching the primary key, group, and privacy; throws a
1231             * {@link com.liferay.portal.NoSuchLayoutException} otherwise.
1232             *
1233             * @param  groupId the primary key of the group
1234             * @param  privateLayout whether the layout is private to the group
1235             * @param  layoutId the primary key of the layout
1236             * @return the matching layout
1237             * @throws PortalException if a matching layout could not be found
1238             */
1239            @Override
1240            public Layout getLayout(long groupId, boolean privateLayout, long layoutId)
1241                    throws PortalException {
1242    
1243                    return layoutPersistence.findByG_P_L(groupId, privateLayout, layoutId);
1244            }
1245    
1246            /**
1247             * Returns the layout for the icon image; throws a {@link
1248             * com.liferay.portal.NoSuchLayoutException} otherwise.
1249             *
1250             * @param  iconImageId the primary key of the icon image
1251             * @return Returns the layout for the icon image
1252             * @throws PortalException if an icon image with the primary key could not
1253             *         be found
1254             */
1255            @Override
1256            public Layout getLayoutByIconImageId(long iconImageId)
1257                    throws PortalException {
1258    
1259                    return layoutPersistence.findByIconImageId(iconImageId);
1260            }
1261    
1262            /**
1263             * Returns all the layouts belonging to the group.
1264             *
1265             * @param  groupId the primary key of the group
1266             * @param  privateLayout whether the layout is private to the group
1267             * @return the matching layouts, or <code>null</code> if no matches were
1268             *         found
1269             */
1270            @Override
1271            public List<Layout> getLayouts(long groupId, boolean privateLayout) {
1272                    return layoutPersistence.findByG_P(groupId, privateLayout);
1273            }
1274    
1275            /**
1276             * Returns all the layouts belonging to the group that are children of the
1277             * parent layout.
1278             *
1279             * @param  groupId the primary key of the group
1280             * @param  privateLayout whether the layout is private to the group
1281             * @param  parentLayoutId the primary key of the parent layout
1282             * @return the matching layouts, or <code>null</code> if no matches were
1283             *         found
1284             */
1285            @Override
1286            public List<Layout> getLayouts(
1287                    long groupId, boolean privateLayout, long parentLayoutId) {
1288    
1289                    return layoutPersistence.findByG_P_P(
1290                            groupId, privateLayout, parentLayoutId);
1291            }
1292    
1293            /**
1294             * Returns a range of all the layouts belonging to the group that are
1295             * children of the parent layout.
1296             *
1297             * <p>
1298             * Useful when paginating results. Returns a maximum of <code>end -
1299             * start</code> instances. <code>start</code> and <code>end</code> are not
1300             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1301             * refers to the first result in the set. Setting both <code>start</code>
1302             * and <code>end</code> to {@link
1303             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1304             * result set.
1305             * </p>
1306             *
1307             * @param  groupId the primary key of the group
1308             * @param  privateLayout whether the layout is private to the group
1309             * @param  parentLayoutId the primary key of the parent layout
1310             * @param  incomplete whether the layout is incomplete
1311             * @param  start the lower bound of the range of layouts
1312             * @param  end the upper bound of the range of layouts (not inclusive)
1313             * @return the matching layouts, or <code>null</code> if no matches were
1314             *         found
1315             */
1316            @Override
1317            public List<Layout> getLayouts(
1318                    long groupId, boolean privateLayout, long parentLayoutId,
1319                    boolean incomplete, int start, int end) {
1320    
1321                    return layoutPersistence.findByG_P_P(
1322                            groupId, privateLayout, parentLayoutId, start, end);
1323            }
1324    
1325            /**
1326             * Returns all the layouts that match the layout IDs and belong to the
1327             * group.
1328             *
1329             * @param  groupId the primary key of the group
1330             * @param  privateLayout whether the layout is private to the group
1331             * @param  layoutIds the primary keys of the layouts
1332             * @return the matching layouts, or an empty list if no matches were found
1333             * @throws PortalException if a group or layout with the primary key could
1334             *         not be found
1335             */
1336            @Override
1337            public List<Layout> getLayouts(
1338                            long groupId, boolean privateLayout, long[] layoutIds)
1339                    throws PortalException {
1340    
1341                    List<Layout> layouts = new ArrayList<>();
1342    
1343                    for (long layoutId : layoutIds) {
1344                            Layout layout = getLayout(groupId, privateLayout, layoutId);
1345    
1346                            layouts.add(layout);
1347                    }
1348    
1349                    return layouts;
1350            }
1351    
1352            /**
1353             * Returns all the layouts that match the type and belong to the group.
1354             *
1355             * @param  groupId the primary key of the group
1356             * @param  privateLayout whether the layout is private to the group
1357             * @param  type the type of the layouts (optionally {@link
1358             *         com.liferay.portal.model.LayoutConstants#TYPE_PORTLET})
1359             * @return the matching layouts, or <code>null</code> if no matches were
1360             *         found
1361             */
1362            @Override
1363            public List<Layout> getLayouts(
1364                    long groupId, boolean privateLayout, String type) {
1365    
1366                    return layoutPersistence.findByG_P_T(groupId, privateLayout, type);
1367            }
1368    
1369            /**
1370             * Returns the layout references for all the layouts that belong to the
1371             * company and belong to the portlet that matches the preferences.
1372             *
1373             * @param  companyId the primary key of the company
1374             * @param  portletId the primary key of the portlet
1375             * @param  preferencesKey the portlet's preference key
1376             * @param  preferencesValue the portlet's preference value
1377             * @return the layout references of the matching layouts
1378             */
1379            @Override
1380            public LayoutReference[] getLayouts(
1381                    long companyId, String portletId, String preferencesKey,
1382                    String preferencesValue) {
1383    
1384                    List<LayoutReference> layoutReferences = layoutFinder.findByC_P_P(
1385                            companyId, portletId, preferencesKey, preferencesValue);
1386    
1387                    return layoutReferences.toArray(
1388                            new LayoutReference[layoutReferences.size()]);
1389            }
1390    
1391            @Override
1392            public List<Layout> getLayoutsByLayoutPrototypeUuid(
1393                    String layoutPrototypeUuid) {
1394    
1395                    return layoutPersistence.findByLayoutPrototypeUuid(layoutPrototypeUuid);
1396            }
1397    
1398            @Override
1399            public int getLayoutsByLayoutPrototypeUuidCount(
1400                    String layoutPrototypeUuid) {
1401    
1402                    return layoutPersistence.countByLayoutPrototypeUuid(
1403                            layoutPrototypeUuid);
1404            }
1405    
1406            @Override
1407            public int getLayoutsCount(Group group, boolean privateLayout)
1408                    throws PortalException {
1409    
1410                    return getLayoutsCount(group, privateLayout, true);
1411            }
1412    
1413            @Override
1414            public int getLayoutsCount(
1415                            Group group, boolean privateLayout, boolean includeUserGroups)
1416                    throws PortalException {
1417    
1418                    LayoutSet layoutSet = layoutSetPersistence.findByG_P(
1419                            group.getGroupId(), privateLayout);
1420    
1421                    int count = layoutSet.getPageCount();
1422    
1423                    if (!group.isUser() || !includeUserGroups) {
1424                            return count;
1425                    }
1426    
1427                    long[] userGroupIds = userPersistence.getUserGroupPrimaryKeys(
1428                            group.getClassPK());
1429    
1430                    if (userGroupIds.length != 0) {
1431                            long userGroupClassNameId = classNameLocalService.getClassNameId(
1432                                    UserGroup.class);
1433    
1434                            for (long userGroupId : userGroupIds) {
1435                                    Group userGroupGroup = groupPersistence.findByC_C_C(
1436                                            group.getCompanyId(), userGroupClassNameId, userGroupId);
1437    
1438                                    layoutSet = layoutSetPersistence.findByG_P(
1439                                            userGroupGroup.getGroupId(), privateLayout);
1440    
1441                                    count += layoutSet.getPageCount();
1442                            }
1443                    }
1444    
1445                    return count;
1446            }
1447    
1448            @Override
1449            public int getLayoutsCount(
1450                    Group group, boolean privateLayout, long parentLayoutId) {
1451    
1452                    return layoutPersistence.countByG_P_P(
1453                            group.getGroupId(), privateLayout, parentLayoutId);
1454            }
1455    
1456            @Override
1457            public int getLayoutsCount(User user, boolean privateLayout)
1458                    throws PortalException {
1459    
1460                    return getLayoutsCount(user, privateLayout, true);
1461            }
1462    
1463            @Override
1464            public int getLayoutsCount(
1465                            User user, boolean privateLayout, boolean includeUserGroups)
1466                    throws PortalException {
1467    
1468                    long classNameId = classNameLocalService.getClassNameId(User.class);
1469    
1470                    Group group = groupPersistence.findByC_C_C(
1471                            user.getCompanyId(), classNameId, user.getUserId());
1472    
1473                    return getLayoutsCount(group, privateLayout, includeUserGroups);
1474            }
1475    
1476            /**
1477             * Returns the primary key to use for the next layout.
1478             *
1479             * @param  groupId the primary key of the group
1480             * @param  privateLayout whether the layout is private to the group
1481             * @return the primary key to use for the next layout
1482             */
1483            @Override
1484            public long getNextLayoutId(long groupId, boolean privateLayout) {
1485                    long nextLayoutId = counterLocalService.increment(
1486                            getCounterName(groupId, privateLayout));
1487    
1488                    if (nextLayoutId == 1) {
1489                            List<Layout> layouts = layoutPersistence.findByG_P(
1490                                    groupId, privateLayout, 0, 1, new LayoutComparator());
1491    
1492                            if (!layouts.isEmpty()) {
1493                                    Layout layout = layouts.get(0);
1494    
1495                                    nextLayoutId = layout.getLayoutId() + 1;
1496    
1497                                    counterLocalService.reset(
1498                                            getCounterName(groupId, privateLayout), nextLayoutId);
1499                            }
1500                    }
1501    
1502                    return nextLayoutId;
1503            }
1504    
1505            /**
1506             * Returns all the layouts without resource permissions
1507             *
1508             * @param  roleId the primary key of the role
1509             * @return all the layouts without resource permissions
1510             */
1511            @Override
1512            public List<Layout> getNoPermissionLayouts(long roleId) {
1513                    return layoutFinder.findByNoPermissions(roleId);
1514            }
1515    
1516            /**
1517             * Returns all the layouts whose friendly URLs are <code>null</code>
1518             *
1519             * @return all the layouts whose friendly URLs are <code>null</code>
1520             */
1521            @Override
1522            public List<Layout> getNullFriendlyURLLayouts() {
1523                    return layoutFinder.findByNullFriendlyURL();
1524            }
1525    
1526            @Override
1527            public Layout getParentLayout(Layout layout) throws PortalException {
1528                    Layout parentLayout = null;
1529    
1530                    if (layout instanceof VirtualLayout) {
1531                            VirtualLayout virtualLayout = (VirtualLayout)layout;
1532    
1533                            Layout sourceLayout = virtualLayout.getSourceLayout();
1534    
1535                            parentLayout = getLayout(
1536                                    sourceLayout.getGroupId(), sourceLayout.isPrivateLayout(),
1537                                    sourceLayout.getParentLayoutId());
1538    
1539                            parentLayout = new VirtualLayout(parentLayout, layout.getGroup());
1540                    }
1541                    else {
1542                            parentLayout = getLayout(
1543                                    layout.getGroupId(), layout.isPrivateLayout(),
1544                                    layout.getParentLayoutId());
1545                    }
1546    
1547                    return parentLayout;
1548            }
1549    
1550            /**
1551             * Returns all the layouts within scope of the group
1552             *
1553             * @param  groupId the primary key of the group
1554             * @param  privateLayout whether the layout is private to the group
1555             * @return the layouts within scope of the group
1556             */
1557            @Override
1558            public List<Layout> getScopeGroupLayouts(
1559                    long groupId, boolean privateLayout) {
1560    
1561                    return layoutFinder.findByScopeGroup(groupId, privateLayout);
1562            }
1563    
1564            @Override
1565            public boolean hasLayouts(Group group, boolean privateLayout)
1566                    throws PortalException {
1567    
1568                    return hasLayouts(group, privateLayout, true);
1569            }
1570    
1571            @Override
1572            public boolean hasLayouts(
1573                            Group group, boolean privateLayout, boolean includeUserGroups)
1574                    throws PortalException {
1575    
1576                    LayoutSet layoutSet = layoutSetPersistence.findByG_P(
1577                            group.getGroupId(), privateLayout);
1578    
1579                    if (layoutSet.getPageCount() > 0) {
1580                            return true;
1581                    }
1582    
1583                    if (!group.isUser() || !includeUserGroups) {
1584                            return false;
1585                    }
1586    
1587                    long[] userGroupIds = userPersistence.getUserGroupPrimaryKeys(
1588                            group.getClassPK());
1589    
1590                    if (userGroupIds.length != 0) {
1591                            long userGroupClassNameId = classNameLocalService.getClassNameId(
1592                                    UserGroup.class);
1593    
1594                            for (long userGroupId : userGroupIds) {
1595                                    Group userGroupGroup = groupPersistence.findByC_C_C(
1596                                            group.getCompanyId(), userGroupClassNameId, userGroupId);
1597    
1598                                    layoutSet = layoutSetPersistence.findByG_P(
1599                                            userGroupGroup.getGroupId(), privateLayout);
1600    
1601                                    if (layoutSet.getPageCount() > 0) {
1602                                            return true;
1603                                    }
1604                            }
1605                    }
1606    
1607                    return false;
1608            }
1609    
1610            /**
1611             * Returns <code>true</code> if the group has any layouts;
1612             * <code>false</code> otherwise.
1613             *
1614             * @param  groupId the primary key of the group
1615             * @param  privateLayout whether the layout is private to the group
1616             * @param  parentLayoutId the primary key of the parent layout
1617             * @return <code>true</code> if the group has any layouts;
1618             *         <code>false</code> otherwise
1619             */
1620            @Override
1621            public boolean hasLayouts(
1622                    long groupId, boolean privateLayout, long parentLayoutId) {
1623    
1624                    return layoutPersistence.countByG_P_P(
1625                            groupId, privateLayout, parentLayoutId) > 0;
1626            }
1627    
1628            @Override
1629            public boolean hasLayouts(User user, boolean privateLayout)
1630                    throws PortalException {
1631    
1632                    return hasLayouts(user, privateLayout, true);
1633            }
1634    
1635            @Override
1636            public boolean hasLayouts(
1637                            User user, boolean privateLayout, boolean includeUserGroups)
1638                    throws PortalException {
1639    
1640                    long classNameId = classNameLocalService.getClassNameId(User.class);
1641    
1642                    Group group = groupPersistence.findByC_C_C(
1643                            user.getCompanyId(), classNameId, user.getUserId());
1644    
1645                    return hasLayouts(group, privateLayout, includeUserGroups);
1646            }
1647    
1648            @Override
1649            public boolean hasLayoutSetPrototypeLayout(
1650                            long layoutSetPrototypeId, String layoutUuid)
1651                    throws PortalException {
1652    
1653                    LayoutSetPrototype layoutSetPrototype =
1654                            layoutSetPrototypeLocalService.getLayoutSetPrototype(
1655                                    layoutSetPrototypeId);
1656    
1657                    return layoutLocalServiceHelper.hasLayoutSetPrototypeLayout(
1658                            layoutSetPrototype, layoutUuid);
1659            }
1660    
1661            @Override
1662            public boolean hasLayoutSetPrototypeLayout(
1663                            String layoutSetPrototypeUuid, long companyId, String layoutUuid)
1664                    throws PortalException {
1665    
1666                    LayoutSetPrototype layoutSetPrototype =
1667                            layoutSetPrototypeLocalService.
1668                                    getLayoutSetPrototypeByUuidAndCompanyId(
1669                                            layoutSetPrototypeUuid, companyId);
1670    
1671                    return layoutLocalServiceHelper.hasLayoutSetPrototypeLayout(
1672                            layoutSetPrototype, layoutUuid);
1673            }
1674    
1675            /**
1676             * @throws     PortalException
1677             * @deprecated As of 7.0.0, replaced by {@link
1678             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#importLayouts(
1679             *             ExportImportConfiguration, File)}}
1680             */
1681            @Deprecated
1682            @Override
1683            public void importLayouts(
1684                            ExportImportConfiguration exportImportConfiguration, File file)
1685                    throws PortalException {
1686    
1687                    throw new UnsupportedOperationException();
1688            }
1689    
1690            /**
1691             * @throws     PortalException
1692             * @deprecated As of 7.0.0, replaced by {@link
1693             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#importLayouts(
1694             *             ExportImportConfiguration, InputStream)}}
1695             */
1696            @Deprecated
1697            @Override
1698            public void importLayouts(
1699                            ExportImportConfiguration exportImportConfiguration, InputStream is)
1700                    throws PortalException {
1701    
1702                    throw new UnsupportedOperationException();
1703            }
1704    
1705            /**
1706             * Imports the layouts from the byte array.
1707             *
1708             * @param      userId the primary key of the user
1709             * @param      groupId the primary key of the group
1710             * @param      privateLayout whether the layout is private to the group
1711             * @param      parameterMap the mapping of parameters indicating which
1712             *             information will be imported. For information on the keys
1713             *             used in the map see {@link
1714             *             com.liferay.portlet.exportimport.lar.PortletDataHandlerKeys}.
1715             * @param      bytes the byte array with the data
1716             * @throws     PortalException if a group or user with the primary key could
1717             *             not be found, or if some other portal exception occurred
1718             * @see        com.liferay.portlet.exportimport.lar.LayoutImporter
1719             * @deprecated As of 7.0.0, with no direct replacement
1720             */
1721            @Deprecated
1722            @Override
1723            public void importLayouts(
1724                            long userId, long groupId, boolean privateLayout,
1725                            Map<String, String[]> parameterMap, byte[] bytes)
1726                    throws PortalException {
1727    
1728                    throw new UnsupportedOperationException();
1729            }
1730    
1731            /**
1732             * Imports the layouts from the file.
1733             *
1734             * @param      userId the primary key of the user
1735             * @param      groupId the primary key of the group
1736             * @param      privateLayout whether the layout is private to the group
1737             * @param      parameterMap the mapping of parameters indicating which
1738             *             information will be imported. For information on the keys
1739             *             used in the map see {@link
1740             *             com.liferay.portlet.exportimport.lar.PortletDataHandlerKeys}.
1741             * @param      file the LAR file with the data
1742             * @throws     PortalException if a group or user with the primary key could
1743             *             not be found, or if some other portal exception occurred
1744             * @see        com.liferay.portlet.exportimport.lar.LayoutImporter
1745             * @deprecated As of 7.0.0, with no direct replacement
1746             */
1747            @Deprecated
1748            @Override
1749            public void importLayouts(
1750                            long userId, long groupId, boolean privateLayout,
1751                            Map<String, String[]> parameterMap, File file)
1752                    throws PortalException {
1753    
1754                    throw new UnsupportedOperationException();
1755            }
1756    
1757            /**
1758             * Imports the layouts from the input stream.
1759             *
1760             * @param      userId the primary key of the user
1761             * @param      groupId the primary key of the group
1762             * @param      privateLayout whether the layout is private to the group
1763             * @param      parameterMap the mapping of parameters indicating which
1764             *             information will be imported. For information on the keys
1765             *             used in the map see {@link
1766             *             com.liferay.portlet.exportimport.lar.PortletDataHandlerKeys}.
1767             * @param      is the input stream
1768             * @throws     PortalException if a group or user with the primary key could
1769             *             not be found, or if some other portal exception occurred
1770             * @see        com.liferay.portlet.exportimport.lar.LayoutImporter
1771             * @deprecated As of 7.0.0, with no direct replacement
1772             */
1773            @Deprecated
1774            @Override
1775            public void importLayouts(
1776                            long userId, long groupId, boolean privateLayout,
1777                            Map<String, String[]> parameterMap, InputStream is)
1778                    throws PortalException {
1779    
1780                    throw new UnsupportedOperationException();
1781            }
1782    
1783            /**
1784             * @throws     PortalException
1785             * @deprecated As of 7.0.0, replaced by {@link
1786             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#importLayoutsDataDeletions(
1787             *             ExportImportConfiguration, File)}
1788             */
1789            @Deprecated
1790            @Override
1791            public void importLayoutsDataDeletions(
1792                            ExportImportConfiguration exportImportConfiguration, File file)
1793                    throws PortalException {
1794    
1795                    throw new UnsupportedOperationException();
1796            }
1797    
1798            /**
1799             * @throws     PortalException
1800             * @deprecated As of 7.0.0, replaced by {@link
1801             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#importLayoutsInBackground(
1802             *             long, ExportImportConfiguration, File)}
1803             */
1804            @Deprecated
1805            @Override
1806            public long importLayoutsInBackground(
1807                            long userId, ExportImportConfiguration exportImportConfiguration,
1808                            File file)
1809                    throws PortalException {
1810    
1811                    throw new UnsupportedOperationException();
1812            }
1813    
1814            /**
1815             * @throws     PortalException
1816             * @deprecated As of 7.0.0, replaced by {@link
1817             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#importLayoutsInBackground(
1818             *             long, long, File)}
1819             */
1820            @Deprecated
1821            @Override
1822            public long importLayoutsInBackground(
1823                            long userId, long exportImportConfigurationId, File file)
1824                    throws PortalException {
1825    
1826                    throw new UnsupportedOperationException();
1827            }
1828    
1829            /**
1830             * @throws     PortalException
1831             * @deprecated As of 7.0.0, with no direct replacement
1832             */
1833            @Deprecated
1834            @Override
1835            public long importLayoutsInBackground(
1836                            long userId, String taskName, long groupId, boolean privateLayout,
1837                            Map<String, String[]> parameterMap, File file)
1838                    throws PortalException {
1839    
1840                    throw new UnsupportedOperationException();
1841            }
1842    
1843            /**
1844             * @throws     PortalException
1845             * @deprecated As of 7.0.0, with no direct replacement
1846             */
1847            @Deprecated
1848            @Override
1849            public long importLayoutsInBackground(
1850                            long userId, String taskName, long groupId, boolean privateLayout,
1851                            Map<String, String[]> parameterMap, InputStream is)
1852                    throws PortalException {
1853    
1854                    throw new UnsupportedOperationException();
1855            }
1856    
1857            /**
1858             * @throws     PortalException
1859             * @deprecated As of 7.0.0, replaced by {@link
1860             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#importPortletDataDeletions(
1861             *             ExportImportConfiguration, File)}
1862             */
1863            @Deprecated
1864            @Override
1865            public void importPortletDataDeletions(
1866                            ExportImportConfiguration exportImportConfiguration, File file)
1867                    throws PortalException {
1868    
1869                    throw new UnsupportedOperationException();
1870            }
1871    
1872            /**
1873             * @throws     PortalException
1874             * @deprecated As of 7.0.0, replaced by {@link
1875             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#importPortletInfo(
1876             *             ExportImportConfiguration, File)}
1877             */
1878            @Deprecated
1879            @Override
1880            public void importPortletInfo(
1881                            ExportImportConfiguration exportImportConfiguration, File file)
1882                    throws PortalException {
1883    
1884                    throw new UnsupportedOperationException();
1885            }
1886    
1887            /**
1888             * @throws     PortalException
1889             * @deprecated As of 7.0.0, replaced by {@link
1890             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#importPortletInfo(
1891             *             ExportImportConfiguration, InputStream)}
1892             */
1893            @Deprecated
1894            @Override
1895            public void importPortletInfo(
1896                            ExportImportConfiguration exportImportConfiguration, InputStream is)
1897                    throws PortalException {
1898    
1899                    throw new UnsupportedOperationException();
1900            }
1901    
1902            /**
1903             * Imports the portlet information (categories, permissions, ... etc.) from
1904             * the file.
1905             *
1906             * @param      userId the primary key of the user
1907             * @param      plid the primary key of the target layout
1908             * @param      groupId the primary key of the target group
1909             * @param      portletId the primary key of the portlet
1910             * @param      parameterMap the mapping of parameters indicating which
1911             *             information will be imported. For information on the keys
1912             *             used in the map see {@link
1913             *             com.liferay.portlet.exportimport.lar.PortletDataHandlerKeys}.
1914             * @param      file the LAR file with the data
1915             * @throws     PortalException if a group, layout, portlet or user with the
1916             *             primary key could not be found
1917             * @deprecated As of 7.0.0, with no direct replacement
1918             */
1919            @Deprecated
1920            @Override
1921            public void importPortletInfo(
1922                            long userId, long plid, long groupId, String portletId,
1923                            Map<String, String[]> parameterMap, File file)
1924                    throws PortalException {
1925    
1926                    throw new UnsupportedOperationException();
1927            }
1928    
1929            /**
1930             * Imports the portlet information (categories, permissions, ... etc.) from
1931             * the input stream.
1932             *
1933             * @param      userId the primary key of the user
1934             * @param      plid the primary key of the layout
1935             * @param      groupId the primary key of the group
1936             * @param      portletId the primary key of the portlet
1937             * @param      parameterMap the mapping of parameters indicating which
1938             *             information will be imported. For information on the keys
1939             *             used in the map see {@link
1940             *             com.liferay.portlet.exportimport.lar.PortletDataHandlerKeys}.
1941             * @param      is the input stream
1942             * @throws     PortalException if a group, portlet, layout or user with the
1943             *             primary key could not be found
1944             * @deprecated As of 7.0.0, with no direct replacement
1945             */
1946            @Deprecated
1947            @Override
1948            public void importPortletInfo(
1949                            long userId, long plid, long groupId, String portletId,
1950                            Map<String, String[]> parameterMap, InputStream is)
1951                    throws PortalException {
1952    
1953                    throw new UnsupportedOperationException();
1954            }
1955    
1956            /**
1957             * @throws     PortalException
1958             * @deprecated As of 7.0.0, with no direct replacement
1959             */
1960            @Deprecated
1961            @Override
1962            public void importPortletInfo(
1963                            long userId, String portletId, Map<String, String[]> parameterMap,
1964                            File file)
1965                    throws PortalException {
1966    
1967                    throw new UnsupportedOperationException();
1968            }
1969    
1970            /**
1971             * @throws     PortalException
1972             * @deprecated As of 7.0.0, with no direct replacement
1973             */
1974            @Deprecated
1975            @Override
1976            public void importPortletInfo(
1977                            long userId, String portletId, Map<String, String[]> parameterMap,
1978                            InputStream is)
1979                    throws PortalException {
1980    
1981                    throw new UnsupportedOperationException();
1982            }
1983    
1984            /**
1985             * @throws     PortalException
1986             * @deprecated As of 7.0.0, replaced by {@link
1987             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#importPortletInfoInBackground(
1988             *             long, ExportImportConfiguration, File)}
1989             */
1990            @Deprecated
1991            @Override
1992            public long importPortletInfoInBackground(
1993                            long userId, ExportImportConfiguration exportImportConfiguration,
1994                            File file)
1995                    throws PortalException {
1996    
1997                    throw new UnsupportedOperationException();
1998            }
1999    
2000            /**
2001             * @throws     PortalException
2002             * @deprecated As of 7.0.0, replaced by {@link
2003             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#importPortletInfoInBackground(
2004             *             long, long, File)}
2005             */
2006            @Deprecated
2007            @Override
2008            public long importPortletInfoInBackground(
2009                            long userId, long exportImportConfigurationId, File file)
2010                    throws PortalException {
2011    
2012                    throw new UnsupportedOperationException();
2013            }
2014    
2015            /**
2016             * @throws     PortalException
2017             * @deprecated As of 7.0.0, with no direct replacement
2018             */
2019            @Deprecated
2020            @Override
2021            public long importPortletInfoInBackground(
2022                            long userId, String taskName, long plid, long groupId,
2023                            String portletId, Map<String, String[]> parameterMap, File file)
2024                    throws PortalException {
2025    
2026                    throw new UnsupportedOperationException();
2027            }
2028    
2029            /**
2030             * @throws     PortalException
2031             * @deprecated As of 7.0.0, with no direct replacement
2032             */
2033            @Deprecated
2034            @Override
2035            public long importPortletInfoInBackground(
2036                            long userId, String taskName, long plid, long groupId,
2037                            String portletId, Map<String, String[]> parameterMap,
2038                            InputStream is)
2039                    throws PortalException {
2040    
2041                    throw new UnsupportedOperationException();
2042            }
2043    
2044            /**
2045             * @throws     PortalException
2046             * @deprecated As of 7.0.0, with no direct replacement
2047             */
2048            @Deprecated
2049            @Override
2050            public long importPortletInfoInBackground(
2051                            long userId, String taskName, String portletId,
2052                            Map<String, String[]> parameterMap, File file)
2053                    throws PortalException {
2054    
2055                    throw new UnsupportedOperationException();
2056            }
2057    
2058            /**
2059             * @throws     PortalException
2060             * @deprecated As of 7.0.0, with no direct replacement
2061             */
2062            @Deprecated
2063            @Override
2064            public long importPortletInfoInBackground(
2065                            long userId, String taskName, String portletId,
2066                            Map<String, String[]> parameterMap, InputStream is)
2067                    throws PortalException {
2068    
2069                    throw new UnsupportedOperationException();
2070            }
2071    
2072            /**
2073             * Sets the layouts for the group, replacing and prioritizing all layouts of
2074             * the parent layout.
2075             *
2076             * @param  groupId the primary key of the group
2077             * @param  privateLayout whether the layout is private to the group
2078             * @param  parentLayoutId the primary key of the parent layout
2079             * @param  layoutIds the primary keys of the layouts
2080             * @param  serviceContext the service context to be applied
2081             * @throws PortalException if a group or layout with the primary key could
2082             *         not be found, if no layouts were specified, if the first layout
2083             *         was not page-able, if the first layout was hidden, or if some
2084             *         other portal exception occurred
2085             */
2086            @Override
2087            public void setLayouts(
2088                            long groupId, boolean privateLayout, long parentLayoutId,
2089                            long[] layoutIds, ServiceContext serviceContext)
2090                    throws PortalException {
2091    
2092                    if (layoutIds == null) {
2093                            return;
2094                    }
2095    
2096                    if (parentLayoutId == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
2097                            if (layoutIds.length < 1) {
2098                                    throw new RequiredLayoutException(
2099                                            RequiredLayoutException.AT_LEAST_ONE);
2100                            }
2101    
2102                            Layout layout = layoutPersistence.findByG_P_L(
2103                                    groupId, privateLayout, layoutIds[0]);
2104    
2105                            LayoutType layoutType = layout.getLayoutType();
2106    
2107                            if (!layoutType.isFirstPageable()) {
2108                                    throw new RequiredLayoutException(
2109                                            RequiredLayoutException.FIRST_LAYOUT_TYPE);
2110                            }
2111                    }
2112    
2113                    Set<Long> layoutIdsSet = new LinkedHashSet<>();
2114    
2115                    for (long layoutId : layoutIds) {
2116                            layoutIdsSet.add(layoutId);
2117                    }
2118    
2119                    Set<Long> newLayoutIdsSet = new HashSet<>();
2120    
2121                    List<Layout> layouts = layoutPersistence.findByG_P_P(
2122                            groupId, privateLayout, parentLayoutId);
2123    
2124                    for (Layout layout : layouts) {
2125                            if (!layoutIdsSet.contains(layout.getLayoutId())) {
2126                                    deleteLayout(layout, true, serviceContext);
2127                            }
2128                            else {
2129                                    newLayoutIdsSet.add(layout.getLayoutId());
2130                            }
2131                    }
2132    
2133                    int priority = 0;
2134    
2135                    for (long layoutId : layoutIdsSet) {
2136                            Layout layout = layoutPersistence.findByG_P_L(
2137                                    groupId, privateLayout, layoutId);
2138    
2139                            layout.setPriority(priority++);
2140    
2141                            layoutPersistence.update(layout);
2142                    }
2143    
2144                    layoutSetLocalService.updatePageCount(groupId, privateLayout);
2145            }
2146    
2147            @Override
2148            public void updateAsset(
2149                            long userId, Layout layout, long[] assetCategoryIds,
2150                            String[] assetTagNames)
2151                    throws PortalException {
2152    
2153                    assetEntryLocalService.updateEntry(
2154                            userId, layout.getGroupId(), layout.getCreateDate(),
2155                            layout.getModifiedDate(), Layout.class.getName(), layout.getPlid(),
2156                            layout.getUuid(), 0, assetCategoryIds, assetTagNames, false, null,
2157                            null, null, ContentTypes.TEXT_HTML,
2158                            layout.getName(LocaleUtil.getDefault()), null, null, null, null, 0,
2159                            0, null);
2160            }
2161    
2162            /**
2163             * Updates the friendly URL of the layout.
2164             *
2165             * @param  userId the primary key of the user
2166             * @param  plid the primary key of the layout
2167             * @param  friendlyURL the friendly URL to be assigned
2168             * @param  languageId the primary key of the language
2169             * @return the updated layout
2170             * @throws PortalException if a group or layout with the primary key could
2171             *         not be found
2172             */
2173            @Override
2174            public Layout updateFriendlyURL(
2175                            long userId, long plid, String friendlyURL, String languageId)
2176                    throws PortalException {
2177    
2178                    Date now = new Date();
2179    
2180                    Layout layout = layoutPersistence.findByPrimaryKey(plid);
2181    
2182                    friendlyURL = layoutLocalServiceHelper.getFriendlyURL(
2183                            layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
2184                            StringPool.BLANK, friendlyURL);
2185    
2186                    layoutLocalServiceHelper.validateFriendlyURL(
2187                            layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
2188                            friendlyURL);
2189    
2190                    layoutFriendlyURLLocalService.updateLayoutFriendlyURL(
2191                            userId, layout.getCompanyId(), layout.getGroupId(),
2192                            layout.getPlid(), layout.isPrivateLayout(), friendlyURL, languageId,
2193                            new ServiceContext());
2194    
2195                    layout.setModifiedDate(now);
2196    
2197                    String defaultLanguageId = LocaleUtil.toLanguageId(
2198                            LocaleUtil.getSiteDefault());
2199    
2200                    if (languageId.equals(defaultLanguageId)) {
2201                            layout.setFriendlyURL(friendlyURL);
2202                    }
2203    
2204                    layoutPersistence.update(layout);
2205    
2206                    return layout;
2207            }
2208    
2209            /**
2210             * Updates the friendly URL of the layout.
2211             *
2212             * @param      plid the primary key of the layout
2213             * @param      friendlyURL the friendly URL to be assigned
2214             * @param      languageId the primary key of the language
2215             * @return     the updated layout
2216             * @throws     PortalException if a group or layout with the primary key
2217             *             could not be found
2218             * @deprecated As of 7.0.0, replaced by {@link #updateFriendlyURL(long,
2219             *             long, String, String)}
2220             */
2221            @Deprecated
2222            @Override
2223            public Layout updateFriendlyURL(
2224                            long plid, String friendlyURL, String languageId)
2225                    throws PortalException {
2226    
2227                    Layout layout = layoutPersistence.findByPrimaryKey(plid);
2228    
2229                    return updateFriendlyURL(
2230                            layout.getUserId(), plid, friendlyURL, languageId);
2231            }
2232    
2233            @Override
2234            public Layout updateIconImage(long plid, byte[] bytes)
2235                    throws PortalException {
2236    
2237                    Layout layout = layoutPersistence.fetchByPrimaryKey(plid);
2238    
2239                    if (layout == null) {
2240                            return null;
2241                    }
2242    
2243                    PortalUtil.updateImageId(layout, true, bytes, "iconImageId", 0, 0, 0);
2244    
2245                    layoutPersistence.update(layout);
2246    
2247                    return layout;
2248            }
2249    
2250            /**
2251             * Updates the layout.
2252             *
2253             * @param  groupId the primary key of the group
2254             * @param  privateLayout whether the layout is private to the group
2255             * @param  layoutId the primary key of the layout
2256             * @param  parentLayoutId the primary key of the layout's new parent layout
2257             * @param  nameMap the locales and localized names to merge (optionally
2258             *         <code>null</code>)
2259             * @param  titleMap the locales and localized titles to merge (optionally
2260             *         <code>null</code>)
2261             * @param  descriptionMap the locales and localized descriptions to merge
2262             *         (optionally <code>null</code>)
2263             * @param  keywordsMap the locales and localized keywords to merge
2264             *         (optionally <code>null</code>)
2265             * @param  robotsMap the locales and localized robots to merge (optionally
2266             *         <code>null</code>)
2267             * @param  type the layout's new type (optionally {@link
2268             *         com.liferay.portal.model.LayoutConstants#TYPE_PORTLET})
2269             * @param  hidden whether the layout is hidden
2270             * @param  friendlyURLMap the layout's locales and localized friendly URLs.
2271             *         To see how the URL is normalized when accessed, see {@link
2272             *         com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
2273             *         String)}.
2274             * @param  iconImage whether the icon image will be updated
2275             * @param  iconBytes the byte array of the layout's new icon image
2276             * @param  serviceContext the service context to be applied. Can set the
2277             *         modification date and expando bridge attributes for the layout.
2278             *         For layouts that are linked to a layout prototype, attributes
2279             *         named <code>layoutPrototypeUuid</code> and
2280             *         <code>layoutPrototypeLinkedEnabled</code> can be specified to
2281             *         provide the unique identifier of the source prototype and a
2282             *         boolean to determine whether a link to it should be enabled to
2283             *         activate propagation of changes made to the linked page in the
2284             *         prototype.
2285             * @return the updated layout
2286             * @throws PortalException if a group or layout with the primary key could
2287             *         not be found, if a unique friendly URL could not be generated, if
2288             *         a valid parent layout ID to use could not be found, if the layout
2289             *         parameters were invalid, or if a portal exception occurred
2290             */
2291            @Override
2292            public Layout updateLayout(
2293                            long groupId, boolean privateLayout, long layoutId,
2294                            long parentLayoutId, Map<Locale, String> nameMap,
2295                            Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
2296                            Map<Locale, String> keywordsMap, Map<Locale, String> robotsMap,
2297                            String type, boolean hidden, Map<Locale, String> friendlyURLMap,
2298                            boolean iconImage, byte[] iconBytes, ServiceContext serviceContext)
2299                    throws PortalException {
2300    
2301                    // Layout
2302    
2303                    parentLayoutId = layoutLocalServiceHelper.getParentLayoutId(
2304                            groupId, privateLayout, parentLayoutId);
2305                    String name = nameMap.get(LocaleUtil.getSiteDefault());
2306                    friendlyURLMap = layoutLocalServiceHelper.getFriendlyURLMap(
2307                            groupId, privateLayout, layoutId, name, friendlyURLMap);
2308    
2309                    String friendlyURL = friendlyURLMap.get(LocaleUtil.getSiteDefault());
2310    
2311                    layoutLocalServiceHelper.validate(
2312                            groupId, privateLayout, layoutId, parentLayoutId, name, type,
2313                            hidden, friendlyURLMap);
2314    
2315                    layoutLocalServiceHelper.validateParentLayoutId(
2316                            groupId, privateLayout, layoutId, parentLayoutId);
2317    
2318                    Date now = new Date();
2319    
2320                    Layout layout = layoutPersistence.findByG_P_L(
2321                            groupId, privateLayout, layoutId);
2322    
2323                    if (parentLayoutId != layout.getParentLayoutId()) {
2324                            int priority = layoutLocalServiceHelper.getNextPriority(
2325                                    groupId, privateLayout, parentLayoutId,
2326                                    layout.getSourcePrototypeLayoutUuid(), -1);
2327    
2328                            layout.setPriority(priority);
2329                    }
2330    
2331                    layout.setModifiedDate(serviceContext.getModifiedDate(now));
2332                    layout.setParentLayoutId(parentLayoutId);
2333                    layout.setNameMap(nameMap);
2334                    layout.setTitleMap(titleMap);
2335                    layout.setDescriptionMap(descriptionMap);
2336                    layout.setKeywordsMap(keywordsMap);
2337                    layout.setRobotsMap(robotsMap);
2338                    layout.setType(type);
2339                    layout.setHidden(hidden);
2340                    layout.setFriendlyURL(friendlyURL);
2341    
2342                    PortalUtil.updateImageId(
2343                            layout, iconImage, iconBytes, "iconImageId", 0, 0, 0);
2344    
2345                    boolean layoutUpdateable = ParamUtil.getBoolean(
2346                            serviceContext, Sites.LAYOUT_UPDATEABLE, true);
2347    
2348                    UnicodeProperties typeSettingsProperties =
2349                            layout.getTypeSettingsProperties();
2350    
2351                    typeSettingsProperties.put(
2352                            Sites.LAYOUT_UPDATEABLE, String.valueOf(layoutUpdateable));
2353    
2354                    if (privateLayout) {
2355                            typeSettingsProperties.put(
2356                                    "privateLayout", String.valueOf(privateLayout));
2357                    }
2358    
2359                    layout.setTypeSettingsProperties(typeSettingsProperties);
2360    
2361                    String layoutPrototypeUuid = ParamUtil.getString(
2362                            serviceContext, "layoutPrototypeUuid");
2363                    boolean layoutPrototypeLinkEnabled = ParamUtil.getBoolean(
2364                            serviceContext, "layoutPrototypeLinkEnabled");
2365    
2366                    if (Validator.isNotNull(layoutPrototypeUuid)) {
2367                            layout.setLayoutPrototypeUuid(layoutPrototypeUuid);
2368                            layout.setLayoutPrototypeLinkEnabled(layoutPrototypeLinkEnabled);
2369                    }
2370    
2371                    layout.setExpandoBridgeAttributes(serviceContext);
2372    
2373                    layoutPersistence.update(layout);
2374    
2375                    // Layout friendly URLs
2376    
2377                    layoutFriendlyURLLocalService.updateLayoutFriendlyURLs(
2378                            serviceContext.getUserId(), layout.getCompanyId(),
2379                            layout.getGroupId(), layout.getPlid(), layout.isPrivateLayout(),
2380                            friendlyURLMap, serviceContext);
2381    
2382                    // Asset
2383    
2384                    updateAsset(
2385                            serviceContext.getUserId(), layout,
2386                            serviceContext.getAssetCategoryIds(),
2387                            serviceContext.getAssetTagNames());
2388    
2389                    return layout;
2390            }
2391    
2392            /**
2393             * Updates the layout.
2394             *
2395             * @param      groupId the primary key of the group
2396             * @param      privateLayout whether the layout is private to the group
2397             * @param      layoutId the primary key of the layout
2398             * @param      parentLayoutId the primary key of the layout's new parent
2399             *             layout
2400             * @param      nameMap the locales and localized names to merge (optionally
2401             *             <code>null</code>)
2402             * @param      titleMap the locales and localized titles to merge
2403             *             (optionally <code>null</code>)
2404             * @param      descriptionMap the locales and localized descriptions to
2405             *             merge (optionally <code>null</code>)
2406             * @param      keywordsMap the locales and localized keywords to merge
2407             *             (optionally <code>null</code>)
2408             * @param      robotsMap the locales and localized robots to merge
2409             *             (optionally <code>null</code>)
2410             * @param      type the layout's new type (optionally {@link
2411             *             com.liferay.portal.model.LayoutConstants#TYPE_PORTLET})
2412             * @param      hidden whether the layout is hidden
2413             * @param      friendlyURL the layout's new friendly URL (optionally {@link
2414             *             com.liferay.portal.util.PropsValues#DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL}
2415             *             or {@link
2416             *             com.liferay.portal.util.PropsValues#DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL}).
2417             *             The default values can be overridden in
2418             *             <code>portal-ext.properties</code> by specifying new values
2419             *             for the corresponding properties defined in {@link
2420             *             com.liferay.portal.util.PropsValues}. To see how the URL is
2421             *             normalized when accessed, see {@link
2422             *             com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil#normalize(
2423             *             String)}.
2424             * @param      iconImage whether the icon image will be updated
2425             * @param      iconBytes the byte array of the layout's new icon image
2426             * @param      serviceContext the service context to be applied. Can set the
2427             *             modification date and expando bridge attributes for the
2428             *             layout. For layouts that are linked to a layout prototype,
2429             *             attributes named <code>layoutPrototypeUuid</code> and
2430             *             <code>layoutPrototypeLinkedEnabled</code> can be specified to
2431             *             provide the unique identifier of the source prototype and a
2432             *             boolean to determine whether a link to it should be enabled
2433             *             to activate propagation of changes made to the linked page in
2434             *             the prototype.
2435             * @return     the updated layout
2436             * @throws     PortalException if a group or layout with the primary key
2437             *             could not be found, if a unique friendly URL could not be
2438             *             generated, if a valid parent layout ID to use could not be
2439             *             found, if the layout parameters were invalid, or if a portal
2440             *             exception occurred
2441             * @deprecated As of 6.2.0, replaced by {@link #updateLayout(long, boolean,
2442             *             long, long, Map, Map, Map, Map, Map, String, boolean, Map,
2443             *             boolean, byte[], ServiceContext)}
2444             */
2445            @Deprecated
2446            @Override
2447            public Layout updateLayout(
2448                            long groupId, boolean privateLayout, long layoutId,
2449                            long parentLayoutId, Map<Locale, String> nameMap,
2450                            Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
2451                            Map<Locale, String> keywordsMap, Map<Locale, String> robotsMap,
2452                            String type, boolean hidden, String friendlyURL, Boolean iconImage,
2453                            byte[] iconBytes, ServiceContext serviceContext)
2454                    throws PortalException {
2455    
2456                    Map<Locale, String> friendlyURLMap = new HashMap<>();
2457    
2458                    friendlyURLMap.put(LocaleUtil.getSiteDefault(), friendlyURL);
2459    
2460                    return updateLayout(
2461                            groupId, privateLayout, layoutId, parentLayoutId, nameMap, titleMap,
2462                            descriptionMap, keywordsMap, robotsMap, type, hidden,
2463                            friendlyURLMap, iconImage, iconBytes, serviceContext);
2464            }
2465    
2466            /**
2467             * Updates the layout replacing its type settings.
2468             *
2469             * @param  groupId the primary key of the group
2470             * @param  privateLayout whether the layout is private to the group
2471             * @param  layoutId the primary key of the layout
2472             * @param  typeSettings the settings to load the unicode properties object.
2473             *         See {@link com.liferay.portal.kernel.util.UnicodeProperties
2474             *         #fastLoad(String)}.
2475             * @return the updated layout
2476             * @throws PortalException if a matching layout could not be found or if a
2477             *         portal exception occurred
2478             */
2479            @Override
2480            public Layout updateLayout(
2481                            long groupId, boolean privateLayout, long layoutId,
2482                            String typeSettings)
2483                    throws PortalException {
2484    
2485                    Date now = new Date();
2486    
2487                    UnicodeProperties typeSettingsProperties = new UnicodeProperties();
2488    
2489                    typeSettingsProperties.fastLoad(typeSettings);
2490    
2491                    validateTypeSettingsProperties(typeSettingsProperties);
2492    
2493                    Layout layout = layoutPersistence.findByG_P_L(
2494                            groupId, privateLayout, layoutId);
2495    
2496                    layout.setModifiedDate(now);
2497                    layout.setTypeSettings(typeSettingsProperties.toString());
2498    
2499                    layoutPersistence.update(layout);
2500    
2501                    return layout;
2502            }
2503    
2504            /**
2505             * Updates the look and feel of the layout.
2506             *
2507             * @param  groupId the primary key of the group
2508             * @param  privateLayout whether the layout is private to the group
2509             * @param  layoutId the primary key of the layout
2510             * @param  themeId the primary key of the layout's new theme
2511             * @param  colorSchemeId the primary key of the layout's new color scheme
2512             * @param  css the layout's new CSS
2513             * @param  wapTheme whether the theme is for WAP browsers
2514             * @return the updated layout
2515             * @throws PortalException if a matching layout could not be found
2516             */
2517            @Override
2518            public Layout updateLookAndFeel(
2519                            long groupId, boolean privateLayout, long layoutId, String themeId,
2520                            String colorSchemeId, String css, boolean wapTheme)
2521                    throws PortalException {
2522    
2523                    Date now = new Date();
2524    
2525                    Layout layout = layoutPersistence.findByG_P_L(
2526                            groupId, privateLayout, layoutId);
2527    
2528                    layout.setModifiedDate(now);
2529    
2530                    if (wapTheme) {
2531                            layout.setWapThemeId(themeId);
2532                            layout.setWapColorSchemeId(colorSchemeId);
2533                    }
2534                    else {
2535                            layout.setThemeId(themeId);
2536                            layout.setColorSchemeId(colorSchemeId);
2537                            layout.setCss(css);
2538                    }
2539    
2540                    layoutPersistence.update(layout);
2541    
2542                    return layout;
2543            }
2544    
2545            /**
2546             * Updates the name of the layout.
2547             *
2548             * @param  layout the layout to be updated
2549             * @param  name the layout's new name
2550             * @param  languageId the primary key of the language. For more information
2551             *         see {@link java.util.Locale}.
2552             * @return the updated layout
2553             * @throws PortalException if the new name was <code>null</code>
2554             */
2555            @Override
2556            public Layout updateName(Layout layout, String name, String languageId)
2557                    throws PortalException {
2558    
2559                    Date now = new Date();
2560    
2561                    layoutLocalServiceHelper.validateName(name, languageId);
2562    
2563                    layout.setModifiedDate(now);
2564                    layout.setName(name, LocaleUtil.fromLanguageId(languageId));
2565    
2566                    layoutPersistence.update(layout);
2567    
2568                    Group group = layout.getGroup();
2569    
2570                    if (group.isLayoutPrototype()) {
2571                            LayoutPrototype layoutPrototype =
2572                                    layoutPrototypeLocalService.getLayoutPrototype(
2573                                            group.getClassPK());
2574    
2575                            layoutPrototype.setModifiedDate(now);
2576                            layoutPrototype.setName(
2577                                    name, LocaleUtil.fromLanguageId(languageId));
2578    
2579                            layoutPrototypePersistence.update(layoutPrototype);
2580                    }
2581    
2582                    return layout;
2583            }
2584    
2585            /**
2586             * Updates the name of the layout matching the group, layout ID, and
2587             * privacy.
2588             *
2589             * @param  groupId the primary key of the group
2590             * @param  privateLayout whether the layout is private to the group
2591             * @param  layoutId the primary key of the layout
2592             * @param  name the layout's new name
2593             * @param  languageId the primary key of the language. For more information
2594             *         see {@link java.util.Locale}.
2595             * @return the updated layout
2596             * @throws PortalException if a matching layout could not be found or if the
2597             *         new name was <code>null</code>
2598             */
2599            @Override
2600            public Layout updateName(
2601                            long groupId, boolean privateLayout, long layoutId, String name,
2602                            String languageId)
2603                    throws PortalException {
2604    
2605                    Layout layout = layoutPersistence.findByG_P_L(
2606                            groupId, privateLayout, layoutId);
2607    
2608                    return updateName(layout, name, languageId);
2609            }
2610    
2611            /**
2612             * Updates the name of the layout matching the primary key.
2613             *
2614             * @param  plid the primary key of the layout
2615             * @param  name the name to be assigned
2616             * @param  languageId the primary key of the language. For more information
2617             *         see {@link java.util.Locale}.
2618             * @return the updated layout
2619             * @throws PortalException if a layout with the primary key could not be
2620             *         found or if the name was <code>null</code>
2621             */
2622            @Override
2623            public Layout updateName(long plid, String name, String languageId)
2624                    throws PortalException {
2625    
2626                    Layout layout = layoutPersistence.findByPrimaryKey(plid);
2627    
2628                    return updateName(layout, name, languageId);
2629            }
2630    
2631            /**
2632             * Updates the parent layout ID of the layout matching the group, layout ID,
2633             * and privacy.
2634             *
2635             * @param  groupId the primary key of the group
2636             * @param  privateLayout whether the layout is private to the group
2637             * @param  layoutId the primary key of the layout
2638             * @param  parentLayoutId the primary key to be assigned to the parent
2639             *         layout
2640             * @return the matching layout
2641             * @throws PortalException if a valid parent layout ID to use could not be
2642             *         found or if a matching layout could not be found
2643             */
2644            @Override
2645            public Layout updateParentLayoutId(
2646                            long groupId, boolean privateLayout, long layoutId,
2647                            long parentLayoutId)
2648                    throws PortalException {
2649    
2650                    parentLayoutId = layoutLocalServiceHelper.getParentLayoutId(
2651                            groupId, privateLayout, parentLayoutId);
2652    
2653                    layoutLocalServiceHelper.validateParentLayoutId(
2654                            groupId, privateLayout, layoutId, parentLayoutId);
2655    
2656                    Date now = new Date();
2657    
2658                    Layout layout = layoutPersistence.findByG_P_L(
2659                            groupId, privateLayout, layoutId);
2660    
2661                    if (parentLayoutId != layout.getParentLayoutId()) {
2662                            int priority = layoutLocalServiceHelper.getNextPriority(
2663                                    groupId, privateLayout, parentLayoutId,
2664                                    layout.getSourcePrototypeLayoutUuid(), -1);
2665    
2666                            layout.setPriority(priority);
2667                    }
2668    
2669                    layout.setModifiedDate(now);
2670                    layout.setParentLayoutId(parentLayoutId);
2671    
2672                    layoutPersistence.update(layout);
2673    
2674                    return layout;
2675            }
2676    
2677            /**
2678             * Updates the parent layout ID of the layout matching the primary key. If a
2679             * layout matching the parent primary key is found, the layout ID of that
2680             * layout is assigned, otherwise {@link
2681             * com.liferay.portal.model.LayoutConstants#DEFAULT_PARENT_LAYOUT_ID} is
2682             * assigned.
2683             *
2684             * @param  plid the primary key of the layout
2685             * @param  parentPlid the primary key of the parent layout
2686             * @return the layout matching the primary key
2687             * @throws PortalException if a layout with the primary key could not be
2688             *         found or if a valid parent layout ID to use could not be found
2689             */
2690            @Override
2691            public Layout updateParentLayoutId(long plid, long parentPlid)
2692                    throws PortalException {
2693    
2694                    Date now = new Date();
2695    
2696                    Layout layout = layoutPersistence.findByPrimaryKey(plid);
2697    
2698                    long parentLayoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID;
2699    
2700                    if (parentPlid > 0) {
2701                            Layout parentLayout = layoutPersistence.fetchByPrimaryKey(
2702                                    parentPlid);
2703    
2704                            if (parentLayout != null) {
2705                                    parentLayoutId = parentLayout.getLayoutId();
2706                            }
2707                    }
2708    
2709                    parentLayoutId = layoutLocalServiceHelper.getParentLayoutId(
2710                            layout.getGroupId(), layout.isPrivateLayout(), parentLayoutId);
2711    
2712                    layoutLocalServiceHelper.validateParentLayoutId(
2713                            layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
2714                            parentLayoutId);
2715    
2716                    if (parentLayoutId != layout.getParentLayoutId()) {
2717                            int priority = layoutLocalServiceHelper.getNextPriority(
2718                                    layout.getGroupId(), layout.isPrivateLayout(), parentLayoutId,
2719                                    layout.getSourcePrototypeLayoutUuid(), -1);
2720    
2721                            layout.setPriority(priority);
2722                    }
2723    
2724                    layout.setModifiedDate(now);
2725                    layout.setParentLayoutId(parentLayoutId);
2726    
2727                    layoutPersistence.update(layout);
2728    
2729                    return layout;
2730            }
2731    
2732            /**
2733             * Updates the parent layout ID and priority of the layout.
2734             *
2735             * @param  plid the primary key of the layout
2736             * @param  parentPlid the primary key of the parent layout
2737             * @param  priority the layout's new priority
2738             * @return the layout matching the primary key
2739             * @throws PortalException if a layout with the primary key could not be
2740             *         found or if a valid parent layout ID could not be found
2741             */
2742            @Override
2743            public Layout updateParentLayoutIdAndPriority(
2744                            long plid, long parentPlid, int priority)
2745                    throws PortalException {
2746    
2747                    Layout layout = updateParentLayoutId(plid, parentPlid);
2748    
2749                    return updatePriority(layout, priority);
2750            }
2751    
2752            /**
2753             * Updates the priorities of the layouts.
2754             *
2755             * @param  groupId the primary key of the group
2756             * @param  privateLayout whether the layout is private to the group
2757             * @throws PortalException if a matching layout could not be found
2758             */
2759            @Override
2760            public void updatePriorities(long groupId, boolean privateLayout)
2761                    throws PortalException {
2762    
2763                    List<Layout> layouts = layoutPersistence.findByG_P(
2764                            groupId, privateLayout);
2765    
2766                    for (Layout layout : layouts) {
2767                            int nextPriority = layoutLocalServiceHelper.getNextPriority(
2768                                    layout.getGroupId(), layout.isPrivateLayout(),
2769                                    layout.getParentLayoutId(),
2770                                    layout.getSourcePrototypeLayoutUuid(), layout.getPriority());
2771    
2772                            layout.setPriority(nextPriority);
2773    
2774                            layoutPersistence.update(layout);
2775                    }
2776            }
2777    
2778            /**
2779             * Updates the priority of the layout.
2780             *
2781             * @param  layout the layout to be updated
2782             * @param  priority the layout's new priority
2783             * @return the updated layout
2784             * @throws PortalException if a portal exception occurred
2785             */
2786            @Override
2787            public Layout updatePriority(Layout layout, int priority)
2788                    throws PortalException {
2789    
2790                    if (layout.getPriority() == priority) {
2791                            return layout;
2792                    }
2793    
2794                    int oldPriority = layout.getPriority();
2795    
2796                    int nextPriority = layoutLocalServiceHelper.getNextPriority(
2797                            layout.getGroupId(), layout.isPrivateLayout(),
2798                            layout.getParentLayoutId(), layout.getSourcePrototypeLayoutUuid(),
2799                            priority);
2800    
2801                    if (oldPriority == nextPriority) {
2802                            return layout;
2803                    }
2804    
2805                    layout.setModifiedDate(new Date());
2806                    layout.setPriority(nextPriority);
2807    
2808                    layoutPersistence.update(layout);
2809    
2810                    List<Layout> layouts = layoutPersistence.findByG_P_P(
2811                            layout.getGroupId(), layout.isPrivateLayout(),
2812                            layout.getParentLayoutId());
2813    
2814                    boolean lessThan = false;
2815    
2816                    if (oldPriority < nextPriority) {
2817                            lessThan = true;
2818                    }
2819    
2820                    layouts = ListUtil.sort(
2821                            layouts, new LayoutPriorityComparator(layout, lessThan));
2822    
2823                    if (layout.getParentLayoutId() ==
2824                                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
2825    
2826                            Layout firstLayout = layouts.get(0);
2827    
2828                            layoutLocalServiceHelper.validateFirstLayout(firstLayout);
2829                    }
2830    
2831                    int newPriority = LayoutConstants.FIRST_PRIORITY;
2832    
2833                    for (Layout curLayout : layouts) {
2834                            int curNextPriority = layoutLocalServiceHelper.getNextPriority(
2835                                    layout.getGroupId(), layout.isPrivateLayout(),
2836                                    layout.getParentLayoutId(),
2837                                    curLayout.getSourcePrototypeLayoutUuid(), newPriority++);
2838    
2839                            if (curLayout.getPriority() == curNextPriority) {
2840                                    continue;
2841                            }
2842    
2843                            curLayout.setModifiedDate(layout.getModifiedDate());
2844                            curLayout.setPriority(curNextPriority);
2845    
2846                            layoutPersistence.update(curLayout);
2847    
2848                            if (curLayout.equals(layout)) {
2849                                    layout = curLayout;
2850                            }
2851                    }
2852    
2853                    return layout;
2854            }
2855    
2856            /**
2857             * Updates the priority of the layout matching the group, layout ID, and
2858             * privacy.
2859             *
2860             * @param  groupId the primary key of the group
2861             * @param  privateLayout whether the layout is private to the group
2862             * @param  layoutId the primary key of the layout
2863             * @param  priority the layout's new priority
2864             * @return the updated layout
2865             * @throws PortalException if a matching layout could not be found
2866             */
2867            @Override
2868            public Layout updatePriority(
2869                            long groupId, boolean privateLayout, long layoutId, int priority)
2870                    throws PortalException {
2871    
2872                    Layout layout = layoutPersistence.findByG_P_L(
2873                            groupId, privateLayout, layoutId);
2874    
2875                    return updatePriority(layout, priority);
2876            }
2877    
2878            /**
2879             * Updates the priority of the layout matching the group, layout ID, and
2880             * privacy, setting the layout's priority based on the priorities of the
2881             * next and previous layouts.
2882             *
2883             * @param  groupId the primary key of the group
2884             * @param  privateLayout whether the layout is private to the group
2885             * @param  layoutId the primary key of the layout
2886             * @param  nextLayoutId the primary key of the next layout
2887             * @param  previousLayoutId the primary key of the previous layout
2888             * @return the updated layout
2889             * @throws PortalException if a matching layout could not be found
2890             */
2891            @Override
2892            public Layout updatePriority(
2893                            long groupId, boolean privateLayout, long layoutId,
2894                            long nextLayoutId, long previousLayoutId)
2895                    throws PortalException {
2896    
2897                    Layout layout = getLayout(groupId, privateLayout, layoutId);
2898    
2899                    int priority = layout.getPriority();
2900    
2901                    Layout nextLayout = null;
2902    
2903                    if (nextLayoutId > -1) {
2904                            nextLayout = getLayout(groupId, privateLayout, nextLayoutId);
2905                    }
2906    
2907                    Layout previousLayout = null;
2908    
2909                    if (previousLayoutId > -1) {
2910                            previousLayout = getLayout(
2911                                    groupId, privateLayout, previousLayoutId);
2912                    }
2913    
2914                    if ((nextLayout != null) && (priority > nextLayout.getPriority())) {
2915                            priority = nextLayout.getPriority();
2916                    }
2917                    else if ((previousLayout != null) &&
2918                                     (priority < previousLayout.getPriority())) {
2919    
2920                            priority = previousLayout.getPriority();
2921                    }
2922    
2923                    return updatePriority(layout, priority);
2924            }
2925    
2926            /**
2927             * Updates the priority of the layout matching the primary key.
2928             *
2929             * @param  plid the primary key of the layout
2930             * @param  priority the layout's new priority
2931             * @return the updated layout
2932             * @throws PortalException if a layout with the primary key could not be
2933             *         found
2934             */
2935            @Override
2936            public Layout updatePriority(long plid, int priority)
2937                    throws PortalException {
2938    
2939                    Layout layout = layoutPersistence.findByPrimaryKey(plid);
2940    
2941                    return updatePriority(layout, priority);
2942            }
2943    
2944            /**
2945             * @deprecated As of 6.2.0, with no direct replacement
2946             */
2947            @Deprecated
2948            @Override
2949            @SuppressWarnings("unused")
2950            public void updateScopedPortletNames(
2951                            long groupId, boolean privateLayout, long layoutId,
2952                            Map<Locale, String> nameMap, List<Locale> nameMapModifiedLocales)
2953                    throws PortalException {
2954            }
2955    
2956            /**
2957             * Updates the names of the portlets within scope of the group, the scope of
2958             * the layout's UUID, and the privacy.
2959             *
2960             * @param      groupId the primary key of the group
2961             * @param      privateLayout whether the layout is private to the group
2962             * @param      layoutId the primary key of the layout whose UUID to match
2963             * @param      name the new name for the portlets
2964             * @param      languageId the primary key of the language
2965             * @throws     PortalException if a matching layout could not be found
2966             * @see        com.liferay.portlet.portletconfiguration.action.EditScopeAction
2967             * @deprecated As of 6.2.0, with no direct replacement
2968             */
2969            @Deprecated
2970            @Override
2971            public void updateScopedPortletNames(
2972                            long groupId, boolean privateLayout, long layoutId, String name,
2973                            String languageId)
2974                    throws PortalException {
2975            }
2976    
2977            /**
2978             * @throws     PortalException
2979             * @deprecated As of 7.0.0, replaced by {@link
2980             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#validateImportLayoutsFile(
2981             *             ExportImportConfiguration, File)}
2982             */
2983            @Deprecated
2984            @Override
2985            public MissingReferences validateImportLayoutsFile(
2986                            ExportImportConfiguration exportImportConfiguration, File file)
2987                    throws PortalException {
2988    
2989                    throw new UnsupportedOperationException();
2990            }
2991    
2992            /**
2993             * @throws     PortalException
2994             * @deprecated As of 7.0.0, replaced by {@link
2995             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#validateImportLayoutsFile(
2996             *             ExportImportConfiguration, InputStream)}
2997             */
2998            @Deprecated
2999            @Override
3000            public MissingReferences validateImportLayoutsFile(
3001                            ExportImportConfiguration exportImportConfiguration,
3002                            InputStream inputStream)
3003                    throws PortalException {
3004    
3005                    throw new UnsupportedOperationException();
3006            }
3007    
3008            /**
3009             * @throws     PortalException
3010             * @deprecated As of 7.0.0, with no direct replacement
3011             */
3012            @Deprecated
3013            @Override
3014            public MissingReferences validateImportLayoutsFile(
3015                            long userId, long groupId, boolean privateLayout,
3016                            Map<String, String[]> parameterMap, File file)
3017                    throws PortalException {
3018    
3019                    throw new UnsupportedOperationException();
3020            }
3021    
3022            /**
3023             * @throws     PortalException
3024             * @deprecated As of 7.0.0, with no direct replacement
3025             */
3026            @Deprecated
3027            @Override
3028            public MissingReferences validateImportLayoutsFile(
3029                            long userId, long groupId, boolean privateLayout,
3030                            Map<String, String[]> parameterMap, InputStream inputStream)
3031                    throws PortalException {
3032    
3033                    throw new UnsupportedOperationException();
3034            }
3035    
3036            /**
3037             * @throws     PortalException
3038             * @deprecated As of 7.0.0, replaced by {@link
3039             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#validateImportPortletInfo(
3040             *             ExportImportConfiguration, File)}
3041             */
3042            @Deprecated
3043            @Override
3044            public MissingReferences validateImportPortletInfo(
3045                            ExportImportConfiguration exportImportConfiguration, File file)
3046                    throws PortalException {
3047    
3048                    throw new UnsupportedOperationException();
3049            }
3050    
3051            /**
3052             * @throws     PortalException
3053             * @deprecated As of 7.0.0, replaced by {@link
3054             *             com.liferay.portlet.exportimport.service.ExportImportLocalService#validateImportPortletInfo(
3055             *             ExportImportConfiguration, InputStream)}
3056             */
3057            @Deprecated
3058            @Override
3059            public MissingReferences validateImportPortletInfo(
3060                            ExportImportConfiguration exportImportConfiguration,
3061                            InputStream inputStream)
3062                    throws PortalException {
3063    
3064                    throw new UnsupportedOperationException();
3065            }
3066    
3067            /**
3068             * @throws     PortalException
3069             * @deprecated As of 7.0.0, with no direct replacement
3070             */
3071            @Deprecated
3072            @Override
3073            public MissingReferences validateImportPortletInfo(
3074                            long userId, long plid, long groupId, String portletId,
3075                            Map<String, String[]> parameterMap, File file)
3076                    throws PortalException {
3077    
3078                    throw new UnsupportedOperationException();
3079            }
3080    
3081            /**
3082             * @throws     PortalException
3083             * @deprecated As of 7.0.0, with no direct replacement
3084             */
3085            @Deprecated
3086            @Override
3087            public MissingReferences validateImportPortletInfo(
3088                            long userId, long plid, long groupId, String portletId,
3089                            Map<String, String[]> parameterMap, InputStream inputStream)
3090                    throws PortalException {
3091    
3092                    throw new UnsupportedOperationException();
3093            }
3094    
3095            protected void validateTypeSettingsProperties(
3096                            UnicodeProperties typeSettingsProperties)
3097                    throws PortalException {
3098    
3099                    String sitemapChangeFrequency = typeSettingsProperties.getProperty(
3100                            "sitemap-changefreq");
3101    
3102                    if (Validator.isNotNull(sitemapChangeFrequency) &&
3103                            !sitemapChangeFrequency.equals("always") &&
3104                            !sitemapChangeFrequency.equals("hourly") &&
3105                            !sitemapChangeFrequency.equals("daily") &&
3106                            !sitemapChangeFrequency.equals("weekly") &&
3107                            !sitemapChangeFrequency.equals("monthly") &&
3108                            !sitemapChangeFrequency.equals("yearly") &&
3109                            !sitemapChangeFrequency.equals("never")) {
3110    
3111                            throw new SitemapChangeFrequencyException();
3112                    }
3113    
3114                    String sitemapInclude = typeSettingsProperties.getProperty(
3115                            "sitemap-include");
3116    
3117                    if (Validator.isNotNull(sitemapInclude) &&
3118                            !sitemapInclude.equals("0") && !sitemapInclude.equals("1")) {
3119    
3120                            throw new SitemapIncludeException();
3121                    }
3122    
3123                    String sitemapPriority = typeSettingsProperties.getProperty(
3124                            "sitemap-priority");
3125    
3126                    if (Validator.isNotNull(sitemapPriority)) {
3127                            try {
3128                                    double priority = Double.parseDouble(sitemapPriority);
3129    
3130                                    if ((priority < 0) || (priority > 1)) {
3131                                            throw new SitemapPagePriorityException();
3132                                    }
3133                            }
3134                            catch (NumberFormatException nfe) {
3135                                    throw new SitemapPagePriorityException();
3136                            }
3137                    }
3138            }
3139    
3140            @BeanReference(type = LayoutLocalServiceHelper.class)
3141            protected LayoutLocalServiceHelper layoutLocalServiceHelper;
3142    
3143    }