Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BPMN 2.0 Modeler » NPE While creating SequenceFlow between events after Mars.2 update
NPE While creating SequenceFlow between events after Mars.2 update [message #1726110] Wed, 09 March 2016 17:16 Go to next message
Bhuvan Mehta is currently offline Bhuvan MehtaFriend
Messages: 58
Registered: July 2009
Member
Hello Colleagues,

We have an use case where in we create an StartEvent connected to EndEvent via SequenceFlow under an Participant when this custom shape is created.
Following is the sample code which was getting used for achieving the same and it was working fine until Mars.1 update from Eclipse BPMN. Unfortunately this seems to be broken after updates from Mars.2

        private void addEvents(Participant createdParticipant) {
            CreateContext createContext2 = new CreateContext();
            final ContainerShape pictogramElementForBusinessObject = (ContainerShape) getFeatureProvider().getPictogramElementForBusinessObject(createdParticipant);
            createContext2.setTargetContainer(pictogramElementForBusinessObject);

            final int yCoordinateForEvent = createContext2.getY() + pictogramElementForBusinessObject.getGraphicsAlgorithm().getHeight() / 2 - 15;

            createContext2.setLocation(createContext2.getX() + 25, yCoordinateForEvent);
            final Object[] startEvent = new StartEventFeatureContainer().getCreateFeature(getFeatureProvider()).create(createContext2);

            createContext2.setLocation(createContext2.getX() + pictogramElementForBusinessObject.getGraphicsAlgorithm().getWidth() - 75, yCoordinateForEvent);
            final Object[] endEvent = new EndEventFeatureContainer().getCreateFeature(getFeatureProvider()).create(createContext2);

            CreateConnectionContext createConnectionContext = new CreateConnectionContext();
            createConnectionContext.setSourcePictogramElement(getFeatureProvider().getPictogramElementForBusinessObject((EObject) startEvent[0]));
            createConnectionContext.setTargetPictogramElement(getFeatureProvider().getPictogramElementForBusinessObject((EObject) endEvent[0]));

            new SequenceFlowFeatureContainer().getCreateConnectionFeature(getFeatureProvider()).create(createConnectionContext);

        }


While trying to debug further for the root cause of the problem i see that when CreateConnectionFeature is trying to create the business object for sequence flow the eResource value for source pictogramelement (StartEvent in this case ) is still 'null' hence it's failing with NullPointerException.
Ideally after create has been called for StartEvent/EndEvent via createfeature then this value shouldn't be null.
Another point when it's checked
((org.eclipse.bpmn2.StartEvent)(EObject) startEvent[0]).eResource()
ofc the value is returned 'null' but if you try to fetch the eResource for ex. as following then value is not 'null'.
Resource startEventResource = ExtendedPropertiesAdapter.getResource((EObject) startEvent[0]);

Not sure why AbstractBpmn2CreateConnection feature does not use fallback mechanism for finding eReource when it's not available to the BusinessObject directly.

StackTrace
java.lang.NullPointerException
at org.eclipse.bpmn2.modeler.core.adapters.ExtendedPropertiesAdapter.adapt(ExtendedPropertiesAdapter.java:186)
at org.eclipse.bpmn2.modeler.core.model.Bpmn2ModelerFactory.createObject(Bpmn2ModelerFactory.java:344)
at org.eclipse.bpmn2.modeler.core.model.Bpmn2ModelerFactory.createObject(Bpmn2ModelerFactory.java:337)
at org.eclipse.bpmn2.modeler.core.features.AbstractBpmn2CreateConnectionFeature.createBusinessObject(AbstractBpmn2CreateConnectionFeature.java:255)
at org.eclipse.bpmn2.modeler.core.features.flow.AbstractCreateFlowFeature.createBusinessObject(AbstractCreateFlowFeature.java:164)
at org.eclipse.bpmn2.modeler.core.features.flow.AbstractCreateFlowFeature.create(AbstractCreateFlowFeature.java:90)
at org.eclipse.bpmn2.modeler.ui.features.flow.SequenceFlowFeatureContainer$CreateSequenceFlowFeature.create(SequenceFlowFeatureContainer.java:239)

Could you please suggest of anything is wrong here in the sequence of calls, to me it seems to be a regression since same code was working fine so far untill Mars.1.
--
Thanks and Regards,
Bhuvan Mehta
Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726120 is a reply to message #1726110] Wed, 09 March 2016 20:16 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

I don't understand how this was working before because a CreateConnectionContext requires both source/target Anchors as well as source/target PictogramElements (!?)
May I suggest the following code for creating your source/target Anchors?

			CreateConnectionContext cc = new CreateConnectionContext();
			PictogramElement source; // the source shape
			PictogramElement target; // the target shape

			Point sp = GraphicsUtil.getShapeCenter((AnchorContainer)source);
			Point tp = GraphicsUtil.getShapeCenter((AnchorContainer)target);
			FixPointAnchor sourceAnchor = AnchorUtil.createAnchor((AnchorContainer)source, tp);
			FixPointAnchor targetAnchor = AnchorUtil.createAnchor((AnchorContainer)target, sp);
			cc.setSourcePictogramElement(source);
			cc.setTargetPictogramElement(target);
			cc.setSourceAnchor(sourceAnchor);
			cc.setTargetAnchor(targetAnchor);


BTW, you may want to investigate the <toolPalette> extension element for your plugin - this allows you to define tool palette items that construct arbitrary sequences of activities, events and gateways without having to write Java code. See the "Workflow Patterns" tool drawer for examples.
Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726124 is a reply to message #1726120] Wed, 09 March 2016 20:34 Go to previous messageGo to next message
Bhuvan Mehta is currently offline Bhuvan MehtaFriend
Messages: 58
Registered: July 2009
Member
Hello Bob,

Thanks for the reply.
Sorry i somehow missed that part of that coding while pasting snippet here. That's more or less similar to what you have also suggested that both Anchor and pictogramElement are required to be set
and looks as following
    	final CreateConnectionContext createContext = new CreateConnectionContext();
        createContext.setSourceAnchor(getAnchor(source, true));
        createContext.setTargetAnchor(getAnchor(target, false));
        createContext.setSourcePictogramElement(getFeatureProvider().getPictogramElementForBusinessObject(source));
        createContext.setTargetPictogramElement(getFeatureProvider().getPictogramElementForBusinessObject(target));
        final ICreateConnectionFeature createConnectionFeature = new SequenceFlowFeatureContainer().getCreateConnectionFeature(getFeatureProvider());
        final Connection connection = createConnectionFeature.create(createContext);
        (SequenceFlow) getFeatureProvider().getBusinessObjectForPictogramElement(connection);


I also tried the proposed snippet from your side and unfortunately that also is not working and reason being the same that after creation of events the eResource value is still null so when sequenceflow is being tried for creation it finds null value for source pictogramelement's eResource.

The same code (ofc setting Anchor and pictogramelement) was working so far with Mars.1 and only failing with latest update. Have re ensured the same with my old eclipse installation.

--
Thanks and Regards,
Bhuvan Mehta
Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726132 is a reply to message #1726124] Wed, 09 March 2016 22:47 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

Hmm, are you sure that your create feature for start/end events is actually adding the model object to the Definitions root hierarchy? Check to make sure that the eContainer of your created StartEvent and EndEvent objects is not null. If it is, then the objects were not correctly inserted into their respective containers (a FlowElementsContainer).
Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726136 is a reply to message #1726132] Thu, 10 March 2016 00:42 Go to previous messageGo to next message
Bhuvan Mehta is currently offline Bhuvan MehtaFriend
Messages: 58
Registered: July 2009
Member
Hello Robert,

How can one ensure that objects are correctly inserted into their respective container.
In my opinion if one is calling create for a business object via create feature and create context that should be sufficient and do the job , isn't it?

Hence in the similar fashion we have been calling the java APIs and same was working fine so far and suddenly doesn't work with new updates from Mars.2.
This means surely something has changed in the sequence of executing theses APIs across releases which causes the issue now.

Do you see an issue in fashion APIs are are called or their sequence which needs change? (As per my initial code snippet or the one suggested by you as well)

Could you please help us regarding the same?

--
Thanks and Regards,
Bhuvan Mehta
Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726245 is a reply to message #1726136] Thu, 10 March 2016 17:30 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

You are correct, the createFeature should insert the new object (Start and End Events in this case) into the model. I'm not sure what happened from Mars.1 to Mars.2 but as a quick fix I can change AbstractBpmn2CreateConnectionFeature.getResource() so that it calls ExtendedPropertiesAdapter.getResource(pe). This will traverse the Graphiti object up to its ResourceSet, and then look for a BPMN2 Resource within that ResourceSet.

I've just created a bugzilla report here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=489375

A new nightly build is on its way...
Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726248 is a reply to message #1726245] Thu, 10 March 2016 17:40 Go to previous messageGo to next message
Bhuvan Mehta is currently offline Bhuvan MehtaFriend
Messages: 58
Registered: July 2009
Member
Hello Robert,

Thanks for the reply and quick solution proposal.
Do let us know once we have the fix available in p2 repo site , will update and let know if it does work as needed.
Ofc it would be interesting to know what exactly changed which caused change in behavior here.
--
Thanks and Regards,
Bhuvan Mehta
Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726249 is a reply to message #1726248] Thu, 10 March 2016 17:42 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

We have a new nightly build here:

http://download.eclipse.org/modeling/mdt/bpmn2/updates/nightly/mars

can you give that a try to see if it fixes this problem?
Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726252 is a reply to message #1726249] Thu, 10 March 2016 17:57 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

Can you please tell me the build number of the Mars.1 version that did not have this bug? I'll see if I can track down the root cause of this regression...
Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726258 is a reply to message #1726252] Thu, 10 March 2016 18:50 Go to previous messageGo to next message
Bhuvan Mehta is currently offline Bhuvan MehtaFriend
Messages: 58
Registered: July 2009
Member
Hello Robert,

Thanks for the update, Well it does work but only to some extent and not completely. Sad
To explain what i mean
- While dragging and dropping the custom shape (Participant with start and end event connected via sequence flow) it gets drawn on graphical editor and no exception is seen at the movement. So far so good. (Improvement from earlier)
- But now when i close and open the editor again, then only container shape (participant) is seen and StartEvent, EndEvent, SequenceFlow are gone missing.
- also on Editor open i get an pop-up stating Import Errors as
"BPMNEdge id="BPMNEdge_SequenceFlow_5": The referenced BPMN element does not exist".


- If i try for deletion of either of event or sequence flow after dropping custom shape then there's a exception thrown stating unsupported operation and may be root of the problem is same.
when i draw these shapes manually within participant and try to delete then there's no such error thrown.

java.lang.UnsupportedOperationException
	at org.eclipse.bpmn2.impl.EventImpl.getIncomingConversationLinks(EventImpl.java:91)
	at org.eclipse.bpmn2.impl.EventImpl.eIsSet(EventImpl.java:197)
	at org.eclipse.bpmn2.impl.CatchEventImpl.eIsSet(CatchEventImpl.java:402)
	at org.eclipse.bpmn2.impl.StartEventImpl.eIsSet(StartEventImpl.java:153)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eIsSet(BasicEObjectImpl.java:1241)
	at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.hasNext(EContentsEList.java:437)
	at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.next(EContentsEList.java:595)
	at org.eclipse.emf.ecore.util.EcoreUtil$CrossReferencer.handleCrossReference(EcoreUtil.java:1794)
	at org.eclipse.emf.ecore.util.EcoreUtil$CrossReferencer.crossReference(EcoreUtil.java:1770)
	at org.eclipse.emf.ecore.util.EcoreUtil$UsageCrossReferencer.findAllUsage(EcoreUtil.java:2677)
	at org.eclipse.emf.ecore.util.EcoreUtil$UsageCrossReferencer.findAll(EcoreUtil.java:2736)
	at org.eclipse.emf.ecore.util.EcoreUtil.delete(EcoreUtil.java:3423)
	at org.eclipse.graphiti.ui.features.DefaultDeleteFeature.deleteBusinessObject(DefaultDeleteFeature.java:188)
	at org.eclipse.graphiti.ui.features.DefaultDeleteFeature.deleteBusinessObjects(DefaultDeleteFeature.java:173)
	at org.eclipse.graphiti.ui.features.DefaultDeleteFeature.delete(DefaultDeleteFeature.java:146)


So looks like current fix got sequence flow creation working but root of the problem lies some where else probably with Event shapes creation itself and that's the reason bpmn model is not in consistent state and reports problems.

Build ID for Mars.1 where functionality was working is : 4.4.2-201502041700
for ex. which contains following time-stamped built jar for bpmn bundles
org.eclipse.bpmn2.modeler.ui_1.2.1.201507081507.jar
org.eclipse.bpmn2.modeler.core_1.2.1.201507081507.jar
and graphiti of following timestamp.
org.eclipse.graphiti.ui_0.12.1.v20150916-0905.jar

Do let me know if any info is needed for further debugging and solving the problem.

--
Thanks and Regards,
Bhuvan Mehta


Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726272 is a reply to message #1726258] Thu, 10 March 2016 21:37 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

Maybe the problem lies with the createdParticipant object. In order for the create methods to correctly insert the flow elements (start/end events and your sequence flow) they need a FlowElementsContainer; Participant is not a FlowElementsContainer, but the Process object it references is. Can you check if the Participant.processRef is non-null (i.e. it should reference a Process that was created previously and inserted into the Definitions root element.
Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726352 is a reply to message #1726272] Fri, 11 March 2016 18:10 Go to previous messageGo to next message
Bhuvan Mehta is currently offline Bhuvan MehtaFriend
Messages: 58
Registered: July 2009
Member
Hello Robert,

Your suspect seems to be correct. It looks like the problem existed with participant creation, as even when i comment out code for adding event and sequence flow within participant i see created participant is not in consistent state.

After going thru you suggestion and debugging the code further i figured out that
- After creating the participant we were creating process object as well so that it can be set as process ref but adding this process ref into definitions root element specifically wasn't there so far.
Hence i added the following line of code for adding the process object into definition root element.

            ModelHandler.getInstance(getDiagram()).getDefinitions().getRootElements().add(process);


This seems to be helping and now i can see the participant object getting created properly and even the another custom code for adding events and sequence flow under it seems to be ok now.
Wondering how this was still working earlier without adding process into definition root element, may be somewhere underneath it was being taken care of automatically which is not the case now.
I will test it further to ensure it does work consistently without any issues, will let you know if any problem.

Thanks a lot for your support.. Smile


--
Thanks and Regards,
Bhuvan Mehta
Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726353 is a reply to message #1726352] Fri, 11 March 2016 18:34 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

There was a problem with adding Participants that has since been fixed: I don't recall all the details, but if the diagram contained only a single Process, and a new Pool (Participant) was added, the original Process was incorrectly added to the Participant.processRef (I think!) What should have been happening (and this has been fixed now) is that a Collaboration element is created and a Participant for the original Process was added; then the new Participant for the Pool was created and added to the Collaboration. I hope all this makes sense, because I'm getting confused just trying to explain it Wink

Anyway, I'm glad it's starting to work again.

Can you explain exactly WHAT you are trying to do with the editor? Why are you writing all this code to mess around with the model? Maybe I can suggest an alternative...

Cheers,
Bob
Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726355 is a reply to message #1726353] Fri, 11 March 2016 18:45 Go to previous messageGo to next message
Bhuvan Mehta is currently offline Bhuvan MehtaFriend
Messages: 58
Registered: July 2009
Member
Hello Bob,

Interesting bug, i hope i have understood it correctly. Smile

Ok use case is simple, a custom handy Participant (Pool) shape for user which comes pre-loaded Start Event and Event connected via Sequence flow.

Not much of tempering but since all this participant, process pool creation, reference attachment and addition to collaboration/root element doesn't happen automatically hence i guess it's required to write the code that way. If there's an optimization possibility or something which can be used out of the box for a participant (pool) creation which takes care of all this then would be happy to know that.
Ofc if flexibility of adding more shape which are connected and added by default to created Participant (Pool) then it would be ice on the cake.. Wink

--
BR,
Bhuvan
Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726565 is a reply to message #1726355] Mon, 14 March 2016 16:58 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

Well, as I mentioned earlier, there is another (easier!) way to do this. Have a look at this screencast:

http://www.screencast.com/users/BobBrodt/folders/Jing/media/b400faee-4b20-4274-88ff-4b40207bc0d1

Also, take a look at the Extension Points document for BPMN2 Modeler here:

https://wiki.eclipse.org/BPMN2-Modeler/ExtensionPoints

and let me know if you have questions.

BTW, there are also other screencasts that demonstrate some of the advanced features, here:

http://www.screencast.com/users/BobBrodt/playlists/BPMN2%20Modeler%20Videos

[Updated on: Mon, 14 March 2016 17:00]

Report message to a moderator

Re: NPE While creating SequenceFlow between events after Mars.2 update [message #1726652 is a reply to message #1726565] Tue, 15 March 2016 11:14 Go to previous message
Bhuvan Mehta is currently offline Bhuvan MehtaFriend
Messages: 58
Registered: July 2009
Member
Hello Robert,

Thanks for the response and sharing links.
Looks promising, we will try out the example/articles as suggested and get back with feedback. Smile

--
Thanks and Regards,
Bhuvan Mehta
Previous Topic:Creating new features in my elements for some actions
Next Topic:open wizard bpmn2
Goto Forum:
  


Current Time: Tue Dec 03 02:46:01 GMT 2024

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

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

Back to the top