ls1intum / Apollon

UML Modeling Editor written in React
https://apollon-library.readthedocs.io
MIT License
61 stars 21 forks source link

Diagram Helper APIs #325

Closed loreanvictor closed 7 months ago

loreanvictor commented 7 months ago

Checklist

Motivation and Context

Consumers of Apollon might need to work with UML models, reading them or modifying them. For example, Artemis reads element details to match instructor feedbacks on modelling exercise submissions, and attaches these feedbacks to the diagram as assessments.

To conduct such operations, consumers would need to manually access and modify UML models. Since these models might be in various schema versions, consumers need to write additional code handling different model versions.

Description

This PR adds helper APIs for reading and modifying UML elements. These functions handle backwards compatibility internally. It causes the Apollon package to expose following methods:

findElement(model: UMLModelCompat, id: string): UMLElement | undefined;
addOrUpdateElement(model: UMLModelCompat, element: UMLElement): void;
findRelationship(model: UMLModelCompat, id: string): UMLRelationship | undefined;
addOrUpdateRelationship(model: UMLModelCompat, relationship: UMLRelationship): void;
findAssessment(model: UMLModelCompat, id: string): Assessment | undefined;
addOrUpdateAssessment(model: UMLModelCompat, assessment: Assessment): void;
isInteractiveElement(model: UMLModelCompat, id: string): boolean;
setInteractiveElement(model: UMLModelCompat, id: string, interactive: boolean): void;
isInteractiveRelationship(model: UMLModelCompat, id: string): boolean;
setInteractiveRelationship(model: UMLModelCompat, id: string, interactive: boolean): void;

Steps for Testing

  1. Install the Apollon package
  2. Import said functions to modify various UML model versions.

Test Coverage

File Branch Line
compat/helpers.ts 100% 100%
compat/index.ts 100% 100%
compat/v2/helpers.ts 100% 100%
compat/v2/index.ts 100% 100%
compat/v2/transform.ts 93.75% 94.02%