Hello,
I am interested in the OLD Requirements elements in Capella, theses ones:
I added a method into the Physical Archi Class to be able to COLLECT the > requirements Packages (pkg):
def get_reqPKG3(self):
“”"
“”"
return create_e_list(self.get_java_object().getOwnedRequirementPkgs(), RequirementPkg)
I do obtain a java list containing the requirements packages successfully:
print(se.get_physical_architecture().get_reqPKG3())
→ <main.JavaList object at 0x000001A011195648>
Then I got interested into getting the requirements pkgs that are INSIDE a requirement package:
- RequirementsPkg 1
- RequirementsPkg 2
I used direclty .getOwnedRequirementPkgs function :
print(se.get_physical_architecture().get_reqPKG3().get_java_object().get(j5).getOwnedRequirementPkgs())
→ [JavaObject id=o480, JavaObject id=o481]
It seems I am obtaining a LIST? Rather than a JavaList?
(get(j5) here gives me one of the packages that are direclty under the phys arch “Physical Requirement”, it’s class (org.eclipse.emf.ecore.impl.EClassImpl@c8d09e4 (name: RequirementsPkg) (instanceClassName: null) (abstract: false, interface: false))):
AS you can expect this does cause a problem, when trying to append / add an element into it and “modify” the model inside a transaction.
I obtain the the error message:
-----------object has no attribute ‘_get_object_id’-------------------
Wether i try to use “append(item)” or ".add(item), i would get that message error, here:
se.get_physical_architecture().get_reqPKG3().get_java_object().get(j5).getOwnedRequirementPkgs().add(j2b) #get_reqPKG_inPkg3
se.get_physical_architecture().get_reqPKG3().get_java_object().get(j5).getOwnedRequirementPkgs().append(j2b)
(j2b here is a requirementsPkg)
==>
Case of using add:
py4j.Py4JException: An exception was raised by the Python Proxy. Return Message: Traceback (most recent call last):
File “D:------\Capella 5.1 Test Python4 capella 4\capella\plugins\org.eclipse.ease.lang.python.py4j_0.7.0.I201907020902\pysrc\ease_py4j_main.py”, line 186, in runcode
exec(compiled, self.locals)
File “L/Python4Capella/NewScript/NewScript.py”, line 368, in
File “D:------\Capella 5.1 Test Python4 capella 4\capella\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\java_gateway.py”, line 1313, in call
args_command, temp_args = self._build_args(*args)
File “D:------\Capella 5.1 Test Python4 capella 4\capella\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\java_gateway.py”, line 1283, in _build_args
[get_command_part(arg, self.pool) for arg in new_args])
File “D:------\Capella 5.1 Test Python4 capella 4\capella\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\java_gateway.py”, line 1283, in
[get_command_part(arg, self.pool) for arg in new_args])
File “D:------\Capella 5.1 Test Python4 capella 4\capella\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\protocol.py”, line 298, in get_command_part
command_part = REFERENCE_TYPE + parameter._get_object_id()
AttributeError: ‘RequirementPkg’ object has no attribute ‘_get_object_id’During handling of the above exception, another exception occurred:
etc…
Case of using append:
py4j.Py4JException: An exception was raised by the Python Proxy. Return Message: Traceback (most recent call last):
File “D:-----\Capella 5.1 Test Python4 capella 4\capella\plugins\org.eclipse.ease.lang.python.py4j_0.7.0.I201907020902\pysrc\ease_py4j_main.py”, line 186, in runcode
exec(compiled, self.locals)
File “L/Python4Capella/NewScript/NewScript.py”, line 367, in
_pyease_sys.path.append(path)
File “D:-----\Capella 5.1 Test Python4 capella 4\capella\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\java_collections.py”, line 427, in append
self.add(value)
File “D:-----\Capella 5.1 Test Python4 capella 4\capella\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\java_gateway.py”, line 1313, in call
args_command, temp_args = self._build_args(*args)
File “D:-----\Capella 5.1 Test Python4 capella 4\capella\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\java_gateway.py”, line 1283, in _build_args
[get_command_part(arg, self.pool) for arg in new_args])
File “D:-------\Capella 5.1 Test Python4 capella 4\capella\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\java_gateway.py”, line 1283, in
[get_command_part(arg, self.pool) for arg in new_args])
File “D:-----\Capella 5.1 Test Python4 capella 4\capella\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\protocol.py”, line 298, in get_command_part
command_part = REFERENCE_TYPE + parameter._get_object_id()
AttributeError: ‘RequirementPkg’ object has no attribute ‘_get_object_id’During handling of the above exception, another exception occurred:
…etc
(Btw, I did create a class called (RequirementPkg) I don’t know if the problem comes from it =>
class RequirementPkg(CapellaElement):
#class RequirementPkg(EObject):
def __init__(self, java_object = None):
if java_object is None:
JavaObject.__init__(self, create_e_object("http://www.polarsys.org/capella/core/requirement/" + capella_version(), "RequirementsPkg"))
elif isinstance(java_object, requirements):
JavaObject.__init__(self, java_object.get_java_object())
else:
JavaObject.__init__(self, java_object)
def get_name(self):
"""
"""
return self.get_java_object().getName()
def set_name(self, value):
"""
"""
self.get_java_object().setName(value)
def get_reqPKG_inPkg3(self):
"""
"""
return create_e_list(self.get_java_object().getOwnedRequirementPkgs(), RequirementPkg
Strangely enough, this method (get_reqPKG_inPkg3) cannot be called here:
se.get_physical_architecture().get_reqPKG3().get_java_object().get(j5).get_reqPKG_inPkg3().add(j2b)
The error message states:
py4j.Py4JException: Method get_reqPKG_inPkg3([]) does not exist
So is seems that my get(j5) is the class i have created? I don’t see any other instance where that class was created though… (i checked on the capella.py, and all other py files)
I wonder where the problem could lie? @YvanLussaud Or any expert/competent on Python4Capella please.
Extra Edit:
I just noticed a problem;
The RequirementPkg I obtain with the code “get(j5)” does not provides me a java object, it’s rather get mt the RequirementsPkg in it’s pure form:
I obtain:
(org.polarsys.capella.core.data.requirement.impl.RequirementsPkgImpl@6b48f568 (id: 7c285582-4263-48e6-a6dd-398e558ffdbc, sid: null) (name: Physical Requirements) (visibleInDoc: true, visibleInLM: true, summary: null, review: null) (additionalInformation: null, level: null))
While I am expecting:
<main.RequirementPkg object at 0x0000023075A76748>
I thought i might get it with a “.get_java_object()” method, but all it gets me is an error message :
print(se.get_physical_architecture().get_reqPKG3().get_java_object().get(j5).get_java_object())
-> ...py4j.protocol.Py4JError: An error occurred while calling o471.get_java_object. Trace:
py4j.Py4JException: Method get_java_object([]) does not exist
End of edit.