You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mr...@apache.org on 2007/12/20 21:15:26 UTC

svn commit: r606017 - in /ode/sandbox/simpel: src/main/antlr/org/apache/ode/simpel/antlr/ src/test/java/org/apache/ode/simpel/ src/test/resources/ tools/

Author: mriou
Date: Thu Dec 20 12:15:25 2007
New Revision: 606017

URL: http://svn.apache.org/viewvc?rev=606017&view=rev
Log:
Task manager process, the biggest longest I could find. Looks kind of messy but that's a start.

Added:
    ode/sandbox/simpel/src/test/resources/task-manager.simpel
Modified:
    ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPEL.g
    ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g
    ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java
    ode/sandbox/simpel/src/test/resources/compile-tests-ok.simpel
    ode/sandbox/simpel/tools/simpel.vim

Modified: ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPEL.g
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPEL.g?rev=606017&r1=606016&r2=606017&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPEL.g (original)
+++ ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPEL.g Thu Dec 20 12:15:25 2007
@@ -9,7 +9,7 @@
     PROCESS; PICK; SEQUENCE; FLOW; IF; ELSEIF; ELSE; WHILE; UNTIL; FOREACH; FORALL; INVOKE;
     RECEIVE; REPLY; ASSIGN; THROW; WAIT; EXIT; TIMEOUT; TRY; CATCH; CATCH_ALL; SCOPE; EVENT;
     ALARM; COMPENSATION; COMPENSATE; CORRELATION; CORR_MAP; PARTNERLINK; VARIABLE; BLOCK_PARAM; 
-    SIGNAL; JOIN;
+    SIGNAL; JOIN; WITH; MAP;
     EXPR; EXT_EXPR; XML_LITERAL; CALL; NAMESPACE; NS; PATH;
 }
 @parser::header {
@@ -93,7 +93,7 @@
 process	:	'process' ns_id body -> ^(PROCESS ns_id body);
 
 proc_stmt
-	:	pick | flow | if_ex | while_ex | until_ex | foreach | forall | try_ex | scope_ex
+	:	pick | flow | if_ex | while_ex | until_ex | foreach | forall | try_ex | scope_ex | with_ex
 		| receive | ((invoke | reply | assign | throw_ex | wait_ex | exit | signal | join
 		| variables | partner_link) SEMI!);
 
@@ -106,15 +106,10 @@
 pick	:	'pick' '{' receive* timeout* '}' -> ^(PICK receive* timeout*);
 timeout	:	'timeout' '(' expr ')' block -> ^(TIMEOUT expr block); 
 
-// TODO links
 flow	:	'parallel' b+=body ('and' b+=body)* -> ^(FLOW $b);
 signal	:	'signal' '('ID (',' expr)? ')' -> ^(SIGNAL ID expr?);
 join	:	'join' '(' k+=ID (',' k+=ID)* (',' expr)? ')' -> ^(JOIN $k expr?);
 
-//if_ex	:	'if' '(' expr ')' block
-//		('else if' '(' expr ')' block)*
-//		('else' block)? -> ^(IF expr block ^(ELSEIF expr block)* ^(ELSE expr block)?);
-
 if_ex	:	'if' '(' expr ')' ifb=body ('else' eb=body)? -> ^(IF expr $ifb (^(ELSE $eb))?);
 
 while_ex:	'while' '(' expr ')' body -> ^(WHILE expr body);
@@ -136,6 +131,10 @@
 compensation
 	:	'compensation' body -> ^(COMPENSATION body);
 
+with_ex :
+                'with' '(' wm+=with_map (',' wm+=with_map)* ')' body -> ^(WITH $wm* body);
+with_map:       ID ':' path_expr -> ^(MAP ID path_expr);
+
 // Simple activities
 invoke	:	'invoke' '(' p=ID ',' o=ID (',' in=ID)? ')' -> ^(INVOKE $p $o $in?);
 
@@ -150,7 +149,7 @@
 	:	 receive_base -> ^(RECEIVE receive_base)
 		| invoke | expr | xml_literal;
 	
-throw_ex:	'throw' '('ID')' -> ^(THROW ID);
+throw_ex:	'throw' '('? ns_id ')'? -> ^(THROW ns_id);
 
 wait_ex	:	'wait' '('expr')' -> ^(WAIT expr);
 
@@ -183,6 +182,7 @@
 
 funct_call
 	:	p+=ID '(' p+=ID* ')' -> ^(CALL ID+);
+// TODO add && || !
 s_expr	:	condExpr;
 condExpr:	aexpr ( ('==' ^|'!=' ^|'<' ^|'>' ^|'<=' ^|'>=' ^) aexpr )?;
 aexpr	:	mexpr (('+'|'-') ^ mexpr)*;

Modified: ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g?rev=606017&r1=606016&r2=606017&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g (original)
+++ ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g Thu Dec 20 12:15:25 2007
@@ -53,7 +53,7 @@
 process	:	^(PROCESS ^(NS pr=ID? nm=ID) body) { System.out.println("PROCESS " + $nm.text); };
 
 proc_stmt
-	:	pick | flow | if_ex | while_ex | until_ex | foreach | forall | try_ex | scope_ex
+	:	pick | flow | if_ex | while_ex | until_ex | foreach | forall | try_ex | scope_ex | with_ex
 		| invoke | receive | reply | assign | throw_ex | wait_ex | exit | signal | join
 		| variable | partner_link;
 block	:	^(SEQUENCE proc_stmt+);
@@ -94,6 +94,10 @@
 compensation
 	:	^(COMPENSATION body);
 
+
+with_ex :       ^(WITH with_map* body);
+with_map:       ^(MAP ID path_expr);
+
 // Simple activities
 invoke	:	^(INVOKE p=ID o=ID in=ID?);
 
@@ -105,7 +109,7 @@
 rvalue
 	:	receive | invoke | expr | xmlElement;
 	
-throw_ex:	^(THROW ID);
+throw_ex:	^(THROW ns_id);
 
 wait_ex	:	^(WAIT expr);
 
@@ -123,7 +127,8 @@
 
 // XML
 xmlElement
-	:	^(XML_ELEMENT XML_NAME xmlAttribute* xmlElementContent*) { System.out.println("ELMT " + $XML_NAME.text); };
+	:	^(XML_EMPTY_ELEMENT XML_NAME xmlAttribute*) | ^(XML_ELEMENT XML_NAME xmlAttribute* xmlElementContent*) 
+                { System.out.println("ELMT " + $XML_NAME.text); };
 xmlAttribute
 	:	^(XML_ATTRIBUTE XML_NAME XML_ATTRIBUTE_VALUE) { System.out.println("ATTR " + $XML_NAME.text); };
 xmlElementContent

Modified: ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java?rev=606017&r1=606016&r2=606017&view=diff
==============================================================================
--- ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java (original)
+++ ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java Thu Dec 20 12:15:25 2007
@@ -92,6 +92,12 @@
         reportErrors("Auction service", c);
     }
 
+    public void testTaskManager() throws Exception {
+        SimPELCompiler c = compiler();
+        c.compileProcess(readProcess("task-manager.simpel"));
+        reportErrors("Auction service", c);
+    }
+
     private String readProcess(String fileName) throws Exception {
         BufferedReader reader = new BufferedReader(new FileReader(
                 getClass().getClassLoader().getResource(fileName).getFile()));

Modified: ode/sandbox/simpel/src/test/resources/compile-tests-ok.simpel
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/test/resources/compile-tests-ok.simpel?rev=606017&r1=606016&r2=606017&view=diff
==============================================================================
--- ode/sandbox/simpel/src/test/resources/compile-tests-ok.simpel (original)
+++ ode/sandbox/simpel/src/test/resources/compile-tests-ok.simpel Thu Dec 20 12:15:25 2007
@@ -138,6 +138,18 @@
 }
 
 #=============================================================
+# Forced Hello World (if and throw)
+#
+
+process HelloWorld {
+  receive(my_pl, hello_op) { |msg_in|
+    if (msg_in != "Hello ") throw(WrongMsg);
+    msg_out = msg_in + " World";
+    reply(msg_out);
+  }
+}
+
+#=============================================================
 # Try / catch / catch all
 #
 
@@ -164,6 +176,7 @@
 process pns::NamespacesProcess {
   msg_in = receive(my_pl, start_op);
   try {
+    msg_in.payload.mns::foo = msg_in.payload.mns::foo + " bar";
     invoke(other_pl, other_op, msg_in);
   } catch(fns::SomeFault) { |f1|
     invoke(fault_pl, inform_f1, f1);
@@ -325,4 +338,16 @@
 
     reply(msg_in);
   }
-}
\ No newline at end of file
+}
+
+#=============================================================
+# With
+#
+
+process WithTest {
+  foo = receive(my_pl, start_op);
+  with(bz1: foo.bar.baz1, bz2: foo.bar.baz2) {
+    bz1.name = bz2.name;
+    bz1.address = bz2.address;
+  }
+}

Added: ode/sandbox/simpel/src/test/resources/task-manager.simpel
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/test/resources/task-manager.simpel?rev=606017&view=auto
==============================================================================
--- ode/sandbox/simpel/src/test/resources/task-manager.simpel (added)
+++ ode/sandbox/simpel/src/test/resources/task-manager.simpel Thu Dec 20 12:15:25 2007
@@ -0,0 +1,196 @@
+namespace b4p = "http://tempo.intalio.org/workflow/ib4p_20051115";
+namespace tms = "http://tempo.intalio.org/workflow/TaskManagementServices-20051109/";
+
+function taskIdFromB4P(c) {
+  return c.b4p::taskMetaData.b4p::taskId;
+}
+
+process TaskManager {
+  partnerLink userProcessPartnerLink, previousTaskManagerPartnerLink, 
+    TMSPartnerLink, uifwPartnerLink, nextTaskManagerPartnerLink;
+
+  var taskId unique;
+
+  createTaskRequest = receive(userProcessPartnerLink, createTask);
+
+  createTaskResponse.root = <b4p:response><b4p:taskMetaData>
+                              <b4p:taskId/><b4p:processId/>
+                              </b4p:taskMetaData><b4p:status>OK</b4p:status>
+                            </b4p:response>;
+
+  with(tmd: createTaskResponse.root.b4p::taskMetaData) {
+    tmd.b4p::processId = createTaskRequest.root.b4p::taskMetaData.b4p::processId;
+    tmd.b4p::taskId = [concat(b4px:create(), $ode:pid)];
+    taskId = tmd.b4p::taskId;
+  }
+
+  reply(userProcessPartnerLink, createTask, createTaskResponse);
+
+  createRequest.createRequest = <tms:createRequest>
+                                  <tms:task>
+                                    <tms:metadata>
+                                      <tms:taskId/><tms:taskType>activity</tms:taskType><tms:description/>
+                                      <tms:processId/><tms:creationDate/><tms:userOwner/><tms:roleOwner/>
+                                      <tms:claimAction/><tms:revokeAction/><tms:saveAction/>
+                                      <tms:completeAction/><tms:formUrl/><tms:userProcessEndpoint/>
+                                      <tms:userProcessNamespaceURI/><tms:userProcessCompleteSOAPAction/>
+                                    </tms:metadata>
+                                    <tms:input/>
+                                  </tms:task>
+                                  <tms:participantToken/>
+                                </tms:createRequest>;
+
+  with(trmd: createTaskResponse.root.b4p::taskMetaData, 
+      rmd: createRequest.createRequest.tms::task.tms::metadata, 
+      tqmd: createTaskRequest.root.b4p::taskMetaData) {
+    rmd.tms::taskId = trmd.b4p::taskId;
+    rmd.tms::description = tqmd.b4p::description;
+    rmd.tms::processId = tqmd.b4p::processId;
+    rmd.tms::formUrl = tqmd.b4p::formUrl;
+    rmd.tms::userProcessEndpoint = tqmd.b4p::userProcessEndpoint;
+    rmd.tms::userProcessNamespaceURI = tqmd.b4p::userProcessNamespaceURI;
+    rmd.tms::userProcessCompleteSOAPAction = tqmd.b4p::userProcessCompleteSOAPAction;
+    rmd.tms::creationDate = [string(current-dateTime())];
+  }
+  createRequest.createRequest.tms::task.tms::input = createTaskRequest.root.b4p::taskInput;
+  createRequest.createRequest = [bpws:doXslTransform("userRoleOwner.xsl", $createRequest.createRequest,
+      "metadata", $createTaskRequest.root/b4p:taskMetaData)];
+  createRequest.createRequest = [bpws:doXslTransform("actions.xsl", $createRequest.createRequest,
+      "metadata", $createTaskRequest.root/b4p:taskMetaData)];
+
+  createResponse = invoke(TMSPartnerLink, create, createRequest);
+
+  if (createTaskRequest.root.b4p::taskMetaData.b4p::isChainedBefore == "true") {
+    nextTaskReady.root = <b4p:chainedExecution><b4p:previousTaskId/><b4p:nextTaskId/>
+                          <b4p:nextTaskURL/></b4p:chainedExecution>;
+    with(tr: createTaskRequest.root.b4p::taskMetaData) {
+      nextTaskReady.root.b4p::previousTaskId = tr.b4p::previousTaskId;
+      nextTaskReady.root.b4p::nextTaskId = tr.b4p::taskId;
+      nextTaskReady.root.b4p::nextTaskURL = tr.b4p::formUrl;
+    }
+    wait([now()+'PT5S']);
+    invoke(previousTaskManagerPartnerLink, nextTaskReady, nextTaskReady);
+  }
+
+  taskCompleted = false;
+  taskClaimed = false;
+  taskEscalated = false;
+  while(taskCompleted == false) {
+    pick {
+      receive(uifwPartnerLink, completeTask, {taskIdFromB4P: taskId}) { |completeTaskRequest|
+        completeTaskResponse.root = <b4p:response><b4p:taskMetaData><b4p:taskId/></b4p:taskMetaData>
+                                    <b4p:status>OK</b4p:status></b4p:response>;
+        completeTaskResponse.root.b4p::taskMetaData.b4p::taskId = completeTaskRequest.root.b4p::taskMetaData.b4p::taskId;
+        
+        with(oc: setOutputAndCompleteRequest.setOutputAndCompleteRequest) {
+          oc = <tms:setOutputAndCompleteRequest><tms:taskId/><tms:data/>
+            <tms:participantToken/></tms:setOutputAndCompleteRequest>;
+          oc.tms::taskId = createTaskResponse.root.b4p::taskMetaData.b4p::taskId;
+          oc.tms::data = completeTaskRequest.root/b4p::taskOutput;
+          oc.tms::participantToken = completeTaskRequest.root.b4p::participantToken;
+        }
+
+        setOutputAndCompleteRespons = invoke(TMSPartnerLink, setOutputAndComplete, setOutputAndCompleteRequest);
+
+        notifyTaskCompletionRequest.root = <b4p:notifyTaskCompletionRequest><b4p:taskMetaData>
+            <b4p:taskId/><b4p:processId/><b4p:userProcessEndpoint/><b4p:userProcessNamespaceURI/>
+            <b4p:userProcessCompleteSOAPAction/><b4p:session/></b4p:taskMetaData>
+            <b4p:taskOutput/><b4p:status>OK</b4p:status></b4p:notifyTaskCompletionRequest>;
+
+        with(ntc: notifyTaskCompletionRequest.root.b4p::taskMetaData, tq: createTaskRequest.root.b4p::taskMetaData) {
+          ntc.b4p::taskId = createTaskResponse.root.b4p::taskMetaData.b4p::taskId;
+          ntc.b4p::processId = tq.b4p::processId;
+          ntc.b4p::userProcessEndpoint = tq.b4p::userProcessEndpoint;
+          ntc.b4p::userProcessNamespaceURI = tq.b4p::userProcessNamespaceURI;
+          ntc.b4p::userProcessCompleteSOAPAction = tq.b4p::userProcessCompleteSOAPAction;
+          ntc.b4p::session = tq.b4p::session;
+        }
+        notifyTaskCompletionRequest.root.b4p::taskOutput = completeTaskRequest.root.b4p::taskOutput;
+
+        notifyTaskCompletionResponse = invoke(userProcessPartnerLink, notifyTaskCompletion, notifyTaskCompletionRequest);
+
+        if (notifyTaskCompletionResponse.root.b4p::isChainedAfter == true) {
+          receive(nextTaskManagerPartnerLink, nextTaskReady) { |nextTaskReady|
+            completeTaskResponse.root = <b4p:response><b4p:taskMetaData><b4p:nextTaskId/>
+                <b4p:nextTaskURL/></b4p:taskMetaData><b4p:status>OK</b4p:status></b4p:response>;
+            with(ct: completeTaskResponse.root.b4p::taskMetaData) {
+              ct.b4p::nextTaskId = nextTaskReady.root.b4p::nextTaskId;
+              ct.b4p::nextTaskURL = nextTaskReady.root.b4p::nextTaskURL;
+            }
+          }
+        }
+
+        reply(completeTaskResponse);
+        taskCompleted = true;
+      }
+
+      receive(userProcessPartnerLink, escalateTask, {taskIdFromB4P: taskId}) { |escalateTaskRequest|
+        reassignRequest.reassignRequest = <tms:reassignRequest><tms:taskId/><tms:userOwner/>
+            <tms:roleOwner/><tms:taskState>READY</tms:taskState><tms:participantToken/></tms:reassignRequest>;
+        with(rr: reassignRequest.reassignRequest, etr: escalateTaskRequest.root) {
+          rr.tms::taskId = etr.b4p::taskId;
+          rr.tms::userOwner = etr.b4p::userOwner;
+          rr.tms::roleOwner = etr.b4p::roleOwner;
+        }
+
+        reassignRequest = invoke(TMSPartnerLink, reassign, reassignRequest);
+
+        taskClaimed = false;
+        escalateTaskResponse.root = <b4p:escalateTaskResponse><b4p:status>OK</b4p:status></b4p:escalateTaskResponse>;
+        reply(escalateTaskResponse);
+        taskEscalated = true;
+      }
+
+      receive(uifwPartnerLink, claimTask, {taskIdFromB4P: taskId}) { |claimTaskRequest|
+        if (taskClaimed == true) throw(b4p::taskAlreadyClaimed);
+
+        initialOwners.root = <b4p:usersAndRoles><b4p:userOwner/><b4p:roleOwner/></b4p:usersAndRoles>;
+        if (taskEscalated == true) {
+          with(io: initialOwners.root.usersAndRoles) {
+            io.b4p::userOwner = escalateTaskRequest.root/b4p::userOwner;
+            io.b4p::roleOwner = escalateTaskRequest.root/b4p::roleOwner;
+          }
+        } else {
+          with(io: initialOwners.root.usersAndRoles) {
+            io.b4p::userOwner = createTaskRequest.root/b4p::userOwner;
+            io.b4p::roleOwner = createTaskRequest.root/b4p::roleOwner;
+          }
+        }
+        with(rr: reassignRequest.reassignRequest, ct: claimTaskRequest.root) {
+          rr = <tms:reassignRequest><tms:taskId/><tms:userOwner/>
+              <tms:taskState>CLAIMED</tms:taskState><tms:participantToken/></tms:reassignRequest>;
+          rr.tms::taskId = ct.b4p::taskId;
+          rr.tms::userOwner = ct.b4p::claimerUser;
+          rr.tms::participantToken = ct.b4p::participantToken;
+        }
+
+        reassignResponse = invoke(TMSPartnerLink, reassign, reassignRequest);
+        taskClaimed = true;
+        claimTaskResponse.root = <b4p:claimTaskResponse><b4p:status>OK</b4p:status></b4p:claimTaskResponse>;
+        reply(claimTaskResponse);
+      }
+
+      receive(uifwPartnerLink, revokeTask, {taskIdFromB4P: taskId}) { |revokeTaskRequest|
+        if (taskClaimed != true) throw(b4p::taskNotClaimed);
+
+        with(rr: reassignRequest.reassignRequest, rt: revokeTaskRequest.root) {
+          rr = <tms:reassignRequest><tms:taskId/><tms:userOwner/>
+              <tms:roleOwner/><tms:taskState>READY</tms:taskState><tms:participantToken/></tms:reassignRequest>;
+          rr = <tms:reassignRequest><tms:taskId/><tms:userOwner/><tms:roleOwner/>
+              <tms:taskState>READY</tms:taskState><tms:participantToken/></tms:reassignRequest>;
+          rr.tms::taskId = rt.b4p::taskId;
+          rr.tms::userOwner = rt.b4p::userOwner;
+          rr.tms::roleOwner = rt.b4p::roleOwner;
+          rr.tms::participantToken = rt.b4p::participantToken;
+        }
+
+        reassignResponse = invoke(TMSPartnerLink, reassign, reassignRequest);
+        taskClaimed = false;
+        revokeTaskResponse.root = <b4p:revokeTaskResponse><b4p:status>OK</b4p:status></b4p:revokeTaskResponse>;
+        reply(revokeTaskResponse);
+      }
+
+    }
+  }
+
+}

Modified: ode/sandbox/simpel/tools/simpel.vim
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/tools/simpel.vim?rev=606017&r1=606016&r2=606017&view=diff
==============================================================================
--- ode/sandbox/simpel/tools/simpel.vim (original)
+++ ode/sandbox/simpel/tools/simpel.vim Thu Dec 20 12:15:25 2007
@@ -21,8 +21,8 @@
 syn keyword simpelException		try catch throw
 syn keyword simpelBoolean		true false
 syn keyword simpelIdentifier		var partnerLink namespace
-syn keyword simpelReserved		process scope event alarm compensation
-syn keyword simpelStatement		invoke receive reply wait compensate exit join signal
+syn keyword simpelReserved		process scope event alarm compensation pick
+syn keyword simpelStatement		invoke receive reply wait compensate exit join signal with
 
 syn keyword simpelFunction      	function
 syn match   simpelBraces	   	"[{}\[\]]"