001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.user;
018:
019: import java.io.InputStream;
020: import java.util.List;
021:
022: import junit.framework.Assert;
023:
024: import org.apache.commons.beanutils.BeanUtils;
025:
026: import edu.iu.uis.eden.clientapp.vo.UserIdVO;
027: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
028: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
029: import edu.iu.uis.eden.plugin.PluginClassLoader;
030: import edu.iu.uis.eden.util.ClassLoaderUtils;
031:
032: /**
033: * For this particular user service a user will be returned
034: * @author ewestfal
035: *
036: */
037: public class PluginTestUserService implements UserService {
038:
039: private static long currentWorkflowId = 1;
040:
041: public UserCapabilities getCapabilities() {
042: return UserCapabilities.getReadOnly();
043: }
044:
045: public WorkflowUser getWorkflowUser(UserId userId)
046: throws EdenUserNotFoundException {
047: assertClassLoader();
048: PluginTestUser user = new PluginTestUser();
049: if (userId instanceof AuthenticationUserId) {
050: user.setAuthenticationUserId((AuthenticationUserId) userId);
051: } else if (userId instanceof UuId) {
052: user.setUuId((UuId) userId);
053: } else if (userId instanceof EmplId) {
054: user.setEmplId((EmplId) userId);
055: } else if (userId instanceof WorkflowUserId) {
056: user.setWorkflowUserId((WorkflowUserId) userId);
057: } else {
058: throw new EdenUserNotFoundException(userId.toString());
059: }
060: if (user.getWorkflowUserId() == null
061: || user.getWorkflowUserId().isEmpty()) {
062: user.setWorkflowUserId(new WorkflowUserId(Long
063: .toString(currentWorkflowId++)));
064: }
065: return user;
066: }
067:
068: public WorkflowUser getWorkflowUser(UserIdVO userId)
069: throws EdenUserNotFoundException {
070: assertClassLoader();
071: throw new UnsupportedOperationException(
072: "PluginTestUserService does not support the getWorkflowUser(UserIdVO) method");
073: }
074:
075: public List search(WorkflowUser user, boolean useWildCards) {
076: assertClassLoader();
077: throw new UnsupportedOperationException(
078: "PluginTestUserService does not support the search method");
079: }
080:
081: public WorkflowUser getBlankUser() {
082: assertClassLoader();
083: return new PluginTestUser();
084: }
085:
086: public WorkflowUser copy(WorkflowUser user, boolean preserveKeys) {
087: try {
088: WorkflowUser copy = (WorkflowUser) BeanUtils
089: .cloneBean(user);
090: if (!preserveKeys) {
091: copy.setWorkflowUserId(null);
092: }
093: return copy;
094: } catch (Exception e) {
095: throw new WorkflowRuntimeException("Problem copying user.",
096: e);
097: }
098: }
099:
100: public void loadXml(InputStream inputStream, WorkflowUser user) {
101: assertClassLoader();
102: // do nothing
103: }
104:
105: public void save(WorkflowUser user) {
106: assertClassLoader();
107: }
108:
109: private void assertClassLoader() {
110: if (ClassLoaderUtils.getDefaultClassLoader() != getClass()
111: .getClassLoader()
112: || !(ClassLoaderUtils.getDefaultClassLoader() instanceof PluginClassLoader)) {
113: Assert
114: .fail("Calls to the PluginTestUserService should be proxied by the appropriate context class loader.");
115: }
116: }
117: }
|