Requirement.py with nest requirements folders

Hi there,
I’m using the APIs from P4C v1.2.0, and am finding that whenever I have requirements in a nested set of folders within a module, the requirements.py getter getOwnedRequirements() does not iterate through all folders. This means that the following methods fail to find all requirements within a module:

  1. RequirementsAddOn.get_incoming_requirements
  2. CapellaModule.get_owned_requirements.

Is this a bug, am I using the API incorrectly, or something else? I am currently getting around this by modifying the APIs to use get_all_contents_by_type and get_incoming_elements.

Thanks
Paul

Hi Paul,

RequirementsAddOn.get_incoming_requirements gives the list of requirements “incoming” from a CapellaElement thus it will return the list of requirements linked to the element:

CapellaModule.get_owned_requirements gives the directly owned requirements for a CapellaModule element and indeed this method is not a in-depth retrieval of the content of the CapellaModule.

If you want such an in-depth retrieval then you will have to write a recursive method also using the Folder.get_owned_requirements method.

Hope this helps.

Regards,
Arnaud

Hi Arnaud,
Many thanks for your response. I’m not finding the behaviour with RequirementsAddOn.get_incoming_requirements(capellaElement) as you describe - it doesn’t harvest all of the requirements linked to the element, but only those at the top level of the module (i.e. not those in folders). I had assumed this was because both this method and the Module.get_owned_requirements use the same java method getOwnedRequirements().
Thanks
Paul

Hi Paul,

I do not get the same behavior as you. I have used this script:

selected_elem = CapellaElement(CapellaPlatform.getFirstSelectedElement())
aird_path = '/'+ CapellaPlatform.getModelPath(selected_elem)

model = CapellaModel()
model.open(aird_path)

reqs = RequirementAddOn.get_incoming_requirements(selected_elem)
for req in reqs:
    print(str(req.get_chapter_name()) + ' ' + str(req.get_text()))

Method RequirementsAddOn.get_incoming_requirements(capellaElement) is available in the requirement.py file (https://github.com/labs4capella/python4capella/blob/master/plugins/Python4Capella/simplified_api/requirement.py).

If you look at the method (from line 44), its code does not rely on getOwnedRequirements().
Would it be possible that you are not using the right method ?

Regards,
Arnaud