Skip to content
Snippets Groups Projects
Commit 63243425 authored by srosse's avatar srosse
Browse files

OO-193: implements a context creator specific for HomePage

parent c46902d8
No related branches found
No related tags found
No related merge requests found
......@@ -308,7 +308,7 @@ public class MembersCourseNodeRunController extends FormBasicController {
}
protected void openHomePage(Identity member, UserRequest ureq) {
String url = "[Identity:" + member.getKey() + "]";
String url = "[HomePage:" + member.getKey() + "]";
BusinessControl bc = BusinessControlFactory.getInstance().createFromString(url);
WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, getWindowControl());
NewControllerFactory.getInstance().launch(ureq, bwControl);
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.user;
import org.olat.basesecurity.BaseSecurityManager;
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.Identity;
import org.olat.core.id.OLATResourceable;
import org.olat.core.id.context.ContextEntry;
import org.olat.core.id.context.DefaultContextEntryControllerCreator;
import org.olat.core.id.context.StateEntry;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
/**
* <h3>Description:</h3>
* <p>
* This class offers a way to launch the users homepage (alias visiting card)
* controller in a new tab
* <p>
* Initial Date: 21.08.2009 <br>
*
* @author gnaegi, gnaegi@frentix.com, www.frentix.com
*/
public class HomePageContextEntryControllerCreator extends DefaultContextEntryControllerCreator {
private static final OLog log = Tracing.createLoggerFor(HomePageContextEntryControllerCreator.class);
/**
* @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)
*/
public Controller createController(ContextEntry ce, UserRequest ureq, WindowControl wControl) {
Identity identity = extractIdentity(ce);
if (identity == null) return null;
UserInfoMainController uimc = new UserInfoMainController(ureq, wControl, identity);
return uimc;
}
@Override
public String getSiteClassName(ContextEntry ce, UserRequest ureq) {
return null;
}
/**
* @see org.olat.core.id.context.ContextEntryControllerCreator#getTabName(org.olat.core.id.context.ContextEntry)
*/
public String getTabName(ContextEntry ce, UserRequest ureq) {
Identity identity = extractIdentity(ce);
if (identity == null) return null;
return UserManagerImpl.getInstance().getUserDisplayName(identity.getUser());
}
/**
* 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;
}
StateEntry state = ce.getTransientState();
if(state instanceof HomePageStateEntry) {
HomePageStateEntry homeState = (HomePageStateEntry)state;
if(homeState.same(key)) {
return homeState.getIdentity();
}
}
Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(key);
if (identity == null) {
log.error("Can not load identity with key::" + key);
}
ce.setTransientState(new HomePageStateEntry(identity));
return identity;
}
@Override
public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) {
Identity identity = extractIdentity(ce);
return identity != null;
}
private class HomePageStateEntry implements StateEntry {
private final Identity identity;
public HomePageStateEntry(Identity identity) {
this.identity = identity;
}
public boolean same(Long key) {
return identity != null && identity.getKey().equals(key);
}
public Identity getIdentity() {
return identity;
}
@Override
public HomePageStateEntry clone() {
return new HomePageStateEntry(identity);
}
}
}
......@@ -72,7 +72,7 @@ public class IdentityContextEntryControllerCreator extends DefaultContextEntryCo
public String getTabName(ContextEntry ce, UserRequest ureq) {
Identity identity = extractIdentity(ce);
if (identity == null) return null;
return identity.getName();
return UserManagerImpl.getInstance().getUserDisplayName(identity.getUser());
}
/**
......
......@@ -19,6 +19,7 @@
**/
package org.olat.user;
import org.olat.basesecurity.IdentityShort;
import org.olat.core.id.User;
import org.olat.core.id.UserConstants;
......@@ -50,11 +51,18 @@ public class UserDisplayNameCreator {
// use first and lastname for display purpose
String first = user.getProperty(UserConstants.FIRSTNAME, null);
String last = user.getProperty(UserConstants.LASTNAME, null);
return getDisplayName(first, last);
}
public String getUserDisplayName(IdentityShort identity) {
return getDisplayName(identity.getFirstName(), identity.getLastName());
}
protected String getDisplayName(String firstName, String lastName) {
// expect null values to make it robust agains NPE and remove whitespace
String combined = (first == null? "" : first) + " " + (last == null? "" : last);
String combined = (firstName == null? "" : firstName) + " " + (lastName == null? "" : lastName);
combined = combined.trim();
if (combined.length() == 0) combined = "unknown user";
return combined;
}
}
......@@ -19,8 +19,6 @@
**/
package org.olat.user;
import org.olat.core.id.User;
import org.olat.core.id.UserConstants;
/**
* <h3>Description:</h3> This bean implements an alternative method to display
......@@ -43,14 +41,11 @@ public class UserDisplayNameCreatorLastnameFirst extends UserDisplayNameCreator{
/**
* Returns the users displayable name, e.g. "Firstname Lastname"
*
* @param user
* @param first The first name
* @param last The last name
* @return
*/
public String getUserDisplayName(User user) {
if (user == null) return "unknown user";
// use first and lastname for display purpose
String first = user.getProperty(UserConstants.FIRSTNAME, null);
String last = user.getProperty(UserConstants.LASTNAME, null);
protected String getDisplayName(String first, String last) {
// expect null values to make it robust against NPE and remove whitespace
String combined = "";
if (last != null) {
......@@ -66,5 +61,4 @@ public class UserDisplayNameCreatorLastnameFirst extends UserDisplayNameCreator{
if (combined.length() == 0) combined = "unknown user";
return combined;
}
}
......@@ -188,6 +188,8 @@ public class UserModule extends AbstractOLATModule {
// Add controller factory extension point to launch user profile controller
NewControllerFactory.getInstance().addContextEntryControllerCreator(Identity.class.getSimpleName(),
new IdentityContextEntryControllerCreator());
NewControllerFactory.getInstance().addContextEntryControllerCreator("HomePage",
new HomePageContextEntryControllerCreator());
NewControllerFactory.getInstance().addContextEntryControllerCreator(User.class.getSimpleName(),
new UserAdminContextEntryControllerCreator());
NewControllerFactory.getInstance().addContextEntryControllerCreator(UserAdminSite.class.getSimpleName(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment