Coverage Report - org.kuali.student.lum.kim.role.type.OrganizationHierarchyRoleTypeService
 
Classes in this File Line Coverage Branch Coverage Complexity
OrganizationHierarchyRoleTypeService
0%
0/38
0%
0/22
4.4
 
 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  
 /**
 17  
  * 
 18  
  */
 19  
 package org.kuali.student.lum.kim.role.type;
 20  
 
 21  
 import java.util.ArrayList;
 22  
 import java.util.LinkedHashMap;
 23  
 import java.util.List;
 24  
 import java.util.Map;
 25  
 
 26  
 import javax.xml.namespace.QName;
 27  
 
 28  
 import org.apache.commons.lang.StringUtils;
 29  
 import org.apache.log4j.Logger;
 30  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 31  
 import org.kuali.rice.core.web.format.BooleanFormatter;
 32  
 import org.kuali.rice.kns.kim.role.RoleTypeServiceBase;
 33  
 import org.kuali.rice.student.bo.KualiStudentKimAttributes;
 34  
 import org.kuali.student.common.exceptions.DoesNotExistException;
 35  
 import org.kuali.student.common.exceptions.InvalidParameterException;
 36  
 import org.kuali.student.common.exceptions.MissingParameterException;
 37  
 import org.kuali.student.common.exceptions.OperationFailedException;
 38  
 import org.kuali.student.common.exceptions.PermissionDeniedException;
 39  
 import org.kuali.student.core.organization.dto.OrgInfo;
 40  
 import org.kuali.student.core.organization.service.OrganizationService;
 41  
 
 42  
 /**
 43  
  * A Role Type Service that will enable an organization qualifier and parsing of the Organization Hierarchy
 44  
  *
 45  
  */
 46  0
 public class OrganizationHierarchyRoleTypeService extends RoleTypeServiceBase {
 47  0
         private static final Logger LOG = Logger.getLogger(OrganizationHierarchyRoleTypeService.class);
 48  
 
 49  
         public static final String DESCEND_HIERARCHY_TRUE_VALUE = "Y";
 50  
     public static final String DESCEND_HIERARCHY_FALSE_VALUE = "N";
 51  
 
 52  
         protected OrganizationService orgService;
 53  
 
 54  
         @Override
 55  
     protected boolean performMatch(Map<String,String> inputQualification, Map<String,String> roleMemberQualifier) {
 56  
         // if no qualification is passed, then we have no basis to reject this
 57  
         // (if a null is let through, then we get an NPE below) 
 58  0
         if ( inputQualification == null || inputQualification.isEmpty() || roleMemberQualifier == null || roleMemberQualifier.isEmpty() ) {
 59  0
             return true;
 60  
         }
 61  
 //      String roleMemberOrganizationShortName = roleMemberQualifier.get(KualiStudentKimAttributes.QUALIFICATION_ORG);
 62  0
         String roleMemberOrganizationId = roleMemberQualifier.get(KualiStudentKimAttributes.QUALIFICATION_ORG_ID); 
 63  
         // if role member qualifiers has a blank or null orgId then assume auto match
 64  0
         if (StringUtils.isBlank(roleMemberOrganizationId)) {
 65  0
                 return true;
 66  
         }
 67  0
         String inputOrgId = inputQualification.get(KualiStudentKimAttributes.QUALIFICATION_ORG_ID);
 68  0
                 List<Map<String,String>> inputSets = new ArrayList<Map<String,String>>();
 69  
         try {
 70  
                 // if role member qualifier says to descend the hierarchy then add in all other org short names from hierarchy
 71  0
             BooleanFormatter format = new BooleanFormatter();
 72  0
             Boolean b = (Boolean)format.convertFromPresentationFormat(roleMemberQualifier.get(KualiStudentKimAttributes.DESCEND_HIERARCHY));
 73  0
                 if (b.booleanValue()) {
 74  
 //                        inputSets.addAll(getHierarchyOrgShortNames(inputOrgId));
 75  0
                     inputSets.addAll(getHierarchyOrgIds(inputOrgId));
 76  
                 }
 77  
 /*
 78  
                 // add in the original org short name
 79  
                 if(inputOrgId!=null){
 80  
                     OrgInfo org = getOrganizationService().getOrganization(inputOrgId);
 81  
                     inputSets.add(new Map<String,String>(KualiStudentKimAttributes.QUALIFICATION_ORG,org.getShortName()));
 82  
                 }
 83  
 */                
 84  
                     // check for a match where roleMemberOrganizationId exists in one of the attribute sets in the list inputSets
 85  0
                     return hasMatch(inputSets, roleMemberOrganizationId);
 86  0
         } catch (Exception e) {
 87  0
                 LOG.error(e);
 88  0
                 throw new RuntimeException(e);
 89  
         }
 90  
     }
 91  
 
 92  
         protected boolean hasMatch(List<Map<String,String>> inputAttributeSets, String roleMemberOrganizationId) {
 93  0
                 for (Map<String,String> inputSet : inputAttributeSets) {
 94  0
                 if (StringUtils.equals(roleMemberOrganizationId, inputSet.get(KualiStudentKimAttributes.QUALIFICATION_ORG_ID))) {
 95  0
                         return true;
 96  
                 }
 97  
         }
 98  0
                 return false;
 99  
         }
 100  
 
 101  
     protected List<Map<String,String>> getHierarchyOrgIds(String inputOrgId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 102  0
         List<Map<String,String>> returnSets = new ArrayList<Map<String,String>>();
 103  0
         returnSets.addAll(getOrgIdsForHierarchy(inputOrgId, "kuali.org.hierarchy.Main"));
 104  0
         returnSets.addAll(getOrgIdsForHierarchy(inputOrgId, "kuali.org.hierarchy.Curriculum"));
 105  0
         return returnSets;
 106  
     }
 107  
     
 108  
     protected List<Map<String,String>> getOrgIdsForHierarchy(String inputOrgId, String orgHierarchy) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException {
 109  0
         List<Map<String,String>> returnSets = new ArrayList<Map<String,String>>();
 110  0
         List<String> ids = getOrganizationService().getAllAncestors(inputOrgId, orgHierarchy);
 111  0
         if (ids.size() > 0) {
 112  0
             List<OrgInfo> orgs = getOrganizationService().getOrganizationsByIdList(ids);
 113  0
             for (OrgInfo orgInfo : orgs) {
 114  0
                 Map<String, String> attrs = new LinkedHashMap<String,String>();
 115  0
                 attrs.put(KualiStudentKimAttributes.QUALIFICATION_ORG_ID, orgInfo.getId());
 116  0
                 returnSets.add(attrs);                        
 117  0
             }
 118  
         }
 119  0
         return returnSets;
 120  
     }
 121  
 
 122  
 /*    
 123  
     
 124  
         protected List<Map<String,String>> getHierarchyOrgShortNames(String inputOrgId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 125  
                 List<Map<String,String>> returnSets = new ArrayList<Map<String,String>>();
 126  
                 returnSets.addAll(getOrgShortNamesForHierarchy(inputOrgId, "kuali.org.hierarchy.Main"));
 127  
                 returnSets.addAll(getOrgShortNamesForHierarchy(inputOrgId, "kuali.org.hierarchy.Curriculum"));
 128  
                 return returnSets;
 129  
         }
 130  
 
 131  
         protected List<Map<String,String>> getOrgShortNamesForHierarchy(String inputOrgId, String orgHierarchy) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException {
 132  
                 List<Map<String,String>> returnSets = new ArrayList<Map<String,String>>();
 133  
             List<String> ids = getOrganizationService().getAllAncestors(inputOrgId, orgHierarchy);
 134  
             if (ids.size() > 0) {
 135  
             List<OrgInfo> orgs = getOrganizationService().getOrganizationsByIdList(ids);
 136  
             for (OrgInfo orgInfo : orgs) {
 137  
                 returnSets.add(new Map<String,String>(KualiStudentKimAttributes.QUALIFICATION_ORG, orgInfo.getShortName()));
 138  
             }
 139  
         }
 140  
             return returnSets;
 141  
         }
 142  
 */
 143  
         protected OrganizationService getOrganizationService() {
 144  0
                 if (null == orgService) {
 145  0
                            orgService = (OrganizationService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/organization","OrganizationService"));
 146  
                 }
 147  0
                 return orgService;
 148  
         }
 149  
 
 150  
 }