View Javadoc

1   /*
2    * Copyright 2005-2009 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.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 org.kuali.rice.kew.engine.node;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  import java.util.ListIterator;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.apache.log4j.Logger;
25  import org.jdom.Element;
26  import org.kuali.rice.kew.engine.RouteContext;
27  import org.kuali.rice.kew.engine.RouteHelper;
28  import org.kuali.rice.kew.exception.WorkflowRuntimeException;
29  import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
30  import org.kuali.rice.kew.routeheader.DocumentContent;
31  import org.kuali.rice.kew.routeheader.StandardDocumentContent;
32  import org.kuali.rice.kew.service.KEWServiceLocator;
33  import org.kuali.rice.kew.util.KEWConstants;
34  import org.kuali.rice.kew.util.XmlHelper;
35  import org.kuali.rice.kim.bo.Person;
36  import org.kuali.rice.kim.service.KIMServiceLocator;
37  
38  
39  /**
40   * A node which will generate an FYI request to a university ID specified in the document content.
41   *
42   * @deprecated Use {@link UniversityIdRoleAttribute} instead
43   *
44   * @author Kuali Rice Team (rice.collab@kuali.org)
45   */
46  public class FYIByUniversityId extends RequestActivationNode {
47      private static final Logger LOG = Logger.getLogger(FYIByUniversityId.class);
48  
49  	public SimpleResult process(RouteContext context, RouteHelper helper)
50  			throws Exception {
51  
52          LOG.debug("processing FYIByUniversityId node");
53          Element rootElement = getRootElement(new StandardDocumentContent(context.getDocument().getDocContent()));
54   		List fieldElements = XmlHelper.findElements(rootElement, "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("true")) {
60          		LOG.debug("Looking for studentUid field:  " + field.getAttributeValue("name"));
61                 	if (field.getAttribute("name")!= null && field.getAttributeValue("name").equals("studentUid")) {
62                 		String employeeId = field.getChildText("value");
63              		LOG.debug("Should send an FYI to employee ID:  " + employeeId);
64                 		if (!StringUtils.isBlank(employeeId)) {
65                 			Person person = KIMServiceLocator.getPersonService().getPerson(employeeId);
66  
67                 			if (person == null) {
68                 				throw new WorkflowRuntimeException("Failed to locate a Person with the given employee ID: " + employeeId);
69                 			}
70                 			if (!context.isSimulation()) {
71                 				KEWServiceLocator.getWorkflowDocumentService().adHocRouteDocumentToPrincipal(person.getPrincipalId(), context.getDocument(), KEWConstants.ACTION_REQUEST_FYI_REQ, null, "Notification Request", person.getPrincipalId(), "Notification Request", true, null);
72                 			}
73                 			//wfDoc.adHocRouteDocumentToPrincipal(KEWConstants.ACTION_REQUEST_FYI_REQ, "Notification Request", new EmplIdVO(field.getChildText("value")), "Notification Request", true);
74                  		LOG.debug("Sent FYI using the adHocRouteDocumentToPrincipal function to UniversityID:  " + person.getEmployeeId());
75                  		break;
76                 	}
77          	}
78          }
79          }
80  		return super.process(context, helper);
81  	}
82  
83  
84      private static Element getRootElement(DocumentContent docContent) {
85          Element rootElement = null;
86          try {
87              rootElement = XmlHelper.buildJDocument(docContent.getDocument()).getRootElement();
88          } catch (Exception e) {
89              throw new WorkflowServiceErrorException("Invalid XML submitted", new ArrayList<Object>());
90          }
91          return rootElement;
92      }
93  
94  
95  	protected Object getService(String serviceName) {
96  		return KEWServiceLocator.getService(serviceName);
97  	}
98  
99  
100 }
101 
102