6. Introduction to Requirement access and management

Welcome to the ReqIF extension Showcase notebook. This notebook will show you some basic (and not so basic) things that you can get done using this library.

The below code loads the library and one of the test models:

[1]:
import capellambse

path_to_model = "../../../tests/data/melodymodel/5_0/Melody Model Test.aird"
model = capellambse.MelodyModel(path_to_model)
model
[1]:
<capellambse.model._model.MelodyModel at 0x78f9a032d490>

You can access a lookup for all requirements defined in a specific layer.

[2]:
model.oa.all_requirements
[2]:
  1. Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3)
  2. Requirement "TypedReq2" (0a9a68b1-ba9a-4793-b2cf-4448f0b4b8cc)
  3. Requirement "TestReq3" (79291c33-5147-4543-9398-9077d582576d)
  4. Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
  5. Requirement "TestReq" (1092f69a-5f3a-4fe6-a8fd-b2dffde90650)

Have a look at all of the available attributes for a Requirement ModelElement:

[3]:
model.oa.all_requirements[0]
[3]:

TestReq1 (Requirements:Requirement)

applied_property_value_groups

(Empty list)

applied_property_values

(Empty list)

attributes
  1. BooleanValueAttribute "AttrDef" (9c692405-b8aa-4caa-b988-51d27db5cd1b)
  2. DateValueAttribute "AttrDef" (b97c09b5-948a-46e8-a656-69d764ddce7d)
  3. IntegerValueAttribute "AttrDef" (85dfd42c-7f6e-4236-a181-bdd784040431)
  4. RealValueAttribute "AttrDef" (d2231d14-854d-4625-b48b-6cf1c2554367)
  5. StringValueAttribute "AttrDef" (ee8a69ef-61b9-4db9-9a0f-628e5d4704e1)
  6. BooleanValueAttribute "None" (dcb8614e-2d1c-4cb3-aa0c-667a297e7489)
chapter_name2
constraints

(Empty list)

descriptionThis is a test requirement of kind 1.
diagrams

(Empty list)

filtering_criteria

(Empty list)

foreign_id1
identifierREQTYPE-1
layerOperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed)
long_name1
nameTestReq1
ownerFolder "Folder" (e16f5cc1-3299-43d0-b1a0-82d31a137111)
parentFolder "Folder" (e16f5cc1-3299-43d0-b1a0-82d31a137111)
prefix3
progress_statusNOT_SET
property_value_groups

(Empty list)

property_value_packages

(Empty list)

property_values

(Empty list)

pvmtProperty Value Management for Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3)
related
  1. Entity "Weather" (4bf0356c-89dd-45e9-b8a6-e0332c026d33)
  2. SystemFunction "Sysexfunc" (00e7b925-cf4c-4cb0-929e-5409a1cd872b)
  3. Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
  4. LogicalComponent "Hogwarts" (0d2edb8f-fa34-4e73-89ec-fb9a63001440)
relations
  1. CapellaIncomingRelation "Controlling the weather" (078b2c69-4352-4cf9-9ea5-6573b75e5eec)
  2. CapellaIncomingRelation "Test req" (24c824ef-b187-4725-a051-a68707e82d70)
  3. InternalRelation (7de4c1a5-e106-4171-902a-502b816b60b0)
  4. CapellaOutgoingRelation (57033242-3766-4961-8091-ce3d9326ed67)
requirements
  1. Entity "Weather" (4bf0356c-89dd-45e9-b8a6-e0332c026d33)
  2. SystemFunction "Sysexfunc" (00e7b925-cf4c-4cb0-929e-5409a1cd872b)
  3. Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
  4. LogicalComponent "Hogwarts" (0d2edb8f-fa34-4e73-89ec-fb9a63001440)
sid
summary
text

Test requirement 1 really l o n g text that is way too long to display here as that

< > " '

  • This is a list
  • an unordered one
  1. Ordered list
  2. Ok
traces

(Empty list)

typeRequirementType "ReqType" (db47fca9-ddb6-4397-8d4b-e397e53d277e)
uuid3c2d312c-37c9-41b5-8c32-67578fa52dc3
validation<capellambse.extensions.validation._validate.ElementValidation object at 0x78f9a98ce600>
visible_on_diagrams
  1. [SDFB] Test CC (uuid: _1sGtYOSREeulYvEGRaHazg)
  2. [OAB] Operational Context (uuid: _u8_YMLB-EeqP7JXhmLvOsg)
xtypeRequirements:Requirement

6.1. Filtering for requirements by type

You probably know about typing of your Requirements. You can have a view of all requirement type folders directly on a specific layer and see the stored requirement_types:

[4]:
model.oa.requirement_types_folders[0]
[4]:

CapellaTypesFolder (CapellaRequirements:CapellaTypesFolder)

applied_property_value_groups

(Empty list)

applied_property_values

(Empty list)

constraints

(Empty list)

data_type_definitions
  1. DataTypeDefinition "DataTypeDef" (3b7ec38a-e26a-4c23-9fa3-275af3f629ee)
  2. EnumerationDataTypeDefinition "EnumDataTypeDef" (637caf95-3229-4607-99a0-7d7b990bc97f)
description
diagrams

(Empty list)

filtering_criteria

(Empty list)

identifier
layerOperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed)
long_nameTypes
module_types
  1. ModuleType "ModuleType" (a67e7f43-4b49-425c-a6a7-d44e1054a488)
name
parentOperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed)
prefix
progress_statusNOT_SET
property_value_groups

(Empty list)

property_value_packages

(Empty list)

property_values

(Empty list)

pvmtProperty Value Management for CapellaTypesFolder "Types" (67bba9cf-953c-4f0b-9986-41991c68d241)
relation_types
  1. RelationType "RelationType" (f1aceb81-5f70-4469-a127-94830eb9be04)
requirement_types
  1. RequirementType "ReqType" (db47fca9-ddb6-4397-8d4b-e397e53d277e)
requirements

(Empty list)

sid
summary
traces

(Empty list)

typeNone
uuid67bba9cf-953c-4f0b-9986-41991c68d241
validation<capellambse.extensions.validation._validate.ElementValidation object at 0x78f99a5fede0>
visible_on_diagrams

(Empty list)

xtypeCapellaRequirements:CapellaTypesFolder
[5]:
reqtype = model.oa.requirement_types_folders[0].requirement_types[0]
reqtype
[5]:

RequirementType (Requirements:RequirementType)

applied_property_value_groups

(Empty list)

applied_property_values

(Empty list)

attribute_definitions
  1. AttributeDefinition "AttrDef" (682bd51d-5451-4930-a97e-8bfca6c3a127)
  2. AttributeDefinitionEnumeration "AttrDefEnum" (c316ab07-c5c3-4866-a896-92e34733055c)
  3. AttributeDefinitionEnumeration "MultiEnum" (f31d4dd3-99f7-41d1-b1ce-f07b20d26eac)
  4. AttributeDefinition "version" (0bd40628-10a5-451e-86da-187c93bc3b10)
constraints

(Empty list)

description
diagrams

(Empty list)

filtering_criteria

(Empty list)

identifier
layerOperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed)
long_nameReqType
name
ownerCapellaTypesFolder "Types" (67bba9cf-953c-4f0b-9986-41991c68d241)
parentCapellaTypesFolder "Types" (67bba9cf-953c-4f0b-9986-41991c68d241)
prefix
progress_statusNOT_SET
property_value_groups

(Empty list)

property_value_packages

(Empty list)

property_values

(Empty list)

pvmtProperty Value Management for RequirementType "ReqType" (db47fca9-ddb6-4397-8d4b-e397e53d277e)
requirements

(Empty list)

sid
summary
traces

(Empty list)

typeNone
uuiddb47fca9-ddb6-4397-8d4b-e397e53d277e
validation<capellambse.extensions.validation._validate.ElementValidation object at 0x78f99a5ffd40>
visible_on_diagrams

(Empty list)

xtypeRequirements:RequirementType

Now we actually want to filter the requirements by this type with name ‘ReqType’. Very original name, we know. You wouldn’t really see the filtering effect since all requirements in the oa layer are of that type. So let us create one new requirement dynamically:

[6]:
new_req = model.oa.requirement_modules[0].requirements.create(
    name="New showcase req1"
)
display(new_req)
model.oa.all_requirements

New showcase req1 (Requirements:Requirement)

applied_property_value_groups

(Empty list)

applied_property_values

(Empty list)

attributes

(Empty list)

chapter_name
constraints

(Empty list)

description
diagrams

(Empty list)

filtering_criteria

(Empty list)

foreign_id0
identifier
layerOperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed)
long_name
nameNew showcase req1
ownerCapellaModule "Test Module" (f8e2195d-b5f5-4452-a12b-79233d943d5e)
parentCapellaModule "Test Module" (f8e2195d-b5f5-4452-a12b-79233d943d5e)
prefix
progress_statusNOT_SET
property_value_groups

(Empty list)

property_value_packages

(Empty list)

property_values

(Empty list)

pvmtProperty Value Management for Requirement "New showcase req1" (45bf975c-b861-4614-abf6-1de8a801a841)
related

(Empty list)

relations

(Empty list)

requirements

(Empty list)

sid
summary
text
traces

(Empty list)

typeNone
uuid45bf975c-b861-4614-abf6-1de8a801a841
validation<capellambse.extensions.validation._validate.ElementValidation object at 0x78f99a5ff290>
visible_on_diagrams

(Empty list)

xtypeRequirements:Requirement
[6]:
  1. Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3)
  2. Requirement "TypedReq2" (0a9a68b1-ba9a-4793-b2cf-4448f0b4b8cc)
  3. Requirement "TestReq3" (79291c33-5147-4543-9398-9077d582576d)
  4. Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
  5. Requirement "New showcase req1" (45bf975c-b861-4614-abf6-1de8a801a841)
  6. Requirement "TestReq" (1092f69a-5f3a-4fe6-a8fd-b2dffde90650)

Info about creation: Whenever you have an ElementList which deals with one specified classtype, here it is Requirement, then the classtype name doesn’t need to be included.

[7]:
model.oa.all_requirements.by_type("ReqType")
[7]:
  1. Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3)
  2. Requirement "TypedReq2" (0a9a68b1-ba9a-4793-b2cf-4448f0b4b8cc)
  3. Requirement "TestReq3" (79291c33-5147-4543-9398-9077d582576d)
  4. Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
  5. Requirement "TestReq" (1092f69a-5f3a-4fe6-a8fd-b2dffde90650)

We see our Requirements with type ReqType are missing the new one. Let’s change that, without using capella.

[8]:
new_req.type = reqtype
model.oa.all_requirements.by_type("ReqType")
[8]:
  1. Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3)
  2. Requirement "TypedReq2" (0a9a68b1-ba9a-4793-b2cf-4448f0b4b8cc)
  3. Requirement "TestReq3" (79291c33-5147-4543-9398-9077d582576d)
  4. Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
  5. Requirement "New showcase req1" (45bf975c-b861-4614-abf6-1de8a801a841)
  6. Requirement "TestReq" (1092f69a-5f3a-4fe6-a8fd-b2dffde90650)

If you are sure about attributes when creating a Requirement you can also include it during creation.

[9]:
model.oa.requirement_modules[0].requirements.create(
    name="ReqType during Creation",
    type=reqtype,
)
model.oa.all_requirements.by_type("ReqType")
[9]:
  1. Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3)
  2. Requirement "TypedReq2" (0a9a68b1-ba9a-4793-b2cf-4448f0b4b8cc)
  3. Requirement "TestReq3" (79291c33-5147-4543-9398-9077d582576d)
  4. Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
  5. Requirement "New showcase req1" (45bf975c-b861-4614-abf6-1de8a801a841)
  6. Requirement "ReqType during Creation" (1f0ae65c-a7d2-4336-bc11-61f235b8f610)
  7. Requirement "TestReq" (1092f69a-5f3a-4fe6-a8fd-b2dffde90650)
[10]:
model.oa.all_requirements[0]
[10]:

TestReq1 (Requirements:Requirement)

applied_property_value_groups

(Empty list)

applied_property_values

(Empty list)

attributes
  1. BooleanValueAttribute "AttrDef" (9c692405-b8aa-4caa-b988-51d27db5cd1b)
  2. DateValueAttribute "AttrDef" (b97c09b5-948a-46e8-a656-69d764ddce7d)
  3. IntegerValueAttribute "AttrDef" (85dfd42c-7f6e-4236-a181-bdd784040431)
  4. RealValueAttribute "AttrDef" (d2231d14-854d-4625-b48b-6cf1c2554367)
  5. StringValueAttribute "AttrDef" (ee8a69ef-61b9-4db9-9a0f-628e5d4704e1)
  6. BooleanValueAttribute "None" (dcb8614e-2d1c-4cb3-aa0c-667a297e7489)
chapter_name2
constraints

(Empty list)

descriptionThis is a test requirement of kind 1.
diagrams

(Empty list)

filtering_criteria

(Empty list)

foreign_id1
identifierREQTYPE-1
layerOperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed)
long_name1
nameTestReq1
ownerFolder "Folder" (e16f5cc1-3299-43d0-b1a0-82d31a137111)
parentFolder "Folder" (e16f5cc1-3299-43d0-b1a0-82d31a137111)
prefix3
progress_statusNOT_SET
property_value_groups

(Empty list)

property_value_packages

(Empty list)

property_values

(Empty list)

pvmtProperty Value Management for Requirement "TestReq1" (3c2d312c-37c9-41b5-8c32-67578fa52dc3)
related
  1. Entity "Weather" (4bf0356c-89dd-45e9-b8a6-e0332c026d33)
  2. SystemFunction "Sysexfunc" (00e7b925-cf4c-4cb0-929e-5409a1cd872b)
  3. Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
  4. LogicalComponent "Hogwarts" (0d2edb8f-fa34-4e73-89ec-fb9a63001440)
relations
  1. CapellaIncomingRelation "Controlling the weather" (078b2c69-4352-4cf9-9ea5-6573b75e5eec)
  2. CapellaIncomingRelation "Test req" (24c824ef-b187-4725-a051-a68707e82d70)
  3. InternalRelation (7de4c1a5-e106-4171-902a-502b816b60b0)
  4. CapellaOutgoingRelation (57033242-3766-4961-8091-ce3d9326ed67)
requirements
  1. Entity "Weather" (4bf0356c-89dd-45e9-b8a6-e0332c026d33)
  2. SystemFunction "Sysexfunc" (00e7b925-cf4c-4cb0-929e-5409a1cd872b)
  3. Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
  4. LogicalComponent "Hogwarts" (0d2edb8f-fa34-4e73-89ec-fb9a63001440)
sid
summary
text

Test requirement 1 really l o n g text that is way too long to display here as that

< > " '

  • This is a list
  • an unordered one
  1. Ordered list
  2. Ok
traces

(Empty list)

typeRequirementType "ReqType" (db47fca9-ddb6-4397-8d4b-e397e53d277e)
uuid3c2d312c-37c9-41b5-8c32-67578fa52dc3
validation<capellambse.extensions.validation._validate.ElementValidation object at 0x78f99a5ffd40>
visible_on_diagrams
  1. [SDFB] Test CC (uuid: _1sGtYOSREeulYvEGRaHazg)
  2. [OAB] Operational Context (uuid: _u8_YMLB-EeqP7JXhmLvOsg)
xtypeRequirements:Requirement

6.2. Export all requirements to excel with pandas

With Pandas you are able to generate data tables and export to many file-types like .xlsx for excel. Note that this requires the xlsxwriter module in addition to pandas itself.

[11]:
import pandas as pd

requirements = [
    {"id": f"Req_{i}", "uuid": req.uuid, "text": req.text}
    for i, req in enumerate(model.oa.all_requirements)
]
data = pd.DataFrame(requirements)
data.to_excel(excel_writer="Test_requirements.xlsx")

6.3. Export a Requirements module as Requirements Interchange Format (.reqif) file

capellambse features basic export functionality for requirements modules, which allows to write .reqif or compressed .reqifz files. These can then be imported into other ReqIF-compliant applications, like CodeBeamer or IBM DOORS.

Let’s first take a glance at the module we’re going to export:

[12]:
req_module = model.by_uuid("f8e2195d-b5f5-4452-a12b-79233d943d5e")
req_module
[12]:

Test Module (CapellaRequirements:CapellaModule)

applied_property_value_groups

(Empty list)

applied_property_values

(Empty list)

attributes
  1. EnumerationValueAttribute "AttrDefEnum" (11a2e07a-41f7-4eee-a94e-f3e33738c487)
constraints

(Empty list)

descriptionThis is a test requirement module.
diagrams

(Empty list)

filtering_criteria

(Empty list)

folders
  1. Folder "Folder" (e16f5cc1-3299-43d0-b1a0-82d31a137111)
identifier1
layerOperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed)
long_nameModule
nameTest Module
parentOperationalAnalysis "Operational Analysis" (ddbef16d-ddb9-4162-934c-f1e40e6f8bed)
prefixT
progress_statusNOT_SET
property_value_groups

(Empty list)

property_value_packages

(Empty list)

property_values

(Empty list)

pvmtProperty Value Management for CapellaModule "Test Module" (f8e2195d-b5f5-4452-a12b-79233d943d5e)
requirement_types_folders

(Empty list)

requirements
  1. Requirement "TypedReq1" (85d41db2-9e17-438b-95cf-49342452ddf3)
  2. Requirement "New showcase req1" (45bf975c-b861-4614-abf6-1de8a801a841)
  3. Requirement "ReqType during Creation" (1f0ae65c-a7d2-4336-bc11-61f235b8f610)
sid
summary
traces

(Empty list)

typeModuleType "ModuleType" (a67e7f43-4b49-425c-a6a7-d44e1054a488)
uuidf8e2195d-b5f5-4452-a12b-79233d943d5e
validation<capellambse.extensions.validation._validate.ElementValidation object at 0x78f98e93f860>
visible_on_diagrams

(Empty list)

xtypeCapellaRequirements:CapellaModule
[13]:
req_module.to_reqif(req_module.name + ".reqif")

And that’s it! This code has created the file “Test Module.reqif” next to this notebook, which contains all Requirements defined in that module.