| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 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 | |
|
| 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 | |
|
| 60 | |
|
| 61 | 0 | if ( inputQualification == null || inputQualification.isEmpty() || roleMemberQualifier == null || roleMemberQualifier.isEmpty() ) { |
| 62 | 0 | return true; |
| 63 | |
} |
| 64 | |
|
| 65 | 0 | String roleMemberOrganizationId = roleMemberQualifier.get(KualiStudentKimAttributes.QUALIFICATION_ORG_ID); |
| 66 | |
|
| 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 | |
|
| 74 | 0 | BooleanFormatter format = new BooleanFormatter(); |
| 75 | 0 | Boolean b = (Boolean)format.convertFromPresentationFormat(roleMemberQualifier.get(KualiStudentKimAttributes.DESCEND_HIERARCHY)); |
| 76 | 0 | if (b.booleanValue()) { |
| 77 | |
|
| 78 | 0 | inputSets.addAll(getHierarchyOrgIds(inputOrgId)); |
| 79 | |
} |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 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 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 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 | |
} |