cancel
Showing results for 
Search instead for 
Did you mean: 

Skip Parse validation while fetching the StartFormData

mittalabhi86
Champ in-the-making
Champ in-the-making
Hello,

I am facing issues with the bpmn entries in database, which are obsolete, in the sense that validations have changed after those were deployed.

For such deployments, I can neither fetch bpmn text, nor can I fetch start form variables. This is because, while doing those two operations, it internally calls the validate() of our Custom ProcessValidator.

Is there a way that I can skip this validation in read operations?
11 REPLIES 11

jbarrez
Star Contributor
Star Contributor
Are you using the ProcessValidator approach?

If so, you can plug in a custom validator, and have custom if() checks for the processes that shouldnt validate for that particular element.

mittalabhi86
Champ in-the-making
Champ in-the-making
Hello,

Yes I am using that approach. But while fetching I am not aware what all definitions in database might have got parsing errors introduced, since changes are made in validator class, and none of the definition in db was changed.

To simplify the problem, I am looking for a solution to disable these validation for read operations, such as while fetching startFormData/ProcessDefinitionText

Regards
Abhishek

trademak
Star Contributor
Star Contributor
You can disable the validation in the DeploymentBuilder. For the other read operations, the validation is not performed.

Best regards,

mittalabhi86
Champ in-the-making
Champ in-the-making
Hi Tijs,

The issue I am facing is, validations are also triggered when I call formService.getStartFormData() and when I fetch the bpmnModel.
My concern is to disable the validations for these read operations. Validations on deployment time are not to be suppressed.

Regards
Abhishek

trademak
Star Contributor
Star Contributor
Hi Abhishek,

Okay that's not intended behaviour. Could you create a unit test showing this issue, so we can reproduce it and fix it?

Thanks,

mittalabhi86
Champ in-the-making
Champ in-the-making
Hello Tijs,

Below is the code to reproduce the issue, along with the steps to reproduce it.
[h2]Steps to reproduce[/h2]
  1. Deploy the BPMN file. This xml contains a parsing violation. But we need to deploy this before injecting the process validator.
  2. Inject the process validator in process engine configuration.
  3.      [java]processEngineConfigurationImpl.setProcessValidator(new ActivitiTestCaseProcessValidator());[/java]
  4. Run the test cases.
[h2] BPMN file as well as the related java code[/h2]
Sample BPMN File:

<?xml version="1.0" encoding="UTF-8"?>
<definitions expressionLanguage="http://www.w3.org/1999/XPath"
    id="definitions" targetNamespace="testapp"
    typeLanguage="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
    xmlns:activiti="http://activiti.org/bpmn"
    xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
    xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC"
    xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <process id="testProcess1" name="test process">
        <property id="processVariable" itemSubjectRef="xsd:string" name="processVariable"/>
        <startEvent activiti:async="true" id="start" name="Start">
            <extensionElements>
                <activiti:formProperty id="task1Variable1"
                    name="task1 Variable1" required="false" type="string"/>
                <activiti:formProperty id="task1Variable2"
                    name="task1 Variable2" required="false" type="string"/>
            </extensionElements>
        </startEvent>
        <serviceTask id="task1" name="Task 1">
            <extensionElements>
                <activiti:field name="variableNames">
                    <activiti:string>             task1Variable1,             task1Variable2           </activiti:string>
                </activiti:field>
            </extensionElements>
        </serviceTask>
        <endEvent id="end" name="End"/>
        <sequenceFlow id="flow1" sourceRef="start" targetRef="task1"/>
        <sequenceFlow id="flow2" sourceRef="task1" targetRef="end"/>
    </process>
</definitions>

Sample Validator:
[java]

import org.activiti.bpmn.model.BpmnModel;
import org.activiti.bpmn.model.FlowElement;
import org.activiti.bpmn.model.Process;
import org.activiti.bpmn.model.ServiceTask;
import org.activiti.validation.ProcessValidator;
import org.activiti.validation.ValidationError;

import java.util.ArrayList;
import java.util.List;

/**
* Sample Process Validator for Activiti Test case.
*/
public class ActivitiTestCaseProcessValidator implements ProcessValidator {

  @Override
  public List<ValidationError> validate(BpmnModel bpmnModel) {
    List<ValidationError> errorList = new ArrayList<>();
    CustomParseValidator customParseValidator = new CustomParseValidator();

    for (Process process : bpmnModel.getProcesses()) {
      customParseValidator.executeParse(bpmnModel, process);
    }

    ValidationError error = null;
    for (String errorRef : bpmnModel.getErrors().keySet()) {
      error = new ValidationError();
      error.setValidatorSetName("Manual BPMN parse validator");
      error.setProblem(errorRef);
      error.setActivityId(bpmnModel.getErrors().get(errorRef));
      errorList.add(error);
    }
    return errorList;
  }

  class CustomParseValidator {
    protected void executeParse(BpmnModel bpmnModel, Process element) {
      for (FlowElement flowElement : element.getFlowElements()) {
        if (!ServiceTask.class.isAssignableFrom(flowElement.getClass())) {
          continue;
        }
        ServiceTask serviceTask = (ServiceTask) flowElement;
        validateAsyncAttribute(serviceTask, bpmnModel, flowElement);
      }
    }

    void validateAsyncAttribute(ServiceTask serviceTask, BpmnModel bpmnModel,
        FlowElement flowElement) {
      if (!serviceTask.isAsynchronous()) {
        bpmnModel.addError("Please set value of 'activiti:async'" +
            "attribute as true for task:" + serviceTask.getName(), flowElement.getId());
      }
    }
  }
}
[/java]

Test case file:
[java]
import junit.framework.Assert;

import org.activiti.engine.ActivitiException;
import org.activiti.engine.FormService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.List;

/**
* Sample Unit Test case for Activiti to illustrate the issue of BPMN Parsing in read ops.
*/
@RunWith(JUnit4.class)
public class ActivitiUnitTestCaseService {


  private final RepositoryService repositoryService;
  private final FormService formService;

  public ActivitiUnitTestCaseService(ProcessEngine processEngine) {
    this.repositoryService = processEngine.getRepositoryService();
    this.formService = processEngine.getFormService();
  }

  private ProcessDefinition getLatestProcessDefinitionVersionByKey(String processDefinitionKey) {
    List<ProcessDefinition> definitions = null;
    try {
      definitions = repositoryService.createProcessDefinitionQuery()
          .processDefinitionKey(processDefinitionKey).orderByProcessDefinitionVersion()
          .latestVersion().desc().list();
      if (definitions.size() == 0) {
        return null;
      }
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
    return definitions.get(0);
  }

  @Test
  public void getLatestProcessDefinitionTextByKey() {
    ProcessDefinition definition = getLatestProcessDefinitionVersionByKey("testProcess1");
    if (definition == null) {
      Assert.fail("Error occurred in fetching process model.");
    }
    try {
      repositoryService.getProcessModel(definition.getId());
      Assert.assertTrue(true);
    } catch (ActivitiException e) {
      Assert.fail("Error occurred in fetching process model.");
    }
  }

  @Test
  public void getStartFormData() {
    ProcessDefinition definition = getLatestProcessDefinitionVersionByKey("testProcess1");
    if (definition == null) {
      Assert.fail("Error occurred in fetching process model.");
    }
    try {
      formService.getStartFormData(definition.getId());
      Assert.assertTrue(true);
    } catch (ActivitiException e) {
      Assert.fail("Error occurred in fetching start form data.");
    }
  }
}
[/java]

I hope this will help in reproducing the issue.

Regards
Abhishek

jbarrez
Star Contributor
Star Contributor
Indeed, you are correct.

I enhanced your unit test a bit, and used it to find the issue and fix it in this commit: https://github.com/Activiti/Activiti/commit/b88fee55d1c133d50bcd2e318c603115d28699a4

Many thanks!

mittalabhi86
Champ in-the-making
Champ in-the-making
Thanks so much Joram for looking into this Smiley Happy

mittalabhi86
Champ in-the-making
Champ in-the-making
Hello,

When are we expecting the next release, as in, when will this change be available to us?

Regards
Abhishek
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.