Hi all,
I’m trying to use the method add to create a ConceptPkg with Concept in Operational Analysis layer but until now I’m not able to create. The mentioned object is found as following
I’ve added some lines under Operational Analysis class
def get_concept_pkg(self) -> ConceptPkg:
"""
Returns: OperationalCapabilityPkg
"""
value = self.get_java_object().getOwnedConceptPkg()
if value is None:
return value
else:
e_object_class = getattr(sys.modules["__main__"], "EObject")
specific_cls = e_object_class.get_class(value)
return specific_cls(value)```
then I've created some classes
class Concept(CapellaElement):
e_class = get_e_classifier("http://www.polarsys.org/capella/core/oa/" + capella_version(), "Concept")
def __init__(self, java_object = None):
if java_object is None:
JavaObject.__init__(self, create_e_object_from_e_classifier(self.e_class))
elif isinstance(java_object, Concept):
JavaObject.__init__(self, java_object.get_java_object())
elif self.e_class.isInstance(java_object):
JavaObject.__init__(self, java_object)
else:
raise AttributeError("Passed object is not compatible with " + self.__class__.__name__ + ": " + str(java_object))```
class ConceptPkg(PropertyValuePkgContainer):
e_class = get_e_classifier("http://www.polarsys.org/capella/core/oa/" + capella_version(), "ConceptPkg")
def __init__(self, java_object = None):
if java_object is None:
JavaObject.__init__(self, create_e_object_from_e_classifier(self.e_class))
elif isinstance(java_object, ConceptPkg):
JavaObject.__init__(self, java_object.get_java_object())
elif self.e_class.isInstance(java_object):
JavaObject.__init__(self, java_object)
else:
raise AttributeError("Passed object is not compatible with " + self.__class__.__name__ + ": " + str(java_object))
def get_owned_concept_pkgs(self) -> List[ConceptPkg]:
return create_e_list(self.get_java_object().getOwnedConceptPkgs(), ConceptPkg)
def get_owned_concepts(self) -> List[Concept]:
return create_e_list(self.get_java_object().getOwnedConcepts(), Concept)
class ConceptCompliance(Relationship):
e_class = get_e_classifier("http://www.polarsys.org/capella/core/oa/" + capella_version(), "ConceptCompliance")
def __init__(self, java_object = None):
if java_object is None:
JavaObject.__init__(self, create_e_object_from_e_classifier(self.e_class))
elif isinstance(java_object, ConceptCompliance):
JavaObject.__init__(self, java_object.get_java_object())
elif self.e_class.isInstance(java_object):
JavaObject.__init__(self, java_object)
else:
raise AttributeError("Passed object is not compatible with " + self.__class__.__name__ + ": " + str(java_object))
def get_comply_with_concept(self) -> List[Concept]:
return create_e_list(self.get_java_object().getComplyWithConcept(), Concept)
def get_compliant_capability(self) -> List[OperationalCapability]:
return create_e_list(self.get_java_object().getCompliantCapability, OperationalCapability)
Then I try to call these methods to create the objects:
include('workspace://Python4Capella/simplified_api/capella.py')
if False:
from simplified_api.capella import *
aird_path = '/In-Flight Entertainment System/In-Flight Entertainment System.aird'
model = CapellaModel()
model.open(aird_path)
se = model.get_system_engineering()
print(se.get_name())
model.start_transaction()
try:
# get operational analysis
oa = se.get_operational_analysis()
# create ConceptPkg instance and set name
concept_pkg = ConceptPkg()
concept_pkg.set_name("Concept Test")
#print(concept_pkg)
# add the ConceptPkg to operational analysis
# create Concept and set name
concept = Concept()
concept.set_name("Concept")
#print(concept)
# add the Concept to the ConceptPkg
oa.get_java_object().getOwnedConceptPkgs().add(concept_pkg.get_java_object())
concept_pkg.get_java_object().getOwnedConcepts().add(concept.get_java_object())
except:
# if something went wrong we rollback the transaction
model.rollback_transaction()
raise
else:
# if everything is ok we commit the transaction
model.commit_transaction()
model.save()
but I’ve missed something because I’ve able to create the relationship of ConceptPkg with Operational Analysis
org.eclipse.ease.ScriptExecutionException: Traceback (most recent call last):
File "workspace://Python4Capella/sample_scripts/concept_test.py", line 39, in <module>
if _pyease_sys.version_info.major == 2:
File "C:\Tools\Capella 6_1_0\capella\plugins\py4j-python_0.10.9.5-bnd-2odeag\src\py4j\java_gateway.py", line 1321, in __call__
return_value = get_return_value(
File "C:\Tools\Capella 6_1_0\capella\plugins\py4j-python_0.10.9.5-bnd-2odeag\src\py4j\protocol.py", line 330, in get_return_value
raise Py4JError(
py4j.protocol.Py4JError: An error occurred while calling o162.getOwnedConceptPkgs. Trace:
py4j.Py4JException: Method getOwnedConceptPkgs([]) 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 jdk.proxy12/jdk.proxy12.$Proxy25.executeScript(Unknown Source)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.internalExecute(Py4jScriptEngine.java:240)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.execute(Py4jScriptEngine.java:227)
at org.eclipse.ease.AbstractScriptEngine.inject(AbstractScriptEngine.java:189)
at org.eclipse.ease.AbstractScriptEngine.run(AbstractScriptEngine.java:242)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Thanks for any help with this