| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package org.kuali.student.lum.workflow.qualifierresolver; |
| 5 | |
|
| 6 | |
import java.io.StringReader; |
| 7 | |
import java.util.ArrayList; |
| 8 | |
import java.util.LinkedHashMap; |
| 9 | |
import java.util.List; |
| 10 | |
import java.util.Map; |
| 11 | |
|
| 12 | |
import javax.xml.parsers.DocumentBuilder; |
| 13 | |
import javax.xml.parsers.DocumentBuilderFactory; |
| 14 | |
import javax.xml.xpath.XPath; |
| 15 | |
import javax.xml.xpath.XPathConstants; |
| 16 | |
|
| 17 | |
import org.kuali.rice.kew.engine.RouteContext; |
| 18 | |
import org.kuali.rice.kew.rule.xmlrouting.XPathHelper; |
| 19 | |
import org.kuali.rice.student.bo.KualiStudentKimAttributes; |
| 20 | |
import org.kuali.student.core.organization.dto.OrgInfo; |
| 21 | |
import org.w3c.dom.DOMException; |
| 22 | |
import org.w3c.dom.Document; |
| 23 | |
import org.w3c.dom.Node; |
| 24 | |
import org.w3c.dom.NodeList; |
| 25 | |
import org.xml.sax.InputSource; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | 0 | public class StaticOrganizationQualifierResolver extends AbstractOrganizationServiceQualifierResolver { |
| 47 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(StaticOrganizationQualifierResolver.class); |
| 48 | |
|
| 49 | |
protected static final String ROUTE_NODE_ORGANIZATION_ID_XML_TAG_NAME = "organizationId"; |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
@Override |
| 55 | |
public List<Map<String,String>> resolve(RouteContext context) { |
| 56 | 0 | List<Map<String,String>> attributeSets = new ArrayList<Map<String,String>>(); |
| 57 | 0 | XPath xPath = XPathHelper.newXPath(); |
| 58 | |
NodeList organizationElements; |
| 59 | |
try { |
| 60 | 0 | DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
| 61 | 0 | Document document = db.parse(new InputSource(new StringReader(context.getNodeInstance().getRouteNode().getContentFragment()))); |
| 62 | 0 | organizationElements = (NodeList) xPath.evaluate("//" + getOrganizationIdXmlTagName(), document, XPathConstants.NODESET); |
| 63 | 0 | } catch (Exception e) { |
| 64 | 0 | LOG.error(e); |
| 65 | 0 | throw new RuntimeException("Encountered an issue fetching organization ids using xml tag name '" + getOrganizationIdXmlTagName() + "'.", e); |
| 66 | 0 | } |
| 67 | 0 | if (organizationElements.getLength() == 0) { |
| 68 | 0 | LOG.error("No organizations found in Route Node xml configuration using xml tag name '" + getOrganizationIdXmlTagName() + "'"); |
| 69 | 0 | throw new RuntimeException("No organizations found in Route Node xml configuration using xml tag name '" + getOrganizationIdXmlTagName() + "'"); |
| 70 | |
} |
| 71 | 0 | String orgId = ""; |
| 72 | |
try { |
| 73 | 0 | for (int i = 0; i < organizationElements.getLength(); i++) { |
| 74 | 0 | Node organizationElement = organizationElements.item(i); |
| 75 | 0 | orgId = ""; |
| 76 | 0 | orgId = organizationElement.getTextContent(); |
| 77 | 0 | OrgInfo orgInfo = getOrganizationService().getOrganization(orgId); |
| 78 | 0 | Map<String,String> attrSet = new LinkedHashMap<String,String>(); |
| 79 | 0 | attrSet.put(KualiStudentKimAttributes.QUALIFICATION_ORG_ID, orgInfo.getId()); |
| 80 | 0 | attributeSets.add(attrSet); |
| 81 | |
} |
| 82 | 0 | } catch (DOMException e) { |
| 83 | 0 | LOG.error(e); |
| 84 | 0 | throw new RuntimeException("Error getting organization from XML node", e); |
| 85 | 0 | } catch (Exception e) { |
| 86 | 0 | LOG.error(e); |
| 87 | 0 | throw new RuntimeException("Error getting organization with id '" + orgId + "' from OrganizationService", e); |
| 88 | 0 | } |
| 89 | 0 | return attributeSets; |
| 90 | |
} |
| 91 | |
|
| 92 | |
protected String getOrganizationIdXmlTagName() { |
| 93 | 0 | return ROUTE_NODE_ORGANIZATION_ID_XML_TAG_NAME; |
| 94 | |
} |
| 95 | |
} |