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.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 boolean hasAncestor(long groupId) {
539                    Group group = null;
540    
541                    if (isStagingGroup()) {
542                            group = getLiveGroup();
543                    }
544                    else {
545                            group = this;
546                    }
547    
548                    String treePath = group.getTreePath();
549    
550                    if ((groupId != group.getGroupId()) &&
551                            treePath.contains(StringPool.SLASH + groupId + StringPool.SLASH)) {
552    
553                            return true;
554                    }
555    
556                    return false;
557            }
558    
559            @Override
560            public boolean hasLocalOrRemoteStagingGroup() {
561                    if (hasStagingGroup() || (getRemoteStagingGroupCount() > 0)) {
562                            return true;
563                    }
564    
565                    return false;
566            }
567    
568            @Override
569            public boolean hasPrivateLayouts() {
570                    if (getPrivateLayoutsPageCount() > 0) {
571                            return true;
572                    }
573                    else {
574                            return false;
575                    }
576            }
577    
578            @Override
579            public boolean hasPublicLayouts() {
580                    if (getPublicLayoutsPageCount() > 0) {
581                            return true;
582                    }
583                    else {
584                            return false;
585                    }
586            }
587    
588            @Override
589            public boolean hasStagingGroup() {
590                    if (isStagingGroup()) {
591                            return false;
592                    }
593    
594                    if (_stagingGroup != null) {
595                            return true;
596                    }
597    
598                    try {
599                            return GroupLocalServiceUtil.hasStagingGroup(getGroupId());
600                    }
601                    catch (Exception e) {
602                            return false;
603                    }
604            }
605    
606            /**
607             * @deprecated As of 7.0.0, replaced by {@link #hasAncestor}
608             */
609            @Override
610            public boolean isChild(long groupId) {
611                    return hasAncestor(groupId);
612            }
613    
614            /**
615             * @deprecated As of 6.1.0, renamed to {@link #isRegularSite}
616             */
617            @Override
618            public boolean isCommunity() {
619                    return isRegularSite();
620            }
621    
622            @Override
623            public boolean isCompany() {
624                    return hasClassName(Company.class) || isCompanyStagingGroup();
625            }
626    
627            @Override
628            public boolean isCompanyStagingGroup() {
629                    Group liveGroup = getLiveGroup();
630    
631                    if (liveGroup == null) {
632                            return false;
633                    }
634    
635                    return liveGroup.isCompany();
636            }
637    
638            @Override
639            public boolean isControlPanel() {
640                    String name = getName();
641    
642                    if (name.equals(GroupConstants.CONTROL_PANEL)) {
643                            return true;
644                    }
645                    else {
646                            return false;
647                    }
648            }
649    
650            @Override
651            public boolean isGuest() {
652                    String name = getName();
653    
654                    if (name.equals(GroupConstants.GUEST)) {
655                            return true;
656                    }
657                    else {
658                            return false;
659                    }
660            }
661    
662            @Override
663            public boolean isInStagingPortlet(String portletId) {
664                    Group liveGroup = getLiveGroup();
665    
666                    if (liveGroup == null) {
667                            return false;
668                    }
669    
670                    return liveGroup.isStagedPortlet(portletId);
671            }
672    
673            @Override
674            public boolean isLayout() {
675                    return hasClassName(Layout.class);
676            }
677    
678            @Override
679            public boolean isLayoutPrototype() {
680                    return hasClassName(LayoutPrototype.class);
681            }
682    
683            @Override
684            public boolean isLayoutSetPrototype() {
685                    return hasClassName(LayoutSetPrototype.class);
686            }
687    
688            @Override
689            public boolean isLimitedToParentSiteMembers() {
690                    if ((getParentGroupId() != GroupConstants.DEFAULT_PARENT_GROUP_ID) &&
691                            (getMembershipRestriction() ==
692                                    GroupConstants.MEMBERSHIP_RESTRICTION_TO_PARENT_SITE_MEMBERS)) {
693    
694                            return true;
695                    }
696    
697                    return false;
698            }
699    
700            @Override
701            public boolean isOrganization() {
702                    return hasClassName(Organization.class);
703            }
704    
705            @Override
706            public boolean isRegularSite() {
707                    return hasClassName(Group.class);
708            }
709    
710            @Override
711            public boolean isRoot() {
712                    if (getParentGroupId() ==
713                                    GroupConstants.DEFAULT_PARENT_GROUP_ID) {
714    
715                            return true;
716                    }
717    
718                    return false;
719            }
720    
721            @Override
722            public boolean isShowSite(
723                            PermissionChecker permissionChecker, boolean privateSite)
724                    throws PortalException, SystemException {
725    
726                    if (!isControlPanel() && !isSite() && !isUser()) {
727                            return false;
728                    }
729    
730                    boolean showSite = true;
731    
732                    Layout defaultLayout = null;
733    
734                    int siteLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(
735                            this, privateSite);
736    
737                    if (siteLayoutsCount == 0) {
738                            boolean hasPowerUserRole = RoleLocalServiceUtil.hasUserRole(
739                                    permissionChecker.getUserId(), permissionChecker.getCompanyId(),
740                                    RoleConstants.POWER_USER, true);
741    
742                            if (isSite()) {
743                                    if (privateSite) {
744                                            showSite =
745                                                    PropsValues.MY_SITES_SHOW_PRIVATE_SITES_WITH_NO_LAYOUTS;
746                                    }
747                                    else {
748                                            showSite =
749                                                    PropsValues.MY_SITES_SHOW_PUBLIC_SITES_WITH_NO_LAYOUTS;
750                                    }
751                            }
752                            else if (isOrganization()) {
753                                    showSite = false;
754                            }
755                            else if (isUser()) {
756                                    if (privateSite) {
757                                            showSite =
758                                                    PropsValues.
759                                                            MY_SITES_SHOW_USER_PRIVATE_SITES_WITH_NO_LAYOUTS;
760    
761                                            if (PropsValues.
762                                                            LAYOUT_USER_PRIVATE_LAYOUTS_POWER_USER_REQUIRED &&
763                                                    !hasPowerUserRole) {
764    
765                                                    showSite = false;
766                                            }
767                                    }
768                                    else {
769                                            showSite =
770                                                    PropsValues.
771                                                            MY_SITES_SHOW_USER_PUBLIC_SITES_WITH_NO_LAYOUTS;
772    
773                                            if (PropsValues.
774                                                            LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED &&
775                                                    !hasPowerUserRole) {
776    
777                                                    showSite = false;
778                                            }
779                                    }
780                            }
781                    }
782                    else {
783                            defaultLayout = LayoutLocalServiceUtil.fetchFirstLayout(
784                                    getGroupId(), privateSite,
785                                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
786    
787                            if ((defaultLayout != null ) &&
788                                    !LayoutPermissionUtil.contains(
789                                            permissionChecker, defaultLayout, true, ActionKeys.VIEW)) {
790    
791                                    showSite = false;
792                            }
793                            else if (isOrganization() && !isSite()) {
794                                    _log.error(
795                                            "Group " + getGroupId() +
796                                                    " is an organization site that does not have pages");
797                            }
798                    }
799    
800                    return showSite;
801            }
802    
803            @Override
804            public boolean isStaged() {
805                    return GetterUtil.getBoolean(
806                            getLiveParentTypeSettingsProperty("staged"));
807            }
808    
809            @Override
810            public boolean isStagedPortlet(String portletId) {
811                    UnicodeProperties typeSettingsProperties =
812                            getParentLiveGroupTypeSettingsProperties();
813    
814                    portletId = PortletConstants.getRootPortletId(portletId);
815    
816                    String typeSettingsProperty = typeSettingsProperties.getProperty(
817                            StagingUtil.getStagedPortletId(portletId));
818    
819                    if (Validator.isNotNull(typeSettingsProperty)) {
820                            return GetterUtil.getBoolean(typeSettingsProperty);
821                    }
822    
823                    try {
824                            Portlet portlet = PortletLocalServiceUtil.getPortletById(portletId);
825    
826                            String portletDataHandlerClass =
827                                    portlet.getPortletDataHandlerClass();
828    
829                            for (Map.Entry<String, String> entry :
830                                            typeSettingsProperties.entrySet()) {
831    
832                                    String key = entry.getKey();
833    
834                                    if (!key.contains(StagingConstants.STAGED_PORTLET)) {
835                                            continue;
836                                    }
837    
838                                    String stagedPortletId = StringUtil.replace(
839                                            key, StagingConstants.STAGED_PORTLET, StringPool.BLANK);
840    
841                                    Portlet stagedPortlet = PortletLocalServiceUtil.getPortletById(
842                                            stagedPortletId);
843    
844                                    if (portletDataHandlerClass.equals(
845                                                    stagedPortlet.getPortletDataHandlerClass())) {
846    
847                                            return GetterUtil.getBoolean(entry.getValue());
848                                    }
849                            }
850                    }
851                    catch (Exception e) {
852                    }
853    
854                    return true;
855            }
856    
857            @Override
858            public boolean isStagedRemotely() {
859                    return GetterUtil.getBoolean(
860                            getLiveParentTypeSettingsProperty("stagedRemotely"));
861            }
862    
863            @Override
864            public boolean isStagingGroup() {
865                    if (getLiveGroupId() == GroupConstants.DEFAULT_LIVE_GROUP_ID) {
866                            return false;
867                    }
868                    else {
869                            return true;
870                    }
871            }
872    
873            @Override
874            public boolean isUser() {
875                    return hasClassName(User.class);
876            }
877    
878            @Override
879            public boolean isUserGroup() {
880                    return hasClassName(UserGroup.class);
881            }
882    
883            @Override
884            public boolean isUserPersonalSite() {
885                    return hasClassName(UserPersonalSite.class);
886            }
887    
888            @Override
889            public void setTypeSettings(String typeSettings) {
890                    _typeSettingsProperties = null;
891    
892                    super.setTypeSettings(typeSettings);
893            }
894    
895            @Override
896            public void setTypeSettingsProperties(
897                    UnicodeProperties typeSettingsProperties) {
898    
899                    _typeSettingsProperties = typeSettingsProperties;
900    
901                    super.setTypeSettings(_typeSettingsProperties.toString());
902            }
903    
904            protected long getDefaultPlid(boolean privateLayout) {
905                    try {
906                            Layout firstLayout = LayoutLocalServiceUtil.fetchFirstLayout(
907                                    getGroupId(), privateLayout,
908                                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
909    
910                            if (firstLayout != null) {
911                                    return firstLayout.getPlid();
912                            }
913                    }
914                    catch (Exception e) {
915                            if (_log.isWarnEnabled()) {
916                                    _log.warn(e.getMessage());
917                            }
918                    }
919    
920                    return LayoutConstants.DEFAULT_PLID;
921            }
922    
923            protected boolean hasClassName(Class<?> clazz) {
924                    long classNameId = getClassNameId();
925    
926                    if (classNameId == PortalUtil.getClassNameId(clazz)) {
927                            return true;
928                    }
929                    else {
930                            return false;
931                    }
932            }
933    
934            private static Log _log = LogFactoryUtil.getLog(GroupImpl.class);
935    
936            private Group _liveGroup;
937            private Group _stagingGroup;
938            private UnicodeProperties _typeSettingsProperties;
939    
940    }