01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-impl/sakai/model/src/java/org/sakaiproject/component/section/sakai/facade/SakaiUtil.java $
03: * $Id: SakaiUtil.java 18229 2006-11-18 01:12:05Z jholtzman@berkeley.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.component.section.sakai.facade;
21:
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24: import org.sakaiproject.section.api.coursemanagement.User;
25: import org.sakaiproject.component.section.sakai.UserImpl;
26: import org.sakaiproject.site.cover.SiteService;
27: import org.sakaiproject.tool.api.Placement;
28: import org.sakaiproject.tool.cover.ToolManager;
29: import org.sakaiproject.user.api.UserNotDefinedException;
30: import org.sakaiproject.user.cover.UserDirectoryService;
31:
32: public class SakaiUtil {
33: private static final Log log = LogFactory.getLog(SakaiUtil.class);
34:
35: /**
36: * Gets a User from Sakai's UserDirectory (legacy) service.
37: *
38: * @param userUid The user uuid
39: * @return
40: */
41: public static final User getUserFromSakai(String userUid) {
42: final org.sakaiproject.user.api.User sakaiUser;
43: try {
44: sakaiUser = UserDirectoryService.getUser(userUid);
45: } catch (UserNotDefinedException e) {
46: log.error("User not found: " + userUid);
47: e.printStackTrace();
48: return null;
49: }
50: return convertUser(sakaiUser);
51: }
52:
53: /**
54: * Converts a sakai user object into a user object suitable for use in the section
55: * manager tool and in section awareness.
56: *
57: * @param sakaiUser The sakai user, as returned by Sakai's legacy SecurityService.
58: *
59: * @return
60: */
61: public static final User convertUser(
62: final org.sakaiproject.user.api.User sakaiUser) {
63: UserImpl user = new UserImpl(sakaiUser.getDisplayId(),
64: sakaiUser.getDisplayName(), sakaiUser.getSortName(),
65: sakaiUser.getId());
66: return user;
67: }
68:
69: /**
70: * @return The current sakai authz reference
71: */
72: public static final String getSiteReference() {
73: Placement placement = ToolManager.getCurrentPlacement();
74: String context = placement.getContext();
75: return SiteService.siteReference(context);
76: }
77:
78: }
|