1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.jes.util;
12
13 import org.astrogrid.applications.beans.v1.cea.castor.types.ExecutionPhase;
14 import org.astrogrid.workflow.beans.v1.Step;
15
16 import org.apache.commons.jxpath.ClassFunctions;
17 import org.apache.commons.jxpath.ExpressionContext;
18 import org.apache.commons.jxpath.Functions;
19 import org.apache.commons.jxpath.Pointer;
20
21
22 /*** A class of jxpath functions,used within policy implementations to search a workflow tree */
23 public class JesFunctions {
24 public static final Functions FUNCTIONS = new ClassFunctions(JesFunctions.class,"jes");
25 /*** returns true if the current node is a step that is in the 'Pending' Execition Phase*/
26 public static boolean isPendingStep(ExpressionContext ctxt) {
27 Pointer p = ctxt.getContextNodePointer();
28 if (p == null) {
29 return false;
30 }
31 Object o = p.getValue();
32 if (! (o instanceof Step)) {
33 return false;
34 }
35 Step s = (Step)o;
36 int count = s.getStepExecutionRecordCount();
37 if (count == 0) {
38 return true;
39 } else {
40 return s.getStepExecutionRecord(count-1).getStatus().getType() == ExecutionPhase.PENDING_TYPE;
41 }
42 }
43 /*** returns true if the current node is a step */
44 public static boolean isStep(ExpressionContext ctxt) {
45 Pointer p = ctxt.getContextNodePointer();
46 if (p == null) {
47 return false;
48 }
49 return p.getValue() instanceof Step;
50 }
51 /*** count the number of execution records contained in this step */
52 public static int execCount(ExpressionContext ctxt) {
53 Pointer p = ctxt.getContextNodePointer();
54 if (p == null) {
55 return 0;
56 }
57 Step step = (Step)p.getValue();
58 if (step == null) {
59 return 0;
60 }
61 return step.getStepExecutionRecordCount();
62 }
63 /*** access the latest status (Execution Phase) for this step */
64 public static String latestStatus(ExpressionContext ctxt) {
65 Pointer p = ctxt.getContextNodePointer();
66 if (p == null) {
67 return "null";
68 }
69 Step step = (Step)p.getValue();
70 if (step == null) {
71 return "null";
72 }
73 int pos = step.getStepExecutionRecordCount();
74 if (pos == 0) {
75 return ExecutionPhase.PENDING.toString();
76 } else {
77 return step.getStepExecutionRecord(pos-1).getStatus().toString();
78 }
79 }
80 }
81
82
83
84
85
86
87
88
89
90
91
92