Type Folders in P4C

I’m trying to create and add Capella Type Folders, enum data types, and data types to my model via P4C but realized that no developed classes are in-store for these elements. Is there a way to make a Capella module into a Capella Type Folder via eClass or any outside source that I can use to start developing types into my projects? Also, if anyone has any references to how to incorporate test cases and sets inside of Capella that would be appreciated. I found a nice way to set up test cases via the type folder and making modules as the test set, but I want to be able to just import a excel file and have it format it directly using this script.

Also is there a way to access a type folder and assign relationships and types to requirements and attributes?

If you are using the requirement addon, you can import requirement.py. It contains needed Python classes.

# include needed for the requirement API
include('workspace://Python4Capella/simplified_api/requirement.py')
if False:
    from simplified_api.requirement import *

There is no Python API at the moment to set Attribute to Requirement, but you can use the Java API:

attr = Attribute()
req.get_java_object().getOwnedAttributes().add(attr.get_java_object())

For the Type of a Folder you can use this Java API:

reqType = create_e_object("http://www.polarsys.org/kitalpha/requirements", "RequirementType")
attrDef = create_e_object("http://www.polarsys.org/kitalpha/requirements", "AttributeDefinition")
attrDef.setDefaultValue(attr.get_java_object())
reqType.getOwnedAttributes().add(attrDef)
folder.get_java_object().setRequirementType(reqType)

For testing I use the EASE test launcher but it might not be the best way to do this.

For Excel files, you can look at the import and export sample scripts.

Sweet, but I’m trying to not just create but to create and check if a Capella Type Folder is already created inside of an architecture and if not, create one and fill the requirement type inside. The biggest issue is trying to check for an object inside the architecture. I’m not sure how to search an architecture for an object that has no class in the Python API.

I was able to add a function to get Capella type folders from an architecture as a ReqIFElement, is there a way to cast/set it to a CapellaTypesFolder so I can use the java API functions for TypeFolder.

You can wrap a Java EObject (model element) using the EObject Python class then use the get_container_by_type method:

py_eobject = EObject(java_eobject)
logical_architecture = py_eobject.get_container_by_type(LogicalArchitecture)

Then you need to check the getOwnedExtensions() Java reference for the requirement Folder:

folder_e_class = get_e_classifier("http://www.polarsys.org/kitalpha/requirements", "Folder")
for extension in logical_architecture.get_java_object().getOwnedExtensions():
    if folder_e_class.isInstance(extension) and <corresponding type>:
        ....

Note that get_e_classifier() has been introduced in version 1.2.0 of Python4Capella.

Not sure to get your last question but you can find some documentation to pass from the Python object to Java object and vise versa here.

I see what you’re trying to tell me and I’m not sure if I’m being clear or if I’m not understanding, but in your example above, how can I use java methods for a class in the Java API for a class not in the Python API.
image
image


To describe what the pictures are representing, I’m trying to access CapellaTypeFolders and get the definitionTypes inside. I was able to make a method in RequirementAdd-on called (get_logical_type_folder) to get the JavaObject of the CapellaTypeFolder (Test Case Type) but I want to access the Java methods for it that I found with the interpreter. I’m not sure what I’m doing wrong but I’ve been playing around with the Java Object trying multiple ways to access these methods and have been unsuccessful.

If you have a Python Object for the Python4Capella API you can use:

my_object.get_java_object().myMethod()

If you have a Java Object:

my_object.myMethod()

And if you want to wrap a Java Object to the Python4Capella API (for instance a CapellaElement):

my_python_object = CapellaElement(my_java_object)

In your case myMethod() could be getId() or getReqIFIdentifier() or setReqIFIdentifier(‘SomeID’).