Skip to content

Commit 6fde2ce

Browse files
committed
Restore functionality of deleteGroup: there is no FK from artifacts to groups yet
1 parent cb71d07 commit 6fde2ce

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java

+7
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,12 @@ public void deleteGroup(String groupId) throws GroupNotFoundException, RegistryS
20872087
.bind(0, normalizeGroupId(groupId))
20882088
.execute();
20892089

2090+
// Delete all artifacts in the group (TODO there is currently no FK from artifacts to groups)
2091+
handle.createUpdate(sqlStatements.deleteArtifactsByGroupId())
2092+
.bind(0, normalizeGroupId(groupId))
2093+
.execute();
2094+
2095+
// Now delete the group (labels and rules etc will cascade)
20902096
int rows = handle.createUpdate(sqlStatements.deleteGroup())
20912097
.bind(0, groupId)
20922098
.execute();
@@ -2719,6 +2725,7 @@ private void resolveReferences(Map<String, ContentHandle> resolvedReferences, Li
27192725
/**
27202726
* IMPORTANT: Private methods can't be @Transactional. Callers MUST have started a transaction.
27212727
*/
2728+
// TODO call this in a cleanup cron job instead?
27222729
private void deleteAllOrphanedContent() {
27232730
log.debug("Deleting all orphaned content");
27242731
handles.withHandleNoException(handle -> {

app/src/test/java/io/apicurio/registry/noprofile/rest/v3/GroupsResourceTest.java

+44-9
Original file line numberDiff line numberDiff line change
@@ -986,15 +986,50 @@ public void testDeleteArtifactsInGroup() throws Exception {
986986
.statusCode(204);
987987

988988
// Verify that all 3 artifacts were deleted
989-
TestUtils.retry(() -> {
990-
given()
991-
.when()
992-
.queryParam("group", group)
993-
.get("/registry/v3/search/artifacts")
994-
.then()
995-
.statusCode(200)
996-
.body("count", equalTo(0));
997-
});
989+
given()
990+
.when()
991+
.queryParam("group", group)
992+
.get("/registry/v3/search/artifacts")
993+
.then()
994+
.statusCode(200)
995+
.body("count", equalTo(0));
996+
}
997+
998+
@Test
999+
public void testDeleteGroupWithArtifacts() throws Exception {
1000+
String group = "testDeleteGroupWithArtifacts";
1001+
String artifactContent = resourceToString("openapi-empty.json");
1002+
1003+
// Create several artifacts in the group.
1004+
createArtifact(group, "EmptyAPI-1", ArtifactType.OPENAPI, artifactContent);
1005+
createArtifact(group, "EmptyAPI-2", ArtifactType.OPENAPI, artifactContent);
1006+
createArtifact(group, "EmptyAPI-3", ArtifactType.OPENAPI, artifactContent);
1007+
1008+
// Make sure we can search for all three artifacts in the group.
1009+
given()
1010+
.when()
1011+
.queryParam("group", group)
1012+
.get("/registry/v3/search/artifacts")
1013+
.then()
1014+
.statusCode(200)
1015+
.body("count", equalTo(3));
1016+
1017+
// Delete the *group* (should delete all artifacts)
1018+
given()
1019+
.when()
1020+
.pathParam("groupId", group)
1021+
.delete("/registry/v3/groups/{groupId}")
1022+
.then()
1023+
.statusCode(204);
1024+
1025+
// Verify that all 3 artifacts were deleted
1026+
given()
1027+
.when()
1028+
.queryParam("group", group)
1029+
.get("/registry/v3/search/artifacts")
1030+
.then()
1031+
.statusCode(200)
1032+
.body("count", equalTo(0));
9981033
}
9991034

10001035
@Test

0 commit comments

Comments
 (0)