01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.engine.node;
18:
19: import java.util.ArrayList;
20: import java.util.List;
21: import java.util.ListIterator;
22:
23: import org.apache.log4j.Logger;
24: import org.jdom.Element;
25:
26: import edu.iu.uis.eden.EdenConstants;
27: import edu.iu.uis.eden.KEWServiceLocator;
28: import edu.iu.uis.eden.WorkflowServiceErrorException;
29: import edu.iu.uis.eden.clientapp.WorkflowDocument;
30: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
31: import edu.iu.uis.eden.engine.RouteContext;
32: import edu.iu.uis.eden.engine.RouteHelper;
33: import edu.iu.uis.eden.routeheader.DocumentContent;
34: import edu.iu.uis.eden.routeheader.StandardDocumentContent;
35: import edu.iu.uis.eden.util.XmlHelper;
36:
37: /**
38: * A node which will generate an FYI request to a network ID specified in the document content.
39: *
40: * @author jitrue
41: */
42: public class FYIByNetworkId extends RequestActivationNode {
43: private static final Logger LOG = Logger
44: .getLogger(FYIByNetworkId.class);
45:
46: public SimpleResult process(RouteContext context, RouteHelper helper)
47: throws Exception {
48:
49: LOG.debug("processing FYIByNetworkId simple node");
50: Long routeHeaderId = context.getDocument().getRouteHeaderId();
51: Element rootElement = getRootElement(new StandardDocumentContent(
52: context.getDocument().getDocContent()));
53: List fieldElements = XmlHelper.findElements(rootElement,
54: "field");
55: ListIterator elementIter = fieldElements.listIterator();
56: while (elementIter.hasNext()) {
57: Element field = (Element) elementIter.next();
58: Element version = field.getParentElement();
59: if (version.getAttribute("current").getValue().equals(
60: "true")) {
61: if (field.getAttribute("name") != null
62: && field.getAttributeValue("name").equals(
63: "networkId")) {
64: if (field.getChildText("value") != null) {
65: WorkflowDocument wfDoc = new WorkflowDocument(
66: new NetworkIdVO(field
67: .getChildText("value")),
68: routeHeaderId);
69: wfDoc.appSpecificRouteDocumentToUser(
70: EdenConstants.ACTION_REQUEST_FYI_REQ,
71: "Notification Request.",
72: new NetworkIdVO(field
73: .getChildText("value")),
74: "Notification Request.", true);
75: }
76: }
77: }
78: }
79: return super .process(context, helper);
80: }
81:
82: private static Element getRootElement(DocumentContent docContent) {
83: Element rootElement = null;
84: try {
85: rootElement = XmlHelper.buildJDocument(
86: docContent.getDocument()).getRootElement();
87: } catch (Exception e) {
88: throw new WorkflowServiceErrorException(
89: "Invalid XML submitted", new ArrayList<Object>());
90: }
91: return rootElement;
92: }
93:
94: protected Object getService(String serviceName) {
95: return KEWServiceLocator.getService(serviceName);
96: }
97:
98: }
|