Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BPMN 2.0 Modeler » MessageFlow in BPMN 2.0 Modeler(Issues in access in BPMN 2.0 models programatically)
MessageFlow in BPMN 2.0 Modeler [message #1427665] Sat, 20 September 2014 15:37 Go to next message
Mahmood Ahmad is currently offline Mahmood AhmadFriend
Messages: 10
Registered: September 2014
Junior Member
Hi,

I was recently advised to try out org.eclipse.bpmn2.modeler.examples.modelreader in order to be able to access model elements through a simple Java programme. The example code accessed and displayed all the elements except MessageFlow elements between elements in two pools. The MessageFlow elements are not accessed although I have also added the following two lines in the code (the code is included for my adaptation of the modelreader.java file from Modeler example).

import org.eclipse.bpmn2.MessageFlow;
import org.eclipse.bpmn2.impl.MessageFlowImpl;

Having designed a test .bpmn file (a collaboration BPMN 2.0 diagram) with one message flow between two pools , my test java program is not able to show the MessageFlow instance which I except to see for the only message flow in .bpmn file. The bpmn file testMessageFlow.bpmn is also attached.

I need a direction here to understand what the problem is behind this.

Your advice, I'll appreciate.

Regards
MA

Package my.package.info

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import org.eclipse.bpmn2.Definitions;
import org.eclipse.bpmn2.FlowElement;
import org.eclipse.bpmn2.RootElement;
import org.eclipse.bpmn2.SequenceFlow;
import org.eclipse.bpmn2.MessageFlow;
import org.eclipse.bpmn2.impl.MessageFlowImpl;
import org.eclipse.bpmn2.impl.SequenceFlowImpl;
import org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.XMLResource;


public class MyBPMN2ModelReader {
	public void ReadThisModel(String theBPMNFile) throws IOException {
		URI uri = URI.createURI(theBPMNFile);
		//URI uri = URI.createURI("SampleProcess.bpmn");
		Bpmn2ResourceFactoryImpl resFactory = new Bpmn2ResourceFactoryImpl();
		Resource resource = resFactory.createResource(uri);
		
		// We need this option because all object references in the file are "by ID"
		// instead of the document reference "URI#fragment" form.
		HashMap<Object, Object> options = new HashMap<Object, Object>();
		options.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true);
		
		// Load the resource
		resource.load(options);
		
		// This is the root element of the XML document
		Definitions d = getDefinitions(resource);

		// Print all elements contained in all Processes found
		List<RootElement> rootElements = d.getRootElements();
		for (RootElement re : rootElements) {
			if (re instanceof org.eclipse.bpmn2.Process) {
				org.eclipse.bpmn2.Process process = (org.eclipse.bpmn2.Process) re;
				System.out.println("Process: name="+process.getName()+" ID="+process.getId());
				for (FlowElement fe : process.getFlowElements()) {
					if (fe instanceof MessageFlowImpl) {
						MessageFlow mf = ((MessageFlow) fe);
						System.out.println("Message flow found.");
					}
					if (fe instanceof SequenceFlowImpl) {
						SequenceFlow sf = ((SequenceFlow) fe);
						if (sf != null) {
							String source = "";
							String target = "";
							if (sf.getSourceRef() != null)
								source = sf.getSourceRef().getId();
							if (sf.getTargetRef() != null)
								target = sf.getTargetRef().getId();
							System.out.println("Sequence Flow: " + source + " -> " + target);
						}
					}
					else {
						System.out.println(fe.eClass().getName()+": name="+fe.getName()+" ID="+fe.getId());
					}
				}

			}
		}
	}
	
	private static Definitions getDefinitions(Resource resource) {
		if (resource!=null && !resource.getContents().isEmpty() && !resource.getContents().get(0).eContents().isEmpty()) {
			// Search for a Definitions object in this Resource
			for (EObject e : resource.getContents()) {
				for (Object o : e.eContents()) {
					if (o instanceof Definitions)
						return (Definitions) o;
				}
			}
		}
		return null;
	}
}


And the test code is:
import java.io.IOException;
public class MyBPMN2ModelReaderTest {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		MyBPMN2ModelReader myReader = new MyBPMN2ModelReader();
		myReader.ReadThisModel("testMessageFlow.bpmn");
	}
}
Re: MessageFlow in BPMN 2.0 Modeler [message #1427666 is a reply to message #1427665] Sat, 20 September 2014 15:40 Go to previous messageGo to next message
Mahmood Ahmad is currently offline Mahmood AhmadFriend
Messages: 10
Registered: September 2014
Junior Member
Hi,

Adding to the above post, the console output is:

Process: name=Initiating Process ID=Process_1
StartEvent: name= ID=StartEvent_1
SendTask: name=Send a message to Pool B ID=SendTask_1
Sequence Flow: StartEvent_1 -> SendTask_1
EndEvent: name= ID=EndEvent_1
Sequence Flow: SendTask_1 -> EndEvent_1
Process: name=PoolB ID=Process_3
StartEvent: name= ID=StartEvent_2
ReceiveTask: name=Receive message from Pool A ID=ReceiveTask_1
Sequence Flow: StartEvent_2 -> ReceiveTask_1
EndEvent: name= ID=EndEvent_2
Sequence Flow: ReceiveTask_1 -> EndEvent_2

Note: There is no print line statement indicating that the reader encountered a MessageFlow element.
Re: MessageFlow in BPMN 2.0 Modeler [message #1428244 is a reply to message #1427666] Sun, 21 September 2014 14:25 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 Mahmood,

MessageFlows are not contained in the Process, but rather in the Collaboration (or Choreography) element. See org.eclipse.bpmn2.Collaboration#getMessageFlows()

Cheers,
Bob
Re: MessageFlow in BPMN 2.0 Modeler [message #1428384 is a reply to message #1428244] Sun, 21 September 2014 19:28 Go to previous messageGo to next message
Mahmood Ahmad is currently offline Mahmood AhmadFriend
Messages: 10
Registered: September 2014
Junior Member
Thanks Bob,

I now have a related query:

I tried to programme and get some print statements for MessageFlow which is defined within the Collaboration root element.

To my code I added the following block (please assume that all the imports are properly made in the java code):

for (RootElement re : rootElements) {
			if (re instanceof Collaboration) {
				Collaboration co = (Collaboration) re;
				System.out.println("Collaboration: name = " + co.getName() +
						" ID = " + co.getId() + "\n");
				for(MessageFlow mf : co.getMessageFlows()) {
					System.out.println("Message Flow: = " + mf.getName());
					InteractionNode src = mf.getSourceRef();
					InteractionNode targ = mf.getTargetRef();
					System.out.println("Source = " + src.toString());
					System.out.println("Target = " + targ.toString());
					List<ConversationLink> srcLinks = src.getOutgoingConversationLinks(); // UnsupportedOperationException line.
					List<ConversationLink> tarLinks = targ.getIncomingConversationLinks();
	 				for(ConversationLink cl : srcLinks) {
						System.out.println("Source = " + cl.getName());
	 				}
	 				for(ConversationLink cl : tarLinks) {
						System.out.println("Target = " + cl.getName());
	 				}
				}
			}
                // .... further code for other elements.
}


I was able to get the source and target for MessageFlow (with null as name, I did not name it), but the string was rather a long one. I wanted only the nodes, so I tried to obtain ConversationLinks but that created an exception (output with error is below).

[Console output starts here]
Collaboration: name = Default Collaboration ID = Collaboration_1
Exception in thread "main"
Message Flow: = null
Source = org.eclipse.bpmn2.impl.InteractionNodeImpl@72d1ad2e (eProxyURI: testMessageFlow.bpmn#SendTask_1)
Target = org.eclipse.bpmn2.impl.InteractionNodeImpl@2d7275fc (eProxyURI: testMessageFlow.bpmn#ReceiveTask_1)
java.lang.UnsupportedOperationException
at org.eclipse.bpmn2.impl.InteractionNodeImpl.getOutgoingConversationLinks(InteractionNodeImpl.java:89)
at org.uwe.serg.eia.bpa.bpmn2.MyBPMN2ModelReader.ReadThisModel(MyBPMN2ModelReader.java:64)
at org.uwe.serg.eia.bpa.bpmn2.MyBPMN2ModelReaderTest.main(MyBPMN2ModelReaderTest.java:23)
[End of console output]

My assumptions about use of ConversationLinks have problems, because the source code of my .bpmn file does not have such links.

Any further advice on this? Thanks for your time.

Regards
Mahmood
Re: MessageFlow in BPMN 2.0 Modeler [message #1428844 is a reply to message #1428384] Mon, 22 September 2014 12:49 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, that's odd...the only way this exception can be thrown is if the src object is not contained in a Resource. See org.eclipse.bpmn2.impl.InteractionNodeImpl.getOutgoingConversationLinks()
I'm afraid the only way to figure out what's going on here is to debug your way through this code and inspect the object hierarchy and its containments.

The features "incomingConversationLinks" and "outgoingConversationLinks" are TRANSIENT, meaning that the XML loader will populate these values when the model is loaded, but will not save them. So, you should NOT see them in your XML file.

[Updated on: Mon, 22 September 2014 12:55]

Report message to a moderator

Re: MessageFlow in BPMN 2.0 Modeler [message #1429581 is a reply to message #1428844] Tue, 23 September 2014 12:26 Go to previous messageGo to next message
Mahmood Ahmad is currently offline Mahmood AhmadFriend
Messages: 10
Registered: September 2014
Junior Member
Thanks Bob,

But I expect my program to be able to capture them, although they are not visible in my .bpmn source. The Correlation example in the BPMN 2.0 By Example document (from OMG) website, the xml code indicates conversations with MessageFlowRefs, still the ConversationLinks are not seen (referring to XML on pages 31-34 of document). This is an example of Conversation within Collaboration and is too complex.

My example model is far too simple. I shall now do some debugging to see if I can see them as you kindly prescribed, and will come back for further discussion.

Regards
Mahmood
Re: MessageFlow in BPMN 2.0 Modeler [message #1441230 is a reply to message #1428844] Thu, 09 October 2014 12:28 Go to previous messageGo to next message
Mahmood Ahmad is currently offline Mahmood AhmadFriend
Messages: 10
Registered: September 2014
Junior Member
Dear Bob,

Apologies for an absence as I needed to attend to some other aspects of my research. I tried debugging the MessageFlow's SourceRef and TargetRef problem. I am still unable to retrieve information about the SourceRef and TargetRef. Most notably I noted the sourceID of the only messageflow in my bpmn model placed in SourceRef -> eProperties -> eProxyURI -> fragment.

Is this normal? What would be the best way to retrieve this SourceRef in this case? I attach my model as well my classes .java file.

I am interested to resolve this as the solution may open some interesting opportunities that use message-flows and their related information in BPMN 2/0 models.

Thanking in anticipation,

Mahmood
Re: MessageFlow in BPMN 2.0 Modeler [message #1442066 is a reply to message #1441230] Fri, 10 October 2014 15:12 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 Mahmood,

When the model is loaded, these references are initialized as proxies; the easiest way to resolve these is to simply do an eGet(), so messageFlow.getSourceRef() should resolve the proxy and populate the messageFlow.sourceRef feature.

HTH,
Bob
Re: MessageFlow in BPMN 2.0 Modeler [message #1446822 is a reply to message #1442066] Fri, 17 October 2014 11:08 Go to previous messageGo to next message
Mahmood Ahmad is currently offline Mahmood AhmadFriend
Messages: 10
Registered: September 2014
Junior Member
Dear Bob,

Thank you for your advice. I have been trying to use eGet() but need a full understanding of it. The eGet() function needs EStructuralFeature as its argument and I need a way to specify it. I have experienced a similar issue with accessing the ProcessRef information of Participant instance within Collaboration in BPMN 2.0 model. And I think the solution lies in the basic understanding of how EMF implements features and the mechanisms to access those features. This is indeed different from directly retrieving the flow elements within a particular Process instance of BPMN 2.0 model.

Among the more recent attempts for resolving the ProcessRef from a Participant instance, I tried the following Java code:

for (RootElement re : rootElements) {
			if (re instanceof Collaboration) {
				Collaboration co = (Collaboration) re;
				System.out.println("Collaboration: name = " + co.getName() +
						" ID = " + co.getId() + "\n");
				//System.out.println("Completed adding collaboration to instantiated ontology.");
				for(Participant pt : co.getParticipants()) {
					System.out.println("Participant = " + pt.getId());
                                       org.eclipse.bpmn2.Process procRef = pt.getProcessRef(); // The getId() call to this ProcessRef does not return a Procee Id
		                       String pRefId = ""; //NullpointerException is because of this line.
// I have written the following code to understand how I can use eGet function that takes EStructuralFeature, but I need a way to specify the correct EStructuralFeature to access the processRef of Participant. This code results in exception.
		                       EObject eObject = (EObject) pt.getProcessRef();
		                       EList<EStructuralFeature> allFeatures = eObject.eClass().getEAllStructuralFeatures();
		                      for(EStructuralFeature esf : allFeatures)
		                          {
		                          Object o = eObject.eGet(esf);
		                          System.out.println("Class of Object o = " + o.getClass().getName());
		                         If(o instanceof String)
		                            {
		                               pRefId = (String) o; // Because o is one of the EList and not a String instance, I should not see anything but a NullPointerException as pRefId is set to null (pRefId = "";)
		                            }
		                        }
				}
			}
		}

Runtime error:
Class of Object o = org.eclipse.emf.ecore.util.EObjectContainmentEList
Class of Object o = org.eclipse.emf.ecore.util.EObjectContainmentEList
Class of Object o = org.eclipse.emf.ecore.util.EObjectResolvingEList
Exception in thread "main" java.lang.NullPointerException
at org.uwe.serg.bpmn20.ont.TestBPMModelsInBPMN20Ontology.AddParticipantToOntology(TestBPMModelsInBPMN20Ontology.java:1704)
at org.uwe.serg.bpmn20.ont.TestBPMModelsInBPMN20Ontology.InstantiateOntologyWithCollaboration(TestBPMModelsInBPMN20Ontology.java:171)
at org.uwe.serg.bpmn20.ont.TestBPMModelsInBPMN20Ontology.ReadModelIntoOnt(TestBPMModelsInBPMN20Ontology.java:102)
at org.uwe.serg.bpmn20.ont.TestBPMModelsInBPMN20Ontology.main(TestBPMModelsInBPMN20Ontology.java:87)
[Program aborted]

Now, obviously, contrary to my expectation, all EStructuralFeature objects are ELists. My question is how to resolve and get the ProcessRef object that is given in the BPMN XML codes as follows:

<bpmn2:collaboration id="_Collaboration_2" name="Handle a patient general reception">
    <bpmn2:participant id="Patient" name="Patient" processRef="CP1"/>
    <bpmn2:participant id="Participant_1" name="Receptionist" processRef="R"/>
    <bpmn2:messageFlow id="MessageFlow_3" name="Request for appointment" sourceRef="SendTask_2" targetRef="ReceiveTask_4"/>
    <bpmn2:messageFlow id="MessageFlow_5" name="Information to visit specialist" sourceRef="SendTask_3" targetRef="ReceiveTask_2"/>
    <bpmn2:messageFlow id="MessageFlow_2" name="Information to visit cancer detection unit" sourceRef="SendTask_4" targetRef="ReceiveTask_1"/>
    <bpmn2:messageFlow id="MessageFlow_6" name="Appointment made" sourceRef="ReceiveTask_5" targetRef="SendTask_1"/>
    <bpmn2:messageFlow id="MessageFlow_4" name="Patient transfer to emergency" sourceRef="SendTask_5" targetRef="ReceiveTask_3"/>
    <bpmn2:messageFlow id="MessageFlow_1" name="Request for appointment by phone" sourceRef="SendTask_1" targetRef="ReceiveTask_5"/>
  </bpmn2:collaboration>

Are the references to these objects present in one of the EList objects mentioned in the error/output stack? These were:
Class of Object o = org.eclipse.emf.ecore.util.EObjectContainmentEList
Class of Object o = org.eclipse.emf.ecore.util.EObjectContainmentEList
Class of Object o = org.eclipse.emf.ecore.util.EObjectResolvingEList

If yes, which one and how can I investigate that? Is this EObjectResolvingEList for ProcessRef object? My goal is to get the Id of that ProcessRef in String format.

I'd appreciate if you could help me understand it further and resolve this issue.

Regards
Mahmood

Re: MessageFlow in BPMN 2.0 Modeler [message #1452675 is a reply to message #1446822] Sat, 25 October 2014 18:24 Go to previous messageGo to next message
Mahmood Ahmad is currently offline Mahmood AhmadFriend
Messages: 10
Registered: September 2014
Junior Member
Hi Bob,

Please excuse my last email as you may not be happy with starting a ProcessRef topic within the MessageFlow problem. I am sorry but I have tried a few things to resolve the issues of accessing SourceRef and TargetRef in MessageFlow as well as ProcessRef problem in Participant, but all in vain.

My deadline is approaching and I am desperate to solve this issue....please if you could help!

In your last email you had indicated that I should eGet() the source/target references using the getSourceRef() and getTargetRef() functions of MessageFlows in order to resolve proxies. However, eGet seems to take some EStructuralFeature (esf) variable as its argument. How can I get that esf? This seems to be the org.eclipse.emf.core concept which I am not familiar with.

Within my code, I am able to get mf.getSourceRef() as the source InteractionNode, but I do not how to resolve proxies in them. The eGet() function needs to get an argument EStructuralFeature which I do not know how to get for my BPMN 2 model.

Is there some documentation that I can read to get the eGet() return the source ref of the messageFlow?

Please could you guide further?

Regards
Mahmood
Re: MessageFlow in BPMN 2.0 Modeler [message #1454314 is a reply to message #1452675] Tue, 28 October 2014 08:23 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

The EStructuralFeatures are all defined in the Bpmn2Package, and should be available like so:

EStructuralFeature f = Bpmn2Package.eINSTANCE.getMessageFlow_SourceRef();

if my memory serves me. If you follow the code for eGet() for this feature, you'll eventually end up in the MessageFlow getSourceRef() method. There should be code in there that checks if the proxy has not been resolved yet and will do the resolution if necessary.

Remember: when in doubt, try something else until it works Wink
Re: MessageFlow in BPMN 2.0 Modeler [message #1695169 is a reply to message #1454314] Tue, 12 May 2015 12:48 Go to previous messageGo to next message
hou lu is currently offline hou luFriend
Messages: 1
Registered: May 2015
Junior Member
Hi Mahmood,

I am also facing the same problem regarding MessageFlow in a Collaboration. I want to know how you use the eGet method with an argument EStructuralFeature to solve the MessageFlow's SourceRef and TargetRef problem. I'm not familar with the EStructuralFeature and I don't know how to use it properly.Can you give some advise?
Thanks in advance.
Re: MessageFlow in BPMN 2.0 Modeler [message #1695182 is a reply to message #1695169] Tue, 12 May 2015 14:00 Go to previous message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

OK, let's everyone take a step back here...
I think the confusion is in the basic EMF API, and this may be my fault for assuming everyone is familiar with EMF. There are lots of tutorials and examples on how to use EMF - I suggest starting there.
Previous Topic:Delete SequenceFlow
Next Topic:Multiple target runtimes per project
Goto Forum:
  


Current Time: Fri Mar 29 13:22:09 GMT 2024

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

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

Back to the top