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