1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.engine.node;
17
18 import org.apache.log4j.Logger;
19 import org.jdom.Element;
20 import org.kuali.rice.core.api.util.xml.XmlHelper;
21 import org.kuali.rice.kew.engine.RouteContext;
22 import org.kuali.rice.kew.engine.RouteHelper;
23 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
24 import org.kuali.rice.kew.routeheader.DocumentContent;
25 import org.kuali.rice.kew.routeheader.StandardDocumentContent;
26 import org.kuali.rice.kew.rule.NetworkIdRoleAttribute;
27 import org.kuali.rice.kew.service.KEWServiceLocator;
28 import org.kuali.rice.kew.api.KewApiConstants;
29 import org.kuali.rice.kim.api.identity.Person;
30 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
31
32 import java.util.ArrayList;
33 import java.util.Collection;
34 import java.util.Iterator;
35
36
37
38
39
40
41
42
43
44 public class FYIByNetworkId extends RequestActivationNode {
45 private static final Logger LOG = Logger.getLogger(FYIByNetworkId.class);
46
47 public SimpleResult process(RouteContext context, RouteHelper helper)
48 throws Exception {
49
50 LOG.debug("processing FYIByNetworkId simple node");
51 String documentId = context.getDocument().getDocumentId();
52 Element rootElement = getRootElement(new StandardDocumentContent(context.getDocument().getDocContent()));
53 Collection<Element> fieldElements = XmlHelper.findElements(rootElement, "field");
54 Iterator<Element> elementIter = fieldElements.iterator();
55 while (elementIter.hasNext()) {
56 Element field = (Element) elementIter.next();
57 Element version = field.getParentElement();
58 if (version.getAttribute("current").getValue().equals("true")) {
59 LOG.debug("Looking for networkId field: " + field.getAttributeValue("name"));
60 if (field.getAttribute("name")!= null && field.getAttributeValue("name").equals("networkId")) {
61 LOG.debug("Should send an FYI to netID: " + field.getChildText("value"));
62 if (field.getChildText("value") != null) {
63 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(field.getChildText("value"));
64
65
66 if (!context.isSimulation()) {
67 KEWServiceLocator.getWorkflowDocumentService().adHocRouteDocumentToPrincipal(user.getPrincipalId(), context.getDocument(), KewApiConstants.ACTION_REQUEST_FYI_REQ, null, null, "Notification Request", user.getPrincipalId(), "Notification Request", true, null);
68 }
69
70 LOG.debug("Sent FYI using the adHocRouteDocumentToPrincipal function to NetworkID: " + user.getPrincipalName());
71 break;
72 }
73 }
74 }
75 }
76 return super.process(context, helper);
77 }
78
79
80 private static Element getRootElement(DocumentContent docContent) {
81 Element rootElement = null;
82 try {
83 rootElement = XmlHelper.buildJDocument(docContent.getDocument()).getRootElement();
84 } catch (Exception e) {
85 throw new WorkflowServiceErrorException("Invalid XML submitted", new ArrayList<Object>());
86 }
87 return rootElement;
88 }
89
90
91 protected Object getService(String serviceName) {
92 return KEWServiceLocator.getService(serviceName);
93 }
94
95
96 }