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 getIconURL(ThemeDisplay themeDisplay) {
186                    String iconURL = themeDisplay.getPathThemeImages() + "/common/";
187    
188                    if (isCompany()) {
189                            iconURL = iconURL.concat("global.png");
190                    }
191                    else if (isLayout()) {
192                            iconURL = iconURL.concat("page.png");
193                    }
194                    else if (isOrganization()) {
195                            iconURL = iconURL.concat("organization_icon.png");
196                    }
197                    else if (isUser()) {
198                            iconURL = iconURL.concat("user_icon.png");
199                    }
200                    else {
201                            iconURL = iconURL.concat("site_icon.png");
202                    }
203    
204                    return iconURL;
205            }
206    
207            @Override
208            public String getLayoutRootNodeName(boolean privateLayout, Locale locale) {
209                    String pagesName = null;
210    
211                    if (isLayoutPrototype() || isLayoutSetPrototype() || isUserGroup()) {
212                            pagesName = "pages";
213                    }
214                    else if (privateLayout) {
215                            if (isUser()) {
216                                    pagesName = "my-dashboard";
217                            }
218                            else {
219                                    pagesName = "private-pages";
220                            }
221                    }
222                    else {
223                            if (isUser()) {
224                                    pagesName = "my-profile";
225                            }
226                            else {
227                                    pagesName = "public-pages";
228                            }
229                    }
230    
231                    return LanguageUtil.get(locale, pagesName);
232            }
233    
234            @Override
235            public Group getLiveGroup() {
236                    if (!isStagingGroup()) {
237                            return null;
238                    }
239    
240                    try {
241                            if (_liveGroup == null) {
242                                    _liveGroup = GroupLocalServiceUtil.getGroup(getLiveGroupId());
243    
244                                    if (_liveGroup instanceof GroupImpl) {
245                                            GroupImpl groupImpl = (GroupImpl)_liveGroup;
246    
247                                            groupImpl._stagingGroup = this;
248                                    }
249                                    else {
250                                            _liveGroup = new GroupWrapper(_liveGroup) {
251    
252                                                    @Override
253                                                    public Group getStagingGroup() {
254                                                            return GroupImpl.this;
255                                                    }
256    
257                                            };
258                                    }
259                            }
260    
261                            return _liveGroup;
262                    }
263                    catch (Exception e) {
264                            _log.error("Error getting live group for " + getLiveGroupId(), e);
265    
266                            return null;
267                    }
268            }
269    
270            @Override
271            public String getLiveParentTypeSettingsProperty(String key) {
272                    UnicodeProperties typeSettingsProperties =
273                            getParentLiveGroupTypeSettingsProperties();
274    
275                    return typeSettingsProperties.getProperty(key);
276            }
277    
278            @Override
279            public long getOrganizationId() {
280                    if (isOrganization()) {
281                            if (isStagingGroup()) {
282                                    Group liveGroup = getLiveGroup();
283    
284                                    return liveGroup.getClassPK();
285                            }
286                            else {
287                                    return getClassPK();
288                            }
289                    }
290    
291                    return 0;
292            }
293    
294            @Override
295            public Group getParentGroup() throws PortalException, SystemException {
296                    long parentGroupId = getParentGroupId();
297    
298                    if (parentGroupId <= 0) {
299                            return null;
300                    }
301    
302                    return GroupLocalServiceUtil.getGroup(parentGroupId);
303            }
304    
305            @Override
306            public UnicodeProperties getParentLiveGroupTypeSettingsProperties() {
307                    try {
308                            if (isLayout()) {
309                                    Group parentGroup = GroupLocalServiceUtil.getGroup(
310                                            getParentGroupId());
311    
312                                    return parentGroup.getParentLiveGroupTypeSettingsProperties();
313                            }
314    
315                            if (isStagingGroup()) {
316                                    Group liveGroup = getLiveGroup();
317    
318                                    return liveGroup.getTypeSettingsProperties();
319                            }
320                    }
321                    catch (Exception e) {
322                    }
323    
324                    return getTypeSettingsProperties();
325            }
326    
327            @Override
328            public String getPathFriendlyURL(
329                    boolean privateLayout, ThemeDisplay themeDisplay) {
330    
331                    if (privateLayout) {
332                            if (isUser()) {
333                                    return themeDisplay.getPathFriendlyURLPrivateUser();
334                            }
335                            else {
336                                    return themeDisplay.getPathFriendlyURLPrivateGroup();
337                            }
338                    }
339                    else {
340                            return themeDisplay.getPathFriendlyURLPublic();
341                    }
342            }
343    
344            @Override
345            public LayoutSet getPrivateLayoutSet() {
346                    LayoutSet layoutSet = null;
347    
348                    try {
349                            layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
350                                    getGroupId(), true);
351                    }
352                    catch (Exception e) {
353                            _log.error(e, e);
354                    }
355    
356                    return layoutSet;
357            }
358    
359            @Override
360            public int getPrivateLayoutsPageCount() {
361                    try {
362                            return LayoutLocalServiceUtil.getLayoutsCount(this, true);
363                    }
364                    catch (Exception e) {
365                            _log.error(e, e);
366                    }
367    
368                    return 0;
369            }
370    
371            @Override
372            public LayoutSet getPublicLayoutSet() {
373                    LayoutSet layoutSet = null;
374    
375                    try {
376                            layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
377                                    getGroupId(), false);
378                    }
379                    catch (Exception e) {
380                            _log.error(e, e);
381                    }
382    
383                    return layoutSet;
384            }
385    
386            @Override
387            public int getPublicLayoutsPageCount() {
388                    try {
389                            return LayoutLocalServiceUtil.getLayoutsCount(this, false);
390                    }
391                    catch (Exception e) {
392                            _log.error(e, e);
393                    }
394    
395                    return 0;
396            }
397    
398            @Override
399            public String getScopeDescriptiveName(ThemeDisplay themeDisplay)
400                    throws PortalException, SystemException {
401    
402                    if (getGroupId() == themeDisplay.getScopeGroupId()) {
403                            StringBundler sb = new StringBundler(5);
404    
405                            sb.append(themeDisplay.translate("current-site"));
406                            sb.append(StringPool.SPACE);
407                            sb.append(StringPool.OPEN_PARENTHESIS);
408                            sb.append(
409                                    HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
410                            sb.append(StringPool.CLOSE_PARENTHESIS);
411    
412                            return sb.toString();
413                    }
414                    else if (isLayout() && (getClassPK() == themeDisplay.getPlid())) {
415                            StringBundler sb = new StringBundler(5);
416    
417                            sb.append(themeDisplay.translate("current-page"));
418                            sb.append(StringPool.SPACE);
419                            sb.append(StringPool.OPEN_PARENTHESIS);
420                            sb.append(
421                                    HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
422                            sb.append(StringPool.CLOSE_PARENTHESIS);
423    
424                            return sb.toString();
425                    }
426                    else if (isLayoutPrototype()) {
427                            return themeDisplay.translate("default");
428                    }
429                    else {
430                            return HtmlUtil.escape(
431                                    getDescriptiveName(themeDisplay.getLocale()));
432                    }
433            }
434    
435            @Override
436            public String getScopeLabel(ThemeDisplay themeDisplay) {
437                    String label = "site";
438    
439                    if (getGroupId() == themeDisplay.getScopeGroupId()) {
440                            label = "current-site";
441                    }
442                    else if (getGroupId() == themeDisplay.getCompanyGroupId()) {
443                            label = "global";
444                    }
445                    else if (isLayout()) {
446                            label = "page";
447                    }
448                    else {
449                            Group scopeGroup = themeDisplay.getScopeGroup();
450    
451                            if (scopeGroup.hasAncestor(getGroupId())) {
452                                    label = "parent-site";
453                            }
454                            else if (hasAncestor(scopeGroup.getGroupId())) {
455                                    label = "child-site";
456                            }
457                    }
458    
459                    return label;
460            }
461    
462            @Override
463            public Group getStagingGroup() {
464                    if (isStagingGroup()) {
465                            return null;
466                    }
467    
468                    try {
469                            if (_stagingGroup == null) {
470                                    _stagingGroup = GroupLocalServiceUtil.getStagingGroup(
471                                            getGroupId());
472    
473                                    if (_stagingGroup instanceof GroupImpl) {
474                                            GroupImpl groupImpl = (GroupImpl)_stagingGroup;
475    
476                                            groupImpl._liveGroup = this;
477                                    }
478                                    else {
479                                            _stagingGroup = new GroupWrapper(_stagingGroup) {
480    
481                                                    @Override
482                                                    public Group getLiveGroup() {
483                                                            return GroupImpl.this;
484                                                    }
485    
486                                            };
487                                    }
488                            }
489    
490                            return _stagingGroup;
491                    }
492                    catch (Exception e) {
493                            _log.error("Error getting staging group for " + getGroupId(), e);
494    
495                            return null;
496                    }
497            }
498    
499            @Override
500            public String getTypeLabel() {
501                    return GroupConstants.getTypeLabel(getType());
502            }
503    
504            @Override
505            public String getTypeSettings() {
506                    if (_typeSettingsProperties == null) {
507                            return super.getTypeSettings();
508                    }
509                    else {
510                            return _typeSettingsProperties.toString();
511                    }
512            }
513    
514            @Override
515            public UnicodeProperties getTypeSettingsProperties() {
516                    if (_typeSettingsProperties == null) {
517                            _typeSettingsProperties = new UnicodeProperties(true);
518    
519                            try {
520                                    _typeSettingsProperties.load(super.getTypeSettings());
521                            }
522                            catch (IOException ioe) {
523                                    _log.error(ioe, ioe);
524                            }
525                    }
526    
527                    return _typeSettingsProperties;
528            }
529    
530            @Override
531            public String getTypeSettingsProperty(String key) {
532                    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
533    
534                    return typeSettingsProperties.getProperty(key);
535            }
536    
537            @Override
538            public String getUnambiguousName(String name, Locale locale) {
539                    try {
540                            StringBundler sb = new StringBundler(5);
541    
542                            sb.append(name);
543                            sb.append(StringPool.SPACE);
544                            sb.append(StringPool.OPEN_PARENTHESIS);
545                            sb.append(getDescriptiveName(locale));
546                            sb.append(StringPool.CLOSE_PARENTHESIS);
547    
548                            return sb.toString();
549                    }
550                    catch (Exception e) {
551                            return name;
552                    }
553            }
554    
555            @Override
556            public boolean hasAncestor(long groupId) {
557                    Group group = null;
558    
559                    if (isStagingGroup()) {
560                            group = getLiveGroup();
561                    }
562                    else {
563                            group = this;
564                    }
565    
566                    String treePath = group.getTreePath();
567    
568                    if ((groupId != group.getGroupId()) &&
569                            treePath.contains(StringPool.SLASH + groupId + StringPool.SLASH)) {
570    
571                            return true;
572                    }
573    
574                    return false;
575            }
576    
577            @Override
578            public boolean hasLocalOrRemoteStagingGroup() {
579                    if (hasStagingGroup() || (getRemoteStagingGroupCount() > 0)) {
580                            return true;
581                    }
582    
583                    return false;
584            }
585    
586            @Override
587            public boolean hasPrivateLayouts() {
588                    if (getPrivateLayoutsPageCount() > 0) {
589                            return true;
590                    }
591                    else {
592                            return false;
593                    }
594            }
595    
596            @Override
597            public boolean hasPublicLayouts() {
598                    if (getPublicLayoutsPageCount() > 0) {
599                            return true;
600                    }
601                    else {
602                            return false;
603                    }
604            }
605    
606            @Override
607            public boolean hasStagingGroup() {
608                    if (isStagingGroup()) {
609                            return false;
610                    }
611    
612                    if (_stagingGroup != null) {
613                            return true;
614                    }
615    
616                    try {
617                            return GroupLocalServiceUtil.hasStagingGroup(getGroupId());
618                    }
619                    catch (Exception e) {
620                            return false;
621                    }
622            }
623    
624            /**
625             * @deprecated As of 7.0.0, replaced by {@link #hasAncestor}
626             */
627            @Override
628            public boolean isChild(long groupId) {
629                    return hasAncestor(groupId);
630            }
631    
632            /**
633             * @deprecated As of 6.1.0, renamed to {@link #isRegularSite}
634             */
635            @Override
636            public boolean isCommunity() {
637                    return isRegularSite();
638            }
639    
640            @Override
641            public boolean isCompany() {
642                    return hasClassName(Company.class) || isCompanyStagingGroup();
643            }
644    
645            @Override
646            public boolean isCompanyStagingGroup() {
647                    Group liveGroup = getLiveGroup();
648    
649                    if (liveGroup == null) {
650                            return false;
651                    }
652    
653                    return liveGroup.isCompany();
654            }
655    
656            @Override
657            public boolean isControlPanel() {
658                    String name = getName();
659    
660                    if (name.equals(GroupConstants.CONTROL_PANEL)) {
661                            return true;
662                    }
663                    else {
664                            return false;
665                    }
666            }
667    
668            @Override
669            public boolean isGuest() {
670                    String name = getName();
671    
672                    if (name.equals(GroupConstants.GUEST)) {
673                            return true;
674                    }
675                    else {
676                            return false;
677                    }
678            }
679    
680            @Override
681            public boolean isInStagingPortlet(String portletId) {
682                    Group liveGroup = getLiveGroup();
683    
684                    if (liveGroup == null) {
685                            return false;
686                    }
687    
688                    return liveGroup.isStagedPortlet(portletId);
689            }
690    
691            @Override
692            public boolean isLayout() {
693                    return hasClassName(Layout.class);
694            }
695    
696            @Override
697            public boolean isLayoutPrototype() {
698                    return hasClassName(LayoutPrototype.class);
699            }
700    
701            @Override
702            public boolean isLayoutSetPrototype() {
703                    return hasClassName(LayoutSetPrototype.class);
704            }
705    
706            @Override
707            public boolean isLimitedToParentSiteMembers() {
708                    if ((getParentGroupId() != GroupConstants.DEFAULT_PARENT_GROUP_ID) &&
709                            (getMembershipRestriction() ==
710                                    GroupConstants.MEMBERSHIP_RESTRICTION_TO_PARENT_SITE_MEMBERS)) {
711    
712                            return true;
713                    }
714    
715                    return false;
716            }
717    
718            @Override
719            public boolean isOrganization() {
720                    return hasClassName(Organization.class);
721            }
722    
723            @Override
724            public boolean isRegularSite() {
725                    return hasClassName(Group.class);
726            }
727    
728            @Override
729            public boolean isRoot() {
730                    if (getParentGroupId() ==
731                                    GroupConstants.DEFAULT_PARENT_GROUP_ID) {
732    
733                            return true;
734                    }
735    
736                    return false;
737            }
738    
739            @Override
740            public boolean isShowSite(
741                            PermissionChecker permissionChecker, boolean privateSite)
742                    throws PortalException, SystemException {
743    
744                    if (!isControlPanel() && !isSite() && !isUser()) {
745                            return false;
746                    }
747    
748                    boolean showSite = true;
749    
750                    Layout defaultLayout = null;
751    
752                    int siteLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(
753                            this, privateSite);
754    
755                    if (siteLayoutsCount == 0) {
756                            boolean hasPowerUserRole = RoleLocalServiceUtil.hasUserRole(
757                                    permissionChecker.getUserId(), permissionChecker.getCompanyId(),
758                                    RoleConstants.POWER_USER, true);
759    
760                            if (isSite()) {
761                                    if (privateSite) {
762                                            showSite =
763                                                    PropsValues.MY_SITES_SHOW_PRIVATE_SITES_WITH_NO_LAYOUTS;
764                                    }
765                                    else {
766                                            showSite =
767                                                    PropsValues.MY_SITES_SHOW_PUBLIC_SITES_WITH_NO_LAYOUTS;
768                                    }
769                            }
770                            else if (isOrganization()) {
771                                    showSite = false;
772                            }
773                            else if (isUser()) {
774                                    if (privateSite) {
775                                            showSite =
776                                                    PropsValues.
777                                                            MY_SITES_SHOW_USER_PRIVATE_SITES_WITH_NO_LAYOUTS;
778    
779                                            if (PropsValues.
780                                                            LAYOUT_USER_PRIVATE_LAYOUTS_POWER_USER_REQUIRED &&
781                                                    !hasPowerUserRole) {
782    
783                                                    showSite = false;
784                                            }
785                                    }
786                                    else {
787                                            showSite =
788                                                    PropsValues.
789                                                            MY_SITES_SHOW_USER_PUBLIC_SITES_WITH_NO_LAYOUTS;
790    
791                                            if (PropsValues.
792                                                            LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED &&
793                                                    !hasPowerUserRole) {
794    
795                                                    showSite = false;
796                                            }
797                                    }
798                            }
799                    }
800                    else {
801                            defaultLayout = LayoutLocalServiceUtil.fetchFirstLayout(
802                                    getGroupId(), privateSite,
803                                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
804    
805                            if ((defaultLayout != null ) &&
806                                    !LayoutPermissionUtil.contains(
807                                            permissionChecker, defaultLayout, true, ActionKeys.VIEW)) {
808    
809                                    showSite = false;
810                            }
811                            else if (isOrganization() && !isSite()) {
812                                    _log.error(
813                                            "Group " + getGroupId() +
814                                                    " is an organization site that does not have pages");
815                            }
816                    }
817    
818                    return showSite;
819            }
820    
821            @Override
822            public boolean isStaged() {
823                    return GetterUtil.getBoolean(
824                            getLiveParentTypeSettingsProperty("staged"));
825            }
826    
827            @Override
828            public boolean isStagedPortlet(String portletId) {
829                    UnicodeProperties typeSettingsProperties =
830                            getParentLiveGroupTypeSettingsProperties();
831    
832                    portletId = PortletConstants.getRootPortletId(portletId);
833    
834                    String typeSettingsProperty = typeSettingsProperties.getProperty(
835                            StagingUtil.getStagedPortletId(portletId));
836    
837                    if (Validator.isNotNull(typeSettingsProperty)) {
838                            return GetterUtil.getBoolean(typeSettingsProperty);
839                    }
840    
841                    try {
842                            Portlet portlet = PortletLocalServiceUtil.getPortletById(portletId);
843    
844                            String portletDataHandlerClass =
845                                    portlet.getPortletDataHandlerClass();
846    
847                            for (Map.Entry<String, String> entry :
848                                            typeSettingsProperties.entrySet()) {
849    
850                                    String key = entry.getKey();
851    
852                                    if (!key.contains(StagingConstants.STAGED_PORTLET)) {
853                                            continue;
854                                    }
855    
856                                    String stagedPortletId = StringUtil.replace(
857                                            key, StagingConstants.STAGED_PORTLET, StringPool.BLANK);
858    
859                                    Portlet stagedPortlet = PortletLocalServiceUtil.getPortletById(
860                                            stagedPortletId);
861    
862                                    if (portletDataHandlerClass.equals(
863                                                    stagedPortlet.getPortletDataHandlerClass())) {
864    
865                                            return GetterUtil.getBoolean(entry.getValue());
866                                    }
867                            }
868                    }
869                    catch (Exception e) {
870                    }
871    
872                    return true;
873            }
874    
875            @Override
876            public boolean isStagedRemotely() {
877                    return GetterUtil.getBoolean(
878                            getLiveParentTypeSettingsProperty("stagedRemotely"));
879            }
880    
881            @Override
882            public boolean isStagingGroup() {
883                    if (getLiveGroupId() == GroupConstants.DEFAULT_LIVE_GROUP_ID) {
884                            return false;
885                    }
886                    else {
887                            return true;
888                    }
889            }
890    
891            @Override
892            public boolean isUser() {
893                    return hasClassName(User.class);
894            }
895    
896            @Override
897            public boolean isUserGroup() {
898                    return hasClassName(UserGroup.class);
899            }
900    
901            @Override
902            public boolean isUserPersonalSite() {
903                    return hasClassName(UserPersonalSite.class);
904            }
905    
906            @Override
907            public void setTypeSettings(String typeSettings) {
908                    _typeSettingsProperties = null;
909    
910                    super.setTypeSettings(typeSettings);
911            }
912    
913            @Override
914            public void setTypeSettingsProperties(
915                    UnicodeProperties typeSettingsProperties) {
916    
917                    _typeSettingsProperties = typeSettingsProperties;
918    
919                    super.setTypeSettings(_typeSettingsProperties.toString());
920            }
921    
922            protected long getDefaultPlid(boolean privateLayout) {
923                    try {
924                            Layout firstLayout = LayoutLocalServiceUtil.fetchFirstLayout(
925                                    getGroupId(), privateLayout,
926                                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
927    
928                            if (firstLayout != null) {
929                                    return firstLayout.getPlid();
930                            }
931                    }
932                    catch (Exception e) {
933                            if (_log.isWarnEnabled()) {
934                                    _log.warn(e.getMessage());
935                            }
936                    }
937    
938                    return LayoutConstants.DEFAULT_PLID;
939            }
940    
941            protected boolean hasClassName(Class<?> clazz) {
942                    long classNameId = getClassNameId();
943    
944                    if (classNameId == PortalUtil.getClassNameId(clazz)) {
945                            return true;
946                    }
947                    else {
948                            return false;
949                    }
950            }
951    
952            private static Log _log = LogFactoryUtil.getLog(GroupImpl.class);
953    
954            private Group _liveGroup;
955            private Group _stagingGroup;
956            private UnicodeProperties _typeSettingsProperties;
957    
958    }