Coverage Report - org.kuali.rice.ken.service.impl.NotificationAuthorizationServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
NotificationAuthorizationServiceImpl
0%
0/15
0%
0/6
2.667
 
 1  
 /*
 2  
  * Copyright 2006-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  
 
 17  
 package org.kuali.rice.ken.service.impl;
 18  
 
 19  
 import org.kuali.rice.core.framework.persistence.dao.GenericDao;
 20  
 import org.kuali.rice.ken.bo.NotificationChannel;
 21  
 import org.kuali.rice.ken.bo.NotificationProducer;
 22  
 import org.kuali.rice.ken.service.NotificationAuthorizationService;
 23  
 import org.kuali.rice.ken.util.NotificationConstants;
 24  
 import org.kuali.rice.kim.api.group.Group;
 25  
 import org.kuali.rice.kim.api.group.GroupService;
 26  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 27  
 import org.kuali.rice.kim.bo.Person;
 28  
 import org.kuali.rice.kim.util.KimConstants;
 29  
 
 30  
 import java.util.List;
 31  
 
 32  
 
 33  
 /**
 34  
  * NotificationAuthorizationService implementation - this is the default out-of-the-box implementation of the service.
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  */
 37  
 public class NotificationAuthorizationServiceImpl implements NotificationAuthorizationService {
 38  0
     private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(NotificationAuthorizationServiceImpl.class);
 39  
 
 40  
     private GenericDao businessObjectDao;
 41  
 
 42  
     /**
 43  
      * Constructs a NotificationAuthorizationServiceImpl class instance.
 44  
      * @param businessObjectDao
 45  
      */
 46  0
     public NotificationAuthorizationServiceImpl(GenericDao businessObjectDao) {
 47  0
         this.businessObjectDao = businessObjectDao;
 48  0
     }
 49  
 
 50  
     /**
 51  
      * @see org.kuali.rice.ken.service.NotificationAuthorizationService#isProducerAuthorizedToSendNotificationForChannel(org.kuali.rice.ken.bo.NotificationProducer, org.kuali.rice.ken.bo.NotificationChannel)
 52  
      */
 53  
     public boolean isProducerAuthorizedToSendNotificationForChannel(NotificationProducer producer, NotificationChannel channel) {
 54  0
         List channels = producer.getChannels();
 55  
 
 56  0
         if(channels.contains(channel)) {
 57  0
             return true;
 58  
         } else {
 59  0
             return false;
 60  
         }
 61  
     }
 62  
 
 63  
     /**
 64  
      * Implements by calling the is user member of service in KEW's workgroup service, looking for a specific membership
 65  
      * in the "NotificationAdmin" workgroup.
 66  
      * @see org.kuali.rice.ken.service.NotificationAuthorizationService#isUserAdministrator(java.lang.String)
 67  
      */
 68  
     public boolean isUserAdministrator(String userId) {
 69  0
             String groupNameId = NotificationConstants.KEW_CONSTANTS.NOTIFICATION_ADMIN_GROUP_NAME;
 70  0
             Person user = KimApiServiceLocator.getPersonService().getPerson(userId);
 71  0
             if (user == null) {
 72  0
                 return false;
 73  
             }
 74  
 
 75  0
         final GroupService groupService = KimApiServiceLocator.getGroupService();
 76  0
         Group group = groupService.getGroupByName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, groupNameId);
 77  0
                 return group == null ? false : groupService.isMemberOfGroup(user.getPrincipalId(), group.getId());
 78  
     }
 79  
 }