Hi everyone,
I’m beginner with python4capella and I’m trying to set the allocated operational activity,so to allocate it requires the “ownedfunctionalallocation of the entity”, for that I have started to write these lines below
class AbstractFunctionalBlock(CapellaElement):
"""
"""
def __init__(self, java_object = None):
if java_object is None:
JavaObject.__init__(self, create_e_object("http://www.polarsys.org/capella/core/fa/" + capella_version(), "AbstractFunctionalBlock"))
elif isinstance(java_object, AbstractFunctionalBlock):
JavaObject.__init__(self, java_object.get_java_object())
elif get_e_classifier("http://www.polarsys.org/capella/core/fa/" + capella_version(), "AbstractFunctionalBlock").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_functional_allocation(self):
"""
"""
value = self.get_java_object().getOwnedFunctionalAllocation()
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)
class Relationship(CapellaElement):
"""
"""
def __init__(self, java_object = None):
if java_object is None:
JavaObject.__init__(self, create_e_object("http://www.polarsys.org/capella/core/core/" + capella_version(), "Relationship"))
elif isinstance(java_object, Relationship):
JavaObject.__init__(self, java_object.get_java_object())
elif get_e_classifier("http://www.polarsys.org/capella/core/core/" + capella_version(), "Relationship").isInstance(java_object):
JavaObject.__init__(self, java_object)
else:
raise AttributeError("Passed object is not compatible with " + self.__class__.__name__ + ": " + str(java_object))
class Allocation(Relationship):
"""
"""
def __init__(self, java_object = None):
if java_object is None:
JavaObject.__init__(self, create_e_object("http://www.polarsys.org/capella/core/core/" + capella_version(), " Allocation"))
elif isinstance(java_object, Allocation):
JavaObject.__init__(self, java_object.get_java_object())
elif get_e_classifier("http://www.polarsys.org/capella/core/core/" + capella_version(), " Allocation").isInstance(java_object):
JavaObject.__init__(self, java_object)
else:
raise AttributeError("Passed object is not compatible with " + self.__class__.__name__ + ": " + str(java_object))
class AbstractFunctionAllocation(Allocation):
"""
"""
def __init__(self, java_object = None):
if java_object is None:
JavaObject.__init__(self, create_e_object("http://www.polarsys.org/capella/core/fa/" + capella_version(), "AbstractFunctionAllocation"))
elif isinstance(java_object, AbstractFunctionAllocation):
JavaObject.__init__(self, java_object.get_java_object())
elif get_e_classifier("http://www.polarsys.org/capella/core/fa/" + capella_version(), "AbstractFunctionAllocation").isInstance(java_object):
JavaObject.__init__(self, java_object)
else:
raise AttributeError("Passed object is not compatible with " + self.__class__.__name__ + ": " + str(java_object))
class ComponentFunctionalAllocation(AbstractFunctionAllocation):
"""
"""
def __init__(self, java_object = None):
if java_object is None:
JavaObject.__init__(self, create_e_object("http://www.polarsys.org/capella/core/fa/" + capella_version(), "ComponentFunctionalAllocation"))
elif isinstance(java_object, ComponentFunctionalAllocation):
JavaObject.__init__(self, java_object.get_java_object())
elif get_e_classifier("http://www.polarsys.org/capella/core/fa/" + capella_version(), "ComponentFunctionalAllocation").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_function(self):
"""
"""
value = self.get_java_object().getFunction()
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)
def get_block(self):
"""
"""
value = self.get_java_object().getBlock()
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 to instantiate the ownedFunctionalAllocation I call inside OperationalActor class as:
def get_owned_functional_allocation(self):
"""
"""
return create_e_list(self.get_java_object().getOwnedFunctionalAllocation(), OperationalActor)
Then to set the allocatedOperationalActivies I added the method as following:
def set_allocated_operational_activities(self, value):
"""
"""
return self.get_java_object().setAllocatedOperationalActivities(value.get_java_object())
Then for the test I have done as follows:
# include needed for the Capella modeller API
include('workspace://Python4Capella/simplified_api/capella.py')
if False:
from simplified_api.capella import *
# include needed for utilities
include('workspace://Python4Capella/utilities/CapellaPlatform.py')
if False:
from utilities.CapellaPlatform import *
# include needed for the requirement API
include('workspace://Python4Capella/simplified_api/requirement.py')
if False:
from simplified_api.requirement import *
aird_path = '/In-Flight Entertainment System/In-Flight Entertainment System.aird'
model = CapellaModel()
model.open(aird_path)
se = model.get_system_engineering()
model.start_transaction()
try:
for entity in se.get_all_contents_by_type(OperationalEntity):
print(entity.get_name())
for allocated in entity.get_allocated_operational_activities():
print(allocated.get_name())
for functional in entity.get_owned_functional_allocation():
print(functional)
entity.set_allocated_operational_activities(functional)
print("end")
except:
model.rollback_transaction()
raise
else:
model.commit_transaction()
model.save(
But at the end I can’t allocate operational activity to the entity. There is something I am not doing correctly but I don’t know what it’s exactly. In my perception the source element and target element are missing but in the ecore “ComponentFunctionalAllocation” I can’t find that relationship. Any idea how to assign operationalActivity to the entity?
Thanks in advance