18
18
import static com .b2international .snowowl .test .commons .rest .RestExtensions .givenAuthenticatedRequest ;
19
19
20
20
import java .util .Map ;
21
+ import java .util .concurrent .TimeUnit ;
21
22
22
23
import com .b2international .commons .json .Json ;
23
24
import com .b2international .snowowl .core .ResourceURI ;
24
25
import com .b2international .snowowl .core .api .IBranchPath ;
26
+ import com .b2international .snowowl .core .branch .Branch ;
27
+ import com .b2international .snowowl .core .repository .RepositoryRequests ;
25
28
import com .b2international .snowowl .snomed .common .SnomedTerminologyComponentConstants ;
26
29
import com .b2international .snowowl .test .commons .ApiTestConstants ;
30
+ import com .b2international .snowowl .test .commons .Services ;
27
31
28
32
import io .restassured .http .ContentType ;
29
33
import io .restassured .response .ValidatableResponse ;
30
34
31
35
/**
36
+ * Common requests for working with Code Systems (only SNOMED CT is supported).
37
+ *
32
38
* @since 4.7
33
39
*/
34
40
public abstract class CodeSystemRestRequests {
35
41
36
- public static ValidatableResponse createCodeSystem (IBranchPath branchPath , String shortName ) {
37
- return createCodeSystem (null , branchPath , shortName );
42
+ public static ValidatableResponse createCodeSystem (String codeSystemId ) {
43
+ String branchPath = RepositoryRequests .branching ().prepareCreate ()
44
+ .setParent (Branch .MAIN_PATH )
45
+ .setName (codeSystemId )
46
+ .build (SnomedTerminologyComponentConstants .TOOLING_ID )
47
+ .execute (Services .bus ())
48
+ .getSync (1 , TimeUnit .MINUTES );
49
+ return createCodeSystem (null , branchPath , codeSystemId );
50
+ }
51
+
52
+ public static ValidatableResponse createCodeSystem (IBranchPath branchPath , String codeSystemId ) {
53
+ return createCodeSystem (branchPath .getPath (), codeSystemId );
54
+ }
55
+
56
+ public static ValidatableResponse createCodeSystem (String branchPath , String codeSystemId ) {
57
+ return createCodeSystem (null , branchPath , codeSystemId );
38
58
}
39
59
40
- public static ValidatableResponse createCodeSystem (ResourceURI extensionOf , String shortName ) {
41
- return createCodeSystem (extensionOf , null , shortName );
60
+ public static ValidatableResponse createCodeSystem (ResourceURI extensionOf , String codeSystemId ) {
61
+ return createCodeSystem (extensionOf , null , codeSystemId );
42
62
}
43
63
44
- private static ValidatableResponse createCodeSystem (ResourceURI extensionOf , IBranchPath branchPath , String shortName ) {
64
+ private static ValidatableResponse createCodeSystem (ResourceURI extensionOf , String branchPath , String codeSystemId ) {
45
65
Json requestBody = Json .object (
46
- "id" , shortName ,
47
- "title" , shortName ,
48
- "url" , "organizationLink" ,
66
+ "id" , codeSystemId ,
67
+ "title" , codeSystemId ,
68
+ "url" , SnomedTerminologyComponentConstants . SNOMED_URI_BASE ,
49
69
"description" , "citation" ,
50
70
"toolingId" , SnomedTerminologyComponentConstants .TOOLING_ID ,
51
- "oid" , "oid_" + shortName ,
52
- "language" , "primaryLanguage"
71
+ "oid" , "oid_" + codeSystemId ,
72
+ "language" , "primaryLanguage" ,
73
+ "extensionOf" , extensionOf ,
74
+ "branchPath" , branchPath
53
75
);
54
76
55
-
56
- if (extensionOf != null ) {
57
- requestBody = requestBody .with ("extensionOf" , extensionOf );
58
- } else if (branchPath != null ) {
59
- requestBody = requestBody .with ("branchPath" , branchPath .getPath ());
60
- }
61
-
62
77
return givenAuthenticatedRequest (ApiTestConstants .CODESYSTEMS_API )
63
78
.contentType (ContentType .JSON )
64
79
.body (requestBody )
@@ -80,6 +95,13 @@ public static ValidatableResponse updateCodeSystem(String id, Map<?, ?> requestB
80
95
.then ();
81
96
}
82
97
98
+ public static ValidatableResponse deleteCodeSystem (String codeSystemId ) {
99
+ return givenAuthenticatedRequest (ApiTestConstants .CODESYSTEMS_API )
100
+ .delete ("/{id}" , codeSystemId )
101
+ .then ();
102
+
103
+ }
104
+
83
105
public static ValidatableResponse upgrade (ResourceURI upgradeOf , ResourceURI extensionOf ) {
84
106
return givenAuthenticatedRequest ("/upgrade" )
85
107
.contentType (ContentType .JSON )
0 commit comments