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.model.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.language.LanguageUtil;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.util.GetterUtil;
022    import com.liferay.portal.kernel.util.HtmlUtil;
023    import com.liferay.portal.kernel.util.LocaleUtil;
024    import com.liferay.portal.kernel.util.OrderByComparator;
025    import com.liferay.portal.kernel.util.StringBundler;
026    import com.liferay.portal.kernel.util.StringPool;
027    import com.liferay.portal.kernel.util.StringUtil;
028    import com.liferay.portal.kernel.util.UnicodeProperties;
029    import com.liferay.portal.kernel.util.Validator;
030    import com.liferay.portal.kernel.webserver.WebServerServletTokenUtil;
031    import com.liferay.portal.model.Account;
032    import com.liferay.portal.model.Company;
033    import com.liferay.portal.model.Group;
034    import com.liferay.portal.model.GroupConstants;
035    import com.liferay.portal.model.GroupWrapper;
036    import com.liferay.portal.model.Layout;
037    import com.liferay.portal.model.LayoutConstants;
038    import com.liferay.portal.model.LayoutPrototype;
039    import com.liferay.portal.model.LayoutSet;
040    import com.liferay.portal.model.LayoutSetPrototype;
041    import com.liferay.portal.model.Organization;
042    import com.liferay.portal.model.Portlet;
043    import com.liferay.portal.model.PortletConstants;
044    import com.liferay.portal.model.RoleConstants;
045    import com.liferay.portal.model.User;
046    import com.liferay.portal.model.UserGroup;
047    import com.liferay.portal.model.UserPersonalSite;
048    import com.liferay.portal.security.permission.ActionKeys;
049    import com.liferay.portal.security.permission.PermissionChecker;
050    import com.liferay.portal.service.CompanyLocalServiceUtil;
051    import com.liferay.portal.service.GroupLocalServiceUtil;
052    import com.liferay.portal.service.LayoutLocalServiceUtil;
053    import com.liferay.portal.service.LayoutPrototypeLocalServiceUtil;
054    import com.liferay.portal.service.LayoutSetLocalServiceUtil;
055    import com.liferay.portal.service.LayoutSetPrototypeLocalServiceUtil;
056    import com.liferay.portal.service.OrganizationLocalServiceUtil;
057    import com.liferay.portal.service.PortletLocalServiceUtil;
058    import com.liferay.portal.service.RoleLocalServiceUtil;
059    import com.liferay.portal.service.UserGroupLocalServiceUtil;
060    import com.liferay.portal.service.UserLocalServiceUtil;
061    import com.liferay.portal.service.permission.LayoutPermissionUtil;
062    import com.liferay.portal.theme.ThemeDisplay;
063    import com.liferay.portal.util.PortalUtil;
064    import com.liferay.portal.util.PropsValues;
065    import com.liferay.portlet.exportimport.lar.PortletDataHandler;
066    import com.liferay.portlet.exportimport.staging.StagingConstants;
067    import com.liferay.portlet.exportimport.staging.StagingUtil;
068    
069    import java.io.IOException;
070    
071    import java.util.ArrayList;
072    import java.util.LinkedHashSet;
073    import java.util.List;
074    import java.util.Locale;
075    import java.util.Map;
076    import java.util.Set;
077    
078    /**
079     * Represents either a site or a generic resource container.
080     *
081     * <p>
082     * Groups are most used in Liferay as a resource container for permissioning and
083     * content scoping purposes. For instance, an site is group, meaning that it can
084     * contain layouts, web content, wiki entries, etc. However, a single layout can
085     * also be a group containing its own unique set of resources. An example of
086     * this would be a site that has several distinct wikis on different layouts.
087     * Each of these layouts would have its own group, and all of the nodes in the
088     * wiki for a certain layout would be associated with that layout's group. This
089     * allows users to be given different permissions on each of the wikis, even
090     * though they are all within the same site. In addition to sites and layouts,
091     * users and organizations are also groups.
092     * </p>
093     *
094     * <p>
095     * Groups also have a second, partially conflicting purpose in Liferay. For
096     * legacy reasons, groups are also the model used to represent sites (known as
097     * communities before Liferay v6.1). Confusion may arise from the fact that a
098     * site group is both the resource container and the site itself, whereas a
099     * layout or organization would have both a primary model and an associated
100     * group.
101     * </p>
102     *
103     * @author Brian Wing Shun Chan
104     */
105    public class GroupImpl extends GroupBaseImpl {
106    
107            @Override
108            public void clearStagingGroup() {
109                    _stagingGroup = null;
110            }
111    
112            @Override
113            public List<Group> getAncestors() throws PortalException {
114                    Group group = null;
115    
116                    if (isStagingGroup()) {
117                            group = getLiveGroup();
118                    }
119                    else {
120                            group = this;
121                    }
122    
123                    List<Group> groups = new ArrayList<>();
124    
125                    while (!group.isRoot()) {
126                            group = group.getParentGroup();
127    
128                            groups.add(group);
129                    }
130    
131                    return groups;
132            }
133    
134            @Override
135            public List<Group> getChildren(boolean site) {
136                    return GroupLocalServiceUtil.getGroups(
137                            getCompanyId(), getGroupId(), site);
138            }
139    
140            /**
141             * @deprecated As of 7.0.0, replaced by {@link
142             *             #getChildrenWithLayouts(boolean, int, int,
143             *             OrderByComparator)}
144             */
145            @Deprecated
146            @Override
147            public List<Group> getChildrenWithLayouts(
148                    boolean site, int start, int end) {
149    
150                    return getChildrenWithLayouts(site, start, end, null);
151            }
152    
153            @Override
154            public List<Group> getChildrenWithLayouts(
155                    boolean site, int start, int end, OrderByComparator<Group> obc) {
156    
157                    return GroupLocalServiceUtil.getLayoutsGroups(
158                            getCompanyId(), getGroupId(), site, start, end, obc);
159            }
160    
161            @Override
162            public int getChildrenWithLayoutsCount(boolean site) {
163                    return GroupLocalServiceUtil.getLayoutsGroupsCount(
164                            getCompanyId(), getGroupId(), site);
165            }
166    
167            @Override
168            public long getDefaultPrivatePlid() {
169                    return getDefaultPlid(true);
170            }
171    
172            @Override
173            public long getDefaultPublicPlid() {
174                    return getDefaultPlid(false);
175            }
176    
177            @Override
178            public List<Group> getDescendants(boolean site) {
179                    Set<Group> descendants = new LinkedHashSet<>();
180    
181                    for (Group group : getChildren(site)) {
182                            descendants.add(group);
183                            descendants.addAll(group.getDescendants(site));
184                    }
185    
186                    return new ArrayList<>(descendants);
187            }
188    
189            @Override
190            public String getDescriptiveName() throws PortalException {
191                    return getDescriptiveName(LocaleUtil.getMostRelevantLocale());
192            }
193    
194            @Override
195            public String getDescriptiveName(Locale locale) throws PortalException {
196                    Group curGroup = this;
197    
198                    String name = getName(locale);
199    
200                    if (Validator.isNull(name)) {
201                            Locale siteDefaultLocale = PortalUtil.getSiteDefaultLocale(
202                                    getGroupId());
203    
204                            name = getName(siteDefaultLocale);
205                    }
206    
207                    if (isCompany() && !isCompanyStagingGroup()) {
208                            name = LanguageUtil.get(locale, "global");
209                    }
210                    else if (isControlPanel()) {
211                            name = LanguageUtil.get(locale, "control-panel");
212                    }
213                    else if (isGuest()) {
214                            Company company = CompanyLocalServiceUtil.getCompany(
215                                    getCompanyId());
216    
217                            Account account = company.getAccount();
218    
219                            name = account.getName();
220                    }
221                    else if (isLayout()) {
222                            Layout layout = LayoutLocalServiceUtil.getLayout(getClassPK());
223    
224                            name = layout.getName(locale);
225                    }
226                    else if (isLayoutPrototype()) {
227                            LayoutPrototype layoutPrototype =
228                                    LayoutPrototypeLocalServiceUtil.getLayoutPrototype(
229                                            getClassPK());
230    
231                            name = layoutPrototype.getName(locale);
232                    }
233                    else if (isLayoutSetPrototype()) {
234                            LayoutSetPrototype layoutSetPrototype =
235                                    LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(
236                                            getClassPK());
237    
238                            name = layoutSetPrototype.getName(locale);
239                    }
240                    else if (isOrganization()) {
241                            long organizationId = getOrganizationId();
242    
243                            Organization organization =
244                                    OrganizationLocalServiceUtil.getOrganization(organizationId);
245    
246                            name = organization.getName();
247    
248                            curGroup = organization.getGroup();
249                    }
250                    else if (isUser()) {
251                            long userId = getClassPK();
252    
253                            User user = UserLocalServiceUtil.getUser(userId);
254    
255                            name = user.getFullName();
256                    }
257                    else if (isUserGroup()) {
258                            long userGroupId = getClassPK();
259    
260                            UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(
261                                    userGroupId);
262    
263                            name = userGroup.getName();
264                    }
265                    else if (isUserPersonalSite()) {
266                            name = LanguageUtil.get(locale, "user-personal-site");
267                    }
268    
269                    if (curGroup.isStaged() && !curGroup.isStagedRemotely() &&
270                            curGroup.isStagingGroup()) {
271    
272                            Group liveGroup = getLiveGroup();
273    
274                            name = liveGroup.getDescriptiveName(locale);
275                    }
276    
277                    return name;
278            }
279    
280            @Override
281            public String getDisplayURL(ThemeDisplay themeDisplay) {
282                    return getDisplayURL(themeDisplay, false);
283            }
284    
285            @Override
286            public String getDisplayURL(
287                    ThemeDisplay themeDisplay, boolean privateLayout) {
288    
289                    if (!privateLayout && (getPublicLayoutsPageCount() > 0)) {
290                            try {
291                                    String groupFriendlyURL = PortalUtil.getGroupFriendlyURL(
292                                            getPublicLayoutSet(), themeDisplay);
293    
294                                    return PortalUtil.addPreservedParameters(
295                                            themeDisplay, groupFriendlyURL);
296                            }
297                            catch (PortalException pe) {
298                                    _log.error(pe, pe);
299                            }
300                    }
301                    else if (privateLayout && (getPrivateLayoutsPageCount() > 0)) {
302                            try {
303                                    String groupFriendlyURL = PortalUtil.getGroupFriendlyURL(
304                                            getPrivateLayoutSet(), themeDisplay);
305    
306                                    return PortalUtil.addPreservedParameters(
307                                            themeDisplay, groupFriendlyURL);
308                            }
309                            catch (PortalException pe) {
310                                    _log.error(pe);
311                            }
312                    }
313    
314                    return StringPool.BLANK;
315            }
316    
317            @Override
318            public String getIconCssClass() {
319                    String iconCss = "sites";
320    
321                    if (isCompany()) {
322                            iconCss = "sites";
323                    }
324                    else if (isLayout()) {
325                            iconCss = "edit-layout";
326                    }
327                    else if (isOrganization()) {
328                            iconCss = "sites";
329                    }
330                    else if (isUser()) {
331                            iconCss = "user";
332                    }
333    
334                    return iconCss;
335            }
336    
337            @Override
338            public String getIconURL(ThemeDisplay themeDisplay) {
339                    String iconURL = StringPool.BLANK;
340    
341                    if (isCompany()) {
342                            iconURL = "../aui/globe";
343                    }
344                    else if (isLayout()) {
345                            iconURL = "../aui/file";
346                    }
347                    else if (isOrganization()) {
348                            iconURL = "../aui/globe";
349                    }
350                    else if (isUser()) {
351                            iconURL = "../aui/user";
352                    }
353                    else {
354                            iconURL = "../aui/globe";
355                    }
356    
357                    return iconURL;
358            }
359    
360            @Override
361            public String getLayoutRootNodeName(boolean privateLayout, Locale locale) {
362                    String pagesName = null;
363    
364                    if (isLayoutPrototype() || isLayoutSetPrototype()) {
365                            pagesName = "pages";
366                    }
367                    else if (privateLayout) {
368                            if (isUser() || isUserGroup()) {
369                                    pagesName = "my-dashboard";
370                            }
371                            else {
372                                    pagesName = "private-pages";
373                            }
374                    }
375                    else {
376                            if (isUser() || isUserGroup()) {
377                                    pagesName = "my-profile";
378                            }
379                            else {
380                                    pagesName = "public-pages";
381                            }
382                    }
383    
384                    return LanguageUtil.get(locale, pagesName);
385            }
386    
387            @Override
388            public Group getLiveGroup() {
389                    if (!isStagingGroup()) {
390                            return null;
391                    }
392    
393                    try {
394                            if (_liveGroup == null) {
395                                    _liveGroup = GroupLocalServiceUtil.getGroup(getLiveGroupId());
396    
397                                    if (_liveGroup instanceof GroupImpl) {
398                                            GroupImpl groupImpl = (GroupImpl)_liveGroup;
399    
400                                            groupImpl._stagingGroup = this;
401                                    }
402                                    else {
403                                            _liveGroup = new GroupWrapper(_liveGroup) {
404    
405                                                    @Override
406                                                    public Group getStagingGroup() {
407                                                            return GroupImpl.this;
408                                                    }
409    
410                                            };
411                                    }
412                            }
413    
414                            return _liveGroup;
415                    }
416                    catch (Exception e) {
417                            _log.error("Error getting live group for " + getLiveGroupId(), e);
418    
419                            return null;
420                    }
421            }
422    
423            @Override
424            public String getLiveParentTypeSettingsProperty(String key) {
425                    UnicodeProperties typeSettingsProperties =
426                            getParentLiveGroupTypeSettingsProperties();
427    
428                    return typeSettingsProperties.getProperty(key);
429            }
430    
431            @Override
432            public String getLogoURL(ThemeDisplay themeDisplay, boolean useDefault) {
433                    long logoId = 0;
434    
435                    LayoutSet publicLayoutSet = getPublicLayoutSet();
436    
437                    if (publicLayoutSet.getLogoId() > 0) {
438                            logoId = publicLayoutSet.getLogoId();
439                    }
440                    else {
441                            LayoutSet privateLayoutSet = getPrivateLayoutSet();
442    
443                            if (privateLayoutSet.getLogoId() > 0) {
444                                    logoId = privateLayoutSet.getLogoId();
445                            }
446                    }
447    
448                    if ((logoId == 0) && !useDefault) {
449                            return null;
450                    }
451    
452                    StringBundler sb = new StringBundler(5);
453    
454                    sb.append(themeDisplay.getPathImage());
455                    sb.append("/layout_set_logo?img_id=");
456                    sb.append(logoId);
457                    sb.append("&t=");
458                    sb.append(WebServerServletTokenUtil.getToken(logoId));
459    
460                    return sb.toString();
461            }
462    
463            @Override
464            public long getOrganizationId() {
465                    if (isOrganization()) {
466                            if (isStagingGroup()) {
467                                    Group liveGroup = getLiveGroup();
468    
469                                    return liveGroup.getClassPK();
470                            }
471                            else {
472                                    return getClassPK();
473                            }
474                    }
475    
476                    return 0;
477            }
478    
479            @Override
480            public Group getParentGroup() throws PortalException {
481                    long parentGroupId = getParentGroupId();
482    
483                    if (parentGroupId <= 0) {
484                            return null;
485                    }
486    
487                    return GroupLocalServiceUtil.getGroup(parentGroupId);
488            }
489    
490            @Override
491            public UnicodeProperties getParentLiveGroupTypeSettingsProperties() {
492                    try {
493                            if (isLayout()) {
494                                    Group parentGroup = GroupLocalServiceUtil.getGroup(
495                                            getParentGroupId());
496    
497                                    return parentGroup.getParentLiveGroupTypeSettingsProperties();
498                            }
499    
500                            if (isStagingGroup()) {
501                                    Group liveGroup = getLiveGroup();
502    
503                                    return liveGroup.getTypeSettingsProperties();
504                            }
505                    }
506                    catch (Exception e) {
507                    }
508    
509                    return getTypeSettingsProperties();
510            }
511    
512            @Override
513            public String getPathFriendlyURL(
514                    boolean privateLayout, ThemeDisplay themeDisplay) {
515    
516                    if (privateLayout) {
517                            if (isUser()) {
518                                    return themeDisplay.getPathFriendlyURLPrivateUser();
519                            }
520                            else {
521                                    return themeDisplay.getPathFriendlyURLPrivateGroup();
522                            }
523                    }
524                    else {
525                            return themeDisplay.getPathFriendlyURLPublic();
526                    }
527            }
528    
529            @Override
530            public LayoutSet getPrivateLayoutSet() {
531                    LayoutSet layoutSet = null;
532    
533                    try {
534                            layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
535                                    getGroupId(), true);
536                    }
537                    catch (Exception e) {
538                            _log.error(e, e);
539                    }
540    
541                    return layoutSet;
542            }
543    
544            @Override
545            public int getPrivateLayoutsPageCount() {
546                    try {
547                            return LayoutLocalServiceUtil.getLayoutsCount(this, true);
548                    }
549                    catch (Exception e) {
550                            _log.error(e, e);
551                    }
552    
553                    return 0;
554            }
555    
556            @Override
557            public LayoutSet getPublicLayoutSet() {
558                    LayoutSet layoutSet = null;
559    
560                    try {
561                            layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
562                                    getGroupId(), false);
563                    }
564                    catch (Exception e) {
565                            _log.error(e, e);
566                    }
567    
568                    return layoutSet;
569            }
570    
571            @Override
572            public int getPublicLayoutsPageCount() {
573                    try {
574                            return LayoutLocalServiceUtil.getLayoutsCount(this, false);
575                    }
576                    catch (Exception e) {
577                            _log.error(e, e);
578                    }
579    
580                    return 0;
581            }
582    
583            @Override
584            public long getRemoteLiveGroupId() {
585                    if (!isStagedRemotely()) {
586                            return GroupConstants.DEFAULT_LIVE_GROUP_ID;
587                    }
588    
589                    return GetterUtil.getLong(getTypeSettingsProperty("remoteGroupId"));
590            }
591    
592            @Override
593            public String getScopeDescriptiveName(ThemeDisplay themeDisplay)
594                    throws PortalException {
595    
596                    if (getGroupId() == themeDisplay.getScopeGroupId()) {
597                            return StringUtil.appendParentheticalSuffix(
598                                    themeDisplay.translate("current-site"),
599                                    HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
600                    }
601                    else if (isLayout() && (getClassPK() == themeDisplay.getPlid())) {
602                            return StringUtil.appendParentheticalSuffix(
603                                    themeDisplay.translate("current-page"),
604                                    HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
605                    }
606                    else if (isLayoutPrototype()) {
607                            return themeDisplay.translate("default");
608                    }
609                    else {
610                            return HtmlUtil.escape(
611                                    getDescriptiveName(themeDisplay.getLocale()));
612                    }
613            }
614    
615            @Override
616            public String getScopeLabel(ThemeDisplay themeDisplay) {
617                    String label = "site";
618    
619                    if (getGroupId() == themeDisplay.getScopeGroupId()) {
620                            label = "current-site";
621                    }
622                    else if (getGroupId() == themeDisplay.getCompanyGroupId()) {
623                            label = "global";
624                    }
625                    else if (isLayout()) {
626                            label = "page";
627                    }
628                    else {
629                            Group scopeGroup = themeDisplay.getScopeGroup();
630    
631                            if (scopeGroup.hasAncestor(getGroupId())) {
632                                    label = "parent-site";
633                            }
634                            else if (hasAncestor(scopeGroup.getGroupId())) {
635                                    label = "child-site";
636                            }
637                    }
638    
639                    return label;
640            }
641    
642            @Override
643            public Group getStagingGroup() {
644                    if (isStagingGroup()) {
645                            return null;
646                    }
647    
648                    try {
649                            if (_stagingGroup == null) {
650                                    _stagingGroup = GroupLocalServiceUtil.getStagingGroup(
651                                            getGroupId());
652    
653                                    if (_stagingGroup instanceof GroupImpl) {
654                                            GroupImpl groupImpl = (GroupImpl)_stagingGroup;
655    
656                                            groupImpl._liveGroup = this;
657                                    }
658                                    else {
659                                            _stagingGroup = new GroupWrapper(_stagingGroup) {
660    
661                                                    @Override
662                                                    public Group getLiveGroup() {
663                                                            return GroupImpl.this;
664                                                    }
665    
666                                            };
667                                    }
668                            }
669    
670                            return _stagingGroup;
671                    }
672                    catch (Exception e) {
673                            _log.error("Error getting staging group for " + getGroupId(), e);
674    
675                            return null;
676                    }
677            }
678    
679            @Override
680            public String getTypeLabel() {
681                    return GroupConstants.getTypeLabel(getType());
682            }
683    
684            @Override
685            public String getTypeSettings() {
686                    if (_typeSettingsProperties == null) {
687                            return super.getTypeSettings();
688                    }
689                    else {
690                            return _typeSettingsProperties.toString();
691                    }
692            }
693    
694            @Override
695            public UnicodeProperties getTypeSettingsProperties() {
696                    if (_typeSettingsProperties == null) {
697                            _typeSettingsProperties = new UnicodeProperties(true);
698    
699                            try {
700                                    _typeSettingsProperties.load(super.getTypeSettings());
701                            }
702                            catch (IOException ioe) {
703                                    _log.error(ioe, ioe);
704                            }
705                    }
706    
707                    return _typeSettingsProperties;
708            }
709    
710            @Override
711            public String getTypeSettingsProperty(String key) {
712                    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
713    
714                    return typeSettingsProperties.getProperty(key);
715            }
716    
717            @Override
718            public String getUnambiguousName(String name, Locale locale) {
719                    try {
720                            return StringUtil.appendParentheticalSuffix(
721                                    name, getDescriptiveName(locale));
722                    }
723                    catch (Exception e) {
724                            return name;
725                    }
726            }
727    
728            @Override
729            public boolean hasAncestor(long groupId) {
730                    Group group = null;
731    
732                    if (isStagingGroup()) {
733                            group = getLiveGroup();
734                    }
735                    else {
736                            group = this;
737                    }
738    
739                    String treePath = group.getTreePath();
740    
741                    if ((groupId != group.getGroupId()) &&
742                            treePath.contains(StringPool.SLASH + groupId + StringPool.SLASH)) {
743    
744                            return true;
745                    }
746    
747                    return false;
748            }
749    
750            @Override
751            public boolean hasLocalOrRemoteStagingGroup() {
752                    if (hasRemoteStagingGroup() || hasStagingGroup()) {
753                            return true;
754                    }
755    
756                    return false;
757            }
758    
759            @Override
760            public boolean hasPrivateLayouts() {
761                    if (getPrivateLayoutsPageCount() > 0) {
762                            return true;
763                    }
764                    else {
765                            return false;
766                    }
767            }
768    
769            @Override
770            public boolean hasPublicLayouts() {
771                    if (getPublicLayoutsPageCount() > 0) {
772                            return true;
773                    }
774                    else {
775                            return false;
776                    }
777            }
778    
779            @Override
780            public boolean hasRemoteStagingGroup() {
781                    if (getRemoteStagingGroupCount() > 0) {
782                            return true;
783                    }
784    
785                    return false;
786            }
787    
788            @Override
789            public boolean hasStagingGroup() {
790                    if (isStagingGroup()) {
791                            return false;
792                    }
793    
794                    if (_stagingGroup != null) {
795                            return true;
796                    }
797    
798                    try {
799                            return GroupLocalServiceUtil.hasStagingGroup(getGroupId());
800                    }
801                    catch (Exception e) {
802                            return false;
803                    }
804            }
805    
806            /**
807             * @deprecated As of 7.0.0, replaced by {@link #hasAncestor}
808             */
809            @Deprecated
810            @Override
811            public boolean isChild(long groupId) {
812                    return hasAncestor(groupId);
813            }
814    
815            @Override
816            public boolean isCompany() {
817                    return hasClassName(Company.class) || isCompanyStagingGroup();
818            }
819    
820            @Override
821            public boolean isCompanyStagingGroup() {
822                    Group liveGroup = getLiveGroup();
823    
824                    if (liveGroup == null) {
825                            return false;
826                    }
827    
828                    return liveGroup.isCompany();
829            }
830    
831            @Override
832            public boolean isControlPanel() {
833                    String groupKey = getGroupKey();
834    
835                    if (groupKey.equals(GroupConstants.CONTROL_PANEL)) {
836                            return true;
837                    }
838                    else {
839                            return false;
840                    }
841            }
842    
843            @Override
844            public boolean isGuest() {
845                    String groupKey = getGroupKey();
846    
847                    if (groupKey.equals(GroupConstants.GUEST)) {
848                            return true;
849                    }
850                    else {
851                            return false;
852                    }
853            }
854    
855            @Override
856            public boolean isInStagingPortlet(String portletId) {
857                    Group liveGroup = getLiveGroup();
858    
859                    if (liveGroup == null) {
860                            return false;
861                    }
862    
863                    return liveGroup.isStagedPortlet(portletId);
864            }
865    
866            @Override
867            public boolean isLayout() {
868                    return hasClassName(Layout.class);
869            }
870    
871            @Override
872            public boolean isLayoutPrototype() {
873                    return hasClassName(LayoutPrototype.class);
874            }
875    
876            @Override
877            public boolean isLayoutSetPrototype() {
878                    return hasClassName(LayoutSetPrototype.class);
879            }
880    
881            @Override
882            public boolean isLimitedToParentSiteMembers() {
883                    if ((getParentGroupId() != GroupConstants.DEFAULT_PARENT_GROUP_ID) &&
884                            (getMembershipRestriction() ==
885                                    GroupConstants.MEMBERSHIP_RESTRICTION_TO_PARENT_SITE_MEMBERS)) {
886    
887                            return true;
888                    }
889    
890                    return false;
891            }
892    
893            @Override
894            public boolean isOrganization() {
895                    return hasClassName(Organization.class);
896            }
897    
898            @Override
899            public boolean isRegularSite() {
900                    return hasClassName(Group.class);
901            }
902    
903            @Override
904            public boolean isRoot() {
905                    if (getParentGroupId() == GroupConstants.DEFAULT_PARENT_GROUP_ID) {
906                            return true;
907                    }
908    
909                    return false;
910            }
911    
912            @Override
913            public boolean isShowSite(
914                            PermissionChecker permissionChecker, boolean privateSite)
915                    throws PortalException {
916    
917                    if (!isControlPanel() && !isSite() && !isUser()) {
918                            return false;
919                    }
920    
921                    boolean showSite = true;
922    
923                    Layout defaultLayout = null;
924    
925                    int siteLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(
926                            this, privateSite);
927    
928                    if (siteLayoutsCount == 0) {
929                            boolean hasPowerUserRole = RoleLocalServiceUtil.hasUserRole(
930                                    permissionChecker.getUserId(), permissionChecker.getCompanyId(),
931                                    RoleConstants.POWER_USER, true);
932    
933                            if (isSite()) {
934                                    if (privateSite) {
935                                            showSite =
936                                                    PropsValues.MY_SITES_SHOW_PRIVATE_SITES_WITH_NO_LAYOUTS;
937                                    }
938                                    else {
939                                            showSite =
940                                                    PropsValues.MY_SITES_SHOW_PUBLIC_SITES_WITH_NO_LAYOUTS;
941                                    }
942                            }
943                            else if (isOrganization()) {
944                                    showSite = false;
945                            }
946                            else if (isUser()) {
947                                    if (privateSite) {
948                                            showSite =
949                                                    PropsValues.
950                                                            MY_SITES_SHOW_USER_PRIVATE_SITES_WITH_NO_LAYOUTS;
951    
952                                            if (PropsValues.
953                                                            LAYOUT_USER_PRIVATE_LAYOUTS_POWER_USER_REQUIRED &&
954                                                    !hasPowerUserRole) {
955    
956                                                    showSite = false;
957                                            }
958                                    }
959                                    else {
960                                            showSite =
961                                                    PropsValues.
962                                                            MY_SITES_SHOW_USER_PUBLIC_SITES_WITH_NO_LAYOUTS;
963    
964                                            if (PropsValues.
965                                                            LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED &&
966                                                    !hasPowerUserRole) {
967    
968                                                    showSite = false;
969                                            }
970                                    }
971                            }
972                    }
973                    else {
974                            defaultLayout = LayoutLocalServiceUtil.fetchFirstLayout(
975                                    getGroupId(), privateSite,
976                                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
977    
978                            if ((defaultLayout != null ) &&
979                                    !LayoutPermissionUtil.contains(
980                                            permissionChecker, defaultLayout, true, ActionKeys.VIEW)) {
981    
982                                    showSite = false;
983                            }
984                            else if (isOrganization() && !isSite()) {
985                                    _log.error(
986                                            "Group " + getGroupId() +
987                                                    " is an organization site that does not have pages");
988                            }
989                    }
990    
991                    return showSite;
992            }
993    
994            @Override
995            public boolean isStaged() {
996                    return GetterUtil.getBoolean(
997                            getLiveParentTypeSettingsProperty("staged"));
998            }
999    
1000            @Override
1001            public boolean isStagedPortlet(String portletId) {
1002                    UnicodeProperties typeSettingsProperties =
1003                            getParentLiveGroupTypeSettingsProperties();
1004    
1005                    portletId = PortletConstants.getRootPortletId(portletId);
1006    
1007                    String typeSettingsProperty = typeSettingsProperties.getProperty(
1008                            StagingUtil.getStagedPortletId(portletId));
1009    
1010                    if (Validator.isNotNull(typeSettingsProperty)) {
1011                            return GetterUtil.getBoolean(typeSettingsProperty);
1012                    }
1013    
1014                    try {
1015                            Portlet portlet = PortletLocalServiceUtil.getPortletById(portletId);
1016    
1017                            PortletDataHandler portletDataHandler =
1018                                    portlet.getPortletDataHandlerInstance();
1019    
1020                            if (portletDataHandler == null) {
1021                                    return false;
1022                            }
1023    
1024                            for (Map.Entry<String, String> entry :
1025                                            typeSettingsProperties.entrySet()) {
1026    
1027                                    String key = entry.getKey();
1028    
1029                                    if (!key.contains(StagingConstants.STAGED_PORTLET)) {
1030                                            continue;
1031                                    }
1032    
1033                                    String stagedPortletId = StringUtil.replace(
1034                                            key, StagingConstants.STAGED_PORTLET, StringPool.BLANK);
1035    
1036                                    Portlet stagedPortlet = PortletLocalServiceUtil.getPortletById(
1037                                            stagedPortletId);
1038    
1039                                    if (portletDataHandler.equals(
1040                                                    stagedPortlet.getPortletDataHandlerInstance())) {
1041    
1042                                            return GetterUtil.getBoolean(entry.getValue());
1043                                    }
1044                            }
1045                    }
1046                    catch (Exception e) {
1047                    }
1048    
1049                    return true;
1050            }
1051    
1052            @Override
1053            public boolean isStagedRemotely() {
1054                    return GetterUtil.getBoolean(
1055                            getLiveParentTypeSettingsProperty("stagedRemotely"));
1056            }
1057    
1058            @Override
1059            public boolean isStagingGroup() {
1060                    if (getLiveGroupId() == GroupConstants.DEFAULT_LIVE_GROUP_ID) {
1061                            return false;
1062                    }
1063                    else {
1064                            return true;
1065                    }
1066            }
1067    
1068            @Override
1069            public boolean isUser() {
1070                    return hasClassName(User.class);
1071            }
1072    
1073            @Override
1074            public boolean isUserGroup() {
1075                    return hasClassName(UserGroup.class);
1076            }
1077    
1078            @Override
1079            public boolean isUserPersonalSite() {
1080                    return hasClassName(UserPersonalSite.class);
1081            }
1082    
1083            @Override
1084            public void setTypeSettings(String typeSettings) {
1085                    _typeSettingsProperties = null;
1086    
1087                    super.setTypeSettings(typeSettings);
1088            }
1089    
1090            @Override
1091            public void setTypeSettingsProperties(
1092                    UnicodeProperties typeSettingsProperties) {
1093    
1094                    _typeSettingsProperties = typeSettingsProperties;
1095    
1096                    super.setTypeSettings(_typeSettingsProperties.toString());
1097            }
1098    
1099            protected long getDefaultPlid(boolean privateLayout) {
1100                    try {
1101                            Layout firstLayout = LayoutLocalServiceUtil.fetchFirstLayout(
1102                                    getGroupId(), privateLayout,
1103                                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
1104    
1105                            if (firstLayout != null) {
1106                                    return firstLayout.getPlid();
1107                            }
1108                    }
1109                    catch (Exception e) {
1110                            if (_log.isWarnEnabled()) {
1111                                    _log.warn(e.getMessage());
1112                            }
1113                    }
1114    
1115                    return LayoutConstants.DEFAULT_PLID;
1116            }
1117    
1118            protected boolean hasClassName(Class<?> clazz) {
1119                    long classNameId = getClassNameId();
1120    
1121                    if (classNameId == PortalUtil.getClassNameId(clazz)) {
1122                            return true;
1123                    }
1124                    else {
1125                            return false;
1126                    }
1127            }
1128    
1129            private static final Log _log = LogFactoryUtil.getLog(GroupImpl.class);
1130    
1131            private Group _liveGroup;
1132            private Group _stagingGroup;
1133            private UnicodeProperties _typeSettingsProperties;
1134    
1135    }