001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kew.engine.node; 017 018import org.apache.commons.lang.StringUtils; 019import org.apache.log4j.Logger; 020import org.jdom.Element; 021import org.kuali.rice.core.api.util.xml.XmlHelper; 022import org.kuali.rice.kew.api.WorkflowRuntimeException; 023import org.kuali.rice.kew.engine.RouteContext; 024import org.kuali.rice.kew.engine.RouteHelper; 025import org.kuali.rice.kew.exception.WorkflowServiceErrorException; 026import org.kuali.rice.kew.routeheader.DocumentContent; 027import org.kuali.rice.kew.routeheader.StandardDocumentContent; 028import org.kuali.rice.kew.service.KEWServiceLocator; 029import org.kuali.rice.kew.api.KewApiConstants; 030import org.kuali.rice.kim.api.identity.Person; 031import org.kuali.rice.kim.api.services.KimApiServiceLocator; 032 033import java.util.ArrayList; 034import java.util.Collection; 035import java.util.Iterator; 036 037 038/** 039 * A node which will generate an FYI request to a university ID specified in the document content. 040 * 041 * @deprecated Use {@link org.kuali.rice.kew.rule.UniversityIdRoleAttribute} instead 042 * 043 * @author Kuali Rice Team (rice.collab@kuali.org) 044 */ 045public class FYIByUniversityId extends RequestActivationNode { 046 private static final Logger LOG = Logger.getLogger(FYIByUniversityId.class); 047 048 public SimpleResult process(RouteContext context, RouteHelper helper) 049 throws Exception { 050 051 LOG.debug("processing FYIByUniversityId node"); 052 Element rootElement = getRootElement(new StandardDocumentContent(context.getDocument().getDocContent())); 053 Collection<Element> fieldElements = XmlHelper.findElements(rootElement, "field"); 054 Iterator<Element> elementIter = fieldElements.iterator(); 055 while (elementIter.hasNext()) { 056 Element field = (Element) elementIter.next(); 057 Element version = field.getParentElement(); 058 if (version.getAttribute("current").getValue().equals("true")) { 059 LOG.debug("Looking for studentUid field: " + field.getAttributeValue("name")); 060 if (field.getAttribute("name")!= null && field.getAttributeValue("name").equals("studentUid")) { 061 String employeeId = field.getChildText("value"); 062 LOG.debug("Should send an FYI to employee ID: " + employeeId); 063 if (!StringUtils.isBlank(employeeId)) { 064 Person person = KimApiServiceLocator.getPersonService().getPerson(employeeId); 065 066 if (person == null) { 067 throw new WorkflowRuntimeException("Failed to locate a Person with the given employee ID: " + employeeId); 068 } 069 if (!context.isSimulation()) { 070 KEWServiceLocator.getWorkflowDocumentService().adHocRouteDocumentToPrincipal(person.getPrincipalId(), context.getDocument(), KewApiConstants.ACTION_REQUEST_FYI_REQ, null, null, "Notification Request", person.getPrincipalId(), "Notification Request", true, null); 071 } 072 //wfDoc.adHocRouteDocumentToPrincipal(KewApiConstants.ACTION_REQUEST_FYI_REQ, "Notification Request", new EmplIdVO(field.getChildText("value")), "Notification Request", true); 073 LOG.debug("Sent FYI using the adHocRouteDocumentToPrincipal function to UniversityID: " + person.getEmployeeId()); 074 break; 075 } 076 } 077 } 078 } 079 return super.process(context, helper); 080 } 081 082 083 private static Element getRootElement(DocumentContent docContent) { 084 Element rootElement = null; 085 try { 086 rootElement = XmlHelper.buildJDocument(docContent.getDocument()).getRootElement(); 087 } catch (Exception e) { 088 throw new WorkflowServiceErrorException("Invalid XML submitted", new ArrayList<Object>()); 089 } 090 return rootElement; 091 } 092 093 094 protected Object getService(String serviceName) { 095 return KEWServiceLocator.getService(serviceName); 096 } 097 098 099} 100 101