View Javadoc
1   /**
2    * Copyright 2005-2014 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.ken.service.impl;
17  
18  import org.apache.log4j.Level;
19  import org.apache.log4j.Logger;
20  import org.kuali.rice.ken.service.NotificationRecipientService;
21  import org.kuali.rice.kim.api.KimConstants.KimGroupMemberTypes;
22  import org.kuali.rice.kim.api.group.Group;
23  import org.kuali.rice.kim.api.group.GroupService;
24  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
25  
26  import java.util.List;
27  
28  /**
29   * NotificationRecipientService implementation
30   * This implementation relies on KIM user and group management
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class NotificationRecipientServiceKimImpl implements NotificationRecipientService
34  {
35      private static final Logger LOG =
36          Logger.getLogger(NotificationRecipientServiceKimImpl.class);
37  
38      protected GroupService getGroupService()
39      {
40          return KimApiServiceLocator.getGroupService();
41      }
42  
43      /**
44       * Uses the IdentityManagementService of KIM to get the members of a group.
45       *
46       * @param groupRecipientId the String name of the recipient group
47       * @return a String array of all direct (child) principals and descendent principals
48       * @see org.kuali.rice.ken.service.NotificationRecipientService#getGroupMembers(java.lang.String)
49       */
50      public String[] getGroupMembers(String groupRecipientId)
51      {
52          Group group = getGroupService().getGroup(groupRecipientId);
53  
54          List<String> ids = getGroupService().getMemberPrincipalIds(group.getId());
55  
56          String[] array = new String[ids.size()];
57          return ids.toArray(array);
58      }
59  
60      /**
61       * This method retrieves the display name for a user.
62       * @param userId
63       * @return String
64       */
65      public String getUserDisplayName(String userId)
66      {
67          //Gary's handling user conversion
68          return null;
69      }
70  
71      /**
72       *
73       * @see org.kuali.rice.ken.service.NotificationRecipientService#isRecipientValid(java.lang.String, java.lang.String)
74       */
75       public boolean isRecipientValid(String recipientId, String recipientType)
76       {
77           boolean b = false;
78  
79           if( KimGroupMemberTypes.GROUP_MEMBER_TYPE.getCode().equals(recipientType) )
80           {
81               b = isGroupRecipientValid( recipientId );
82           }
83           else if( KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode().equals(recipientType) )
84           {
85               b = isUserRecipientValid( recipientId );
86           }
87           else
88           {
89               if( LOG.isEnabledFor(Level.ERROR) )
90               {
91                   LOG.error("Recipient Type is neither of two acceptable values");
92               }
93           }
94           return b;
95       }
96  
97      /**
98       * This overridden method ...
99       *
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 }