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.log4j.Logger; 019import org.jdom.Element; 020import org.kuali.rice.core.api.util.xml.XmlHelper; 021import org.kuali.rice.kew.engine.RouteContext; 022import org.kuali.rice.kew.engine.RouteHelper; 023import org.kuali.rice.kew.exception.WorkflowServiceErrorException; 024import org.kuali.rice.kew.routeheader.DocumentContent; 025import org.kuali.rice.kew.routeheader.StandardDocumentContent; 026import org.kuali.rice.kew.rule.NetworkIdRoleAttribute; 027import org.kuali.rice.kew.service.KEWServiceLocator; 028import org.kuali.rice.kew.api.KewApiConstants; 029import org.kuali.rice.kim.api.identity.Person; 030import org.kuali.rice.kim.api.services.KimApiServiceLocator; 031 032import java.util.ArrayList; 033import java.util.Collection; 034import java.util.Iterator; 035 036 037/** 038 * A node which will generate an FYI request to a network ID specified in the document content. 039 * 040 * @deprecated Use {@link NetworkIdRoleAttribute} instead 041 * 042 * @author Kuali Rice Team (rice.collab@kuali.org) 043 */ 044public class FYIByNetworkId extends RequestActivationNode { 045 private static final Logger LOG = Logger.getLogger(FYIByNetworkId.class); 046 047 public SimpleResult process(RouteContext context, RouteHelper helper) 048 throws Exception { 049 050 LOG.debug("processing FYIByNetworkId simple node"); 051 String documentId = context.getDocument().getDocumentId(); 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 networkId field: " + field.getAttributeValue("name")); 060 if (field.getAttribute("name")!= null && field.getAttributeValue("name").equals("networkId")) { 061 LOG.debug("Should send an FYI to netID: " + field.getChildText("value")); 062 if (field.getChildText("value") != null) { 063 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(field.getChildText("value")); 064 065 //WorkflowDocument wfDoc = new WorkflowDocument(new NetworkIdVO(field.getChildText("value")), documentId); 066 if (!context.isSimulation()) { 067 KEWServiceLocator.getWorkflowDocumentService().adHocRouteDocumentToPrincipal(user.getPrincipalId(), context.getDocument(), KewApiConstants.ACTION_REQUEST_FYI_REQ, null, null, "Notification Request", user.getPrincipalId(), "Notification Request", true, null); 068 } 069 //wfDoc.adHocRouteDocumentToPrincipal(KewApiConstants.ACTION_REQUEST_FYI_REQ, "Notification Request", new NetworkIdVO(field.getChildText("value")), "Notification Request", true); 070 LOG.debug("Sent FYI using the adHocRouteDocumentToPrincipal function to NetworkID: " + user.getPrincipalName()); 071 break; 072 } 073 } 074 } 075 } 076 return super.process(context, helper); 077 } 078 079 080 private static Element getRootElement(DocumentContent docContent) { 081 Element rootElement = null; 082 try { 083 rootElement = XmlHelper.buildJDocument(docContent.getDocument()).getRootElement(); 084 } catch (Exception e) { 085 throw new WorkflowServiceErrorException("Invalid XML submitted", new ArrayList<Object>()); 086 } 087 return rootElement; 088 } 089 090 091 protected Object getService(String serviceName) { 092 return KEWServiceLocator.getService(serviceName); 093 } 094 095 096}