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.EmplIdVO;
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 university ID specified in the document content.
39: *
40: * @author jitrue
41: */
42: public class FYIByUniversityId extends RequestActivationNode {
43: private static final Logger LOG = Logger
44: .getLogger(FYIByUniversityId.class);
45:
46: public SimpleResult process(RouteContext context, RouteHelper helper)
47: throws Exception {
48:
49: LOG
50: .debug("processing FYIByUniversityId requestActivation node");
51: Long routeHeaderId = context.getDocument().getRouteHeaderId();
52: Element rootElement = getRootElement(new StandardDocumentContent(
53: context.getDocument().getDocContent()));
54: List fieldElements = XmlHelper.findElements(rootElement,
55: "field");
56: ListIterator elementIter = fieldElements.listIterator();
57: while (elementIter.hasNext()) {
58: Element field = (Element) elementIter.next();
59: Element version = field.getParentElement();
60: if (version.getAttribute("current").getValue().equals(
61: "true")) {
62: if (field.getAttribute("name") != null
63: && field.getAttributeValue("name").equals(
64: "universityId")) {
65: if (field.getChildText("value") != null) {
66: WorkflowDocument wfDoc = new WorkflowDocument(
67: new EmplIdVO(field
68: .getChildText("value")),
69: routeHeaderId);
70: wfDoc.appSpecificRouteDocumentToUser(
71: EdenConstants.ACTION_REQUEST_FYI_REQ,
72: "Notification Request.", new EmplIdVO(
73: field.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: }
|