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