How to create IncomingRelations for requirements

Hi all,
I’m trying to automate the generation of links between requiments and (Logical) Components using python4capella, starting from an Assignment attribute included in the ReqIF file.
I managed the deletion of old links, but I didn’t succeded so far in the generation of new links. I realized that the only EObject defined in the model is the AbstractRelation, but the Java objects instantiated are CapelleIncomingRelation or CapellaOutgoingRelation. Is it possible to create it by python?

At ther beginnig I tried to code an AbstractRelation class, which of course doesn’t work because it is mapped to an abstract java class, while the concrete classes CapellaIncomingRelation/CapellaOutgoingRelation aren’t mapped to a corresponding EObject.


    class AbstractRelation(ReqIFElement):
        """
        """
        def __init__(self, java_object = None):
            """
            """
            if java_object is None:
                JavaObject.__init__(self, create_e_object("http://www.polarsys.org/kitalpha/requirements", "AbstractRelation"))
            elif isinstance(java_object, AbstractRelation):
                JavaObject.__init__(self, java_object.get_java_object())
            else:
                JavaObject.__init__(self, java_object)
 

any suggestion on how to proceed?
I would like also to know how to contribute to the Python4Capella project and share some additional classes for the simplified model.,

You can keep this Python class to declare common attributes and methods. You can remove the constructor or raise a ValueError in it:

    class AbstractRelation(ReqIFElement):
        """
        """
        def __init__(self, java_object = None):
            if java_object is None:
               raise ValueError("No matching EClass for this type")
            elif isinstance(java_object, AbstractRelation):
                JavaObject.__init__(self, java_object.get_java_object())
            else:
                JavaObject.__init__(self, java_object)

Then you need to use the EPackage nsURI where are defined CapellaIncomingRelation and CapellaOutgoingRelation:

    class CapellaIncomingRelation(AbstractRelation):
        """
        """
        def __init__(self, java_object = None):
            if java_object is None:
               JavaObject.__init__(self, create_e_object("http://www.polarsys.org/capella/requirements", "CapellaIncomingRelation"))
            elif isinstance(java_object, CapellaIncomingRelation):
                JavaObject.__init__(self, java_object.get_java_object())
            else:
                JavaObject.__init__(self, java_object)

and

    class CapellaOutgoingRelation(AbstractRelation):
        """
        """
        def __init__(self, java_object = None):
            if java_object is None:
               JavaObject.__init__(self, create_e_object("http://www.polarsys.org/capella/requirements", "CapellaOutgoingRelation"))
            elif isinstance(java_object, CapellaOutgoingRelation):
                JavaObject.__init__(self, java_object.get_java_object())
            else:
                JavaObject.__init__(self, java_object)

But the idea of the Python API for the requirement add-on is to hide this. I’m not sure yet how we will provide methods to add such links but it will be hidden like in the requirement.py file.

To contribute you can open a pull request, see github documentation. But the main idea of the Python API is to also simplify the underlying complexity of the Capella metamodel. Also to generate the Python API and tests we use the following specification model. To contribute new classes you probably need to contact Sophie on github to see if its relevant. For bug fixes, you can create a pull request and I’ll have a look at it and merge it when needed.

Thank you for the support. It worked! The capability of manipulating the model with python is giving a real valuable support to maintain the model aligned with DOORS. Just to share with you the concept. Below, there is a requirement imported in Capella. No links are defined towards the Logical Components. The assignment defines that the requirement should be allocated to a set of components.

image

After running the python script, this is what you get.
image

The next step will be to update the requirement Assignment attribute from the model links and export the requirements either in Excel or in ReqIF.

That’s the idea of providing a Python API, the second idea is to make it MBSE oriented and hide technical artifacts. We are still limited on setters, but it will be the next step. I’m glade to see people using it.