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