diff --git a/src/main/java/org/olat/NewControllerFactory.java b/src/main/java/org/olat/NewControllerFactory.java index 33dd10270afdcd340e521936e2dcce512cf87ba2..3da37ec879219bab2608bb2080eea6756939c7d9 100644 --- a/src/main/java/org/olat/NewControllerFactory.java +++ b/src/main/java/org/olat/NewControllerFactory.java @@ -137,6 +137,11 @@ public class NewControllerFactory extends LogDelegator { WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, origControl); return launch(ureq, bwControl); } + + private ContextEntryControllerCreator getContextEntryControllerCreator(String type) { + ContextEntryControllerCreator typeHandler = contextEntryControllerCreators.get(type); + return typeHandler.clone(); + } /** * Launch a controller in a tab or site in the given window from a user @@ -180,7 +185,7 @@ public class NewControllerFactory extends LogDelegator { String firstType = mainCe.getOLATResourceable().getResourceableTypeName(); // String firstTypeId = ClassToId.getInstance().lookup() BusinessGroup - ContextEntryControllerCreator typeHandler = contextEntryControllerCreators.get(firstType); + ContextEntryControllerCreator typeHandler = getContextEntryControllerCreator(firstType); if (typeHandler == null) { logWarn("Cannot found an handler for context entry: " + mainCe, null); return false;//simply return and don't throw a red screen diff --git a/src/main/java/org/olat/admin/user/UserAdminContextEntryControllerCreator.java b/src/main/java/org/olat/admin/user/UserAdminContextEntryControllerCreator.java index 4180151f2cfef5c356673a1ccb8a4ed4a7aab62d..cbf841de28d7f7720eda6e2b01ef152c9f57d128 100644 --- a/src/main/java/org/olat/admin/user/UserAdminContextEntryControllerCreator.java +++ b/src/main/java/org/olat/admin/user/UserAdminContextEntryControllerCreator.java @@ -24,6 +24,7 @@ import org.olat.core.gui.UserRequest; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; /** @@ -36,12 +37,18 @@ import org.olat.core.id.context.DefaultContextEntryControllerCreator; * @author srosse */ public class UserAdminContextEntryControllerCreator extends DefaultContextEntryControllerCreator { + + @Override + public ContextEntryControllerCreator clone() { + return this; + } /** * @see org.olat.core.id.context.ContextEntryControllerCreator#createController(org.olat.core.id.context.ContextEntry, * org.olat.core.gui.UserRequest, * org.olat.core.gui.control.WindowControl) */ + @Override public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { return null; } diff --git a/src/main/java/org/olat/core/id/context/ContextEntryControllerCreator.java b/src/main/java/org/olat/core/id/context/ContextEntryControllerCreator.java index 45a2788266066f88cc72b932502289b6eb93d673..e654a7fa65f4d485f698d1807e9e72dd91f79c4b 100644 --- a/src/main/java/org/olat/core/id/context/ContextEntryControllerCreator.java +++ b/src/main/java/org/olat/core/id/context/ContextEntryControllerCreator.java @@ -44,6 +44,13 @@ import org.olat.core.id.OLATResourceable; * @author Felix Jost */ public interface ContextEntryControllerCreator { + + /** + * Return a request scoped instance of the creator if the + * creator cannot be accessed by multiple users simultaneously. + * @return + */ + public ContextEntryControllerCreator clone(); /** * Factory method to create the run controller for this contex. diff --git a/src/main/java/org/olat/core/id/context/DefaultContextEntryControllerCreator.java b/src/main/java/org/olat/core/id/context/DefaultContextEntryControllerCreator.java index ef132378678b50f29bbd2d9f1556985648a980e5..a3f3b4038b38ea8c55ac6869eae8f5e8aac57ad6 100644 --- a/src/main/java/org/olat/core/id/context/DefaultContextEntryControllerCreator.java +++ b/src/main/java/org/olat/core/id/context/DefaultContextEntryControllerCreator.java @@ -31,8 +31,12 @@ import org.olat.core.id.OLATResourceable; * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com * */ -public class DefaultContextEntryControllerCreator implements ContextEntryControllerCreator { +public abstract class DefaultContextEntryControllerCreator implements ContextEntryControllerCreator { + + @Override + public abstract ContextEntryControllerCreator clone(); + @Override public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { return null; } @@ -41,10 +45,12 @@ public class DefaultContextEntryControllerCreator implements ContextEntryControl return null; } + @Override public String getSiteClassName(ContextEntry ce, UserRequest ureq) { return null; } + @Override public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { return true; } diff --git a/src/main/java/org/olat/core/id/context/SiteContextEntryControllerCreator.java b/src/main/java/org/olat/core/id/context/SiteContextEntryControllerCreator.java index ab8766a54be6f98c76ccd609dafe676c1bf858d3..1944c1c7c723767dad0f154138f726eb2566e691 100644 --- a/src/main/java/org/olat/core/id/context/SiteContextEntryControllerCreator.java +++ b/src/main/java/org/olat/core/id/context/SiteContextEntryControllerCreator.java @@ -41,6 +41,11 @@ public class SiteContextEntryControllerCreator extends DefaultContextEntryContro this.site = site; } + @Override + public ContextEntryControllerCreator clone() { + return this; + } + public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { return null; } diff --git a/src/main/java/org/olat/core/util/mail/MailBoxExtension.java b/src/main/java/org/olat/core/util/mail/MailBoxExtension.java index 8458a6bf2dec2e49d6ab4f068cf1f08de9f9df42..e94381261cc2770128391a6382b33304bd7c74d8 100644 --- a/src/main/java/org/olat/core/util/mail/MailBoxExtension.java +++ b/src/main/java/org/olat/core/util/mail/MailBoxExtension.java @@ -33,6 +33,7 @@ import org.olat.core.id.Identity; import org.olat.core.id.context.BusinessControl; import org.olat.core.id.context.BusinessControlFactory; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; @@ -68,28 +69,7 @@ public class MailBoxExtension extends BasicManager implements MailContextResolve } public void init() { - NewControllerFactory.getInstance().addContextEntryControllerCreator("Inbox", new DefaultContextEntryControllerCreator(){ - @Override - public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - return null; - } - - @Override - public String getTabName(ContextEntry ce, UserRequest ureq) { - // opens in home-tab - return null; - } - - @Override - public String getSiteClassName(ContextEntry ce, UserRequest ureq) { - return HomeSite.class.getName(); - } - - @Override - public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - return true; - } - }); + NewControllerFactory.getInstance().addContextEntryControllerCreator("Inbox", new InboxContextEntry()); } /** @@ -168,4 +148,33 @@ public class MailBoxExtension extends BasicManager implements MailContextResolve WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, wControl); NewControllerFactory.getInstance().launch(ureq, bwControl); } + + private static class InboxContextEntry extends DefaultContextEntryControllerCreator { + + @Override + public ContextEntryControllerCreator clone() { + return this; + } + + @Override + public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + return null; + } + + @Override + public String getTabName(ContextEntry ce, UserRequest ureq) { + // opens in home-tab + return null; + } + + @Override + public String getSiteClassName(ContextEntry ce, UserRequest ureq) { + return HomeSite.class.getName(); + } + + @Override + public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + return true; + } + } } diff --git a/src/main/java/org/olat/course/site/CourseSiteContextEntryControllerCreator.java b/src/main/java/org/olat/course/site/CourseSiteContextEntryControllerCreator.java index 3ec84887e76fcf5200a2b9ff8d3ef3ed08a9caa0..2b550ec86e0ccebd30d14927d95bb0a72ba016cb 100644 --- a/src/main/java/org/olat/course/site/CourseSiteContextEntryControllerCreator.java +++ b/src/main/java/org/olat/course/site/CourseSiteContextEntryControllerCreator.java @@ -29,6 +29,7 @@ import org.olat.core.gui.control.navigation.SiteDefinition; import org.olat.core.gui.control.navigation.SiteDefinitions; import org.olat.core.id.OLATResourceable; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.course.site.model.CourseSiteConfiguration; import org.olat.course.site.model.LanguageConfiguration; @@ -47,8 +48,14 @@ import org.olat.repository.RepositoyUIFactory; * @author gnaegi, gnaegi@frentix.com, www.frentix.com */ public class CourseSiteContextEntryControllerCreator extends DefaultContextEntryControllerCreator { - + + private RepositoryEntry repoEntry; private SiteDefinitions siteDefinitions; + + @Override + public ContextEntryControllerCreator clone() { + return new CourseSiteContextEntryControllerCreator(); + } /** * @see org.olat.core.id.context.ContextEntryControllerCreator#createController(org.olat.core.id.context.ContextEntry, @@ -57,10 +64,7 @@ public class CourseSiteContextEntryControllerCreator extends DefaultContextEntry */ @Override public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - OLATResourceable ores = ce.getOLATResourceable(); - - RepositoryManager repom = RepositoryManager.getInstance(); - RepositoryEntry re = repom.lookupRepositoryEntry(ores.getResourceableId()); + RepositoryEntry re = getRepositoryEntry(ce); Controller ctrl = RepositoyUIFactory.createLaunchController(re, ureq, wControl); return ctrl; } @@ -70,9 +74,7 @@ public class CourseSiteContextEntryControllerCreator extends DefaultContextEntry */ @Override public String getTabName(ContextEntry ce, UserRequest ureq) { - OLATResourceable ores = ce.getOLATResourceable(); - RepositoryManager repom = RepositoryManager.getInstance(); - RepositoryEntry re = repom.lookupRepositoryEntry(ores.getResourceableId()); + RepositoryEntry re = getRepositoryEntry(ce); CourseSiteDef siteDef = getCourseSite(ureq, re); if(siteDef != null) { return "Hello"; @@ -85,9 +87,7 @@ public class CourseSiteContextEntryControllerCreator extends DefaultContextEntry */ @Override public String getSiteClassName(ContextEntry ce, UserRequest ureq) { - OLATResourceable ores = ce.getOLATResourceable(); - RepositoryManager repom = RepositoryManager.getInstance(); - RepositoryEntry re = repom.lookupRepositoryEntry(ores.getResourceableId()); + RepositoryEntry re = getRepositoryEntry(ce); CourseSiteDef siteDef = getCourseSite(ureq, re); if(siteDef != null) { return siteDef.getClass().getName().replace("Def", ""); @@ -97,10 +97,7 @@ public class CourseSiteContextEntryControllerCreator extends DefaultContextEntry @Override public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - OLATResourceable ores = ce.getOLATResourceable(); - RepositoryManager repom = RepositoryManager.getInstance(); - RepositoryEntry re = repom.lookupRepositoryEntry(ores.getResourceableId()); - return re != null; + return getRepositoryEntry(ce) != null; } private SiteDefinitions getSitesDefinitions() { @@ -129,4 +126,13 @@ public class CourseSiteContextEntryControllerCreator extends DefaultContextEntry } return null; } + + private RepositoryEntry getRepositoryEntry(ContextEntry ce) { + if(repoEntry == null) { + OLATResourceable ores = ce.getOLATResourceable(); + RepositoryManager rm = RepositoryManager.getInstance(); + repoEntry = rm.lookupRepositoryEntry(ores.getResourceableId()); + } + return repoEntry; + } } diff --git a/src/main/java/org/olat/group/BusinessGroupCardContextEntryControllerCreator.java b/src/main/java/org/olat/group/BusinessGroupCardContextEntryControllerCreator.java index 3d9635573736d4b0193cfd54ab77a0ea9cd88f9e..58f658a33eb0cc4616b4dc6f080036d1229b1b07 100644 --- a/src/main/java/org/olat/group/BusinessGroupCardContextEntryControllerCreator.java +++ b/src/main/java/org/olat/group/BusinessGroupCardContextEntryControllerCreator.java @@ -19,15 +19,13 @@ */ package org.olat.group; -import java.util.Collections; -import java.util.List; - import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.core.id.OLATResourceable; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.group.ui.homepage.GroupInfoMainController; @@ -37,6 +35,13 @@ import org.olat.group.ui.homepage.GroupInfoMainController; */ public class BusinessGroupCardContextEntryControllerCreator extends DefaultContextEntryControllerCreator { + private BusinessGroup group; + + @Override + public ContextEntryControllerCreator clone() { + return new BusinessGroupCardContextEntryControllerCreator(); + } + /** * @see org.olat.core.id.context.ContextEntryControllerCreator#createController(org.olat.core.id.context.ContextEntry, * org.olat.core.gui.UserRequest, @@ -44,10 +49,7 @@ public class BusinessGroupCardContextEntryControllerCreator extends DefaultConte */ @Override public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - OLATResourceable ores = ce.getOLATResourceable(); - Long gKey = ores.getResourceableId(); - BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); - BusinessGroup bgroup = bgs.loadBusinessGroup(gKey); + BusinessGroup bgroup = getBusinessGroup(ce); if(bgroup != null) { return new GroupInfoMainController(ureq, wControl, bgroup); } @@ -59,22 +61,25 @@ public class BusinessGroupCardContextEntryControllerCreator extends DefaultConte */ @Override public String getTabName(ContextEntry ce, UserRequest ureq) { - OLATResourceable ores = ce.getOLATResourceable(); - Long gKey = ores.getResourceableId(); - BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); - List<BusinessGroupShort> bgroup = bgs.loadShortBusinessGroups(Collections.singletonList(gKey)); - if(bgroup.size() == 1) { - return bgroup.get(0).getName(); + BusinessGroup bgroup = getBusinessGroup(ce); + if(bgroup != null) { + return bgroup.getName(); } return null; } @Override public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - OLATResourceable ores = ce.getOLATResourceable(); - Long gKey = ores.getResourceableId(); - BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); - List<BusinessGroupShort> bgroup = bgs.loadShortBusinessGroups(Collections.singletonList(gKey)); - return (bgroup.size() == 1); + return getBusinessGroup(ce) != null; + } + + private BusinessGroup getBusinessGroup(ContextEntry ce) { + if(group == null) { + OLATResourceable ores = ce.getOLATResourceable(); + Long gKey = ores.getResourceableId(); + BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + group = bgs.loadBusinessGroup(gKey); + } + return group; } } diff --git a/src/main/java/org/olat/group/BusinessGroupContextEntryControllerCreator.java b/src/main/java/org/olat/group/BusinessGroupContextEntryControllerCreator.java index 2e1bea421eb4b9212f3d2f51f161e03b17623fd8..619be44388769cd6f701620f03ca1c42f78bd118 100644 --- a/src/main/java/org/olat/group/BusinessGroupContextEntryControllerCreator.java +++ b/src/main/java/org/olat/group/BusinessGroupContextEntryControllerCreator.java @@ -28,6 +28,7 @@ import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.core.id.OLATResourceable; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.group.right.BGRightManager; import org.olat.group.ui.BGControllerFactory; @@ -45,6 +46,14 @@ import org.olat.resource.accesscontrol.AccessControlModule; * @author gnaegi, gnaegi@frentix.com, www.frentix.com */ public class BusinessGroupContextEntryControllerCreator extends DefaultContextEntryControllerCreator { + + private BusinessGroup group; + private Boolean authorized; + + @Override + public ContextEntryControllerCreator clone() { + return new BusinessGroupContextEntryControllerCreator(); + } /** * @see org.olat.core.id.context.ContextEntryControllerCreator#createController(org.olat.core.id.context.ContextEntry, @@ -52,21 +61,10 @@ public class BusinessGroupContextEntryControllerCreator extends DefaultContextEn * org.olat.core.gui.control.WindowControl) */ public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - OLATResourceable ores = ce.getOLATResourceable(); - - Long gKey = ores.getResourceableId(); - BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); - Controller ctrl = null; - BusinessGroup bgroup = bgs.loadBusinessGroup(gKey); - if(bgroup != null) { - BGRightManager rightManager = CoreSpringFactory.getImpl(BGRightManager.class); - if (ureq.getUserSession().getRoles().isOLATAdmin() || ureq.getUserSession().getRoles().isGroupManager() - || bgs.isIdentityInBusinessGroup(ureq.getIdentity(), bgroup) - || rightManager.hasBGRight(Constants.PERMISSION_ACCESS, ureq.getIdentity(), bgroup.getResource()) - || isAccessControlled(bgroup)) { - ctrl = BGControllerFactory.getInstance().createRunControllerFor(ureq, wControl, bgroup); - } + BusinessGroup bgroup = getBusinessGroup(ce); + if(bgroup != null && isAuthorized(ureq, bgroup)) { + ctrl = BGControllerFactory.getInstance().createRunControllerFor(ureq, wControl, bgroup); } return ctrl; } @@ -76,27 +74,14 @@ public class BusinessGroupContextEntryControllerCreator extends DefaultContextEn */ @Override public String getTabName(ContextEntry ce, UserRequest ureq) { - OLATResourceable ores = ce.getOLATResourceable(); - Long gKey = ores.getResourceableId(); - BusinessGroup bgroup = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(gKey); + BusinessGroup bgroup = getBusinessGroup(ce); return bgroup == null ? "" : bgroup.getName(); } @Override public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - OLATResourceable ores = ce.getOLATResourceable(); - Long gKey = ores.getResourceableId(); - BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); - BusinessGroup bgroup = bgs.loadBusinessGroup(gKey); - if (bgroup == null) { - return false; - } - BGRightManager rightManager = CoreSpringFactory.getImpl(BGRightManager.class); - return ureq.getUserSession().getRoles().isOLATAdmin() - || ureq.getUserSession().getRoles().isGroupManager() - || bgs.isIdentityInBusinessGroup(ureq.getIdentity(), bgroup) - || rightManager.hasBGRight(Constants.PERMISSION_ACCESS, ureq.getIdentity(), bgroup.getResource()) - || isAccessControlled(bgroup); + BusinessGroup bgroup = getBusinessGroup(ce); + return bgroup != null && isAuthorized(ureq, bgroup); } private boolean isAccessControlled(BusinessGroup bgroup) { @@ -109,4 +94,25 @@ public class BusinessGroupContextEntryControllerCreator extends DefaultContextEn } return false; } + + private boolean isAuthorized(UserRequest ureq, BusinessGroup bgroup) { + if(authorized == null) { + authorized = ureq.getUserSession().getRoles().isOLATAdmin() + || ureq.getUserSession().getRoles().isGroupManager() + || CoreSpringFactory.getImpl(BusinessGroupService.class).isIdentityInBusinessGroup(ureq.getIdentity(), bgroup) + || CoreSpringFactory.getImpl(BGRightManager.class).hasBGRight(Constants.PERMISSION_ACCESS, ureq.getIdentity(), bgroup.getResource()) + || isAccessControlled(bgroup); + } + return authorized.booleanValue(); + } + + private BusinessGroup getBusinessGroup(ContextEntry ce) { + if(group == null) { + OLATResourceable ores = ce.getOLATResourceable(); + Long gKey = ores.getResourceableId(); + BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + group = bgs.loadBusinessGroup(gKey); + } + return group; + } } diff --git a/src/main/java/org/olat/home/controllerCreators/GuestHomeCEControllerCreator.java b/src/main/java/org/olat/home/controllerCreators/GuestHomeCEControllerCreator.java index 8505c16671c8e49f14808e778adaceae1edc53a8..424a9c4a7e829debdb783a8e1ac877c0def79850 100644 --- a/src/main/java/org/olat/home/controllerCreators/GuestHomeCEControllerCreator.java +++ b/src/main/java/org/olat/home/controllerCreators/GuestHomeCEControllerCreator.java @@ -23,6 +23,7 @@ import org.olat.core.gui.UserRequest; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.home.HomeSite; @@ -38,17 +39,25 @@ import org.olat.home.HomeSite; public class GuestHomeCEControllerCreator extends DefaultContextEntryControllerCreator { public GuestHomeCEControllerCreator() { - + // + } + + @Override + public ContextEntryControllerCreator clone() { + return this; } + @Override public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { return null; } + @Override public String getSiteClassName(ContextEntry ce, UserRequest ureq) { return HomeSite.class.getName(); } + @Override public String getTabName(ContextEntry ce, UserRequest ureq) { return null; } diff --git a/src/main/java/org/olat/modules/webFeed/portfolio/LiveBlogContextEntryControllerCreator.java b/src/main/java/org/olat/modules/webFeed/portfolio/LiveBlogContextEntryControllerCreator.java index dee63e8550ca95f8f3dac9f73b4b1a04a44e4e81..59d6057f74c74d04ff59d3a3216f6ebecda95465 100644 --- a/src/main/java/org/olat/modules/webFeed/portfolio/LiveBlogContextEntryControllerCreator.java +++ b/src/main/java/org/olat/modules/webFeed/portfolio/LiveBlogContextEntryControllerCreator.java @@ -28,6 +28,7 @@ import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.core.id.OLATResourceable; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; @@ -53,43 +54,56 @@ public class LiveBlogContextEntryControllerCreator { public LiveBlogContextEntryControllerCreator(final FeedManager feedManager) { - NewControllerFactory.getInstance().addContextEntryControllerCreator("LiveBlog", new DefaultContextEntryControllerCreator(){ - - @Override - public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - OLATResourceable ores = ce.getOLATResourceable(); - Feed feed = feedManager.getFeed(ores); - boolean isOwner = feed.getAuthor() != null && ureq.getIdentity() != null && feed.getAuthor().equals(ureq.getIdentity().getName()); - FeedSecurityCallback secCallback = new FeedResourceSecurityCallback(isOwner, isOwner); - FeedMainController controller = new FeedMainController(ores, ureq, wControl, BlogUIFactory.getInstance(ureq.getLocale()), secCallback); - Component main = controller.getInitialComponent(); - return new LayoutMain3ColsController(ureq, wControl, null, null, main, "LiveBlog" + ores.getResourceableId()); - } + NewControllerFactory.getInstance().addContextEntryControllerCreator("LiveBlog", new LBContextEntryControllerCreator(feedManager)); + } + + private static class LBContextEntryControllerCreator extends DefaultContextEntryControllerCreator { + + private final FeedManager feedManager; + + public LBContextEntryControllerCreator(FeedManager feedManager) { + this.feedManager = feedManager; + } + + @Override + public ContextEntryControllerCreator clone() { + return this; + } - @Override - public String getTabName(ContextEntry ce, UserRequest ureq) { - OLATResourceable ores = ce.getOLATResourceable(); - Feed feed = feedManager.getFeed(ores); - return feed.getTitle(); - } + @Override + public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + OLATResourceable ores = ce.getOLATResourceable(); + Feed feed = feedManager.getFeed(ores); + boolean isOwner = feed.getAuthor() != null && ureq.getIdentity() != null && feed.getAuthor().equals(ureq.getIdentity().getName()); + FeedSecurityCallback secCallback = new FeedResourceSecurityCallback(isOwner, isOwner); + FeedMainController controller = new FeedMainController(ores, ureq, wControl, BlogUIFactory.getInstance(ureq.getLocale()), secCallback); + Component main = controller.getInitialComponent(); + return new LayoutMain3ColsController(ureq, wControl, null, null, main, "LiveBlog" + ores.getResourceableId()); + } - @Override - public String getSiteClassName(ContextEntry ce, UserRequest ureq) { - return null; - } + @Override + public String getTabName(ContextEntry ce, UserRequest ureq) { + OLATResourceable ores = ce.getOLATResourceable(); + Feed feed = feedManager.getFeed(ores); + return feed.getTitle(); + } - @Override - public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - try { - OLATResourceable ores = ce.getOLATResourceable(); - Feed feed = feedManager.getFeed(ores); - return feed != null; - } catch (Exception e) { - log.warn("Try to load a live blog with an invalid context entry: " + ce, e); - return false; - } + @Override + public String getSiteClassName(ContextEntry ce, UserRequest ureq) { + return null; + } + + @Override + public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + try { + OLATResourceable ores = ce.getOLATResourceable(); + Feed feed = feedManager.getFeed(ores); + return feed != null; + } catch (Exception e) { + log.warn("Try to load a live blog with an invalid context entry: " + ce, e); + return false; } - - }); + } + } } diff --git a/src/main/java/org/olat/portfolio/EPArtefactPoolExtension.java b/src/main/java/org/olat/portfolio/EPArtefactPoolExtension.java index 8612c380d36db99696b4c4a60d8c04b8101e08a8..97a0b95ce2b172ddb320f430bb597f4ef21840bd 100644 --- a/src/main/java/org/olat/portfolio/EPArtefactPoolExtension.java +++ b/src/main/java/org/olat/portfolio/EPArtefactPoolExtension.java @@ -29,6 +29,7 @@ import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; import org.olat.core.id.context.BusinessControlFactory; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.core.id.context.TabContext; import org.olat.core.util.resource.OresHelper; @@ -47,31 +48,37 @@ import org.olat.portfolio.model.artefacts.AbstractArtefact; public class EPArtefactPoolExtension { public EPArtefactPoolExtension() { - - NewControllerFactory.getInstance().addContextEntryControllerCreator(AbstractArtefact.class.getSimpleName(), new DefaultContextEntryControllerCreator(){ - - @Override - public String getSiteClassName(ContextEntry ce, UserRequest ureq) { - return HomeSite.class.getName(); - } + NewControllerFactory.getInstance().addContextEntryControllerCreator(AbstractArtefact.class.getSimpleName(), new ArtefactContextEntryControllerCreator()); + } + + private static class ArtefactContextEntryControllerCreator extends DefaultContextEntryControllerCreator{ + + @Override + public ContextEntryControllerCreator clone() { + return this; + } + + @Override + public String getSiteClassName(ContextEntry ce, UserRequest ureq) { + return HomeSite.class.getName(); + } - @Override - public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - return true; - } + @Override + public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + return true; + } - @Override - public TabContext getTabContext(UserRequest ureq, OLATResourceable ores, ContextEntry mainEntry, List<ContextEntry> entries) { - Identity identity = ureq.getIdentity(); + @Override + public TabContext getTabContext(UserRequest ureq, OLATResourceable ores, ContextEntry mainEntry, List<ContextEntry> entries) { + Identity identity = ureq.getIdentity(); - OLATResourceable mapsRes = OresHelper.createOLATResourceableType("EPArtefacts"); - ContextEntry mapsEntry = BusinessControlFactory.getInstance().createContextEntry(mapsRes); - List<ContextEntry> rewritedEntries = new ArrayList<ContextEntry>(); - rewritedEntries.add(mapsEntry);//Menu node - rewritedEntries.add(mainEntry);//Map - OLATResourceable homeRes = OresHelper.createOLATResourceableInstance("HomeSite", identity.getKey()); - return new TabContext("", homeRes, rewritedEntries); - } - }); + OLATResourceable mapsRes = OresHelper.createOLATResourceableType("EPArtefacts"); + ContextEntry mapsEntry = BusinessControlFactory.getInstance().createContextEntry(mapsRes); + List<ContextEntry> rewritedEntries = new ArrayList<ContextEntry>(); + rewritedEntries.add(mapsEntry);//Menu node + rewritedEntries.add(mainEntry);//Map + OLATResourceable homeRes = OresHelper.createOLATResourceableInstance("HomeSite", identity.getKey()); + return new TabContext("", homeRes, rewritedEntries); + } } } diff --git a/src/main/java/org/olat/portfolio/EPMapExtension.java b/src/main/java/org/olat/portfolio/EPMapExtension.java index 1621c8c37af035928a2605c01dd8595af0e8f0cc..015119d39e45a727af9ba7dda7c95161cd7f38b2 100644 --- a/src/main/java/org/olat/portfolio/EPMapExtension.java +++ b/src/main/java/org/olat/portfolio/EPMapExtension.java @@ -31,6 +31,7 @@ import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; import org.olat.core.id.context.BusinessControlFactory; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.core.id.context.TabContext; import org.olat.core.util.resource.OresHelper; @@ -50,7 +51,12 @@ public class EPMapExtension { NewControllerFactory.getInstance().addContextEntryControllerCreator(EPDefaultMap.class.getSimpleName(), new MapContextEntryControllerCreator()); } - private class MapContextEntryControllerCreator extends DefaultContextEntryControllerCreator { + private static class MapContextEntryControllerCreator extends DefaultContextEntryControllerCreator { + + @Override + public ContextEntryControllerCreator clone() { + return this; + } @Override public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { diff --git a/src/main/java/org/olat/portfolio/EPMapOnInvitationExtension.java b/src/main/java/org/olat/portfolio/EPMapOnInvitationExtension.java index 7ef266cd0fd83dc9192f2ba9af62287b70a2ede4..656f1e02c9283608a93208b5067b66f4fe2502ad 100644 --- a/src/main/java/org/olat/portfolio/EPMapOnInvitationExtension.java +++ b/src/main/java/org/olat/portfolio/EPMapOnInvitationExtension.java @@ -26,6 +26,7 @@ import org.olat.core.gui.UserRequest; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.portfolio.manager.EPFrontendManager; import org.olat.portfolio.model.structel.PortfolioStructureMap; @@ -43,61 +44,67 @@ import org.olat.portfolio.model.structel.PortfolioStructureMap; public class EPMapOnInvitationExtension { public EPMapOnInvitationExtension() { + NewControllerFactory.getInstance().addContextEntryControllerCreator("MapInvitation", new MapOnInvitationContextEntryControllerCreator()); + } + + private static class MapOnInvitationContextEntryControllerCreator extends DefaultContextEntryControllerCreator { - NewControllerFactory.getInstance().addContextEntryControllerCreator("MapInvitation", new DefaultContextEntryControllerCreator(){ - - @Override - public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - //fxdiff FXOLAT-151: better check invitation - if(!ureq.getUserSession().getRoles().isInvitee()) { - return null; - } - - PortfolioStructureMap map = getMapFromContext(ce); - EPSecurityCallback secCallback = new EPSecurityCallbackImpl(false, true); - Controller epCtr = EPUIFactory.createMapViewController(ureq, wControl, map, secCallback); - - LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(ureq, wControl, null, null, epCtr.getInitialComponent(), null); - layoutCtr.addDisposableChildController(epCtr); - return layoutCtr; - } - - @Override - public String getTabName(ContextEntry ce, UserRequest ureq) { - PortfolioStructureMap map = getMapFromContext(ce); - return map.getTitle(); - } + @Override + public ContextEntryControllerCreator clone() { + return this; + } - @Override - public String getSiteClassName(ContextEntry ce, UserRequest ureq) { + @Override + public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + //fxdiff FXOLAT-151: better check invitation + if(!ureq.getUserSession().getRoles().isInvitee()) { return null; } - - @Override - public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - //fxdiff FXOLAT-151: better check invitation - if(!ureq.getUserSession().getRoles().isInvitee()) { - return false; - } - - final EPFrontendManager ePFMgr = (EPFrontendManager) CoreSpringFactory.getBean("epFrontendManager"); - PortfolioStructureMap map = getMapFromContext(ce); - if (map == null) return false; - boolean visible = ePFMgr.isMapVisible(ureq.getIdentity(), map.getOlatResource()); - return visible; - } - /** - * @param ContextEntry - * @return the loaded map or null if not found - */ - private PortfolioStructureMap getMapFromContext(final ContextEntry ce) { - final Long mapKey = ce.getOLATResourceable().getResourceableId(); - final EPFrontendManager ePFMgr = (EPFrontendManager) CoreSpringFactory.getBean("epFrontendManager"); - final PortfolioStructureMap map = (PortfolioStructureMap) ePFMgr.loadPortfolioStructureByKey(mapKey); - return map; + PortfolioStructureMap map = getMapFromContext(ce); + EPSecurityCallback secCallback = new EPSecurityCallbackImpl(false, true); + Controller epCtr = EPUIFactory.createMapViewController(ureq, wControl, map, secCallback); + + LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(ureq, wControl, null, null, epCtr.getInitialComponent(), null); + layoutCtr.addDisposableChildController(epCtr); + return layoutCtr; + } + + @Override + public String getTabName(ContextEntry ce, UserRequest ureq) { + PortfolioStructureMap map = getMapFromContext(ce); + return map.getTitle(); + } + + @Override + public String getSiteClassName(ContextEntry ce, UserRequest ureq) { + return null; + } + + @Override + public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + //fxdiff FXOLAT-151: better check invitation + if(!ureq.getUserSession().getRoles().isInvitee()) { + return false; } - }); + final EPFrontendManager ePFMgr = (EPFrontendManager) CoreSpringFactory.getBean("epFrontendManager"); + PortfolioStructureMap map = getMapFromContext(ce); + if (map == null) return false; + boolean visible = ePFMgr.isMapVisible(ureq.getIdentity(), map.getOlatResource()); + return visible; + } + + /** + * @param ContextEntry + * @return the loaded map or null if not found + */ + private PortfolioStructureMap getMapFromContext(final ContextEntry ce) { + final Long mapKey = ce.getOLATResourceable().getResourceableId(); + final EPFrontendManager ePFMgr = (EPFrontendManager) CoreSpringFactory.getBean("epFrontendManager"); + final PortfolioStructureMap map = (PortfolioStructureMap) ePFMgr.loadPortfolioStructureByKey(mapKey); + return map; + } + } } diff --git a/src/main/java/org/olat/portfolio/EPMyMapsExtension.java b/src/main/java/org/olat/portfolio/EPMyMapsExtension.java index 3e3959e4242d52424c7b9a26499ebdf0c5491d72..8fdc690b26209a89adc19a3d769db9f7dad07d02 100644 --- a/src/main/java/org/olat/portfolio/EPMyMapsExtension.java +++ b/src/main/java/org/olat/portfolio/EPMyMapsExtension.java @@ -24,6 +24,7 @@ import org.olat.core.gui.UserRequest; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.home.HomeSite; import org.olat.portfolio.model.structel.EPDefaultMap; @@ -41,30 +42,35 @@ import org.olat.portfolio.model.structel.EPDefaultMap; public class EPMyMapsExtension { public EPMyMapsExtension() { + NewControllerFactory.getInstance().addContextEntryControllerCreator(EPDefaultMap.class.getSimpleName(), new MyMapsContextEntryControllerCreator()); + } + + private static class MyMapsContextEntryControllerCreator extends DefaultContextEntryControllerCreator { + + @Override + public ContextEntryControllerCreator clone() { + return this; + } - NewControllerFactory.getInstance().addContextEntryControllerCreator(EPDefaultMap.class.getSimpleName(), new DefaultContextEntryControllerCreator(){ - - @Override - public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - return null; - } + @Override + public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + return null; + } - @Override - public String getTabName(ContextEntry ce, UserRequest ureq) { - // opens in home-tab - return null; - } + @Override + public String getTabName(ContextEntry ce, UserRequest ureq) { + // opens in home-tab + return null; + } - @Override - public String getSiteClassName(ContextEntry ce, UserRequest ureq) { - return HomeSite.class.getName(); - } + @Override + public String getSiteClassName(ContextEntry ce, UserRequest ureq) { + return HomeSite.class.getName(); + } - @Override - public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - return true; - } - - }); + @Override + public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + return true; + } } } diff --git a/src/main/java/org/olat/portfolio/EPMyStructuredMapsExtension.java b/src/main/java/org/olat/portfolio/EPMyStructuredMapsExtension.java index add40d4c96505b006201298b52c2b86c01d9ea5c..00b515f3cabd589b35d51c9a26dab1c556748209 100644 --- a/src/main/java/org/olat/portfolio/EPMyStructuredMapsExtension.java +++ b/src/main/java/org/olat/portfolio/EPMyStructuredMapsExtension.java @@ -24,6 +24,7 @@ import org.olat.core.gui.UserRequest; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.home.HomeSite; import org.olat.portfolio.model.structel.EPStructuredMap; @@ -41,29 +42,35 @@ public class EPMyStructuredMapsExtension { public EPMyStructuredMapsExtension() { - NewControllerFactory.getInstance().addContextEntryControllerCreator(EPStructuredMap.class.getSimpleName(), new DefaultContextEntryControllerCreator(){ + NewControllerFactory.getInstance().addContextEntryControllerCreator(EPStructuredMap.class.getSimpleName(), new MyStructuredMapsContextEntryControllerCreator()); + } + + private static class MyStructuredMapsContextEntryControllerCreator extends DefaultContextEntryControllerCreator { + + @Override + public ContextEntryControllerCreator clone() { + return this; + } - @Override - public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - return null; - } + @Override + public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + return null; + } - @Override - public String getTabName(ContextEntry ce, UserRequest ureq) { - // opens in home-tab - return null; - } + @Override + public String getTabName(ContextEntry ce, UserRequest ureq) { + // opens in home-tab + return null; + } - @Override - public String getSiteClassName(ContextEntry ce, UserRequest ureq) { - return HomeSite.class.getName(); - } + @Override + public String getSiteClassName(ContextEntry ce, UserRequest ureq) { + return HomeSite.class.getName(); + } - @Override - public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - return true; - } - - }); + @Override + public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + return true; + } } } diff --git a/src/main/java/org/olat/portfolio/EPOtherMapsExtension.java b/src/main/java/org/olat/portfolio/EPOtherMapsExtension.java index 1a92b494f89c25619fd448d0372256e14f175d98..1cc67529c7a96595bb4dbc5ea3ebaf7f373a0fc5 100644 --- a/src/main/java/org/olat/portfolio/EPOtherMapsExtension.java +++ b/src/main/java/org/olat/portfolio/EPOtherMapsExtension.java @@ -24,6 +24,7 @@ import org.olat.core.gui.UserRequest; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.home.HomeSite; @@ -40,31 +41,35 @@ import org.olat.home.HomeSite; public class EPOtherMapsExtension { public EPOtherMapsExtension() { + NewControllerFactory.getInstance().addContextEntryControllerCreator("Map", new OtherMapsContextEntryControllerCreator()); + } + + private static class OtherMapsContextEntryControllerCreator extends DefaultContextEntryControllerCreator { - NewControllerFactory.getInstance().addContextEntryControllerCreator("Map", - new DefaultContextEntryControllerCreator() { - - @Override - public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - return null; - } + @Override + public ContextEntryControllerCreator clone() { + return this; + } - @Override - public String getTabName(ContextEntry ce, UserRequest ureq) { - // opens in home-tab - return null; - } + @Override + public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + return null; + } - @Override - public String getSiteClassName(ContextEntry ce, UserRequest ureq) { - return HomeSite.class.getName(); - } + @Override + public String getTabName(ContextEntry ce, UserRequest ureq) { + // opens in home-tab + return null; + } - @Override - public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - return true; - } + @Override + public String getSiteClassName(ContextEntry ce, UserRequest ureq) { + return HomeSite.class.getName(); + } - }); + @Override + public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + return true; + } } } \ No newline at end of file diff --git a/src/main/java/org/olat/repository/CatalogContextEntryControllerCreator.java b/src/main/java/org/olat/repository/CatalogContextEntryControllerCreator.java index 6f1a58b3745f8c59ccb101e5f450a612bb73cb11..9edd95208484bfe8641adb3b2d80c8d1b1980af5 100644 --- a/src/main/java/org/olat/repository/CatalogContextEntryControllerCreator.java +++ b/src/main/java/org/olat/repository/CatalogContextEntryControllerCreator.java @@ -24,6 +24,7 @@ import org.olat.core.gui.UserRequest; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.repository.site.RepositorySite; @@ -36,6 +37,11 @@ import org.olat.repository.site.RepositorySite; */ public class CatalogContextEntryControllerCreator extends DefaultContextEntryControllerCreator { + @Override + public ContextEntryControllerCreator clone() { + return this; + } + @Override public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { return null; diff --git a/src/main/java/org/olat/repository/RepositoryContextEntryControllerCreator.java b/src/main/java/org/olat/repository/RepositoryContextEntryControllerCreator.java index d14d3cb488f86772b6060351695d0604a04add34..92307e0a92602d776e0a3c07b1b2f5b1eb92cbdd 100644 --- a/src/main/java/org/olat/repository/RepositoryContextEntryControllerCreator.java +++ b/src/main/java/org/olat/repository/RepositoryContextEntryControllerCreator.java @@ -24,6 +24,7 @@ import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.core.id.OLATResourceable; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; /** @@ -38,19 +39,23 @@ import org.olat.core.id.context.DefaultContextEntryControllerCreator; */ public class RepositoryContextEntryControllerCreator extends DefaultContextEntryControllerCreator { + private RepositoryEntry repoEntry; + + @Override + public ContextEntryControllerCreator clone() { + return new RepositoryContextEntryControllerCreator(); + } + /** * @see org.olat.core.id.context.ContextEntryControllerCreator#createController(org.olat.core.id.context.ContextEntry, * org.olat.core.gui.UserRequest, * org.olat.core.gui.control.WindowControl) */ + @Override public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - OLATResourceable ores = ce.getOLATResourceable(); - - RepositoryManager repom = RepositoryManager.getInstance(); - RepositoryEntry re = repom.lookupRepositoryEntry(ores.getResourceableId()); + RepositoryEntry re = getRepositoryEntry(ce); Controller ctrl = RepositoyUIFactory.createLaunchController(re, ureq, wControl); return ctrl; - } /** @@ -58,10 +63,7 @@ public class RepositoryContextEntryControllerCreator extends DefaultContextEntry */ @Override public String getTabName(ContextEntry ce, UserRequest ureq) { - OLATResourceable ores = ce.getOLATResourceable(); - - RepositoryManager repom = RepositoryManager.getInstance(); - RepositoryEntry re = repom.lookupRepositoryEntry(ores.getResourceableId()); + RepositoryEntry re = getRepositoryEntry(ce); return re.getDisplayname(); } @@ -75,10 +77,15 @@ public class RepositoryContextEntryControllerCreator extends DefaultContextEntry @Override public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - OLATResourceable ores = ce.getOLATResourceable(); - RepositoryManager repom = RepositoryManager.getInstance(); - RepositoryEntry re = repom.lookupRepositoryEntry(ores.getResourceableId()); - return re != null; - } - + return getRepositoryEntry(ce) != null; + } + + private RepositoryEntry getRepositoryEntry(ContextEntry ce) { + if(repoEntry == null) { + OLATResourceable ores = ce.getOLATResourceable(); + RepositoryManager rm = RepositoryManager.getInstance(); + repoEntry = rm.lookupRepositoryEntry(ores.getResourceableId()); + } + return repoEntry; + } } diff --git a/src/main/java/org/olat/user/HomePageContextEntryControllerCreator.java b/src/main/java/org/olat/user/HomePageContextEntryControllerCreator.java index c5e41256a323c87be17cf8568136d58722fa59e1..3c853851e6f13bbe9943793c507a92c0ab9a8942 100644 --- a/src/main/java/org/olat/user/HomePageContextEntryControllerCreator.java +++ b/src/main/java/org/olat/user/HomePageContextEntryControllerCreator.java @@ -26,6 +26,7 @@ import org.olat.core.gui.control.WindowControl; import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.core.id.context.StateEntry; import org.olat.core.logging.OLog; @@ -44,11 +45,17 @@ import org.olat.core.logging.Tracing; public class HomePageContextEntryControllerCreator extends DefaultContextEntryControllerCreator { private static final OLog log = Tracing.createLoggerFor(HomePageContextEntryControllerCreator.class); + @Override + public ContextEntryControllerCreator clone() { + return this; + } + /** * @see org.olat.core.id.context.ContextEntryControllerCreator#createController(org.olat.core.id.context.ContextEntry, * org.olat.core.gui.UserRequest, * org.olat.core.gui.control.WindowControl) */ + @Override public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { Identity identity = extractIdentity(ce); if (identity == null) return null; @@ -64,6 +71,7 @@ public class HomePageContextEntryControllerCreator extends DefaultContextEntryCo /** * @see org.olat.core.id.context.ContextEntryControllerCreator#getTabName(org.olat.core.id.context.ContextEntry) */ + @Override public String getTabName(ContextEntry ce, UserRequest ureq) { Identity identity = extractIdentity(ce); if (identity == null) return null; diff --git a/src/main/java/org/olat/user/IdentityContextEntryControllerCreator.java b/src/main/java/org/olat/user/IdentityContextEntryControllerCreator.java index c85fc8c9614e0d26c2c62cb8d589ab6c95e7b8d2..0e6cac31526467bf44f17eaba8e91d60caa00ad6 100644 --- a/src/main/java/org/olat/user/IdentityContextEntryControllerCreator.java +++ b/src/main/java/org/olat/user/IdentityContextEntryControllerCreator.java @@ -26,6 +26,7 @@ import org.olat.core.gui.control.WindowControl; import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; import org.olat.core.id.context.ContextEntry; +import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; @@ -44,20 +45,27 @@ import org.olat.home.HomeSite; public class IdentityContextEntryControllerCreator extends DefaultContextEntryControllerCreator { private static final OLog log = Tracing.createLoggerFor(IdentityContextEntryControllerCreator.class); + private Identity identity; + + @Override + public ContextEntryControllerCreator clone() { + return new IdentityContextEntryControllerCreator(); + } + /** * @see org.olat.core.id.context.ContextEntryControllerCreator#createController(org.olat.core.id.context.ContextEntry, * org.olat.core.gui.UserRequest, * org.olat.core.gui.control.WindowControl) */ + @Override public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - Identity identity = extractIdentity(ce); + Identity identity = getIdentity(ce); if (identity == null) return null; UserInfoMainController uimc = new UserInfoMainController(ureq, wControl, identity); return uimc; } @Override - //fxdiff BAKS-7 Resume function public String getSiteClassName(ContextEntry ce, UserRequest ureq) { Long resId = ce.getOLATResourceable().getResourceableId(); if(resId != null && resId.equals(ureq.getIdentity().getKey())) { @@ -69,35 +77,37 @@ public class IdentityContextEntryControllerCreator extends DefaultContextEntryCo /** * @see org.olat.core.id.context.ContextEntryControllerCreator#getTabName(org.olat.core.id.context.ContextEntry) */ + @Override public String getTabName(ContextEntry ce, UserRequest ureq) { - Identity identity = extractIdentity(ce); + Identity identity = getIdentity(ce); if (identity == null) return null; return UserManagerImpl.getInstance().getUserDisplayName(identity); } + @Override + public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { + return getIdentity(ce) != null; + } + /** * Helper to get the identity that is encoded into the context entry * * @param ce * @return the identity or NULL if not found */ - private Identity extractIdentity(ContextEntry ce) { - OLATResourceable resource = ce.getOLATResourceable(); - Long key = resource.getResourceableId(); - if (key == null || key.equals(0)) { - log.error("Can not load identity with key::" + key); - return null; - } - Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(key); - if (identity == null) { - log.error("Can not load identity with key::" + key); + private Identity getIdentity(ContextEntry ce) { + if(identity == null) { + OLATResourceable resource = ce.getOLATResourceable(); + Long key = resource.getResourceableId(); + if (key == null || key.equals(0)) { + log.error("Can not load identity with key::" + key); + return null; + } + identity = BaseSecurityManager.getInstance().loadIdentityByKey(key); + if (identity == null) { + log.error("Can not load identity with key::" + key); + } } return identity; } - - @Override - public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { - Identity identity = extractIdentity(ce); - return identity!=null; - } }