JSON-LD format. The attributes of the elements are in kerml:esiData. There will be an element named UML Model. The below code fragment shows the attributes of this element. | Code Block |
|---|
| "kerml:esiData":
{
"name": "UML Model",
"namespace": "com.nomagic.magicdraw.uml_model",
"project":
{
"@id": "429f969a-5c81-45f4-94af-8cf983f22950"
},
"internalVersion": "1",
"version": "17.0",
"sections":
[
{
"@id": "b3e68e8e-2253-4726-8d05-d8f74fd0ba5a"
}
]
}, |
Take the first esiproject:EsiDataSection from the feature's sections list, which is b3e68e8e. The excerpt of the b3e68e8e data is shown below. | Code Block |
|---|
| {
"kerml:name": "model",
"@base": "http://127.0.0.1:8111/osmc/resources/4615e8fa-81e5-40e0-a51b-8496a48caf18/revisions/5/elements",
"kerml:nsURI": "http://www.nomagic.com/ns/magicdraw/esiproject/1.0",
"@type": "esiproject:EsiDataSection",
"kerml:owner":
{
"@id": "429f969a-5c81-45f4-94af-8cf983f22950"
},
"kerml:revision": "http://127.0.0.1:8111/osmc/resources/4615e8fa-81e5-40e0-a51b-8496a48caf18/revisions/5",
"@context":
{
"esiproject:EsiDataSection": "http://127.0.0.1:8111/osmc/schema/esiproject/2014345/EsiDataSection",
"kerml": "http://127.0.0.1:8111/osmc/schema/kerml/20140325"
},
"kerml:ownedElement": [],
"kerml:modifiedTime": "20180731223607ICT",
"kerml:esiData":
{
"featuredBy":
{
"@id": "c9256728-4617-4097-8e9e-dc63e2823bf8"
},
"rootElements":
[
"ca9a0235-f0f7-46b7-a142-e79a67c2d00d"
],
"name": "model",
"project":
{
"@id": "429f969a-5c81-45f4-94af-8cf983f22950"
},
"properties": []
},
"kerml:resource": "http://127.0.0.1:8111/osmc/resources/4615e8fa-81e5-40e0-a51b-8496a48caf18",
"kerml:esiID": "b3e68e8e-2253-4726-8d05-d8f74fd0ba5a",
"@id": "#b3e68e8e-2253-4726-8d05-d8f74fd0ba5a"
} |
The first ID in the rootElements list of the data section will be the ID of the UML model root element in the resource. The root element should always be of the uml:Package type or derived from it. Traversing to a MagicDraw modelOnce a root project is retrieved, the whole hierarchy can be retrieved layer by layer. An element can be retrieved from /elements/{elementId}. Child UUIDs of the resulting element are in kerml:ownedElement. Multiple elements can be retrieved by POST to /elements. In this case, you need to put UUID in the uuid.txtfile to load elements. | Code Block |
|---|
| 4eeb2e6d-9cbc-4f59-9d74-69263e52ba54,520bc74d-b5b4-40d5-87cb-9d0b8aba5d2e,7a057ae7-6281-462d-9dcd-de9931633f5c,a6212656-5ad1-4de6-a47f-db656c2c25fd |
The command to load those elements is: | Code Block |
|---|
| curl -v -H "Content-Type: text/plain" -X POST -s --cookie cookie.txt --insecure -d @uuid.txt --insecure "https://server:8111/osmc/resources/${projectId}/elements" |
In most cases, loading multiple elements at once is substantially faster than loading them one by one. Creating elementsTo use REST API to create elements, you are required to have knowledge about UML models, especially how to set the owner. A combination of parent-child type yields differences in the owner attribute. For example, if you want to create a class under a class, you need to set the UMLClass attribute in the child class. For a class under a package, you need to set owningPackage in the child class. The easiest way to know which attribute is needed is to try creating it in MagicDraw and get it in REST API. There are two URLs to create element(s), /resources/{resourceId}/elements and /resources/{resourceId}/elements{elementId}. Please note that the elementId in the latter form is not the parent. An Ecore is needed to create an element. It can be specified in the following ways: |