Java Code Examples for org.activiti.bpmn.model.ActivitiListener#setImplementation()

The following examples show how to use org.activiti.bpmn.model.ActivitiListener#setImplementation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventJavaTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testStartEventWithExecutionListener() throws Exception {
  BpmnModel bpmnModel = new BpmnModel();
  Process process = new Process();
  process.setId("simpleProcess");
  process.setName("Very simple process");
  bpmnModel.getProcesses().add(process);
  StartEvent startEvent = new StartEvent();
  startEvent.setId("startEvent1");
  TimerEventDefinition timerDef = new TimerEventDefinition();
  timerDef.setTimeDuration("PT5M");
  startEvent.getEventDefinitions().add(timerDef);
  ActivitiListener listener = new ActivitiListener();
  listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
  listener.setImplementation("${test}");
  listener.setEvent("end");
  startEvent.getExecutionListeners().add(listener);
  process.addFlowElement(startEvent);
  UserTask task = new UserTask();
  task.setId("reviewTask");
  task.setAssignee("kermit");
  process.addFlowElement(task);
  SequenceFlow flow1 = new SequenceFlow();
  flow1.setId("flow1");
  flow1.setSourceRef("startEvent1");
  flow1.setTargetRef("reviewTask");
  process.addFlowElement(flow1);
  EndEvent endEvent = new EndEvent();
  endEvent.setId("endEvent1");
  process.addFlowElement(endEvent);

  byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);

  new BpmnXMLConverter().validateModel(new InputStreamSource(new ByteArrayInputStream(xml)));

  Deployment deployment = repositoryService.createDeployment().name("test").addString("test.bpmn20.xml", new String(xml)).deploy();
  repositoryService.deleteDeployment(deployment.getId());
}
 
Example 2
Source File: ActivitiListenerParser.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {

    ActivitiListener listener = new ActivitiListener();
    BpmnXMLUtil.addXMLLocation(listener, xtr);
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CLASS))) {
      listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CLASS));
      listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
    } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_EXPRESSION))) {
      listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_EXPRESSION));
      listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
    } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_DELEGATEEXPRESSION))) {
      listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_DELEGATEEXPRESSION));
      listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
    }
    listener.setEvent(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_EVENT));
    listener.setOnTransaction(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_ON_TRANSACTION));

    if (StringUtils.isNotEmpty((xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CUSTOM_PROPERTIES_RESOLVER_CLASS)))) {
      listener.setCustomPropertiesResolverImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CUSTOM_PROPERTIES_RESOLVER_CLASS));
      listener.setCustomPropertiesResolverImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
    } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CUSTOM_PROPERTIES_RESOLVER_EXPRESSION))) {
      listener.setCustomPropertiesResolverImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CUSTOM_PROPERTIES_RESOLVER_EXPRESSION));
      listener.setCustomPropertiesResolverImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
    } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CUSTOM_PROPERTIES_RESOLVER_DELEGATEEXPRESSION))) {
      listener.setCustomPropertiesResolverImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CUSTOM_PROPERTIES_RESOLVER_DELEGATEEXPRESSION));
      listener.setCustomPropertiesResolverImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
    }
    addListenerToParent(listener, parentElement);
    parseChildElements(xtr, listener, model, new FieldExtensionParser());
  }
 
Example 3
Source File: EventJavaTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testStartEventWithExecutionListener() throws Exception {
  BpmnModel bpmnModel = new BpmnModel();
  Process process = new Process();
  process.setId("simpleProcess");
  process.setName("Very simple process");
  bpmnModel.getProcesses().add(process);
  StartEvent startEvent = new StartEvent();
  startEvent.setId("startEvent1");
  TimerEventDefinition timerDef = new TimerEventDefinition();
  timerDef.setTimeDuration("PT5M");
  startEvent.getEventDefinitions().add(timerDef);
  ActivitiListener listener = new ActivitiListener();
  listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
  listener.setImplementation("${test}");
  listener.setEvent("end");
  startEvent.getExecutionListeners().add(listener);
  process.addFlowElement(startEvent);
  UserTask task = new UserTask();
  task.setId("reviewTask");
  task.setAssignee("kermit");
  process.addFlowElement(task);
  SequenceFlow flow1 = new SequenceFlow();
  flow1.setId("flow1");
  flow1.setSourceRef("startEvent1");
  flow1.setTargetRef("reviewTask");
  process.addFlowElement(flow1);
  EndEvent endEvent = new EndEvent();
  endEvent.setId("endEvent1");
  process.addFlowElement(endEvent);
  
  byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);
  
  new BpmnXMLConverter().validateModel(new InputStreamSource(new ByteArrayInputStream(xml)));
  
  Deployment deployment = repositoryService.createDeployment().name("test").addString("test.bpmn20.xml", new String(xml))
      .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE)
      .deploy();
  repositoryService.deleteDeployment(deployment.getId());
}
 
Example 4
Source File: TaskAutoRedirectParseHandler.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
protected void executeParse(BpmnParse bpmnParse, UserTask userTask) {
    super.executeParse(bpmnParse, userTask);

    // 实验后不能添加
    ActivitiListener listener = new ActivitiListener();
    listener.setEvent("create");
    listener.setImplementationType("class");
    listener.setImplementation("me.kafeitu.activiti.chapter21.listeners.TaskAutoRedirectListener");
    userTask.getTaskListeners().add(listener);
}
 
Example 5
Source File: ProxyUserTaskBpmnParseHandler.java    From lemon with Apache License 2.0 5 votes vote down vote up
public void configEvent(TaskDefinition taskDefinition, BpmnParse bpmnParse,
        String eventName) {
    ActivitiListener activitiListener = new ActivitiListener();
    activitiListener.setEvent(eventName);
    activitiListener
            .setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
    activitiListener.setImplementation("#{" + taskListenerId + "}");
    taskDefinition
            .addTaskListener(eventName, bpmnParse.getListenerFactory()
                    .createDelegateExpressionTaskListener(activitiListener));
}
 
Example 6
Source File: BpmnJsonConverterUtil.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected static void parseListeners(JsonNode listenersNode, BaseElement element, boolean isTaskListener) {  
  if (listenersNode == null) return;
  listenersNode = validateIfNodeIsTextual(listenersNode);
  for (JsonNode listenerNode : listenersNode) {
    listenerNode = validateIfNodeIsTextual(listenerNode);
    JsonNode eventNode = listenerNode.get(PROPERTY_LISTENER_EVENT);
    if (eventNode != null && eventNode.isNull() == false && StringUtils.isNotEmpty(eventNode.asText())) {
      
      ActivitiListener listener = new ActivitiListener();
      listener.setEvent(eventNode.asText());
      if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_CLASS_NAME, listenerNode))) {
        listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
        listener.setImplementation(getValueAsString(PROPERTY_LISTENER_CLASS_NAME, listenerNode));
      } else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_EXPRESSION, listenerNode))) {
        listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
        listener.setImplementation(getValueAsString(PROPERTY_LISTENER_EXPRESSION, listenerNode));
      } else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_DELEGATE_EXPRESSION, listenerNode))) {
        listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
        listener.setImplementation(getValueAsString(PROPERTY_LISTENER_DELEGATE_EXPRESSION, listenerNode));
      }
      
      JsonNode fieldsNode = listenerNode.get(PROPERTY_LISTENER_FIELDS);
      if (fieldsNode != null) {
        for (JsonNode fieldNode : fieldsNode) {
          JsonNode nameNode = fieldNode.get(PROPERTY_FIELD_NAME);
          if (nameNode != null && nameNode.isNull() == false && StringUtils.isNotEmpty(nameNode.asText())) {
            FieldExtension fieldExtension = new FieldExtension();
            fieldExtension.setFieldName(nameNode.asText());
            fieldExtension.setStringValue(getValueAsString(PROPERTY_FIELD_STRING_VALUE, fieldNode));
            if (StringUtils.isEmpty(fieldExtension.getStringValue())) {
              fieldExtension.setStringValue(getValueAsString(PROPERTY_FIELD_STRING, fieldNode));
            }
            if (StringUtils.isEmpty(fieldExtension.getStringValue())) {
              fieldExtension.setExpression(getValueAsString(PROPERTY_FIELD_EXPRESSION, fieldNode));
            }
            listener.getFieldExtensions().add(fieldExtension);
          }
        }
      }
      
      if (element instanceof Process) {
        ((Process) element).getExecutionListeners().add(listener);
      } else if (element instanceof SequenceFlow) {
        ((SequenceFlow) element).getExecutionListeners().add(listener);
      } else if (element instanceof UserTask) {
        if (isTaskListener) {
          ((UserTask) element).getTaskListeners().add(listener);
        } else {
          ((UserTask) element).getExecutionListeners().add(listener);
        }
      }  else if (element instanceof FlowElement) {
        ((FlowElement) element).getExecutionListeners().add(listener);
      }
    }
  }
}