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