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