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