cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to call a ProcessValidator from Command

igoyetche
Champ in-the-making
Champ in-the-making
Hi,

I'm trying to call a custom ProccesValidator of Activiti designer from a toolbar command, so I started with the example of ProcessValidator in GitHub "BPMN20ProcessValidator".
I took this code and added to it a Command to call the "validateDiagram(Diagram diagram, IProgressMonitor monitor)" Method, that I'm not sure if is it OK. After trying with a lot of things, to call this method with no success, I given up with this:


public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    final IEditorPart activeEditor = window.getActivePage().getActiveEditor();
    ActivitiDiagramEditor editor = (ActivitiDiagramEditor) activeEditor;
    final IDiagramTypeProvider pro = editor.getDiagramTypeProvider();
    final Diagram diagram = pro.getDiagram();

    final ProcessValidator processValidator = (ProcessValidator) ExtensionPointUtil.getProcessValidator(PluginConstants.VALIDATOR_ID);   

    processValidator.validateDiagram(diagram, new NullProgressMonitor());
   



The problem with the code above is that when I obtain the processValidator I defined, it comes with the diagramWorkerContext in null, and it throws a NullReferenceException.

I searched in all the GitHub Activiti Designer code and I didn't find how could I set the diagramWorkerContext, so I'm starting to believe that I'm using it in a way that is not expected to use it.

My doubt is: how is expected way to use the processValidator??, exist any example of it??

Please I appreciate any help!!, I been trying to made this for weeks without luck and It's for a very important project.

Thanks in advance,
igoeyche
2 REPLIES 2

frederikherema1
Star Contributor
Star Contributor
The process validator you are referring to cannot be used outside of the Designer. However, it's your lucky day. We recently added a new module that can be used separately: https://github.com/Activiti/Activiti/tree/master/modules/activiti-process-validation

Add it as a dependency to your project, get hold of an instance of https://github.com/Activiti/Activiti/blob/master/modules/activiti-process-validation/src/main/java/o... and run your model through that, instead.

igoyetche
Champ in-the-making
Champ in-the-making
Hi,
First of all, thanks for the quick response, it was very helpful.

Now there is something that I don't finish to understand, my code is the following:

<java>
public void Validate(String path)
{
  ProcessEngine processengine = ProcessEngines.getDefaultProcessEngine();
  RepositoryService repositoryService = processengine.getRepositoryService();
  DeploymentBuilder db = repositoryService.createDeployment().disableBpmnValidation().disableSchemaValidation();
 
  try
  {
   db.addInputStream("ProcessToValidate.bpmn20.xml", new FileInputStream(path)).disableBpmnValidation();
   db.deploy();
  }
  catch (Exception e)
  {
  }
 
  List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery().list();
  if (processDefinitionList.size() > 0)
  {
   BpmnModel model = repositoryService.getBpmnModel(processDefinitionList.get(0).getId());
   
   final ProcessValidatorFactory pvf = new ProcessValidatorFactory();
                 final ProcessValidator pV = pvf.createDefaultProcessValidator();
        
                 List<ValidationError> errors = pV.validate(model);
  }
  else
  {
   // Deploy failed
  }
}

</java>

So, the problem is that when the DeploymentBuilder does the deploy() it calls the validator and if the model has any error, it doesn't generate the  ProcessDefinition. So I can't call the validator outside the deploy method and get the list of errors when it has errors, that is what I want.

Does exist another way to get de BpmnModel and use it to validate?, Or way to get the list errors?

Thanks in advance