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