cancel
Showing results for 
Search instead for 
Did you mean: 

Own validator without own export marshaller

christianelmer
Champ in-the-making
Champ in-the-making
Hello,

can I write my own validating diagram class without using my own export marshaller? Because I want define rules for the diagrams, but I want use the standard BPMN export marshaller to export the diagrams.

Now my own validator extension only works if I write also an export marshaller with this code:


final boolean validDiagram = invokeValidator(IntellixProcessValidator.VALIDATOR_ID, diagram, monitor);
if (!validDiagram) {
        addProblemToDiagram(diagram, "Marshalling to " + getFormatName()
                + " format was skipped because validation of the diagram failed.", null);
} else {
        InputStream stream = getInputStreamForDiagram(diagram);
        saveResource(getRelativeURIForDiagram(diagram, FILENAME_PATTERN), stream, monitor);
}

The validateDiagram method of the validator has this code:


public boolean validateDiagram(Diagram diagram, IProgressMonitor monitor) {
        boolean valid = false;

        clearMarkers(getResource(diagram.eResource().getURI()));
       
        monitor.beginTask("Activiti Intellix Validation", 1);

        // Check correctness of the diagram

        return valid;
    }

Best regards,
Christian
22 REPLIES 22

christianelmer
Champ in-the-making
Champ in-the-making
Thank you Tijs, now its worked.

I see the multi line text at task and resizing of task - nice features! But the "Yes, import a BPMN 2.0 file" is still not selectable.

tiesebarrell
Champ in-the-making
Champ in-the-making
That's right, it hasn't been implemented yet. It's on the list, though Smiley Happy

christianelmer
Champ in-the-making
Champ in-the-making
Did you also changed something at the plug in development for own validators. Because I can' override the method validateDiagram, if I extends from AbstractProcessValidator. I have build and installed the designer 5.7.1 at the Eclipse SDK for develop with the new version. I have also installed Graphiti 0.8.0.

Thanks,
Christian

tiesebarrell
Champ in-the-making
Champ in-the-making
Hello Christian,

no, nothing changed there as far as I know. There's no override needed (AbstractProcessValidator doesn't provide a base implementation), but you should implement the method from the interface if that's what you mean. Maybe something's not setup correctly with your dependencies. Can you subclass AbstractProcessValidator at all or can't you find the class?

You can find an example in the org.activiti.designer.validation.bpmn20.validation.BPMN20ProcessValidator class itself, because it actually just extends AbstractProcessValidator. For your dependencies in MANIFEST.MF, you'll probably need a set like this (this is an old example as far as versions go):

Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.activiti.designer.eclipse;bundle-version="5.7.0",
org.activiti.designer.model;bundle-version="5.7.0",
org.eclipse.graphiti.mm;bundle-version="0.7.1",
org.eclipse.graphiti.ui;bundle-version="0.7.1",
org.activiti.designer.gui;bundle-version="5.7.0",
org.eclipse.emf;bundle-version="2.6.0",
org.activiti.designer.export.bpmn20;bundle-version="5.7.0"

Hope this helps.

christianelmer
Champ in-the-making
Champ in-the-making
Now it works without the Override Annotation. Its also works with the new Designer version 5.7.1. I have used this dependencies:

Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.activiti.designer.export.bpmn20;bundle-version="5.7.1",
org.activiti.designer.eclipse;bundle-version="5.7.1",
org.activiti.designer.model;bundle-version="5.7.1",
org.eclipse.emf;bundle-version="2.6.0",
org.eclipse.graphiti.mm;bundle-version="0.8.0",
org.eclipse.graphiti.ui;bundle-version="0.8.0",
org.eclipse.core.resources;bundle-version="3.6.0"

I have one more problem. I use this line to add a message to the problem view:


addProblemToDiagram(diagram,"[…]",((FlowNode)object).getId());

But if the message appears, it writes "Location: unknown" and no task. In this case the "object" is an EndEvent object.

tiesebarrell
Champ in-the-making
Champ in-the-making
Christian, could you maybe attach your validator? It's easier to look into any problems that way.

christianelmer
Champ in-the-making
Champ in-the-making
Here the Validator, a little bit clipped and with one simple check:


[…]
public class ProcessValidator extends AbstractProcessValidator {

    […]
   
    public final boolean validateDiagram(final Diagram diagram, final IProgressMonitor monitor) {
        this.diagram = diagram;
        this.monitor = monitor;
        boolean valid = false;

        // Clear markers for this diagram first
        clearMarkers(getResource(diagram.eResource().getURI()));

        monitor.beginTask(VALIDATOR_NAME, 1);

        valid = checkGetJob();

        return valid;
    }
 
    /**
     * Checks if an receive task with the id "getjob" is in front of every end event.
     *
     * @return The correctness of the diagram.
     */
    private boolean checkGetJob() {
        boolean valid = true;

        final EList<EObject> contents = getResourceForDiagram(diagram).getContents();
        for (final EObject object : contents) {
            if (object instanceof EndEvent) {
                final List<SequenceFlow> incomingFlows = ((EndEvent)object).getIncoming();
                for (SequenceFlow flow : incomingFlows) {
                    if (!flow.getSourceRef().getId().equals("getjob")) {
                        addProblemToDiagram(diagram,
                                "The last task before an EndEvent have to be a receive task with the Id \"getjob\"",
                                ((FlowNode)object).getId());
                        valid = false;
                    }
                }
            }
        }
        monitor.worked(1);
        return valid;
    }
}

tiesebarrell
Champ in-the-making
Champ in-the-making
Thanks, I'll take a look at it soon. It might be the case that the location is never correctly linked to the XML file, if that's what you're referring to. I think I haven't implemented that yet.

tiesebarrell
Champ in-the-making
Champ in-the-making
Christian,

I've checked, but the Location field is simply not implemented in the base class (it's not an issue in your code, but ours), so it will always be empty (or unknown). I'm unsure how the location in the .activiti file would help, but I could look into adding it. I also don't know if I can determine the correct line number from the model element, but that would be part of the investigation. Can you add a Jira issue for this if you feel it's important?

I don't understand what you mean by there's no task. Can you explain?

christianelmer
Champ in-the-making
Champ in-the-making
Hey Tiese,

I mean the Location column at the problem view, there is only "Unknown", not the task with the failure. I thought I have seen it in a previous version of my or the standard validator. Another strange thing is, that there is a little cross on red background inside the task with the failure, not after the saving progress when the failure was produced, but atfer the next saving progress. I hope you understand.

Greetings,
Christian