| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.rice.kew.rule; |
| 17 |
|
|
| 18 |
|
import java.io.StringReader; |
| 19 |
|
import java.util.ArrayList; |
| 20 |
|
import java.util.HashMap; |
| 21 |
|
import java.util.List; |
| 22 |
|
import java.util.Map; |
| 23 |
|
|
| 24 |
|
import javax.xml.xpath.XPath; |
| 25 |
|
import javax.xml.xpath.XPathConstants; |
| 26 |
|
import javax.xml.xpath.XPathExpressionException; |
| 27 |
|
|
| 28 |
|
import org.apache.commons.lang.StringUtils; |
| 29 |
|
import org.kuali.rice.kew.engine.RouteContext; |
| 30 |
|
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
| 31 |
|
import org.kuali.rice.kew.identity.Id; |
| 32 |
|
import org.kuali.rice.kew.routeheader.DocumentContent; |
| 33 |
|
import org.kuali.rice.kew.rule.bo.RuleAttribute; |
| 34 |
|
import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute; |
| 35 |
|
import org.kuali.rice.kew.rule.xmlrouting.XPathHelper; |
| 36 |
|
import org.w3c.dom.Element; |
| 37 |
|
import org.w3c.dom.NodeList; |
| 38 |
|
import org.xml.sax.InputSource; |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
@author |
| 46 |
|
|
|
|
|
| 0% |
Uncovered Elements: 82 (82) |
Complexity: 22 |
Complexity Density: 0.43 |
|
| 47 |
|
public abstract class AbstractIdRoleAttribute extends AbstractRoleAttribute |
| 48 |
|
implements GenericXMLRuleAttribute { |
| 49 |
|
|
| 50 |
|
private static final String XML_ELEMENT_LABEL = "xmlElementLabel"; |
| 51 |
|
private static final String ROLE_NAME_LABEL = "roleNameLabel"; |
| 52 |
|
|
| 53 |
|
private String idValue; |
| 54 |
|
private Map paramMap = new HashMap(); |
| 55 |
|
private RuleAttribute ruleAttribute; |
| 56 |
|
|
| 57 |
|
protected abstract String getAttributeElementName(); |
| 58 |
|
|
| 59 |
|
protected abstract Id resolveId(String id); |
| 60 |
|
|
| 61 |
|
protected abstract String getIdName(); |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
@see |
| 68 |
|
|
| 69 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
| 70 |
0
|
public List<String> getQualifiedRoleNames(String roleName,... |
| 71 |
|
DocumentContent documentContent) { |
| 72 |
0
|
try { |
| 73 |
0
|
readConfiguration(); |
| 74 |
0
|
String elementName = (String) getParamMap().get(XML_ELEMENT_LABEL); |
| 75 |
0
|
List<String> qualifiedRoleNames = new ArrayList<String>(); |
| 76 |
0
|
XPath xPath = XPathHelper.newXPath(); |
| 77 |
0
|
NodeList idNodes = (NodeList) xPath.evaluate("//" |
| 78 |
|
+ getAttributeElementName() + "/" + elementName, |
| 79 |
|
documentContent.getDocument(), XPathConstants.NODESET); |
| 80 |
0
|
for (int index = 0; index < idNodes.getLength(); index++) { |
| 81 |
0
|
Element idElement = (Element) idNodes.item(index); |
| 82 |
0
|
String id = idElement.getTextContent(); |
| 83 |
0
|
qualifiedRoleNames.add(id); |
| 84 |
|
} |
| 85 |
0
|
return qualifiedRoleNames; |
| 86 |
|
} catch (XPathExpressionException e) { |
| 87 |
0
|
throw new WorkflowRuntimeException( |
| 88 |
|
"Failed to evaulate XPath expression to find ids.", e); |
| 89 |
|
} |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
@see |
| 97 |
|
|
| 98 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 99 |
0
|
public ResolvedQualifiedRole resolveQualifiedRole(... |
| 100 |
|
RouteContext routeContext, String roleName, String qualifiedRole) { |
| 101 |
0
|
String roleNameLabel = (String) getParamMap().get(ROLE_NAME_LABEL); |
| 102 |
0
|
if (roleNameLabel == null) { |
| 103 |
0
|
readConfiguration(); |
| 104 |
0
|
roleNameLabel = (String) getParamMap().get(ROLE_NAME_LABEL); |
| 105 |
|
} |
| 106 |
0
|
ResolvedQualifiedRole resolvedRole = new ResolvedQualifiedRole(); |
| 107 |
0
|
resolvedRole.setQualifiedRoleLabel(roleNameLabel); |
| 108 |
0
|
resolvedRole.getRecipients().add(resolveId(qualifiedRole)); |
| 109 |
0
|
return resolvedRole; |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
@see |
| 116 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 117 |
0
|
@Override... |
| 118 |
|
public String getDocContent() { |
| 119 |
0
|
readConfiguration(); |
| 120 |
0
|
if (!StringUtils.isBlank(getIdValue())) { |
| 121 |
0
|
String elementName = (String) getParamMap().get(XML_ELEMENT_LABEL); |
| 122 |
0
|
return "<" + getAttributeElementName() + "><" + elementName + ">" |
| 123 |
|
+ getIdValue() + "</" + elementName + "></" |
| 124 |
|
+ getAttributeElementName() + ">"; |
| 125 |
|
} |
| 126 |
0
|
return ""; |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
|
|
|
| 0% |
Uncovered Elements: 37 (37) |
Complexity: 10 |
Complexity Density: 0.48 |
|
| 134 |
0
|
protected void readConfiguration() {... |
| 135 |
0
|
String idInMap = (String) getParamMap().get(getIdName()); |
| 136 |
0
|
if (getIdValue() == null) { |
| 137 |
0
|
setIdValue(idInMap); |
| 138 |
|
} |
| 139 |
0
|
if (getIdValue() != null) { |
| 140 |
0
|
getParamMap().put(getIdName(), getIdValue()); |
| 141 |
|
} |
| 142 |
0
|
if (ruleAttribute != null) { |
| 143 |
0
|
String xmlConfigData = ruleAttribute.getXmlConfigData(); |
| 144 |
0
|
if (!StringUtils.isBlank(xmlConfigData)) { |
| 145 |
0
|
XPath xPath = XPathHelper.newXPath(); |
| 146 |
0
|
try { |
| 147 |
0
|
String xmlElementLabel = xPath.evaluate("/configuration/" |
| 148 |
|
+ XML_ELEMENT_LABEL, new InputSource( |
| 149 |
|
new StringReader(xmlConfigData))); |
| 150 |
0
|
String roleNameLabel = xPath.evaluate("/configuration/" |
| 151 |
|
+ ROLE_NAME_LABEL, new InputSource( |
| 152 |
|
new StringReader(xmlConfigData))); |
| 153 |
0
|
if (!StringUtils.isBlank(xmlElementLabel)) { |
| 154 |
0
|
getParamMap().put(XML_ELEMENT_LABEL, xmlElementLabel); |
| 155 |
|
} |
| 156 |
0
|
if (!StringUtils.isBlank(roleNameLabel)) { |
| 157 |
0
|
getParamMap().put(ROLE_NAME_LABEL, roleNameLabel); |
| 158 |
|
} |
| 159 |
|
|
| 160 |
|
} catch (XPathExpressionException e) { |
| 161 |
0
|
throw new WorkflowRuntimeException( |
| 162 |
|
"Failed to locate Rule Attribute configuration."); |
| 163 |
|
} |
| 164 |
|
} |
| 165 |
|
} |
| 166 |
|
|
| 167 |
0
|
if (StringUtils.isBlank((String) getParamMap().get(XML_ELEMENT_LABEL))) { |
| 168 |
0
|
getParamMap().put(XML_ELEMENT_LABEL, getIdName()); |
| 169 |
|
} |
| 170 |
0
|
if (getParamMap().get(ROLE_NAME_LABEL) == null) { |
| 171 |
0
|
getParamMap().put(ROLE_NAME_LABEL, ""); |
| 172 |
|
} |
| 173 |
|
} |
| 174 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 175 |
0
|
public String getIdValue() {... |
| 176 |
0
|
return this.idValue; |
| 177 |
|
} |
| 178 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 179 |
0
|
public void setIdValue(String idValue) {... |
| 180 |
0
|
this.idValue = idValue; |
| 181 |
|
} |
| 182 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 183 |
0
|
public Map getParamMap() {... |
| 184 |
0
|
return paramMap; |
| 185 |
|
} |
| 186 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 187 |
0
|
public void setParamMap(Map paramMap) {... |
| 188 |
0
|
this.paramMap = paramMap; |
| 189 |
|
} |
| 190 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 191 |
0
|
public void setRuleAttribute(RuleAttribute ruleAttribute) {... |
| 192 |
0
|
this.ruleAttribute = ruleAttribute; |
| 193 |
|
} |
| 194 |
|
|
| 195 |
|
} |