Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BPMN 2.0 Modeler » How to validate incoming connections?
icon5.gif  How to validate incoming connections? [message #1691984] Sat, 11 April 2015 13:08 Go to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 193
Registered: July 2009
Senior Member
Hi,

I have a question what's the recommended way to validate a incoming connection?
I have implemented a custom event element.
Now I want to be notified when a new SequenceFlow is connected to my custom event (incoming connection) so I can change some of my custom extension elements.

Is this possible?

Thanks for help

==
Ralph
Re: How to validate incoming connections? [message #1692101 is a reply to message #1691984] Mon, 13 April 2015 13:20 Go to previous messageGo to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Hi Ralph,

This is not really "validation" per se, but you could try hooking in to the object LifeCycle event notification in your IBpmn2RuntimeExtension class. Something like this:

	@Override
	public void notify(LifecycleEvent event) {
		if (event.eventType == EventType.PICTOGRAMELEMENT_ADDED) {
			Connection c = (Connection) event.target;
			Shape s = (Shape) c.getEnd().getParent();
			BaseElement be = BusinessObjectUtil.getFirstBaseElement( s );
			// determine if this is one of your custom shapes and modify accordingly...
		}
	}


Don't forget, you'll have to wrap any changes you make in a transaction, the usual way.

Also, you'll probably want to handle the case where the connection is removed with EventType.PICTOGRAMELEMENT_DELETED. Be advised that any changes you make will be in a separate transaction, so when the user clicks "undo" the first time will undo your changes, the second one will undo the connection creation.

HTH
Bob

[Updated on: Mon, 13 April 2015 13:30]

Report message to a moderator

Re: How to validate incoming connections? [message #1692127 is a reply to message #1692101] Mon, 13 April 2015 17:36 Go to previous messageGo to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 193
Registered: July 2009
Senior Member
Hi Bob,

yes you are right - it's not a validation but more a converter what I am looking for.
The solution I found in the meantime was the following:

The EventAdapter
In the CustomShapeFeatureContainer of my custom Event Element I override the getAddFeature and then the decorateShape method to add a Event Adapter class to my object. Like this:

@Override
public IAddFeature getAddFeature(IFeatureProvider fp) {
	return new AddIntermediateCatchEventFeature(fp) {

		@Override
		protected void decorateShape(IAddContext context,
				ContainerShape containerShape,
				IntermediateCatchEvent businessObject) {
			super.decorateShape(context, containerShape,
					businessObject);

			setFillColor(containerShape);

			// add a notifyChangeAdapter to validate the ActiviytID
		    businessObject.eAdapters().add(new ImixsEventAdapter());
		    
		}
	};
}


My ImixsEventAdapter handles the notifyChanged() method to verify the situation. ....

	public void notifyChanged(Notification notification) {
		IntermediateCatchEvent imixsEvent = null;
		if (ImixsBPMNPlugin.isImixsEvent(notification.getNotifier())) {
			imixsEvent = (IntermediateCatchEvent) notification.getNotifier();
			int type = notification.getEventType();
			if (type == Notification.ADD) {
				// add notification - test if this is a SequenceFlow...
				if (notification.getNewValue() instanceof SequenceFlow) {
					// compute next processid.....
					....
					// update the business object....					
					imixsEvent.eSet(feature, currentActivityID);

				}
		....


This works very well. And I was not forced to wrapp the changes to my business object into a transaction.
I'm afraid that you're not thrilled by this solution Wink

So far in my implementation (still based on the customTask example) I have not subclassed the IntermediateCatchEvent. So I wonder what is the moment where I should add a LiveCycle event notification to my business object? The getAddFeature() method seems to be the only point where I can add adapter classes?
Can you please explain where/how to hook in the LifeCycle event notification?

The Converter
The other thing that I'm still exploring, is the validator concept. I figured out how to implement a validator by extending the AbstractModelConstraint class and do a lot of configuration in the plugin.xml. Finally I was able to validate some of my elements by overriding the validate(IValidationContext ctx) method

public class ImixsValidator extends AbstractModelConstraint {

	public IStatus validate(IValidationContext ctx) {
		EObject eObj = ctx.getTarget();
		EMFEventType eType = ctx.getEventType();
...
}


After all I recognized that the Validator is not able to manipulate a business object. I can only signal a validation problem. But also this would make sense for me to double check my models. Can you give me a short code example how the recommended way for a custom Validator implementatin looks like? There seem to be different concepts of 'batch' and 'live' mode.

Maybe I can help by starting a new developer tutorial in the wiki pages.


===
Ralph


Re: How to validate incoming connections? [message #1692150 is a reply to message #1692127] Tue, 14 April 2015 01:28 Go to previous messageGo to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Hey Ralph,

On the contrary, I am thrilled at your use of EMF adapters Smile especially if you can make all your model changes inside the same transaction as the AddFeature for the SequenceFlow! The best place I've found to add EMF event adapters is in the IBpmn2RuntimeExtension#notify() method - have a look at JBPM5RuntimeExtension for an example.

Again, you should look at the jbpm plugin for an example of how to override/augment the core validation code. The jbpm plugin.xml defines some overrides for certain BPMN2 types (e.g. "Process", "Signal", "Escalation", etc.) The handlers for these validators are invoked from the org.eclipse.bpmn2.modeler.runtime.jboss.jbpm5.validation.JbpmModelConstraint class.

Let me know if you need more explanation than this...

Bob
Re: How to validate incoming connections? [message #1692298 is a reply to message #1692150] Tue, 14 April 2015 21:40 Go to previous messageGo to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 193
Registered: July 2009
Senior Member
Hi Bob,

thanks for the tip. I tried it but with now success.
I used the notify() method of my runtimeExtension in that way:

@Override
public void notify(LifecycleEvent event) {
	if (event.eventType == EventType.BUSINESSOBJECT_CREATED) {
		EObject object = (EObject) event.target;			
		if (object instanceof IntermediateCatchEvent) {
                               // so far it works...
			EStructuralFeature feature = ModelDecorator.getAnyAttribute(
					(IntermediateCatchEvent) object, "activityid");
                               // feature is always null 
			if (feature != null && feature instanceof EAttribute) {
				if (ImixsRuntimeExtension.targetNamespace
					.equals(((EAttributeImpl) feature)
							.getExtendedMetaData().getNamespace())) {
					object.eAdapters().add(new ImixsEventAdapter());
				}
			}
		}


The problem is, that when the BUSINESSOBJECT_CREATED event is fired during the bpmn file is loaded, no custom attributes of the business obejct are yet available. So I can not test if the event is interesting to me. I only can see that it is an instance of a IntermediateCatchEvent but not if it belongs to my targetNamespace Sad

I also tried BUSINESSOBJECT_INITIALIZED. But as you documented this event will not be fired when the file is loaded.
The notify method in my runtimeExtension only works when I drag a new custom event element from the toolbar into my model. But not when the model is loaded.

A solution would be to add the adapter to any IntermediateCatchEvent and test the business object again inside my adapter to skip my code if the event did not belong to my customEvent type.
===
Ralph

[Updated on: Tue, 14 April 2015 21:41]

Report message to a moderator

Re: How to validate incoming connections? [message #1692299 is a reply to message #1692298] Tue, 14 April 2015 21:50 Go to previous messageGo to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 193
Registered: July 2009
Senior Member
Hi Bob,

one more detail about my implementation: The reason why I did not need a transaction was simply because during the event I only change the value of an existing attribute and did not modify the structure of my <bpmn2:extensionElements>. I think the latter requires a also transaction.

===
Ralph
Re: How to validate incoming connections? [message #1692441 is a reply to message #1692299] Wed, 15 April 2015 17:30 Go to previous message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Um, nope. Even something as simple as changing an attribute value will cause EMF to fire a model change notification. The only way to turn off notification that I know of (and this should be used with caution!) is to turn the EObject's notification delivery flag off like this:

void updateMyObject(EObject object) {
  try {
    object.eSetDeliver(false);
    object.setSomeAttribute("Hello world");
  }
  finally {
    object.eSetDeliver(true);
  }
}


As far as your chicken & egg problem is concerned, this has been a problem for me as well. If all else fails, you can always inject an eAdapter during file loading by providing your own Bpmn2ModelerResourceImpl implementation. Take a look at how this is done in DroolsResourceFactoryImpl and DroolsResourceImpl in the jBPM plugin.

[Updated on: Wed, 15 April 2015 17:30]

Report message to a moderator

Previous Topic:Creating a documentation of BPMN 2.0 model
Next Topic:Routing problem with Lanes since version 1.1.2?
Goto Forum:
  


Current Time: Mon Oct 14 01:15:29 GMT 2024

Powered by FUDForum. Page generated in 0.04702 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top