| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.lum.workflow.qualifierresolver; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.List; |
| 20 | |
|
| 21 | |
import javax.xml.namespace.QName; |
| 22 | |
|
| 23 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
| 24 | |
import org.kuali.rice.kew.role.XPathQualifierResolver; |
| 25 | |
import org.kuali.rice.kew.rule.bo.RuleAttribute; |
| 26 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
| 27 | |
import org.kuali.rice.student.bo.KualiStudentKimAttributes; |
| 28 | |
import org.kuali.student.core.organization.dto.OrgInfo; |
| 29 | |
import org.kuali.student.core.organization.service.OrganizationService; |
| 30 | |
import org.kuali.student.core.search.dto.SearchParam; |
| 31 | |
import org.kuali.student.core.search.dto.SearchRequest; |
| 32 | |
import org.kuali.student.core.search.dto.SearchResult; |
| 33 | |
import org.kuali.student.core.search.dto.SearchResultCell; |
| 34 | |
import org.kuali.student.core.search.dto.SearchResultRow; |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
public abstract class AbstractCocOrgQualifierResolver extends XPathQualifierResolver { |
| 41 | |
|
| 42 | 0 | protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger |
| 43 | |
.getLogger(AbstractCocOrgQualifierResolver.class); |
| 44 | |
|
| 45 | |
public static final String KUALI_ORG_TYPE_CURRICULUM_PARENT = "kuali.org.CurriculumParent"; |
| 46 | |
public static final String KUALI_ORG_HIERARCHY_CURRICULUM = "kuali.org.hierarchy.Curriculum"; |
| 47 | |
public static final String KUALI_ORG_DEPARTMENT = "kuali.org.Department"; |
| 48 | |
public static final String KUALI_ORG_COLLEGE = "kuali.org.College"; |
| 49 | |
public static final String KUALI_ORG_COC = "kuali.org.COC"; |
| 50 | |
public static final String KUALI_ORG_DIVISION = "kuali.org.Division"; |
| 51 | |
public static final String KUALI_ORG_PROGRAM = "kuali.org.Program"; |
| 52 | |
|
| 53 | |
|
| 54 | |
public static final String DOCUMENT_CONTENT_XML_ROOT_ELEMENT_NAME = "info"; |
| 55 | |
|
| 56 | |
protected OrganizationService orgService; |
| 57 | |
|
| 58 | |
private static final String ORG_RESOLVER_CONFIG = |
| 59 | |
"<resolverConfig>" + |
| 60 | |
"<baseXPathExpression>/documentContent/applicationContent/" + DOCUMENT_CONTENT_XML_ROOT_ELEMENT_NAME + "</baseXPathExpression>" + |
| 61 | |
"<qualifier name=\"" + KualiStudentKimAttributes.QUALIFICATION_ORG_ID + "\">" + |
| 62 | |
"<xPathExpression>./orgId</xPathExpression>" + |
| 63 | |
"</qualifier>" + |
| 64 | |
"</resolverConfig>"; |
| 65 | |
|
| 66 | 0 | private final static RuleAttribute ruleAttribute = new RuleAttribute(); |
| 67 | |
|
| 68 | |
static { |
| 69 | 0 | ruleAttribute.setXmlConfigData(ORG_RESOLVER_CONFIG); |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | 0 | public AbstractCocOrgQualifierResolver() { |
| 76 | 0 | setRuleAttribute(ruleAttribute); |
| 77 | 0 | } |
| 78 | |
|
| 79 | |
protected OrganizationService getOrganizationService() { |
| 80 | 0 | if (null == orgService) { |
| 81 | 0 | orgService = (OrganizationService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/organization","OrganizationService")); |
| 82 | |
} |
| 83 | 0 | return orgService; |
| 84 | |
} |
| 85 | |
|
| 86 | |
protected void setOrganizationService(OrganizationService orgSvc) { |
| 87 | 0 | orgService = orgSvc; |
| 88 | 0 | } |
| 89 | |
|
| 90 | |
protected boolean isOrgType(OrgInfo orgInfo, String orgType) { |
| 91 | |
String actualType; |
| 92 | 0 | if ((null != orgInfo) && (null != (actualType = orgInfo.getType()))) { |
| 93 | 0 | return actualType.equals(orgType); |
| 94 | |
} |
| 95 | 0 | return false; |
| 96 | |
} |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
protected String getAttribute(List<AttributeSet> attributeSets, String searchStr) { |
| 104 | |
String attrStr; |
| 105 | |
|
| 106 | 0 | for (AttributeSet set : attributeSets) { |
| 107 | 0 | attrStr = set.get(searchStr); |
| 108 | 0 | if (null != attrStr) { |
| 109 | 0 | return attrStr; |
| 110 | |
} |
| 111 | |
} |
| 112 | 0 | return null; |
| 113 | |
} |
| 114 | |
|
| 115 | |
protected List<SearchResultRow> relatedOrgsFromOrgId(String orgId, String relationType, String relatedOrgType) { |
| 116 | 0 | List<SearchResultRow> results = null; |
| 117 | 0 | if (null != orgId) { |
| 118 | 0 | List<SearchParam> queryParamValues = new ArrayList<SearchParam>(2); |
| 119 | 0 | SearchParam qpRelType = new SearchParam(); |
| 120 | 0 | qpRelType.setKey("org.queryParam.relationType"); |
| 121 | 0 | qpRelType.setValue(relationType); |
| 122 | 0 | queryParamValues.add(qpRelType); |
| 123 | |
|
| 124 | 0 | SearchParam qpOrgId = new SearchParam(); |
| 125 | 0 | qpOrgId.setKey("org.queryParam.orgId"); |
| 126 | 0 | qpOrgId.setValue(orgId); |
| 127 | 0 | queryParamValues.add(qpOrgId); |
| 128 | |
|
| 129 | 0 | SearchParam qpRelOrgType = new SearchParam(); |
| 130 | 0 | qpRelOrgType.setKey("org.queryParam.relatedOrgType"); |
| 131 | 0 | qpRelOrgType.setValue(relatedOrgType); |
| 132 | 0 | queryParamValues.add(qpRelOrgType); |
| 133 | |
|
| 134 | 0 | SearchRequest searchRequest = new SearchRequest(); |
| 135 | 0 | searchRequest.setSearchKey("org.search.orgQuickViewByRelationTypeRelatedOrgTypeOrgId"); |
| 136 | 0 | searchRequest.setParams(queryParamValues); |
| 137 | |
try { |
| 138 | 0 | SearchResult result = getOrganizationService().search(searchRequest); |
| 139 | 0 | results = result.getRows(); |
| 140 | 0 | } catch (Exception e) { |
| 141 | 0 | LOG.error("Error calling org service"); |
| 142 | 0 | throw new RuntimeException(e); |
| 143 | 0 | } |
| 144 | |
} |
| 145 | 0 | return results; |
| 146 | |
} |
| 147 | |
|
| 148 | |
protected List<AttributeSet> attributeSetFromSearchResult(List<SearchResultRow> results, |
| 149 | |
String orgShortNameKey, String orgIdKey) { |
| 150 | 0 | List<AttributeSet> returnAttrSetList = new ArrayList<AttributeSet>(); |
| 151 | 0 | if(results!=null){ |
| 152 | 0 | for(SearchResultRow result:results){ |
| 153 | 0 | AttributeSet attributeSet = new AttributeSet(); |
| 154 | 0 | String resolvedOrgId = ""; |
| 155 | 0 | String resolvedOrgShortName = ""; |
| 156 | 0 | for (SearchResultCell resultCell : result.getCells()) { |
| 157 | 0 | if ("org.resultColumn.orgId".equals(resultCell |
| 158 | |
.getKey())) { |
| 159 | 0 | resolvedOrgId = resultCell.getValue(); |
| 160 | 0 | } else if ("org.resultColumn.orgShortName" |
| 161 | |
.equals(resultCell.getKey())) { |
| 162 | 0 | resolvedOrgShortName = resultCell.getValue(); |
| 163 | |
} |
| 164 | |
} |
| 165 | 0 | if(orgShortNameKey!=null){ |
| 166 | 0 | attributeSet.put(orgShortNameKey, resolvedOrgShortName); |
| 167 | |
} |
| 168 | 0 | if(orgIdKey!=null){ |
| 169 | 0 | attributeSet.put(orgIdKey, resolvedOrgId); |
| 170 | |
} |
| 171 | 0 | attributeSet.put(KualiStudentKimAttributes.QUALIFICATION_ORG, resolvedOrgShortName); |
| 172 | 0 | attributeSet.put(KualiStudentKimAttributes.QUALIFICATION_ORG_ID, resolvedOrgId); |
| 173 | 0 | returnAttrSetList.add(attributeSet); |
| 174 | 0 | } |
| 175 | |
} |
| 176 | 0 | return returnAttrSetList; |
| 177 | |
} |
| 178 | |
|
| 179 | |
protected List<AttributeSet> cocAttributeSetsFromAncestors(String orgId, String orgType, String orgShortNameKey,String orgIdKey){ |
| 180 | 0 | List<AttributeSet> returnAttributeSets = new ArrayList<AttributeSet>(); |
| 181 | 0 | List<OrgInfo> orgsForRouting = null; |
| 182 | |
|
| 183 | 0 | if(orgId!=null){ |
| 184 | |
try { |
| 185 | 0 | List<String> orgIds = new ArrayList<String>(); |
| 186 | |
|
| 187 | 0 | orgIds.add(orgId); |
| 188 | 0 | orgIds.addAll(getOrganizationService().getAllAncestors(orgId, KUALI_ORG_HIERARCHY_CURRICULUM)); |
| 189 | 0 | orgsForRouting = getOrganizationService().getOrganizationsByIdList(orgIds); |
| 190 | 0 | } catch (Exception e) { |
| 191 | 0 | LOG.error("Error calling org service"); |
| 192 | 0 | throw new RuntimeException(e); |
| 193 | 0 | } |
| 194 | 0 | if(orgsForRouting!=null){ |
| 195 | 0 | for(OrgInfo orgForRouting:orgsForRouting){ |
| 196 | 0 | if(orgType!=null && orgType.equals(orgForRouting.getType())){ |
| 197 | 0 | List<SearchResultRow> results = relatedOrgsFromOrgId(orgForRouting.getId(),KUALI_ORG_TYPE_CURRICULUM_PARENT,KUALI_ORG_COC); |
| 198 | 0 | returnAttributeSets.addAll(attributeSetFromSearchResult(results,orgShortNameKey,orgIdKey)); |
| 199 | 0 | } |
| 200 | |
} |
| 201 | |
} |
| 202 | |
} |
| 203 | 0 | return returnAttributeSets; |
| 204 | |
} |
| 205 | |
} |