Update the Status of a Property Value

How to change the Status of a String Property Value using Python4Capella. For example I want to change the status value from “TO_BE_REVIEWED” to “REVIEWED_OK”

Welcome !

The following script will set the status of a new created object to REVIEWED, you might need to get another literal in your case:

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

aird_path = '/In-Flight Entertainment System/In-Flight Entertainment System.aird'
model = CapellaModel()
model.open(aird_path)

def get_progress_status_enum(se):
    progress_status_enum = None
    for enumeration in se.get_java_object().eContainer().getOwnedEnumerationPropertyTypes():
        if enumeration.getName() == 'ProgressStatus':
            progress_status_enum = EnumerationPropertyType(enumeration)
            return progress_status_enum
    return progress_status_enum

se = model.get_system_engineering()
progress_status_enum = get_progress_status_enum(se)

new_status = None
for literal in progress_status_enum.get_owned_literals():
    if literal.get_name() == 'REVIEWED':
        new_status = literal

capella_element = LogicalComponentPkg()
capella_element.get_java_object().setStatus(new_status.get_java_object())

print(capella_element.get_status())

To change an existing object from your Capella model you will need to navigate to this element in your model. You will also need to do the change in a transaction for the change to take effect.

1 Like

Hi Yvan,

That worked and solved my issue!

Thanks for the help!

Regards
Srikar

2 Likes

Another epic response from @YvanLussaud :slight_smile:

2 Likes

Hello,
it works but not for diagram…
How can I set the status of a diagram? The getStatus() method correctly works but i cannot find any method to change the status of a diagram.

Thx for your help

Hello Romain,

Diagrams and other representations elements are not CapellaElement and their status/description is stored using eAnnotations, in your case on the DRepresentationDescriptor:

        <eAnnotations xmi:type="description:DAnnotation" uid="_oGiQMDhJEe-9PsSz_18myg" source="http://www.polarsys.org/capella/core/ProgressStatus">
          <references xmi:type="org.polarsys.capella.core.data.capellacore:EnumerationPropertyLiteral" href="In-Flight%20Entertainment%20System.capella#effb5795-a739-4c90-b148-364576eafaf5"/>
        </eAnnotations>
        <eAnnotations xmi:type="description:DAnnotation" uid="_o_OywDhJEe-9PsSz_18myg" source="http://www.polarsys.org/capella/core/StatusReview">
          <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_o_PZ0DhJEe-9PsSz_18myg" key="value" value="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/>
        </eAnnotations>

An example of script that list all diagrams and shows the progress status and description for each of them:

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

aird_path = '/In-Flight Entertainment System/In-Flight Entertainment System.aird'
model = CapellaModel()
model.open(aird_path)

for diagram in model.get_all_diagrams():
    print("Diagram", diagram.get_name())
    progress = None
    description = None
    for annotation in diagram.get_java_object().getEAnnotations():
        if annotation.getSource() == "http://www.polarsys.org/capella/core/ProgressStatus" and not annotation.getReferences().isEmpty():
            progress = EnumerationPropertyLiteral(annotation.getReferences().get(0))
        if annotation.getSource() == "http://www.polarsys.org/capella/core/StatusReview":
            description = annotation.getDetails().get("value")
    if progress:
        print(" - progress:", progress.get_name())
    if description:
        print(" - description", description)
1 Like

Thx a lot for your help

1 Like

sorry, for a side questions: it works to read the value as you provided (thx for that). As i do not know well the type EnumerationPropertyLiteral, how i change/set the status to another value?

You can get the new_status with the the script above.

  • Then you can change the value like this:

    • Create the annotation if needed:
e_annotation_e_class = get_e_classifier("http://www.eclipse.org/sirius/description/1.1.0", "DAnnotation")
annotation = create_e_object_from_e_classifier(e_annotation_e_class)

annotation.setSource("http://www.polarsys.org/capella/core/ProgressStatus")

diagram.get_java_object().getEAnnotations().add(annotation)
  • Set the new progress status
# remove old value if the annotation already exists
annotation.getReferences().clear()
# add the new status
annotation.getReferences().add(new_status.get_java_object())
  • For the description:

    • Create the annotation if needed:
e_annotation_e_class = get_e_classifier("http://www.eclipse.org/sirius/description/1.1.0", "DAnnotation")
annotation = create_e_object_from_e_classifier(e_annotation_e_class)

annotation.setSource("http://www.polarsys.org/capella/core/StatusReview")

diagram.get_java_object().getEAnnotations().add(annotation)
  • Set the new description
annotation.getDetails().put("value", "New description")

In order for the change to take effect you will need to put this code in a transaction and save the your model (see tips and tricks).

1 Like

Thx, but it seems that the diagram.get_java_object().getEAnnotations().add(annotation) is not working (not the right type?) because if have the following error:

java.lang.ArrayStoreException

Do you have the complete stack ? Usually it’s related to adding an element to a list that is from an other type than the list itself.

EDIT: I created a EAnnotation instead of a DAnnotation but the eAnnotation reference is used…

With your modifications (Dannotation instead of eAnnotation) seems to fix the issue.

Thx a lot for your help

1 Like