1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
package org.kuali.student.lum.workflow.qualifierresolver; |
5 |
|
|
6 |
|
import java.util.ArrayList; |
7 |
|
import java.util.HashSet; |
8 |
|
import java.util.List; |
9 |
|
import java.util.Set; |
10 |
|
|
11 |
|
import javax.xml.namespace.QName; |
12 |
|
import javax.xml.xpath.XPath; |
13 |
|
import javax.xml.xpath.XPathConstants; |
14 |
|
import javax.xml.xpath.XPathExpressionException; |
15 |
|
|
16 |
|
import org.apache.commons.lang.StringUtils; |
17 |
|
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
18 |
|
import org.kuali.rice.kew.engine.RouteContext; |
19 |
|
import org.kuali.rice.kew.engine.node.RouteNodeUtils; |
20 |
|
import org.kuali.rice.kew.role.QualifierResolver; |
21 |
|
import org.kuali.rice.kew.rule.xmlrouting.XPathHelper; |
22 |
|
import org.kuali.rice.kew.util.KEWConstants; |
23 |
|
import org.kuali.rice.kew.util.XmlHelper; |
24 |
|
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
25 |
|
import org.kuali.rice.student.bo.KualiStudentKimAttributes; |
26 |
|
import org.kuali.student.core.organization.service.OrganizationService; |
27 |
|
import org.kuali.student.core.search.dto.SearchParam; |
28 |
|
import org.kuali.student.core.search.dto.SearchRequest; |
29 |
|
import org.kuali.student.core.search.dto.SearchResult; |
30 |
|
import org.kuali.student.core.search.dto.SearchResultCell; |
31 |
|
import org.kuali.student.core.search.dto.SearchResultRow; |
32 |
|
import org.w3c.dom.Document; |
33 |
|
import org.w3c.dom.Element; |
34 |
|
import org.w3c.dom.Node; |
35 |
|
import org.w3c.dom.NodeList; |
36 |
|
|
37 |
|
|
38 |
|
@link |
39 |
|
|
40 |
|
|
|
|
| 0% |
Uncovered Elements: 98 (98) |
Complexity: 19 |
Complexity Density: 0.27 |
|
41 |
|
public abstract class AbstractOrganizationServiceQualifierResolver implements QualifierResolver { |
42 |
|
private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AbstractOrganizationServiceQualifierResolver.class); |
43 |
|
|
44 |
|
protected static final String DOCUMENT_CONTENT_XML_DEFAULT_ORG_ID_KEY = "orgId"; |
45 |
|
protected static final String DOCUMENT_CONTENT_XML_ORG_ID_KEY = "organizationIdDocumentContentKey"; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
public static final String DOCUMENT_CONTENT_XML_ROOT_ELEMENT_NAME = "info"; |
50 |
|
|
51 |
|
private OrganizationService organizationService; |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
53 |
0
|
protected OrganizationService getOrganizationService() {... |
54 |
0
|
if (null == organizationService) { |
55 |
0
|
organizationService = (OrganizationService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/organization", "OrganizationService")); |
56 |
|
} |
57 |
0
|
return organizationService; |
58 |
|
} |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
0
|
protected void setOrganizationService(OrganizationService orgSvc) {... |
61 |
0
|
organizationService = orgSvc; |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@param |
68 |
|
|
69 |
|
@return |
70 |
|
|
71 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 5 |
Complexity Density: 0.28 |
|
72 |
0
|
protected Set<String> getOrganizationIdsFromDocumentContent(RouteContext context) {... |
73 |
0
|
String baseXpathExpression = "/" + KEWConstants.DOCUMENT_CONTENT_ELEMENT + "/" + KEWConstants.APPLICATION_CONTENT_ELEMENT + "/" + DOCUMENT_CONTENT_XML_ROOT_ELEMENT_NAME; |
74 |
0
|
String orgXpathExpression = "./" + getOrganizationIdDocumentContentFieldKey(context); |
75 |
0
|
Document xmlContent = context.getDocumentContent().getDocument(); |
76 |
0
|
XPath xPath = XPathHelper.newXPath(); |
77 |
0
|
try { |
78 |
0
|
NodeList baseElements = (NodeList) xPath.evaluate(baseXpathExpression, xmlContent, XPathConstants.NODESET); |
79 |
0
|
if (LOG.isDebugEnabled()) { |
80 |
0
|
LOG.debug("Found " + baseElements.getLength() + " baseElements to parse for AttributeSets using document XML:"); |
81 |
0
|
XmlHelper.printDocumentStructure(xmlContent); |
82 |
|
} |
83 |
0
|
Set<String> distinctiveOrganizationIds = new HashSet<String>(); |
84 |
0
|
for (int i = 0; i < baseElements.getLength(); i++) { |
85 |
0
|
Node baseNode = baseElements.item(i); |
86 |
0
|
NodeList attributes = (NodeList) xPath.evaluate(orgXpathExpression, baseNode, XPathConstants.NODESET); |
87 |
0
|
for (int j = 0; j < attributes.getLength(); j++) { |
88 |
0
|
Element attributeElement = (Element) attributes.item(j); |
89 |
0
|
distinctiveOrganizationIds.add(attributeElement.getTextContent()); |
90 |
|
} |
91 |
|
} |
92 |
0
|
return distinctiveOrganizationIds; |
93 |
|
} catch (XPathExpressionException e) { |
94 |
0
|
throw new RuntimeException("Encountered an issue executing XPath.", e); |
95 |
|
} |
96 |
|
} |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
98 |
0
|
protected String getOrganizationIdDocumentContentFieldKey(RouteContext context) {... |
99 |
0
|
String organizationIdFieldKey = RouteNodeUtils.getValueOfCustomProperty(context.getNodeInstance().getRouteNode(), DOCUMENT_CONTENT_XML_ORG_ID_KEY); |
100 |
0
|
if (StringUtils.isBlank(organizationIdFieldKey)) { |
101 |
0
|
LOG.info("Cannot find element '" + DOCUMENT_CONTENT_XML_ORG_ID_KEY + "' on Route Node XML configuration. Will use default value of '" + DOCUMENT_CONTENT_XML_DEFAULT_ORG_ID_KEY + "'."); |
102 |
0
|
organizationIdFieldKey = DOCUMENT_CONTENT_XML_DEFAULT_ORG_ID_KEY; |
103 |
|
} |
104 |
0
|
return organizationIdFieldKey; |
105 |
|
} |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 3 |
Complexity Density: 0.12 |
|
107 |
0
|
protected List<SearchResultRow> relatedOrgsFromOrgId(String orgId, String relationType, String relatedOrgType) {... |
108 |
0
|
List<SearchResultRow> results = null; |
109 |
0
|
if (null != orgId) { |
110 |
0
|
List<SearchParam> queryParamValues = new ArrayList<SearchParam>(2); |
111 |
0
|
SearchParam qpRelType = new SearchParam(); |
112 |
0
|
qpRelType.setKey("org.queryParam.relationType"); |
113 |
0
|
qpRelType.setValue(relationType); |
114 |
0
|
queryParamValues.add(qpRelType); |
115 |
|
|
116 |
0
|
SearchParam qpOrgId = new SearchParam(); |
117 |
0
|
qpOrgId.setKey("org.queryParam.orgId"); |
118 |
0
|
qpOrgId.setValue(orgId); |
119 |
0
|
queryParamValues.add(qpOrgId); |
120 |
|
|
121 |
0
|
SearchParam qpRelOrgType = new SearchParam(); |
122 |
0
|
qpRelOrgType.setKey("org.queryParam.relatedOrgType"); |
123 |
0
|
qpRelOrgType.setValue(relatedOrgType); |
124 |
0
|
queryParamValues.add(qpRelOrgType); |
125 |
|
|
126 |
0
|
SearchRequest searchRequest = new SearchRequest(); |
127 |
0
|
searchRequest.setSearchKey("org.search.orgQuickViewByRelationTypeRelatedOrgTypeOrgId"); |
128 |
0
|
searchRequest.setParams(queryParamValues); |
129 |
0
|
try { |
130 |
0
|
SearchResult result = getOrganizationService().search(searchRequest); |
131 |
0
|
results = result.getRows(); |
132 |
|
} catch (Exception e) { |
133 |
0
|
LOG.error("Error calling org service"); |
134 |
0
|
throw new RuntimeException(e); |
135 |
|
} |
136 |
|
} |
137 |
0
|
return results; |
138 |
|
} |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 6 |
Complexity Density: 0.32 |
|
140 |
0
|
protected List<AttributeSet> attributeSetFromSearchResult(List<SearchResultRow> results, String orgShortNameKey, String orgIdKey) {... |
141 |
0
|
List<AttributeSet> returnAttrSetList = new ArrayList<AttributeSet>(); |
142 |
0
|
if (results != null) { |
143 |
0
|
for (SearchResultRow result : results) { |
144 |
0
|
AttributeSet attributeSet = new AttributeSet(); |
145 |
0
|
String resolvedOrgId = ""; |
146 |
0
|
String resolvedOrgShortName = ""; |
147 |
0
|
for (SearchResultCell resultCell : result.getCells()) { |
148 |
0
|
if ("org.resultColumn.orgId".equals(resultCell.getKey())) { |
149 |
0
|
resolvedOrgId = resultCell.getValue(); |
150 |
0
|
} else if ("org.resultColumn.orgShortName".equals(resultCell.getKey())) { |
151 |
0
|
resolvedOrgShortName = resultCell.getValue(); |
152 |
|
} |
153 |
|
} |
154 |
0
|
if (orgShortNameKey != null) { |
155 |
0
|
attributeSet.put(orgShortNameKey, resolvedOrgShortName); |
156 |
|
} |
157 |
0
|
if (orgIdKey != null) { |
158 |
0
|
attributeSet.put(orgIdKey, resolvedOrgId); |
159 |
|
} |
160 |
0
|
attributeSet.put(KualiStudentKimAttributes.QUALIFICATION_ORG, resolvedOrgShortName); |
161 |
0
|
attributeSet.put(KualiStudentKimAttributes.QUALIFICATION_ORG_ID, resolvedOrgId); |
162 |
0
|
returnAttrSetList.add(attributeSet); |
163 |
|
} |
164 |
|
} |
165 |
0
|
return returnAttrSetList; |
166 |
|
} |
167 |
|
|
168 |
|
} |