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