34
34
import org .jbpm .process .core .timer .Timer ;
35
35
import org .jbpm .process .instance .InternalProcessRuntime ;
36
36
import org .jbpm .process .instance .impl .Action ;
37
+ import org .jbpm .ruleflow .core .Metadata ;
37
38
import org .jbpm .util .ContextFactory ;
38
39
import org .jbpm .workflow .core .DroolsAction ;
40
+ import org .jbpm .workflow .core .WorkflowProcess ;
41
+ import org .jbpm .workflow .core .impl .NodeImpl ;
39
42
import org .jbpm .workflow .core .node .StateBasedNode ;
40
43
import org .jbpm .workflow .instance .impl .ExtendedNodeInstanceImpl ;
41
44
import org .jbpm .workflow .instance .impl .WorkflowProcessInstanceImpl ;
51
54
import org .kie .kogito .jobs .ExpirationTime ;
52
55
import org .kie .kogito .jobs .JobsService ;
53
56
import org .kie .kogito .jobs .ProcessInstanceJobDescription ;
57
+ import org .kie .kogito .process .expr .Expression ;
58
+ import org .kie .kogito .process .expr .ExpressionHandlerFactory ;
54
59
import org .kie .kogito .timer .TimerInstance ;
55
60
import org .slf4j .Logger ;
56
61
import org .slf4j .LoggerFactory ;
@@ -68,6 +73,8 @@ public abstract class StateBasedNodeInstance extends ExtendedNodeInstanceImpl im
68
73
69
74
private Map <String , String > timerInstancesReference ;
70
75
76
+ private transient KogitoProcessContext context ;
77
+
71
78
public StateBasedNode getEventBasedNode () {
72
79
return (StateBasedNode ) getNode ();
73
80
}
@@ -144,8 +151,8 @@ protected ExpirationTime createTimerInstance(Timer timer) {
144
151
switch (timer .getTimeType ()) {
145
152
case Timer .TIME_CYCLE :
146
153
147
- String tempDelay = resolveExpression (timer .getDelay ());
148
- String tempPeriod = resolveExpression (timer .getPeriod ());
154
+ String tempDelay = resolveTimerExpression (timer .getDelay ());
155
+ String tempPeriod = resolveTimerExpression (timer .getPeriod ());
149
156
if (DateTimeUtils .isRepeatable (tempDelay )) {
150
157
String [] values = DateTimeUtils .parseISORepeatable (tempDelay );
151
158
String tempRepeatLimit = values [0 ];
@@ -174,7 +181,7 @@ protected ExpirationTime createTimerInstance(Timer timer) {
174
181
}
175
182
176
183
case Timer .TIME_DURATION :
177
- delay = resolveExpression (timer .getDelay ());
184
+ delay = resolveTimerExpression (timer .getDelay ());
178
185
179
186
return DurationExpirationTime .repeat (businessCalendar .calculateBusinessTimeAsDuration (delay ));
180
187
case Timer .TIME_DATE :
@@ -196,14 +203,14 @@ protected ExpirationTime configureTimerInstance(Timer timer) {
196
203
case Timer .TIME_CYCLE :
197
204
if (timer .getPeriod () != null ) {
198
205
199
- long actualDelay = DateTimeUtils .parseDuration (resolveExpression (timer .getDelay ()));
206
+ long actualDelay = DateTimeUtils .parseDuration (resolveTimerExpression (timer .getDelay ()));
200
207
if (timer .getPeriod () == null ) {
201
208
return DurationExpirationTime .repeat (actualDelay , actualDelay , Integer .MAX_VALUE );
202
209
} else {
203
- return DurationExpirationTime .repeat (actualDelay , DateTimeUtils .parseDuration (resolveExpression (timer .getPeriod ())), Integer .MAX_VALUE );
210
+ return DurationExpirationTime .repeat (actualDelay , DateTimeUtils .parseDuration (resolveTimerExpression (timer .getPeriod ())), Integer .MAX_VALUE );
204
211
}
205
212
} else {
206
- String resolvedDelay = resolveExpression (timer .getDelay ());
213
+ String resolvedDelay = resolveTimerExpression (timer .getDelay ());
207
214
208
215
// when using ISO date/time period is not set
209
216
long [] repeatValues = null ;
@@ -233,7 +240,7 @@ protected ExpirationTime configureTimerInstance(Timer timer) {
233
240
duration = DateTimeUtils .parseDuration (timer .getDelay ());
234
241
} catch (RuntimeException e ) {
235
242
// cannot parse delay, trying to interpret it
236
- s = resolveExpression (timer .getDelay ());
243
+ s = resolveTimerExpression (timer .getDelay ());
237
244
duration = DateTimeUtils .parseDuration (s );
238
245
}
239
246
return DurationExpirationTime .after (duration );
@@ -243,13 +250,29 @@ protected ExpirationTime configureTimerInstance(Timer timer) {
243
250
return ExactExpirationTime .of (timer .getDate ());
244
251
} catch (RuntimeException e ) {
245
252
// cannot parse delay, trying to interpret it
246
- s = resolveExpression (timer .getDate ());
253
+ s = resolveTimerExpression (timer .getDate ());
247
254
return ExactExpirationTime .of (s );
248
255
}
249
256
}
250
257
throw new UnsupportedOperationException ("Not supported timer definition" );
251
258
}
252
259
260
+ private String resolveTimerExpression (String expression ) {
261
+ if (!isExpression (expression )) {
262
+ WorkflowProcess process = ((NodeImpl ) getNode ()).getProcess ();
263
+ Expression exprObject = ExpressionHandlerFactory .get (process .getExpressionLanguage (), expression );
264
+ if (exprObject .isValid ()) {
265
+ if (context == null ) {
266
+ context = ContextFactory .fromNode (this );
267
+ }
268
+ String varName = (String ) process .getMetaData ().get (Metadata .VARIABLE );
269
+ Object target = varName == null ? this .getProcessInstance ().getVariables () : context .getVariable (varName );
270
+ return exprObject .eval (target , String .class , context );
271
+ }
272
+ }
273
+ return resolveExpression (expression );
274
+ }
275
+
253
276
protected void handleSLAViolation () {
254
277
if (slaCompliance == KogitoProcessInstance .SLA_PENDING ) {
255
278
InternalProcessRuntime processRuntime = ((InternalProcessRuntime ) getProcessInstance ().getKnowledgeRuntime ().getProcessRuntime ());
0 commit comments