Coverage Report - org.kuali.rice.kew.identity.service.impl.IdentityHelperServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
IdentityHelperServiceImpl
0%
0/65
0%
0/36
3.643
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kew.identity.service.impl;
 17  
 
 18  
 import org.apache.commons.logging.Log;
 19  
 import org.apache.commons.logging.LogFactory;
 20  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 21  
 import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient;
 22  
 import org.kuali.rice.kew.actionrequest.Recipient;
 23  
 import org.kuali.rice.kew.api.KewApiConstants;
 24  
 import org.kuali.rice.kew.api.identity.EmployeeId;
 25  
 import org.kuali.rice.kew.api.identity.PrincipalId;
 26  
 import org.kuali.rice.kew.api.identity.PrincipalName;
 27  
 import org.kuali.rice.kew.api.user.UserId;
 28  
 import org.kuali.rice.kew.identity.service.IdentityHelperService;
 29  
 import org.kuali.rice.kew.workgroup.GroupId;
 30  
 import org.kuali.rice.kew.workgroup.GroupNameId;
 31  
 import org.kuali.rice.kew.workgroup.WorkflowGroupId;
 32  
 import org.kuali.rice.kim.api.group.Group;
 33  
 import org.kuali.rice.kim.api.identity.Person;
 34  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 35  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 36  
 
 37  
 /**
 38  
  *
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  *
 41  
  */
 42  0
 public class IdentityHelperServiceImpl implements IdentityHelperService {
 43  
 
 44  0
         private static final Log logger = LogFactory.getLog(IdentityHelperServiceImpl.class);
 45  
 
 46  
                 public String getIdForPrincipalName(String principalName) {
 47  0
                 if (principalName == null) {
 48  0
                         throw new RiceIllegalArgumentException("Can't lookup a principal ID for a null principal name.");
 49  
                 }
 50  0
                 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName);
 51  0
                 if (principal == null) {
 52  0
                         throw new RiceIllegalArgumentException("Given principal name of '" + principalName + "' was invalid.  Failed to lookup a corresponding principal ID.");
 53  
                 }
 54  0
                 return principal.getPrincipalId();
 55  
         }
 56  
 
 57  
                 public void validatePrincipalId(String principalId) {
 58  
                         // the getPrincipal method attempts to load the principal with the id and throws an exception if it fails
 59  0
                         getPrincipal(principalId);
 60  0
                 }
 61  
 
 62  
         public String getIdForGroupName(String namespace, String groupName) {
 63  0
                 Group group = KimApiServiceLocator.getGroupService().getGroupByNameAndNamespaceCode(namespace, groupName);
 64  0
                 if (group == null) {
 65  0
                         throw new RiceIllegalArgumentException("Given namespace of '" + namespace + "' and name of '" + groupName + "' was invalid.  Failed to lookup a corresponding group ID.");
 66  
                 }
 67  0
                 return group.getId();
 68  
         }
 69  
 
 70  
 
 71  
         public Recipient getPrincipalRecipient(String principalId) {
 72  0
                 Principal principal = getPrincipal(principalId);
 73  0
                 return new KimPrincipalRecipient(principal);
 74  
         }
 75  
 
 76  
         public Principal getPrincipal(String principalId) {
 77  0
                 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(principalId);
 78  0
                 if (principal == null) {
 79  0
                         throw new RiceIllegalArgumentException("Could not locate a principal with the given principalId of " + principalId);
 80  
                 }
 81  0
                 return principal;
 82  
         }
 83  
 
 84  
         public Principal getPrincipalByPrincipalName(String principalName) {
 85  0
                 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName);
 86  0
                 if (principal == null) {
 87  0
                         throw new RiceIllegalArgumentException("Could not locate a principal with the given principalName of " + principalName);
 88  
                 }
 89  0
                 return principal;
 90  
         }
 91  
 
 92  
         public Group getGroupByName(String namespaceCode, String name) {
 93  0
                 Group group = KimApiServiceLocator.getGroupService().getGroupByNameAndNamespaceCode(namespaceCode, name);
 94  0
                 if (group == null) {
 95  0
                         throw new RiceIllegalArgumentException("Could not locate a group with the given namspace of '" + namespaceCode + "' and group name of '" + name + "'");
 96  
                 }
 97  0
                 return group;
 98  
         }
 99  
 
 100  
         public Person getPerson(String principalId) {
 101  0
                 Person person = KimApiServiceLocator.getPersonService().getPerson(principalId);
 102  0
                 if (person == null) {
 103  0
                         throw new RiceIllegalArgumentException("Could not locate a person with the given principal id of " + principalId);
 104  
                 }
 105  0
                 return person;
 106  
         }
 107  
 
 108  
         public Person getPersonByPrincipalName(String principalName) {
 109  0
                 Person person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(principalName);
 110  0
                 if (person == null) {
 111  0
                         throw new RiceIllegalArgumentException("Could not locate a person with the given principal name of " + principalName);
 112  
                 }
 113  0
                 return person;
 114  
         }
 115  
 
 116  
         public Person getPersonByEmployeeId(String employeeId) {
 117  0
                 Person person = KimApiServiceLocator.getPersonService().getPersonByEmployeeId(employeeId);
 118  0
                 if (person == null) {
 119  0
                         throw new RiceIllegalArgumentException("Could not locate a person with the given employee id of " + employeeId);
 120  
                 }
 121  0
                 return person;
 122  
         }
 123  
 
 124  
 
 125  
         public Group getGroup(String groupId) {
 126  0
                 Group group = KimApiServiceLocator.getGroupService().getGroup(groupId);
 127  0
                 if (group == null) {
 128  0
                         throw new RiceIllegalArgumentException("Could not locate a group with the given groupId of " + groupId);
 129  
                 }
 130  0
                 return group;
 131  
         }
 132  
 
 133  
         public Group getGroup(GroupId groupId) {
 134  0
                 if (groupId == null || groupId.isEmpty()) {
 135  0
                         return null;
 136  0
                 } else if (groupId instanceof WorkflowGroupId) {
 137  0
                         return KimApiServiceLocator.getGroupService().getGroup(""+((WorkflowGroupId)groupId).getGroupId());
 138  0
                 } else if (groupId instanceof GroupNameId) {
 139  0
                         return KimApiServiceLocator.getGroupService().getGroupByNameAndNamespaceCode(
 140  
                     ((GroupNameId) groupId).getNamespace(), ((GroupNameId) groupId).getNameId());
 141  
                 }
 142  0
                 throw new RiceIllegalArgumentException("Invalid GroupId type was passed: " + groupId);
 143  
         }
 144  
 
 145  
         public Principal getPrincipal(UserId userId) {
 146  0
                 if (userId == null) {
 147  0
                         return null;
 148  0
                 } else if (userId instanceof PrincipalId) {
 149  0
                         String principalId = ((PrincipalId)userId).getPrincipalId();
 150  0
                         return KimApiServiceLocator.getIdentityService().getPrincipal(principalId);
 151  0
                 } else if (userId instanceof PrincipalName) {
 152  0
                         String principalName = ((PrincipalName)userId).getId();
 153  0
                         return KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName);
 154  0
                 } else if (userId instanceof EmployeeId) {
 155  0
                         String employeeId = ((EmployeeId)userId).getEmployeeId();
 156  0
                         Person person = getPersonByEmployeeId(employeeId);
 157  0
                         return getPrincipal(person.getPrincipalId());
 158  
                 }
 159  0
                 throw new RiceIllegalArgumentException("Invalid UserIdDTO type was passed: " + userId);
 160  
         }
 161  
         
 162  
         public Principal getSystemPrincipal() {
 163  0
                 return getPrincipalByPrincipalName(KewApiConstants.SYSTEM_USER);
 164  
         }
 165  
 
 166  
 }