001 /** 002 * Copyright 2005-2011 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.ken.service.impl; 017 018 import org.apache.log4j.Level; 019 import org.apache.log4j.Logger; 020 import org.kuali.rice.ken.service.NotificationRecipientService; 021 import org.kuali.rice.kim.api.KimConstants.KimGroupMemberTypes; 022 import org.kuali.rice.kim.api.group.Group; 023 import org.kuali.rice.kim.api.group.GroupService; 024 import org.kuali.rice.kim.api.services.KimApiServiceLocator; 025 026 import java.util.List; 027 028 /** 029 * NotificationRecipientService implementation 030 * This implementation relies on KIM user and group management 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033 public class NotificationRecipientServiceKimImpl implements NotificationRecipientService 034 { 035 private static final Logger LOG = 036 Logger.getLogger(NotificationRecipientServiceKimImpl.class); 037 038 protected GroupService getGroupService() 039 { 040 return KimApiServiceLocator.getGroupService(); 041 } 042 043 /** 044 * Uses the IdentityManagementService of KIM to get the members of a group. 045 * 046 * @param groupRecipientId the String name of the recipient group 047 * @return a String array of all direct (child) principals and descendent principals 048 * @see org.kuali.rice.ken.service.NotificationRecipientService#getGroupMembers(java.lang.String) 049 */ 050 public String[] getGroupMembers(String groupRecipientId) 051 { 052 Group group = getGroupService().getGroup(groupRecipientId); 053 054 List<String> ids = getGroupService().getMemberPrincipalIds(group.getId()); 055 056 String[] array = new String[ids.size()]; 057 return ids.toArray(array); 058 } 059 060 /** 061 * This method retrieves the display name for a user. 062 * @param userId 063 * @return String 064 */ 065 public String getUserDisplayName(String userId) 066 { 067 //Gary's handling user conversion 068 return null; 069 } 070 071 /** 072 * 073 * @see org.kuali.rice.ken.service.NotificationRecipientService#isRecipientValid(java.lang.String, java.lang.String) 074 */ 075 public boolean isRecipientValid(String recipientId, String recipientType) 076 { 077 boolean b = false; 078 079 if( KimGroupMemberTypes.GROUP_MEMBER_TYPE.getCode().equals(recipientType) ) 080 { 081 b = isGroupRecipientValid( recipientId ); 082 } 083 else if( KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode().equals(recipientType) ) 084 { 085 b = isUserRecipientValid( recipientId ); 086 } 087 else 088 { 089 if( LOG.isEnabledFor(Level.ERROR) ) 090 { 091 LOG.error("Recipient Type is neither of two acceptable values"); 092 } 093 } 094 return b; 095 } 096 097 /** 098 * This overridden method ... 099 * 100 * @see org.kuali.rice.ken.service.NotificationRecipientService#isGroupRecipientValid(java.lang.String) 101 */ 102 public boolean isGroupRecipientValid(String groupRecipientId) 103 { 104 return (KimApiServiceLocator.getGroupService().getGroup( groupRecipientId ) != null); 105 } 106 107 /** 108 * This overridden method ... 109 * 110 * @see org.kuali.rice.ken.service.NotificationRecipientService#isUserRecipientValid(java.lang.String) 111 */ 112 public boolean isUserRecipientValid(String principalName) 113 { 114 return (KimApiServiceLocator.getIdentityService() 115 .getPrincipalByPrincipalName(principalName) != null); 116 } 117 118 }