forked from Systems-Modeling/SysML-v2-API-Java-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-sysml-v2-api-java-client.jsh
More file actions
executable file
·52 lines (43 loc) · 2.42 KB
/
Copy pathtest-sysml-v2-api-java-client.jsh
File metadata and controls
executable file
·52 lines (43 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//usr/bin/env jshell --show-version "$0" "$@"; exit $?
/env -class-path ~/SysML-v2-API-Java-Client/build/libs/sysml-v2-api-client-2020-05-rc1-all.jar
import java.util.Arrays;
import java.util.UUID;
import org.omg.sysml.ApiClient;
import org.omg.sysml.api.*;
import org.omg.sysml.model.*;
var apiClient = new ApiClient();
apiClient.setBasePath("http://localhost:9000");
var project = new Project();
project.setName("MyProject");
var projectApi = new ProjectApi(apiClient);
var projectResponse = projectApi.postProject(project);
System.out.println("--- Project ---");
System.out.println(projectResponse);
var firstBlock = new Element();
firstBlock.put("@type", "Block");
// Fluent API getters/setters also supported
var firstIdentity = new ElementIdentity().id(UUID.fromString("b92bb8e8-740b-4eee-b621-91a82be67d6a"));
var firstElementVersion = new ElementVersion().data(firstBlock).identity(firstIdentity);
var secondBlock = new Element();
secondBlock.put("@type", "Block");
var secondIdentity = new ElementIdentity().id(UUID.fromString("a429229d-333a-4f2d-89b4-82354d29109d"));
var secondElementVersion = new ElementVersion().data(secondBlock).identity(secondIdentity);
var firstCommit = new Commit().changes(Arrays.asList(firstElementVersion, secondElementVersion));
var commitApi = new CommitApi(apiClient);
var firstCommitResponse = commitApi.postCommitByProject(projectResponse.getId(), firstCommit);
System.out.println("--- First Commit ---");
System.out.println(firstCommitResponse);
var generalization = new Element();
generalization.put("@type", "Generalization");
var firstBlockIdentified = new Identified().atId(UUID.fromString("b92bb8e8-740b-4eee-b621-91a82be67d6a"));
generalization.put("source", Arrays.asList(firstBlockIdentified));
var secondBlockIdentified = new Identified().atId(UUID.fromString("a429229d-333a-4f2d-89b4-82354d29109d"));
generalization.put("target", Arrays.asList(secondBlockIdentified));
// Note that no ElementIdentity is provided. Server will generate one when not provided.
var generalizationElementVersion = new ElementVersion().data(generalization);
var firstCommitRecord = new Record().id(firstCommitResponse.getId());
var secondCommit = new Commit().previousCommit(firstCommitRecord).changes(Arrays.asList(generalizationElementVersion));
var secondCommitResponse = commitApi.postCommitByProject(projectResponse.getId(), secondCommit);
System.out.println("--- Second Commit ---");
System.out.println(secondCommitResponse);
/exit