Skip to content

Commit d416c1e

Browse files
committed
feat!: support deletion of Code Systems via DELETE /codesystems/:id
1 parent 86d97bc commit d416c1e

File tree

3 files changed

+70
-17
lines changed
  • commons/com.b2international.commons/src/com/b2international/commons/json
  • core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/codesystem
  • tests/com.b2international.snowowl.test.commons/src/com/b2international/snowowl/test/commons/codesystem

3 files changed

+70
-17
lines changed

commons/com.b2international.commons/src/com/b2international/commons/json/Json.java

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ public static <T> List<T> array(T...values) {
7272
return ImmutableList.copyOf(values);
7373
}
7474

75+
/**
76+
* Construct a new {@link Json} object which is basically a Map of String keys to any Object value. <code>null</code> values are ignored and the
77+
* associated keys will not be registered in the resulting {@link Json} object.
78+
*
79+
* @param properties - key-value property pairs or <code>null</code>
80+
* @return a {@link Json} object instance, never <code>null</code>
81+
*/
7582
public static Json object(Object...properties) {
7683
final ImmutableMap.Builder<String, Object> props = ImmutableMap.builder();
7784
if (properties != null) {

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/codesystem/CodeSystemRestService.java

+24
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.b2international.snowowl.core.codesystem.CodeSystemRequests;
2828
import com.b2international.snowowl.core.codesystem.CodeSystems;
2929
import com.b2international.snowowl.core.events.util.Promise;
30+
import com.b2international.snowowl.core.request.ResourceRequests;
3031
import com.b2international.snowowl.core.rest.AbstractRestService;
3132
import com.b2international.snowowl.core.rest.RestApiError;
3233

@@ -180,4 +181,27 @@ public void update(
180181
.getSync(COMMIT_TIMEOUT, TimeUnit.MINUTES);
181182
}
182183

184+
@ApiOperation(
185+
value="Delete a CodeSystem",
186+
notes="Deletes a CodeSystem permanently from the server")
187+
@ApiResponses({
188+
@ApiResponse(code = 204, message = "No content", response = Void.class),
189+
@ApiResponse(code = 400, message = "Bad Request", response = RestApiError.class),
190+
@ApiResponse(code = 409, message = "CodeSystem cannot be deleted", response = RestApiError.class)
191+
})
192+
@DeleteMapping(value = "/{codeSystemId}")
193+
@ResponseStatus(HttpStatus.NO_CONTENT)
194+
public void delete(
195+
@ApiParam(value="The code system identifier")
196+
@PathVariable(value="codeSystemId")
197+
final String codeSystemId,
198+
199+
@RequestHeader(value = X_AUTHOR, required = false)
200+
final String author) {
201+
ResourceRequests.prepareDelete(codeSystemId)
202+
.build(author, "Delete ".concat(codeSystemId))
203+
.execute(getBus())
204+
.getSync(COMMIT_TIMEOUT, TimeUnit.MINUTES);
205+
}
206+
183207
}

tests/com.b2international.snowowl.test.commons/src/com/b2international/snowowl/test/commons/codesystem/CodeSystemRestRequests.java

+39-17
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,62 @@
1818
import static com.b2international.snowowl.test.commons.rest.RestExtensions.givenAuthenticatedRequest;
1919

2020
import java.util.Map;
21+
import java.util.concurrent.TimeUnit;
2122

2223
import com.b2international.commons.json.Json;
2324
import com.b2international.snowowl.core.ResourceURI;
2425
import com.b2international.snowowl.core.api.IBranchPath;
26+
import com.b2international.snowowl.core.branch.Branch;
27+
import com.b2international.snowowl.core.repository.RepositoryRequests;
2528
import com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants;
2629
import com.b2international.snowowl.test.commons.ApiTestConstants;
30+
import com.b2international.snowowl.test.commons.Services;
2731

2832
import io.restassured.http.ContentType;
2933
import io.restassured.response.ValidatableResponse;
3034

3135
/**
36+
* Common requests for working with Code Systems (only SNOMED CT is supported).
37+
*
3238
* @since 4.7
3339
*/
3440
public abstract class CodeSystemRestRequests {
3541

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);
3858
}
3959

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);
4262
}
4363

44-
private static ValidatableResponse createCodeSystem(ResourceURI extensionOf, IBranchPath branchPath, String shortName) {
64+
private static ValidatableResponse createCodeSystem(ResourceURI extensionOf, String branchPath, String codeSystemId) {
4565
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,
4969
"description", "citation",
5070
"toolingId", SnomedTerminologyComponentConstants.TOOLING_ID,
51-
"oid", "oid_" + shortName,
52-
"language", "primaryLanguage"
71+
"oid", "oid_" + codeSystemId,
72+
"language", "primaryLanguage",
73+
"extensionOf", extensionOf,
74+
"branchPath", branchPath
5375
);
5476

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-
6277
return givenAuthenticatedRequest(ApiTestConstants.CODESYSTEMS_API)
6378
.contentType(ContentType.JSON)
6479
.body(requestBody)
@@ -80,6 +95,13 @@ public static ValidatableResponse updateCodeSystem(String id, Map<?, ?> requestB
8095
.then();
8196
}
8297

98+
public static ValidatableResponse deleteCodeSystem(String codeSystemId) {
99+
return givenAuthenticatedRequest(ApiTestConstants.CODESYSTEMS_API)
100+
.delete("/{id}", codeSystemId)
101+
.then();
102+
103+
}
104+
83105
public static ValidatableResponse upgrade(ResourceURI upgradeOf, ResourceURI extensionOf) {
84106
return givenAuthenticatedRequest("/upgrade")
85107
.contentType(ContentType.JSON)

0 commit comments

Comments
 (0)