How to export/import VP requirements internal requirements alloc. with Py4C

Hi,
I would like to export (ideally import!) internal requirements allocation of a VP Requirement with Py4C:
Capture

I unsuccessfully try to use get_owned_relations() to export. could you help me?

thanks
dvd

The requirements API has been improved in version 1.1.0. With this version Requirement.get_owned_relations() should return a list of CapellaIncomingRelation and CapellaOutgoingRelation. You should be able to call get_source() and get_target().

I performed some tests.

get_source() always return MyRequirement and not incoming links of “Requirement Allocation”. get_target() always return the outgoing links of “Requirement Allocation” of MyRequirement
&
get_source() and get_target don’t work if the source (ie MyRequirement) and the target (an internal link toward another requirement) are requirements (internal requirements allocation)

I just had a look at the Capella metamodel and InternalRelation is an other type of AbstractRelation that is not supported currently. You can add the following class to the requirement.py file to support it:

class InternalRelation(AbstractRelation):
    """
    """
    def __init__(self, java_object = None):
        """
        """
        if java_object is None:
            JavaObject.__init__(self, create_e_object("http://www.polarsys.org/capella/requirements", "InternalRelation"))
        elif isinstance(java_object, CapellaOutgoingRelation):
            JavaObject.__init__(self, java_object.get_java_object())
        elif get_e_classifier("http://www.polarsys.org/capella/requirements", "InternalRelation").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_source(self):
        """
        """
        value = self.get_java_object().getSource()
        if value is None:
            return value
        else:
            return Requirement(value)
    def set_source(self, value):
        """
        """
        self.get_java_object().setSource(value.get_java_object())
    def get_target(self):
        """
        """
        value = self.get_java_object().getTarget()
        if value is None:
            return value
        else:
            return Requirement(value)
    def set_target(self, value):
        """
        """
        self.get_java_object().setTarget(value.get_java_object())

Thanks for your quick answer.
I added the class to the requirement.py.
This class prevents get_all_contents_by_type(Requirement) to execute:

I made a mistake the InternalRelation is in an other EPackage named requirements to. So the code of the class should be:

class InternalRelation(AbstractRelation):
    """
    """
    def __init__(self, java_object = None):
        """
        """
        if java_object is None:
            JavaObject.__init__(self, create_e_object("http://www.polarsys.org/kitalpha/requirements", "InternalRelation"))
        elif isinstance(java_object, InternalRelation):
            JavaObject.__init__(self, java_object.get_java_object())
        elif get_e_classifier("http://www.polarsys.org/kitalpha/requirements", "InternalRelation").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_source(self):
        """
        """
        value = self.get_java_object().getSource()
        if value is None:
            return value
        else:
            return Requirement(value)
    def set_source(self, value):
        """
        """
        self.get_java_object().setSource(value.get_java_object())
    def get_target(self):
        """
        """
        value = self.get_java_object().getTarget()
        if value is None:
            return value
        else:
            return Requirement(value)
    def set_target(self, value):
        """
        """
        self.get_java_object().setTarget(value.get_java_object())

Good Job :slight_smile:
it works!

see you
dvd

1 Like