Coverage Report - org.kuali.student.lum.kim.role.type.OrgDerivedRoleTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
OrgDerivedRoleTypeServiceImpl
0%
0/48
0%
0/22
2.857
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.lum.kim.role.type;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 20  
 import org.kuali.rice.kim.api.KimConstants;
 21  
 import org.kuali.rice.kim.api.role.RoleMembership;
 22  
 import org.kuali.rice.kns.kim.role.DerivedRoleTypeServiceBase;
 23  
 import org.kuali.rice.student.bo.KualiStudentKimAttributes;
 24  
 import org.kuali.student.core.organization.dto.OrgPersonRelationInfo;
 25  
 import org.kuali.student.core.organization.service.OrganizationService;
 26  
 
 27  
 import javax.xml.namespace.QName;
 28  
 import java.util.*;
 29  
 
 30  0
 public class OrgDerivedRoleTypeServiceImpl extends DerivedRoleTypeServiceBase {
 31  
         
 32  0
         private static final org.apache.log4j.Logger LOG = 
 33  
                         org.apache.log4j.Logger.getLogger(OrgDerivedRoleTypeServiceImpl.class);
 34  
         
 35  
         private OrganizationService orgService;
 36  0
         private List<String> includedOrgPersonRelationTypes = null;
 37  0
         private List<String> excludedOrgPersonRelationTypes = null;
 38  
         
 39  
         
 40  
         /**
 41  
          * This method should grab the orgId from the qualification 
 42  
          * use the org service to find person-org relations (getPersonIdsForOrgByRelationType)
 43  
          * return the members.
 44  
          * 
 45  
          * See DerivedRoleTypeServiceBase
 46  
          */
 47  
         /* (non-Javadoc)
 48  
          * @see org.kuali.rice.kns.kim.role.DerivedRoleTypeServiceBase#getRoleMembersFromDerivedRole(java.lang.String, java.lang.String, org.kuali.rice.kim.bo.types.dto.Map<String,String>)
 49  
          */
 50  
         @Override
 51  
         public List<RoleMembership> getRoleMembersFromDerivedRole(
 52  
                         String namespaceCode, String roleName, Map<String,String> qualification) {
 53  0
                 if (null == orgService) {
 54  0
                            orgService = (OrganizationService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/organization","OrganizationService"));
 55  
                 }
 56  
                 
 57  0
                 validateRequiredAttributesAgainstReceived(qualification);
 58  0
                 List<RoleMembership> members = new ArrayList<RoleMembership>();
 59  
                 
 60  0
                 String orgId = qualification.get(KualiStudentKimAttributes.QUALIFICATION_ORG_ID);
 61  
 //                String org = qualification.get(KualiStudentKimAttributes.QUALIFICATION_ORG);
 62  0
                 if (LOG.isDebugEnabled()) {
 63  0
                     LOG.debug("Using Org Values:");
 64  0
                     LOG.debug("------ Org ID: " + orgId);
 65  
 //                    LOG.debug("------ Org Short Name: " + org);
 66  
             }
 67  0
                 if (StringUtils.isEmpty(orgId)) {
 68  0
                     throw new RuntimeException("No valid qualifier value found for key: " + KualiStudentKimAttributes.QUALIFICATION_ORG_ID);
 69  
                 }
 70  
                 //Put the org name into the attribute set
 71  0
                 Map<String,String> attributes = new LinkedHashMap<String,String>();
 72  
 //                attributes.put(KualiStudentKimAttributes.QUALIFICATION_ORG, org);
 73  
 
 74  
                 try {
 75  
                         //If the includedOrgPersonRelationType is set, restrict members to that relationship type
 76  0
                         if(includedOrgPersonRelationTypes!=null){
 77  0
                                 for(String orgPersonRelationType:includedOrgPersonRelationTypes){
 78  0
                                         List<String> principalIds = orgService.getPersonIdsForOrgByRelationType(orgId, orgPersonRelationType);
 79  0
                                         for(String principalId:principalIds){
 80  0
                                                 RoleMembership member = RoleMembership.Builder.create(null/*roleId*/, null, principalId, KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, attributes).build();
 81  0
                                                 members.add(member);
 82  0
                                         }
 83  0
                                 }
 84  
                         //Otherwise get all members of the organization except for the excluded
 85  
                         }else{
 86  
                             //getCurrent Date
 87  0
                             Date now = new Date();
 88  0
                                 List<OrgPersonRelationInfo> relations = orgService.getAllOrgPersonRelationsByOrg(orgId);
 89  0
                                 for(OrgPersonRelationInfo relation:relations){
 90  0
                                         if(excludedOrgPersonRelationTypes==null||!excludedOrgPersonRelationTypes.contains(relation.getType())){
 91  
                                             //Add role membership only for memberships that are valid meaning expiration date is greater than or equal to current date.
 92  0
                                             if(relation.getExpirationDate()!=null){
 93  0
                                                 if(relation.getExpirationDate().compareTo(now)>=0){
 94  0
                                                     RoleMembership member = RoleMembership.Builder.create(null/*roleId*/, null, relation.getPersonId(), KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, attributes).build();
 95  0
                                                     members.add(member);
 96  0
                                                 }
 97  
                                             }
 98  
                                             else{
 99  0
                             RoleMembership member = RoleMembership.Builder.create(null/*roleId*/, null, relation.getPersonId(), KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, attributes).build();
 100  0
                             members.add(member);
 101  0
                                             }
 102  
                                         }
 103  
                                 }
 104  
                         }
 105  0
                 } catch (Exception e) {
 106  0
                         LOG.warn("Error getting relations from Org Service for Org:"+orgId+". ",e);
 107  0
                 } 
 108  
         
 109  0
                 return members;
 110  
         }
 111  
 
 112  
         public OrganizationService getOrgService() {
 113  0
                 return orgService;
 114  
         }
 115  
 
 116  
         public void setOrgService(OrganizationService orgService) {
 117  0
                 this.orgService = orgService;
 118  0
         }
 119  
 
 120  
         public List<String> getIncludedOrgPersonRelationTypes() {
 121  0
                 return includedOrgPersonRelationTypes;
 122  
         }
 123  
 
 124  
         public void setIncludedOrgPersonRelationTypes(
 125  
                         List<String> includedOrgPersonRelationTypes) {
 126  0
                 this.includedOrgPersonRelationTypes = includedOrgPersonRelationTypes;
 127  0
         }
 128  
 
 129  
         public List<String> getExcludedOrgPersonRelationTypes() {
 130  0
                 return excludedOrgPersonRelationTypes;
 131  
         }
 132  
 
 133  
         public void setExcludedOrgPersonRelationTypes(
 134  
                         List<String> excludedOrgPersonRelationTypes) {
 135  0
                 this.excludedOrgPersonRelationTypes = excludedOrgPersonRelationTypes;
 136  0
         }
 137  
 
 138  
 
 139  
 
 140  
 }