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