Conditional Expression in Intermidiate Catching event

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member II

Conditional Expression in Intermidiate Catching event

Jump to solution

I am trying to use intermididate catching event in my process definition, but only want to signal it based on condition. I can see signalExpression is there inside catching event but bpmn modelere is not allowing me to use this.

I posted similar question os stack overflow https://stackoverflow.com/questions/60350138/signalexpression-in-activiti-6-0-intermediate-catching-...

 

Can someone help.

1 Solution

Accepted Solutions
Active Member II

Re: Conditional Expression in Intermidiate Catching event

Jump to solution

Hi,

Clearly the signal expression is not a standard BPMN and is an extension. To make it work this is what I had to do.

  1. Had to extend CatchEventXMLConverter and add it in BpmnXMLConverter.
     BpmnXMLConverter.addConverter(new CatchEventXMLConverter() {
          @Override
          protected void writeSignalDefinition(Event parentEvent,
              SignalEventDefinition signalDefinition, XMLStreamWriter xtw) throws Exception {
            xtw.writeStartElement(ELEMENT_EVENT_SIGNALDEFINITION);
            writeDefaultAttribute("activiti:"+ATTRIBUTE_SIGNAL_EXPRESSION, signalDefinition.getSignalExpression(), xtw);
            if (parentEvent instanceof ThrowEvent && signalDefinition.isAsync()) {
              BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, "true", xtw);
            }
            boolean didWriteExtensionStartElement =
                BpmnXMLUtil.writeExtensionElements(signalDefinition, false, xtw);
            if (didWriteExtensionStartElement) {
              xtw.writeEndElement();
            }
            xtw.writeEndElement();
          }
        });
  2. Had to extend IntermediateCatchSignalEventActivityBehavior and register it process engine configuration.
    getProcessEngineConfiguration())
                .setActivityBehaviorFactory(new DefaultActivityBehaviorFactory() {
                  @Override
                  public IntermediateCatchSignalEventActivityBehavior createIntermediateCatchSignalEventActivityBehavior(
                      IntermediateCatchEvent intermediateCatchEvent,
                      SignalEventDefinition signalEventDefinition, Signal signal) {
    
    
                    return new IntermediateCatchSignalEventActivityBehavior(signalEventDefinition,
                        signal) {
                    
                      private static final long serialVersionUID = 1L;
    
                      @Override
                      public void execute(DelegateExecution execution) {
                        CommandContext commandContext = Context.getCommandContext();
                        ExecutionEntity executionEntity = (ExecutionEntity) execution;
    
                        String signalName = null;
    
                        Expression signalExpression =
                            commandContext.getProcessEngineConfiguration().getExpressionManager()
                                .createExpression(signalEventDefinition.getSignalExpression());
                        signalName = signalExpression.getValue(execution).toString();
    
    
                        commandContext.getEventSubscriptionEntityManager().insertSignalEvent(signalName,
                            signal, executionEntity);
                      }
    
                    };
                  }
    
                })
  3. I removed signalRef completely But you can tweak the code and use both flavour.

Thanks

-Vishal

View solution in original post

3 Replies
Highlighted
Community Manager
Community Manager

Re: Conditional Expression in Intermidiate Catching event

Jump to solution

Hi @vgaur,

I see on Stack that someone chipped in - looks like you have resolved your issue? If so, it would be great if you could update this post with how you resolved your problem.

Many thanks, 

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!
Active Member II

Re: Conditional Expression in Intermidiate Catching event

Jump to solution

Hi,

Clearly the signal expression is not a standard BPMN and is an extension. To make it work this is what I had to do.

  1. Had to extend CatchEventXMLConverter and add it in BpmnXMLConverter.
     BpmnXMLConverter.addConverter(new CatchEventXMLConverter() {
          @Override
          protected void writeSignalDefinition(Event parentEvent,
              SignalEventDefinition signalDefinition, XMLStreamWriter xtw) throws Exception {
            xtw.writeStartElement(ELEMENT_EVENT_SIGNALDEFINITION);
            writeDefaultAttribute("activiti:"+ATTRIBUTE_SIGNAL_EXPRESSION, signalDefinition.getSignalExpression(), xtw);
            if (parentEvent instanceof ThrowEvent && signalDefinition.isAsync()) {
              BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, "true", xtw);
            }
            boolean didWriteExtensionStartElement =
                BpmnXMLUtil.writeExtensionElements(signalDefinition, false, xtw);
            if (didWriteExtensionStartElement) {
              xtw.writeEndElement();
            }
            xtw.writeEndElement();
          }
        });
  2. Had to extend IntermediateCatchSignalEventActivityBehavior and register it process engine configuration.
    getProcessEngineConfiguration())
                .setActivityBehaviorFactory(new DefaultActivityBehaviorFactory() {
                  @Override
                  public IntermediateCatchSignalEventActivityBehavior createIntermediateCatchSignalEventActivityBehavior(
                      IntermediateCatchEvent intermediateCatchEvent,
                      SignalEventDefinition signalEventDefinition, Signal signal) {
    
    
                    return new IntermediateCatchSignalEventActivityBehavior(signalEventDefinition,
                        signal) {
                    
                      private static final long serialVersionUID = 1L;
    
                      @Override
                      public void execute(DelegateExecution execution) {
                        CommandContext commandContext = Context.getCommandContext();
                        ExecutionEntity executionEntity = (ExecutionEntity) execution;
    
                        String signalName = null;
    
                        Expression signalExpression =
                            commandContext.getProcessEngineConfiguration().getExpressionManager()
                                .createExpression(signalEventDefinition.getSignalExpression());
                        signalName = signalExpression.getValue(execution).toString();
    
    
                        commandContext.getEventSubscriptionEntityManager().insertSignalEvent(signalName,
                            signal, executionEntity);
                      }
    
                    };
                  }
    
                })
  3. I removed signalRef completely But you can tweak the code and use both flavour.

Thanks

-Vishal

View solution in original post

Highlighted
Community Manager
Community Manager

Re: Conditional Expression in Intermidiate Catching event

Jump to solution

Hi @vgaur,

Thanks for posting your solution - really helpful to other hub members.

Kind regards, 

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!