incubator-agila-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r232578 - in /incubator/agila/trunk/modules/bpm: ./ src/java/org/apache/agila/util/ src/test-resources/ src/test-resources/node/ src/test/org/apache/agila/util/
Date Sun, 14 Aug 2005 04:49:28 GMT
Author: clim
Date: Sat Aug 13 21:49:04 2005
New Revision: 232578

URL: http://svn.apache.org/viewcvs?rev=232578&view=rev
Log:
Added groovy functionality. Patch submitted by David Black (August 13, 2005).

Added:
    incubator/agila/trunk/modules/bpm/src/test-resources/GroovyNodeWorkflow.xml
    incubator/agila/trunk/modules/bpm/src/test-resources/node/
    incubator/agila/trunk/modules/bpm/src/test-resources/node/ExampleGroovyTask.groovy
    incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/util/DummyNodeContextImpl.java
Modified:
    incubator/agila/trunk/modules/bpm/project.xml
    incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/util/XMLUtil.java
    incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/util/XMLUtilTestCase.java

Modified: incubator/agila/trunk/modules/bpm/project.xml
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/project.xml?rev=232578&r1=232577&r2=232578&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpm/project.xml (original)
+++ incubator/agila/trunk/modules/bpm/project.xml Sat Aug 13 21:49:04 2005
@@ -62,6 +62,15 @@
       </dependency>
 
       <dependency>
+          <groupId>commons-beanutils</groupId>
+          <artifactId>commons-beanutils</artifactId>
+          <version>1.7.0</version>
+          <properties>
+              <war.bundle>true</war.bundle>
+          </properties>
+      </dependency>
+
+      <dependency>
           <groupId>concurrent</groupId>
           <artifactId>concurrent</artifactId>
           <version>1.3.4</version>
@@ -144,6 +153,15 @@
            <version>1.8.0.1</version>
        </dependency>
 
+       <!-- Groovy Dependencies -->
+       <dependency>
+           <groupId>groovy</groupId>
+           <artifactId>groovy-all</artifactId>
+           <version>1.0-jsr-02</version>
+            <properties>
+                <war.bundle>true</war.bundle>
+            </properties>
+       </dependency>
   </dependencies>
 
   <build>
@@ -187,6 +205,7 @@
                     <includes>
                         <include>**/*.properties</include>
                         <include>**/*.xml</include>
+                        <include>**/*.groovy</include>
                     </includes>
                 </resource>
             </resources>

Modified: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/util/XMLUtil.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/util/XMLUtil.java?rev=232578&r1=232577&r2=232578&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/util/XMLUtil.java (original)
+++ incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/util/XMLUtil.java Sat Aug
13 21:49:04 2005
@@ -27,18 +27,20 @@
 
 import org.apache.agila.impl.BusinessProcessImpl;
 import org.apache.commons.beanutils.BeanUtils;
+import org.codehaus.groovy.control.CompilationFailedException;
 import org.dom4j.io.SAXReader;
 import org.dom4j.Document;
 import org.dom4j.DocumentException;
 import org.dom4j.Element;
 import org.dom4j.Attribute;
 
+import groovy.lang.GroovyClassLoader;
+
 import java.io.File;
 import java.io.FileReader;
 import java.io.Reader;
 import java.util.List;
 import java.util.Iterator;
-import java.lang.reflect.InvocationTargetException;
 
 /**
  *  Utility class for converting workflow XML to objects
@@ -117,8 +119,10 @@
             e.printStackTrace();
         } catch (InstantiationException e) {
             e.printStackTrace();
+        } catch (CompilationFailedException e) {
+            e.printStackTrace();
         }
-
+        
         return graph;
     }
 
@@ -159,16 +163,28 @@
     }
 
     protected static void digestNode(BusinessProcessImpl graph, Element node)
-            throws ClassNotFoundException, IllegalAccessException, InstantiationException
{
+            throws ClassNotFoundException, IllegalAccessException, InstantiationException,
CompilationFailedException {
 
         /*
          * get the class, id and type
          */
         String classname = node.attribute("class").getValue();
-
-
-        // TODO may wish to also use the Thread context class loader
-        Node n = (Node) Class.forName(classname).newInstance();
+        Node n = null;
+        
+        // Check if its a groovy script, if it is then assume for 
+        // now we can find it on the classpath, and load/compile it 
+        // TODO enable loading from elsewhere e.g. a database table
+        if (classname.startsWith("groovy:")) {
+            String groovyScript = classname.substring("groovy:".length());
+            ClassLoader parent = XMLUtil.class.getClassLoader();
+            GroovyClassLoader loader = new GroovyClassLoader(parent);
+            Class groovyClass = loader.parseClass(parent.getResourceAsStream(groovyScript));
+            n = (Node) groovyClass.newInstance();
+        }
+        else {
+            // TODO may wish to also use the Thread context class loader
+            n = (Node) Class.forName(classname).newInstance();
+        }
 
         n.setNodeId(new NodeID(Integer.parseInt(node.attribute("id").getValue())));
 
@@ -275,4 +291,4 @@
 
         XMLUtil.deserializeXML(reader);
     }
-}
\ No newline at end of file
+}

Added: incubator/agila/trunk/modules/bpm/src/test-resources/GroovyNodeWorkflow.xml
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/test-resources/GroovyNodeWorkflow.xml?rev=232578&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/test-resources/GroovyNodeWorkflow.xml (added)
+++ incubator/agila/trunk/modules/bpm/src/test-resources/GroovyNodeWorkflow.xml Sat Aug 13
21:49:04 2005
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+* Copyright 2004 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License")
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+
+-->
+
+<process-model name="Groovy Task Node Workflow">
+    <graph>
+        <nodes>
+            <node id="1" type="start" class="org.apache.agila.model.node.StartNode" display_name="Start">
+                <actors/>
+                <bindings/>
+            </node>
+
+            <node id="3" type="activity" class="groovy:node/ExampleGroovyTask.groovy"
display_name="Example Groovy Task">
+                <actors>
+                    <actor name="Self"/>
+                </actors>
+            </node>
+
+            <node id="2" type="stop" class="org.apache.agila.model.node.StopNode" display_name="Stop">
+                <actors/>
+                <bindings/>
+            </node>
+        </nodes>
+        <connections>
+            <connection startid="1" endid="3" display_name="Example Groovy Task"/>
+            <connection startid="3" endid="2" display_name="End"/>
+        </connections>
+        <guiinfo>
+            <gui id="2">
+                <location x="540" y="60" w="31" h="40"/>
+            </gui>
+            <gui id="1">
+                <location x="180" y="70" w="31" h="40"/>
+            </gui>
+            <gui id="3">
+                <location x="193" y="255" w="100" h="100"/>
+            </gui>
+        </guiinfo>
+    </graph>
+</process-model>

Added: incubator/agila/trunk/modules/bpm/src/test-resources/node/ExampleGroovyTask.groovy
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/test-resources/node/ExampleGroovyTask.groovy?rev=232578&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/test-resources/node/ExampleGroovyTask.groovy (added)
+++ incubator/agila/trunk/modules/bpm/src/test-resources/node/ExampleGroovyTask.groovy Sat
Aug 13 21:49:04 2005
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package node;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Date;
+
+import groovy.xml.MarkupBuilder;
+import org.apache.agila.model.Connection;
+import org.apache.agila.model.NodeContext;
+import org.apache.agila.model.node.BaseNodeImpl;
+import org.apache.agila.services.task.HTTPRenderer;
+import org.apache.agila.services.task.HTTPResponseHandler;
+import org.apache.agila.services.task.Renderer;
+import org.apache.agila.services.task.ResponseHandler;
+import org.apache.agila.services.task.ResponseHandlerResponse;
+import org.apache.agila.services.task.TaskActivity;
+import org.apache.agila.services.task.TaskService;
+import org.apache.agila.services.user.UserID;
+
+class ExampleGroovyTask extends BaseNodeImpl implements TaskActivity, HTTPResponseHandler,
HTTPRenderer {
+
+    NodeContext nodeContext;
+    String taskId;
+    String tokenId;
+
+    public boolean doStart( NodeContext ctx ) {
+        TaskService ts = ctx.getTaskService();
+        ts.assignTask( ctx.getNextExecutionToken().getTokenID(), "A task for you", new UserID(
1 ), new Date() );
+        return false;
+    }
+
+    public Connection[] doEnd( NodeContext ctx ) {
+        return getOutboundConnections();
+    }
+
+    public Renderer getRenderer( NodeContext ctx, Class type ) {
+        this.nodeContext = ctx;
+        return this;
+    }
+
+    public ResponseHandler getResponseHandler( NodeContext ctx, Class type ) {
+        this.nodeContext = ctx;
+        return this;
+    }
+
+    public String render( HttpServletRequest request, HttpServletResponse response ) {
+        if ( null != request ) {
+            taskId = request.getParameter( "taskid" );
+        } else {
+            // For test code
+            taskId = "1";
+        }
+
+        StringWriter writer = new StringWriter();
+        MarkupBuilder builder = new MarkupBuilder( writer );
+        Map instanceData = getInstanceData( nodeContext );
+
+        createForm( builder, instanceData, request, response );
+
+        return writer.toString();
+    }
+
+    public ResponseHandlerResponse processAction( HttpServletRequest request, HttpServletResponse
response ) {
+    }
+
+    protected Map getInstanceData( NodeContext ctx ) {
+        return ctx.getInstanceData();
+    }
+
+    protected createForm( MarkupBuilder builder, Map instanceData, HttpServletRequest request,
HttpServletResponse response ) {
+        builder.html()
+        {
+            head()
+            {
+                title( "Workflow task" )
+                {
+                }
+            }
+            body()
+            {
+                form( action:getSubmitURL( request ), method:"post") {
+
+                input( type:"hidden", name:"action", value:"submit_task_info")
+                input( type:"hidden", name:"taskid", value:getTaskId())
+
+                p( "This is a groovy task!" )
+
+                input( name:"submit", type:"submit", value:"Submit")
+            }
+            }
+        }
+    }
+
+    protected String getTaskId() {
+        return taskId;
+    }
+
+    protected String getTokenId() {
+        return tokenId;
+    }
+
+    protected String getSubmitURL( HttpServletRequest request ) {
+        return "myservlet\\dotask";
+    }
+}

Added: incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/util/DummyNodeContextImpl.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/util/DummyNodeContextImpl.java?rev=232578&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/util/DummyNodeContextImpl.java
(added)
+++ incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/util/DummyNodeContextImpl.java
Sat Aug 13 21:49:04 2005
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.agila.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.agila.engine.Token;
+import org.apache.agila.model.NodeContext;
+import org.apache.agila.services.TimerService;
+import org.apache.agila.services.notification.NotificationService;
+import org.apache.agila.services.task.TaskService;
+
+
+/**
+ * DummyNodeContextImpl is a NodeContext for test code, all it does
+ * right now is return an empty instance data map.
+ *
+ * @author <a href="mailto:dblack@codecurl.org">David Black</a>
+ * @version $Id$
+ */
+public class DummyNodeContextImpl implements NodeContext {
+
+    public DummyNodeContextImpl() {
+        super();
+    }
+
+    public Object getBoundValue( String name ) {
+        return null;
+    }
+
+    public void setBoundValue( String name, Object value ) {
+    }
+
+    public Map getInstanceData() {
+        return new HashMap();
+    }
+
+    public Token getCurrentExecutionToken() {
+        return null;
+    }
+
+    public Token getNextExecutionToken() {
+        return null;
+    }
+
+    public TimerService getTimerService() {
+        return null;
+    }
+
+    public TaskService getTaskService() {
+        return null;
+    }
+
+    public NotificationService getNotificationService() {
+        return null;
+    }
+
+    public Map getAppData() {
+        return null;
+    }
+}

Modified: incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/util/XMLUtilTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/util/XMLUtilTestCase.java?rev=232578&r1=232577&r2=232578&view=diff
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/util/XMLUtilTestCase.java
(original)
+++ incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/util/XMLUtilTestCase.java
Sat Aug 13 21:49:04 2005
@@ -16,33 +16,37 @@
 
 package org.apache.agila.util;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
 import junit.framework.TestCase;
 
+import org.apache.agila.example.LeaveApplicationTask;
 import org.apache.agila.model.BusinessProcess;
-import org.apache.agila.model.Variable;
-import org.apache.agila.model.NodeID;
 import org.apache.agila.model.Node;
-import org.apache.agila.example.LeaveApplicationTask;
-
+import org.apache.agila.model.NodeContext;
+import org.apache.agila.model.NodeID;
+import org.apache.agila.model.Variable;
+import org.apache.agila.services.task.HTTPRenderer;
+import org.apache.agila.services.task.Renderer;
+import org.apache.agila.services.task.TaskActivity;
 import org.dom4j.Document;
 import org.dom4j.DocumentException;
 import org.dom4j.io.SAXReader;
 
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.Reader;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 public class XMLUtilTestCase extends TestCase {
 
     // NOTE: If additional features are added to the xml, this file should also be updated
     // and more test cases should be added for those features
     private String workflowXML = "LeaveApplication.xml";
+    private String groovyNodeWorkflowXML = "GroovyNodeWorkflow.xml";
 
     private BusinessProcess businessProcess;
+    private BusinessProcess businessProcessWithGroovyNode;
 
     public void testName_NotNull() {
         assertNotNull( businessProcess.getName() );
@@ -84,6 +88,24 @@
         assertEquals("bar property", 123, task.getBar());
     }
 
+    public void testGroovyNode() throws IOException {
+        Node node = businessProcessWithGroovyNode.getNode(new NodeID(3));
+        assertTrue("Not the groovy node node.ExampleGroovyTask", node.getClass().getName().equals("node.ExampleGroovyTask"));
+        assertTrue("Node not a TaskActivity", node instanceof TaskActivity);
+
+        TaskActivity task = (TaskActivity)node;
+        NodeContext ctx = new DummyNodeContextImpl();
+        Renderer renderer = task.getRenderer(ctx, null);
+        assertTrue("Renderer is not a HTTPRenderer, badness", renderer instanceof HTTPRenderer);
+        HTTPRenderer httpRenderer = (HTTPRenderer) renderer;
+        String html = httpRenderer.render(null, null);
+
+        // Some simple checks for the known content
+        assertTrue("html element not present in task html", html.indexOf("html") != -1);
+        assertTrue("body element not present in task html", html.indexOf("body") != -1);
+        assertTrue("submit button not present in task html", html.indexOf("submit") != -1);
+    }
+
     private int getRequiredVariables() {
         int retVal = 0;
 
@@ -121,8 +143,13 @@
         return( new BufferedReader( new InputStreamReader( getClass().getClassLoader().getResourceAsStream(
workflowXML ) ) ) );
     }
 
+    private BufferedReader getGroovyNodeWorkflow() {
+        return( new BufferedReader( new InputStreamReader( getClass().getClassLoader().getResourceAsStream(
groovyNodeWorkflowXML ) ) ) );
+    }
+
     public void setUp() throws Exception {
         businessProcess = XMLUtil.deserializeXML( getWorkflow() );
+        businessProcessWithGroovyNode = XMLUtil.deserializeXML( getGroovyNodeWorkflow() );
     }
 
     public void tearDown() throws Exception {



Mime
View raw message