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