setSourcePhysicalPort

Hi All,

I wonder if you can help me with an addition to the simplified capella api?

Ordinarily when attempting to set source ports onto an exchange (Functional or Component), we can use the following:

def set_source_port(self, value):
    """
    """
    return self.get_java_object().setSource(value.get_java_object())

I added the above to the component exchange class after using the sirius interpreter to check if that was the correct Java function. It was and it worked for component exchanges!

For Physical Links and setting physical source ports, the interpreter suggests that instead of ‘aql:self.source’ we use, ‘aql:self.sourcePhysicalPort’ to identify the source port.
As a result of this I’ve added the below function under the Physical Link class in the simplified capella api:

 def set_source_port(self, value):
     """
     """
     return self.get_java_object().setSourcePhysicalPort(value.get_java_object())

This does not work, and it’s the same for ‘setTargetPhysicalPort’. Can anyone help me with why this wouldn’t work or ways to fix it?

For reference, this is the error message (which indicates that it may not be included in a file that I cannot access):

org.eclipse.ease.ScriptExecutionException: Traceback (most recent call last):
File “L/Python4Capella/WIP/Exchange Link Accelerator/Road Map/EA Import Development/EA_Paste_PhysicalLinks.py”, line 133, in
File “L/Python4Capella/simplified_api/capella.py”, line 2598, in set_source_port
File “C:\Users\acook\Capella Suite\Capella 1.4.2\Capella 1.4.2\Capella 1.4.2\eclipse\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\java_gateway.py”, line 1322, in call
answer, self.gateway_client, self.target_id, self.name)
File “C:\Users\acook\Capella Suite\Capella 1.4.2\Capella 1.4.2\Capella 1.4.2\eclipse\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\protocol.py”, line 332, in get_return_value
format(target_id, “.”, name, value))
py4j.protocol.Py4JError: An error occurred while calling o1096.setSourcePhysicalPort. Trace:
py4j.Py4JException: Method setSourcePhysicalPort([class org.polarsys.capella.core.data.cs.impl.PhysicalPortImpl]) does not exist
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:326)
at py4j.Gateway.invoke(Gateway.java:274)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.ClientServerConnection.sendCommand(ClientServerConnection.java:244)
at py4j.CallbackClient.sendCommand(CallbackClient.java:384)
at py4j.CallbackClient.sendCommand(CallbackClient.java:356)
at py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:106)
at com.sun.proxy.$Proxy30.executeScript(Unknown Source)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.internalExecute(Py4jScriptEngine.java:236)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.execute(Py4jScriptEngine.java:226)
at org.eclipse.ease.AbstractScriptEngine.inject(AbstractScriptEngine.java:245)
at org.eclipse.ease.AbstractScriptEngine.run(AbstractScriptEngine.java:309)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

The trace suggest you called set_source_port() on a PhysicalPort instead of a PhysicalLink:

Method setSourcePhysicalPort([class org.polarsys.capella.core.data.cs.impl.PhysicalPortImpl]) does not exist

You should double check the type of the element you are calling the method from. Maybe you passed a Java PhysicalPort to the constructor of the Python class PhysicalLink ?

2 Likes

Hi Yvan,

Thanks for your speedy response!
You make a good point but I’m not sure how I’m calling a PhysicalPort. In the section of my script that is calling these functions I call the PhysicalLink() class here:

#prepare the link to be added
PL = PhysicalLink()
PL.set_name(Exchange_Name)
PL.set_source_port(PPS)
PL.set_target_port(PPT)

I’m attempting to assign the source (PPS) and target (PPT) target port to PL before I add it to the model. Any idea why it would then be trying the function/method for a port?

By looking at the Java API you should be able to use:

PL.get_java_object().getLinkEnds().add(PPS.get_java_object())
PL.get_java_object().getLinkEnds().add(PPT.get_java_object())

Source and target ports getters are derived from the links ends EReference.

1 Like

Fantastic thank you so much!

I tried to use ‘setLinkEnds’ but that didn’t work and I then ignored it.

This works perfectly, I massively appreciate your help Yvan!

1 Like