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 java.util.ArrayList;
 19  
 import java.util.Date;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.xml.namespace.QName;
 23  
 
 24  
 import org.apache.commons.lang.StringUtils;
 25  
 import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
 26  
 import org.kuali.rice.kim.bo.Role;
 27  
 import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo;
 28  
 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
 29  
 import org.kuali.rice.kim.service.support.impl.KimDerivedRoleTypeServiceBase;
 30  
 import org.kuali.rice.student.bo.KualiStudentKimAttributes;
 31  
 import org.kuali.student.core.organization.dto.OrgPersonRelationInfo;
 32  
 import org.kuali.student.core.organization.service.OrganizationService;
 33  
 
 34  0
 public class OrgDerivedRoleTypeServiceImpl extends KimDerivedRoleTypeServiceBase {
 35  
         
 36  0
         private static final org.apache.log4j.Logger LOG = 
 37  
                         org.apache.log4j.Logger.getLogger(OrgDerivedRoleTypeServiceImpl.class);
 38  
         
 39  
         private OrganizationService orgService;
 40  0
         private List<String> includedOrgPersonRelationTypes = null;
 41  0
         private List<String> excludedOrgPersonRelationTypes = null;
 42  
         
 43  
         
 44  
         /**
 45  
          * This method should grab the orgId from the qualification 
 46  
          * use the org service to find person-org relations (getPersonIdsForOrgByRelationType)
 47  
          * return the members.
 48  
          * 
 49  
          * See KimDerivedRoleTypeServiceBase
 50  
          */
 51  
         /* (non-Javadoc)
 52  
          * @see org.kuali.rice.kim.service.support.impl.KimDerivedRoleTypeServiceBase#getRoleMembersFromApplicationRole(java.lang.String, java.lang.String, org.kuali.rice.kim.bo.types.dto.AttributeSet)
 53  
          */
 54  
         @Override
 55  
         public List<RoleMembershipInfo> getRoleMembersFromApplicationRole(
 56  
                         String namespaceCode, String roleName, AttributeSet qualification) {
 57  0
                 if (null == orgService) {
 58  0
                            orgService = (OrganizationService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/organization","OrganizationService"));
 59  
                 }
 60  
                 
 61  0
                 validateRequiredAttributesAgainstReceived(qualification);
 62  0
                 List<RoleMembershipInfo> members = new ArrayList<RoleMembershipInfo>();
 63  
                 
 64  0
                 String orgId = qualification.get(KualiStudentKimAttributes.QUALIFICATION_ORG_ID);
 65  
 //                String org = qualification.get(KualiStudentKimAttributes.QUALIFICATION_ORG);
 66  0
                 if (LOG.isDebugEnabled()) {
 67  0
                     LOG.debug("Using Org Values:");
 68  0
                     LOG.debug("------ Org ID: " + orgId);
 69  
 //                    LOG.debug("------ Org Short Name: " + org);
 70  
             }
 71  0
                 if (StringUtils.isEmpty(orgId)) {
 72  0
                     throw new RuntimeException("No valid qualifier value found for key: " + KualiStudentKimAttributes.QUALIFICATION_ORG_ID);
 73  
                 }
 74  
                 //Put the org name into the attribute set
 75  0
                 AttributeSet attributes = new AttributeSet();
 76  
 //                attributes.put(KualiStudentKimAttributes.QUALIFICATION_ORG, org);
 77  
 
 78  
                 try {
 79  
                         //If the includedOrgPersonRelationType is set, restrict members to that relationship type
 80  0
                         if(includedOrgPersonRelationTypes!=null){
 81  0
                                 for(String orgPersonRelationType:includedOrgPersonRelationTypes){
 82  0
                                         List<String> principalIds = orgService.getPersonIdsForOrgByRelationType(orgId, orgPersonRelationType);
 83  0
                                         for(String principalId:principalIds){
 84  0
                                                 RoleMembershipInfo member = new RoleMembershipInfo(null/*roleId*/, null, principalId, Role.PRINCIPAL_MEMBER_TYPE, attributes);
 85  0
                                                 members.add(member);
 86  0
                                         }
 87  0
                                 }
 88  
                         //Otherwise get all members of the organization except for the excluded
 89  
                         }else{
 90  
                             //getCurrent Date
 91  0
                             Date now = new Date();
 92  0
                                 List<OrgPersonRelationInfo> relations = orgService.getAllOrgPersonRelationsByOrg(orgId);
 93  0
                                 for(OrgPersonRelationInfo relation:relations){
 94  0
                                         if(excludedOrgPersonRelationTypes==null||!excludedOrgPersonRelationTypes.contains(relation.getType())){
 95  
                                             //Add role membership only for memberships that are valid meaning expiration date is greater than or equal to current date.
 96  0
                                             if(relation.getExpirationDate()!=null){
 97  0
                                                 if(relation.getExpirationDate().compareTo(now)>=0){
 98  0
                                                     RoleMembershipInfo member = new RoleMembershipInfo(null/*roleId*/, null, relation.getPersonId(), Role.PRINCIPAL_MEMBER_TYPE, attributes);
 99  0
                                                     members.add(member);
 100  0
                                                 }
 101  
                                             }
 102  
                                             else{
 103  0
                             RoleMembershipInfo member = new RoleMembershipInfo(null/*roleId*/, null, relation.getPersonId(), Role.PRINCIPAL_MEMBER_TYPE, attributes);
 104  0
                             members.add(member);
 105  0
                                             }
 106  
                                         }
 107  
                                 }
 108  
                         }
 109  0
                 } catch (Exception e) {
 110  0
                         LOG.warn("Error getting relations from Org Service for Org:"+orgId+". ",e);
 111  0
                 } 
 112  
         
 113  0
                 return members;
 114  
         }
 115  
 
 116  
         public OrganizationService getOrgService() {
 117  0
                 return orgService;
 118  
         }
 119  
 
 120  
         public void setOrgService(OrganizationService orgService) {
 121  0
                 this.orgService = orgService;
 122  0
         }
 123  
 
 124  
         public List<String> getIncludedOrgPersonRelationTypes() {
 125  0
                 return includedOrgPersonRelationTypes;
 126  
         }
 127  
 
 128  
         public void setIncludedOrgPersonRelationTypes(
 129  
                         List<String> includedOrgPersonRelationTypes) {
 130  0
                 this.includedOrgPersonRelationTypes = includedOrgPersonRelationTypes;
 131  0
         }
 132  
 
 133  
         public List<String> getExcludedOrgPersonRelationTypes() {
 134  0
                 return excludedOrgPersonRelationTypes;
 135  
         }
 136  
 
 137  
         public void setExcludedOrgPersonRelationTypes(
 138  
                         List<String> excludedOrgPersonRelationTypes) {
 139  0
                 this.excludedOrgPersonRelationTypes = excludedOrgPersonRelationTypes;
 140  0
         }
 141  
 
 142  
 
 143  
 
 144  
 }