001
014
015 package com.liferay.portal.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.language.LanguageUtil;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portal.kernel.util.GetterUtil;
022 import com.liferay.portal.kernel.util.HtmlUtil;
023 import com.liferay.portal.kernel.util.LocaleUtil;
024 import com.liferay.portal.kernel.util.OrderByComparator;
025 import com.liferay.portal.kernel.util.StringPool;
026 import com.liferay.portal.kernel.util.StringUtil;
027 import com.liferay.portal.kernel.util.UnicodeProperties;
028 import com.liferay.portal.kernel.util.Validator;
029 import com.liferay.portal.model.Account;
030 import com.liferay.portal.model.Company;
031 import com.liferay.portal.model.Group;
032 import com.liferay.portal.model.GroupConstants;
033 import com.liferay.portal.model.GroupWrapper;
034 import com.liferay.portal.model.Layout;
035 import com.liferay.portal.model.LayoutConstants;
036 import com.liferay.portal.model.LayoutPrototype;
037 import com.liferay.portal.model.LayoutSet;
038 import com.liferay.portal.model.LayoutSetPrototype;
039 import com.liferay.portal.model.Organization;
040 import com.liferay.portal.model.Portlet;
041 import com.liferay.portal.model.PortletConstants;
042 import com.liferay.portal.model.RoleConstants;
043 import com.liferay.portal.model.User;
044 import com.liferay.portal.model.UserGroup;
045 import com.liferay.portal.model.UserPersonalSite;
046 import com.liferay.portal.security.permission.ActionKeys;
047 import com.liferay.portal.security.permission.PermissionChecker;
048 import com.liferay.portal.service.CompanyLocalServiceUtil;
049 import com.liferay.portal.service.GroupLocalServiceUtil;
050 import com.liferay.portal.service.LayoutLocalServiceUtil;
051 import com.liferay.portal.service.LayoutPrototypeLocalServiceUtil;
052 import com.liferay.portal.service.LayoutSetLocalServiceUtil;
053 import com.liferay.portal.service.LayoutSetPrototypeLocalServiceUtil;
054 import com.liferay.portal.service.OrganizationLocalServiceUtil;
055 import com.liferay.portal.service.PortletLocalServiceUtil;
056 import com.liferay.portal.service.RoleLocalServiceUtil;
057 import com.liferay.portal.service.UserGroupLocalServiceUtil;
058 import com.liferay.portal.service.UserLocalServiceUtil;
059 import com.liferay.portal.service.permission.LayoutPermissionUtil;
060 import com.liferay.portal.theme.ThemeDisplay;
061 import com.liferay.portal.util.PortalUtil;
062 import com.liferay.portal.util.PropsValues;
063 import com.liferay.portlet.exportimport.lar.PortletDataHandler;
064 import com.liferay.portlet.exportimport.staging.StagingConstants;
065 import com.liferay.portlet.exportimport.staging.StagingUtil;
066
067 import java.io.IOException;
068
069 import java.util.ArrayList;
070 import java.util.LinkedHashSet;
071 import java.util.List;
072 import java.util.Locale;
073 import java.util.Map;
074 import java.util.Set;
075
076
103 public class GroupImpl extends GroupBaseImpl {
104
105 @Override
106 public void clearStagingGroup() {
107 _stagingGroup = null;
108 }
109
110 @Override
111 public List<Group> getAncestors() throws PortalException {
112 Group group = null;
113
114 if (isStagingGroup()) {
115 group = getLiveGroup();
116 }
117 else {
118 group = this;
119 }
120
121 List<Group> groups = new ArrayList<>();
122
123 while (!group.isRoot()) {
124 group = group.getParentGroup();
125
126 groups.add(group);
127 }
128
129 return groups;
130 }
131
132 @Override
133 public List<Group> getChildren(boolean site) {
134 return GroupLocalServiceUtil.getGroups(
135 getCompanyId(), getGroupId(), site);
136 }
137
138
143 @Deprecated
144 @Override
145 public List<Group> getChildrenWithLayouts(
146 boolean site, int start, int end) {
147
148 return getChildrenWithLayouts(site, start, end, null);
149 }
150
151 @Override
152 public List<Group> getChildrenWithLayouts(
153 boolean site, int start, int end, OrderByComparator<Group> obc) {
154
155 return GroupLocalServiceUtil.getLayoutsGroups(
156 getCompanyId(), getGroupId(), site, start, end, obc);
157 }
158
159 @Override
160 public int getChildrenWithLayoutsCount(boolean site) {
161 return GroupLocalServiceUtil.getLayoutsGroupsCount(
162 getCompanyId(), getGroupId(), site);
163 }
164
165 @Override
166 public long getDefaultPrivatePlid() {
167 return getDefaultPlid(true);
168 }
169
170 @Override
171 public long getDefaultPublicPlid() {
172 return getDefaultPlid(false);
173 }
174
175 @Override
176 public List<Group> getDescendants(boolean site) {
177 Set<Group> descendants = new LinkedHashSet<>();
178
179 for (Group group : getChildren(site)) {
180 descendants.add(group);
181 descendants.addAll(group.getDescendants(site));
182 }
183
184 return new ArrayList<>(descendants);
185 }
186
187 @Override
188 public String getDescriptiveName() throws PortalException {
189 return getDescriptiveName(LocaleUtil.getMostRelevantLocale());
190 }
191
192 @Override
193 public String getDescriptiveName(Locale locale) throws PortalException {
194 Group curGroup = this;
195
196 String name = getName(locale);
197
198 if (Validator.isNull(name)) {
199 Locale siteDefaultLocale = PortalUtil.getSiteDefaultLocale(
200 getGroupId());
201
202 name = getName(siteDefaultLocale);
203 }
204
205 if (isCompany() && !isCompanyStagingGroup()) {
206 name = LanguageUtil.get(locale, "global");
207 }
208 else if (isControlPanel()) {
209 name = LanguageUtil.get(locale, "control-panel");
210 }
211 else if (isGuest()) {
212 Company company = CompanyLocalServiceUtil.getCompany(
213 getCompanyId());
214
215 Account account = company.getAccount();
216
217 name = account.getName();
218 }
219 else if (isLayout()) {
220 Layout layout = LayoutLocalServiceUtil.getLayout(getClassPK());
221
222 name = layout.getName(locale);
223 }
224 else if (isLayoutPrototype()) {
225 LayoutPrototype layoutPrototype =
226 LayoutPrototypeLocalServiceUtil.getLayoutPrototype(
227 getClassPK());
228
229 name = layoutPrototype.getName(locale);
230 }
231 else if (isLayoutSetPrototype()) {
232 LayoutSetPrototype layoutSetPrototype =
233 LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(
234 getClassPK());
235
236 name = layoutSetPrototype.getName(locale);
237 }
238 else if (isOrganization()) {
239 long organizationId = getOrganizationId();
240
241 Organization organization =
242 OrganizationLocalServiceUtil.getOrganization(organizationId);
243
244 name = organization.getName();
245
246 curGroup = organization.getGroup();
247 }
248 else if (isUser()) {
249 long userId = getClassPK();
250
251 User user = UserLocalServiceUtil.getUser(userId);
252
253 name = user.getFullName();
254 }
255 else if (isUserGroup()) {
256 long userGroupId = getClassPK();
257
258 UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(
259 userGroupId);
260
261 name = userGroup.getName();
262 }
263 else if (isUserPersonalSite()) {
264 name = LanguageUtil.get(locale, "user-personal-site");
265 }
266
267 if (curGroup.isStaged() && !curGroup.isStagedRemotely() &&
268 curGroup.isStagingGroup()) {
269
270 Group liveGroup = getLiveGroup();
271
272 name = liveGroup.getDescriptiveName(locale);
273 }
274
275 return name;
276 }
277
278 @Override
279 public String getDisplayURL(ThemeDisplay themeDisplay) {
280 return getDisplayURL(themeDisplay, false);
281 }
282
283 @Override
284 public String getDisplayURL(
285 ThemeDisplay themeDisplay, boolean privateLayout) {
286
287 if (!privateLayout && (getPublicLayoutsPageCount() > 0)) {
288 try {
289 String groupFriendlyURL = PortalUtil.getGroupFriendlyURL(
290 getPublicLayoutSet(), themeDisplay);
291
292 return PortalUtil.addPreservedParameters(
293 themeDisplay, groupFriendlyURL);
294 }
295 catch (PortalException pe) {
296 _log.error(pe, pe);
297 }
298 }
299 else if (privateLayout && (getPrivateLayoutsPageCount() > 0)) {
300 try {
301 String groupFriendlyURL = PortalUtil.getGroupFriendlyURL(
302 getPrivateLayoutSet(), themeDisplay);
303
304 return PortalUtil.addPreservedParameters(
305 themeDisplay, groupFriendlyURL);
306 }
307 catch (PortalException pe) {
308 _log.error(pe);
309 }
310 }
311
312 return StringPool.BLANK;
313 }
314
315 @Override
316 public String getIconCssClass() {
317 String iconCss = "icon-globe";
318
319 if (isCompany()) {
320 iconCss = "icon-globe";
321 }
322 else if (isLayout()) {
323 iconCss = "icon-file";
324 }
325 else if (isOrganization()) {
326 iconCss = "icon-globe";
327 }
328 else if (isUser()) {
329 iconCss = "icon-user";
330 }
331
332 return iconCss;
333 }
334
335 @Override
336 public String getIconURL(ThemeDisplay themeDisplay) {
337 String iconURL = StringPool.BLANK;
338
339 if (isCompany()) {
340 iconURL = "../aui/globe";
341 }
342 else if (isLayout()) {
343 iconURL = "../aui/file";
344 }
345 else if (isOrganization()) {
346 iconURL = "../aui/globe";
347 }
348 else if (isUser()) {
349 iconURL = "../aui/user";
350 }
351 else {
352 iconURL = "../aui/globe";
353 }
354
355 return iconURL;
356 }
357
358 @Override
359 public String getLayoutRootNodeName(boolean privateLayout, Locale locale) {
360 String pagesName = null;
361
362 if (isLayoutPrototype() || isLayoutSetPrototype() || isUserGroup()) {
363 pagesName = "pages";
364 }
365 else if (privateLayout) {
366 if (isUser()) {
367 pagesName = "my-dashboard";
368 }
369 else {
370 pagesName = "private-pages";
371 }
372 }
373 else {
374 if (isUser()) {
375 pagesName = "my-profile";
376 }
377 else {
378 pagesName = "public-pages";
379 }
380 }
381
382 return LanguageUtil.get(locale, pagesName);
383 }
384
385 @Override
386 public Group getLiveGroup() {
387 if (!isStagingGroup()) {
388 return null;
389 }
390
391 try {
392 if (_liveGroup == null) {
393 _liveGroup = GroupLocalServiceUtil.getGroup(getLiveGroupId());
394
395 if (_liveGroup instanceof GroupImpl) {
396 GroupImpl groupImpl = (GroupImpl)_liveGroup;
397
398 groupImpl._stagingGroup = this;
399 }
400 else {
401 _liveGroup = new GroupWrapper(_liveGroup) {
402
403 @Override
404 public Group getStagingGroup() {
405 return GroupImpl.this;
406 }
407
408 };
409 }
410 }
411
412 return _liveGroup;
413 }
414 catch (Exception e) {
415 _log.error("Error getting live group for " + getLiveGroupId(), e);
416
417 return null;
418 }
419 }
420
421 @Override
422 public String getLiveParentTypeSettingsProperty(String key) {
423 UnicodeProperties typeSettingsProperties =
424 getParentLiveGroupTypeSettingsProperties();
425
426 return typeSettingsProperties.getProperty(key);
427 }
428
429 @Override
430 public long getOrganizationId() {
431 if (isOrganization()) {
432 if (isStagingGroup()) {
433 Group liveGroup = getLiveGroup();
434
435 return liveGroup.getClassPK();
436 }
437 else {
438 return getClassPK();
439 }
440 }
441
442 return 0;
443 }
444
445 @Override
446 public Group getParentGroup() throws PortalException {
447 long parentGroupId = getParentGroupId();
448
449 if (parentGroupId <= 0) {
450 return null;
451 }
452
453 return GroupLocalServiceUtil.getGroup(parentGroupId);
454 }
455
456 @Override
457 public UnicodeProperties getParentLiveGroupTypeSettingsProperties() {
458 try {
459 if (isLayout()) {
460 Group parentGroup = GroupLocalServiceUtil.getGroup(
461 getParentGroupId());
462
463 return parentGroup.getParentLiveGroupTypeSettingsProperties();
464 }
465
466 if (isStagingGroup()) {
467 Group liveGroup = getLiveGroup();
468
469 return liveGroup.getTypeSettingsProperties();
470 }
471 }
472 catch (Exception e) {
473 }
474
475 return getTypeSettingsProperties();
476 }
477
478 @Override
479 public String getPathFriendlyURL(
480 boolean privateLayout, ThemeDisplay themeDisplay) {
481
482 if (privateLayout) {
483 if (isUser()) {
484 return themeDisplay.getPathFriendlyURLPrivateUser();
485 }
486 else {
487 return themeDisplay.getPathFriendlyURLPrivateGroup();
488 }
489 }
490 else {
491 return themeDisplay.getPathFriendlyURLPublic();
492 }
493 }
494
495 @Override
496 public LayoutSet getPrivateLayoutSet() {
497 LayoutSet layoutSet = null;
498
499 try {
500 layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
501 getGroupId(), true);
502 }
503 catch (Exception e) {
504 _log.error(e, e);
505 }
506
507 return layoutSet;
508 }
509
510 @Override
511 public int getPrivateLayoutsPageCount() {
512 try {
513 return LayoutLocalServiceUtil.getLayoutsCount(this, true);
514 }
515 catch (Exception e) {
516 _log.error(e, e);
517 }
518
519 return 0;
520 }
521
522 @Override
523 public LayoutSet getPublicLayoutSet() {
524 LayoutSet layoutSet = null;
525
526 try {
527 layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
528 getGroupId(), false);
529 }
530 catch (Exception e) {
531 _log.error(e, e);
532 }
533
534 return layoutSet;
535 }
536
537 @Override
538 public int getPublicLayoutsPageCount() {
539 try {
540 return LayoutLocalServiceUtil.getLayoutsCount(this, false);
541 }
542 catch (Exception e) {
543 _log.error(e, e);
544 }
545
546 return 0;
547 }
548
549 @Override
550 public long getRemoteLiveGroupId() {
551 if (!isStagedRemotely()) {
552 return GroupConstants.DEFAULT_LIVE_GROUP_ID;
553 }
554
555 return GetterUtil.getLong(getTypeSettingsProperty("remoteGroupId"));
556 }
557
558 @Override
559 public String getScopeDescriptiveName(ThemeDisplay themeDisplay)
560 throws PortalException {
561
562 if (getGroupId() == themeDisplay.getScopeGroupId()) {
563 return StringUtil.appendParentheticalSuffix(
564 themeDisplay.translate("current-site"),
565 HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
566 }
567 else if (isLayout() && (getClassPK() == themeDisplay.getPlid())) {
568 return StringUtil.appendParentheticalSuffix(
569 themeDisplay.translate("current-page"),
570 HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
571 }
572 else if (isLayoutPrototype()) {
573 return themeDisplay.translate("default");
574 }
575 else {
576 return HtmlUtil.escape(
577 getDescriptiveName(themeDisplay.getLocale()));
578 }
579 }
580
581 @Override
582 public String getScopeLabel(ThemeDisplay themeDisplay) {
583 String label = "site";
584
585 if (getGroupId() == themeDisplay.getScopeGroupId()) {
586 label = "current-site";
587 }
588 else if (getGroupId() == themeDisplay.getCompanyGroupId()) {
589 label = "global";
590 }
591 else if (isLayout()) {
592 label = "page";
593 }
594 else {
595 Group scopeGroup = themeDisplay.getScopeGroup();
596
597 if (scopeGroup.hasAncestor(getGroupId())) {
598 label = "parent-site";
599 }
600 else if (hasAncestor(scopeGroup.getGroupId())) {
601 label = "child-site";
602 }
603 }
604
605 return label;
606 }
607
608 @Override
609 public Group getStagingGroup() {
610 if (isStagingGroup()) {
611 return null;
612 }
613
614 try {
615 if (_stagingGroup == null) {
616 _stagingGroup = GroupLocalServiceUtil.getStagingGroup(
617 getGroupId());
618
619 if (_stagingGroup instanceof GroupImpl) {
620 GroupImpl groupImpl = (GroupImpl)_stagingGroup;
621
622 groupImpl._liveGroup = this;
623 }
624 else {
625 _stagingGroup = new GroupWrapper(_stagingGroup) {
626
627 @Override
628 public Group getLiveGroup() {
629 return GroupImpl.this;
630 }
631
632 };
633 }
634 }
635
636 return _stagingGroup;
637 }
638 catch (Exception e) {
639 _log.error("Error getting staging group for " + getGroupId(), e);
640
641 return null;
642 }
643 }
644
645 @Override
646 public String getTypeLabel() {
647 return GroupConstants.getTypeLabel(getType());
648 }
649
650 @Override
651 public String getTypeSettings() {
652 if (_typeSettingsProperties == null) {
653 return super.getTypeSettings();
654 }
655 else {
656 return _typeSettingsProperties.toString();
657 }
658 }
659
660 @Override
661 public UnicodeProperties getTypeSettingsProperties() {
662 if (_typeSettingsProperties == null) {
663 _typeSettingsProperties = new UnicodeProperties(true);
664
665 try {
666 _typeSettingsProperties.load(super.getTypeSettings());
667 }
668 catch (IOException ioe) {
669 _log.error(ioe, ioe);
670 }
671 }
672
673 return _typeSettingsProperties;
674 }
675
676 @Override
677 public String getTypeSettingsProperty(String key) {
678 UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
679
680 return typeSettingsProperties.getProperty(key);
681 }
682
683 @Override
684 public String getUnambiguousName(String name, Locale locale) {
685 try {
686 return StringUtil.appendParentheticalSuffix(
687 name, getDescriptiveName(locale));
688 }
689 catch (Exception e) {
690 return name;
691 }
692 }
693
694 @Override
695 public boolean hasAncestor(long groupId) {
696 Group group = null;
697
698 if (isStagingGroup()) {
699 group = getLiveGroup();
700 }
701 else {
702 group = this;
703 }
704
705 String treePath = group.getTreePath();
706
707 if ((groupId != group.getGroupId()) &&
708 treePath.contains(StringPool.SLASH + groupId + StringPool.SLASH)) {
709
710 return true;
711 }
712
713 return false;
714 }
715
716 @Override
717 public boolean hasLocalOrRemoteStagingGroup() {
718 if (hasRemoteStagingGroup() || hasStagingGroup()) {
719 return true;
720 }
721
722 return false;
723 }
724
725 @Override
726 public boolean hasPrivateLayouts() {
727 if (getPrivateLayoutsPageCount() > 0) {
728 return true;
729 }
730 else {
731 return false;
732 }
733 }
734
735 @Override
736 public boolean hasPublicLayouts() {
737 if (getPublicLayoutsPageCount() > 0) {
738 return true;
739 }
740 else {
741 return false;
742 }
743 }
744
745 @Override
746 public boolean hasRemoteStagingGroup() {
747 if (getRemoteStagingGroupCount() > 0) {
748 return true;
749 }
750
751 return false;
752 }
753
754 @Override
755 public boolean hasStagingGroup() {
756 if (isStagingGroup()) {
757 return false;
758 }
759
760 if (_stagingGroup != null) {
761 return true;
762 }
763
764 try {
765 return GroupLocalServiceUtil.hasStagingGroup(getGroupId());
766 }
767 catch (Exception e) {
768 return false;
769 }
770 }
771
772
775 @Deprecated
776 @Override
777 public boolean isChild(long groupId) {
778 return hasAncestor(groupId);
779 }
780
781
784 @Deprecated
785 @Override
786 public boolean isCommunity() {
787 return isRegularSite();
788 }
789
790 @Override
791 public boolean isCompany() {
792 return hasClassName(Company.class) || isCompanyStagingGroup();
793 }
794
795 @Override
796 public boolean isCompanyStagingGroup() {
797 Group liveGroup = getLiveGroup();
798
799 if (liveGroup == null) {
800 return false;
801 }
802
803 return liveGroup.isCompany();
804 }
805
806 @Override
807 public boolean isControlPanel() {
808 String groupKey = getGroupKey();
809
810 if (groupKey.equals(GroupConstants.CONTROL_PANEL)) {
811 return true;
812 }
813 else {
814 return false;
815 }
816 }
817
818 @Override
819 public boolean isGuest() {
820 String groupKey = getGroupKey();
821
822 if (groupKey.equals(GroupConstants.GUEST)) {
823 return true;
824 }
825 else {
826 return false;
827 }
828 }
829
830 @Override
831 public boolean isInStagingPortlet(String portletId) {
832 Group liveGroup = getLiveGroup();
833
834 if (liveGroup == null) {
835 return false;
836 }
837
838 return liveGroup.isStagedPortlet(portletId);
839 }
840
841 @Override
842 public boolean isLayout() {
843 return hasClassName(Layout.class);
844 }
845
846 @Override
847 public boolean isLayoutPrototype() {
848 return hasClassName(LayoutPrototype.class);
849 }
850
851 @Override
852 public boolean isLayoutSetPrototype() {
853 return hasClassName(LayoutSetPrototype.class);
854 }
855
856 @Override
857 public boolean isLimitedToParentSiteMembers() {
858 if ((getParentGroupId() != GroupConstants.DEFAULT_PARENT_GROUP_ID) &&
859 (getMembershipRestriction() ==
860 GroupConstants.MEMBERSHIP_RESTRICTION_TO_PARENT_SITE_MEMBERS)) {
861
862 return true;
863 }
864
865 return false;
866 }
867
868 @Override
869 public boolean isOrganization() {
870 return hasClassName(Organization.class);
871 }
872
873 @Override
874 public boolean isRegularSite() {
875 return hasClassName(Group.class);
876 }
877
878 @Override
879 public boolean isRoot() {
880 if (getParentGroupId() == GroupConstants.DEFAULT_PARENT_GROUP_ID) {
881 return true;
882 }
883
884 return false;
885 }
886
887 @Override
888 public boolean isShowSite(
889 PermissionChecker permissionChecker, boolean privateSite)
890 throws PortalException {
891
892 if (!isControlPanel() && !isSite() && !isUser()) {
893 return false;
894 }
895
896 boolean showSite = true;
897
898 Layout defaultLayout = null;
899
900 int siteLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(
901 this, privateSite);
902
903 if (siteLayoutsCount == 0) {
904 boolean hasPowerUserRole = RoleLocalServiceUtil.hasUserRole(
905 permissionChecker.getUserId(), permissionChecker.getCompanyId(),
906 RoleConstants.POWER_USER, true);
907
908 if (isSite()) {
909 if (privateSite) {
910 showSite =
911 PropsValues.MY_SITES_SHOW_PRIVATE_SITES_WITH_NO_LAYOUTS;
912 }
913 else {
914 showSite =
915 PropsValues.MY_SITES_SHOW_PUBLIC_SITES_WITH_NO_LAYOUTS;
916 }
917 }
918 else if (isOrganization()) {
919 showSite = false;
920 }
921 else if (isUser()) {
922 if (privateSite) {
923 showSite =
924 PropsValues.
925 MY_SITES_SHOW_USER_PRIVATE_SITES_WITH_NO_LAYOUTS;
926
927 if (PropsValues.
928 LAYOUT_USER_PRIVATE_LAYOUTS_POWER_USER_REQUIRED &&
929 !hasPowerUserRole) {
930
931 showSite = false;
932 }
933 }
934 else {
935 showSite =
936 PropsValues.
937 MY_SITES_SHOW_USER_PUBLIC_SITES_WITH_NO_LAYOUTS;
938
939 if (PropsValues.
940 LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED &&
941 !hasPowerUserRole) {
942
943 showSite = false;
944 }
945 }
946 }
947 }
948 else {
949 defaultLayout = LayoutLocalServiceUtil.fetchFirstLayout(
950 getGroupId(), privateSite,
951 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
952
953 if ((defaultLayout != null ) &&
954 !LayoutPermissionUtil.contains(
955 permissionChecker, defaultLayout, true, ActionKeys.VIEW)) {
956
957 showSite = false;
958 }
959 else if (isOrganization() && !isSite()) {
960 _log.error(
961 "Group " + getGroupId() +
962 " is an organization site that does not have pages");
963 }
964 }
965
966 return showSite;
967 }
968
969 @Override
970 public boolean isStaged() {
971 return GetterUtil.getBoolean(
972 getLiveParentTypeSettingsProperty("staged"));
973 }
974
975 @Override
976 public boolean isStagedPortlet(String portletId) {
977 UnicodeProperties typeSettingsProperties =
978 getParentLiveGroupTypeSettingsProperties();
979
980 portletId = PortletConstants.getRootPortletId(portletId);
981
982 String typeSettingsProperty = typeSettingsProperties.getProperty(
983 StagingUtil.getStagedPortletId(portletId));
984
985 if (Validator.isNotNull(typeSettingsProperty)) {
986 return GetterUtil.getBoolean(typeSettingsProperty);
987 }
988
989 try {
990 Portlet portlet = PortletLocalServiceUtil.getPortletById(portletId);
991
992 PortletDataHandler portletDataHandler =
993 portlet.getPortletDataHandlerInstance();
994
995 if (portletDataHandler == null) {
996 return false;
997 }
998
999 for (Map.Entry<String, String> entry :
1000 typeSettingsProperties.entrySet()) {
1001
1002 String key = entry.getKey();
1003
1004 if (!key.contains(StagingConstants.STAGED_PORTLET)) {
1005 continue;
1006 }
1007
1008 String stagedPortletId = StringUtil.replace(
1009 key, StagingConstants.STAGED_PORTLET, StringPool.BLANK);
1010
1011 Portlet stagedPortlet = PortletLocalServiceUtil.getPortletById(
1012 stagedPortletId);
1013
1014 if (portletDataHandler.equals(
1015 stagedPortlet.getPortletDataHandlerInstance())) {
1016
1017 return GetterUtil.getBoolean(entry.getValue());
1018 }
1019 }
1020 }
1021 catch (Exception e) {
1022 }
1023
1024 return true;
1025 }
1026
1027 @Override
1028 public boolean isStagedRemotely() {
1029 return GetterUtil.getBoolean(
1030 getLiveParentTypeSettingsProperty("stagedRemotely"));
1031 }
1032
1033 @Override
1034 public boolean isStagingGroup() {
1035 if (getLiveGroupId() == GroupConstants.DEFAULT_LIVE_GROUP_ID) {
1036 return false;
1037 }
1038 else {
1039 return true;
1040 }
1041 }
1042
1043 @Override
1044 public boolean isUser() {
1045 return hasClassName(User.class);
1046 }
1047
1048 @Override
1049 public boolean isUserGroup() {
1050 return hasClassName(UserGroup.class);
1051 }
1052
1053 @Override
1054 public boolean isUserPersonalSite() {
1055 return hasClassName(UserPersonalSite.class);
1056 }
1057
1058 @Override
1059 public void setTypeSettings(String typeSettings) {
1060 _typeSettingsProperties = null;
1061
1062 super.setTypeSettings(typeSettings);
1063 }
1064
1065 @Override
1066 public void setTypeSettingsProperties(
1067 UnicodeProperties typeSettingsProperties) {
1068
1069 _typeSettingsProperties = typeSettingsProperties;
1070
1071 super.setTypeSettings(_typeSettingsProperties.toString());
1072 }
1073
1074 protected long getDefaultPlid(boolean privateLayout) {
1075 try {
1076 Layout firstLayout = LayoutLocalServiceUtil.fetchFirstLayout(
1077 getGroupId(), privateLayout,
1078 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
1079
1080 if (firstLayout != null) {
1081 return firstLayout.getPlid();
1082 }
1083 }
1084 catch (Exception e) {
1085 if (_log.isWarnEnabled()) {
1086 _log.warn(e.getMessage());
1087 }
1088 }
1089
1090 return LayoutConstants.DEFAULT_PLID;
1091 }
1092
1093 protected boolean hasClassName(Class<?> clazz) {
1094 long classNameId = getClassNameId();
1095
1096 if (classNameId == PortalUtil.getClassNameId(clazz)) {
1097 return true;
1098 }
1099 else {
1100 return false;
1101 }
1102 }
1103
1104 private static final Log _log = LogFactoryUtil.getLog(GroupImpl.class);
1105
1106 private Group _liveGroup;
1107 private Group _stagingGroup;
1108 private UnicodeProperties _typeSettingsProperties;
1109
1110 }