Skip to content

Commit bd82908

Browse files
authored
Add delete backup asset version support
1 parent 40941ec commit bd82908

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

cloudinary-core/src/main/java/com/cloudinary/Api.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,25 @@ public ApiResponse renameFolder(String path, String toPath, Map options) throws
802802

803803
}
804804

805+
public ApiResponse deleteBackedUpAssets(String assetId, String[] versionIds, Map options) throws Exception {
806+
if (options == null || options.isEmpty()) options = ObjectUtils.asMap();
807+
if (StringUtils.isEmpty(assetId)) {
808+
throw new IllegalArgumentException("AssetId parameter is required");
809+
}
810+
811+
if (versionIds == null || versionIds.length == 0) {
812+
throw new IllegalArgumentException("VersionIds parameter is required");
813+
}
814+
815+
List<String> url = Arrays.asList("resources", "backup", assetId);
816+
817+
Map<String, Object> params = new HashMap<String, Object>();
818+
params.put("version_ids[]", StringUtils.join(versionIds, "&"));
819+
820+
return callApi(HttpMethod.DELETE, url, params, options);
821+
822+
}
823+
805824
private Map<String, ?> extractParams(Map options, List<String> keys) {
806825
Map<String, Object> result = new HashMap<String, Object>();
807826
for (String key : keys) {

cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractApiTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,4 +1278,24 @@ public void testRenameFolder() throws Exception {
12781278
Map response = api.renameFolder(folderName, "newFolderName", ObjectUtils.emptyMap());
12791279
assertNotNull(response);
12801280
}
1281+
1282+
@Test
1283+
public void testDeleteBackedupAsset() throws Exception {
1284+
if (MockableTest.shouldTestFeature(Feature.BACKEDUP_ASSETS)) {
1285+
Map result = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("backup", true));
1286+
1287+
String publicId = (String) result.get("public_id");
1288+
String assetId = (String) result.get("asset_id");
1289+
1290+
ApiResponse getVersionsResp = api.resource(publicId, ObjectUtils.asMap("versions", true));
1291+
List<Map> versions = (List<Map>) getVersionsResp.get("versions");
1292+
String firstAssetVersion = (String) versions.get(0).get("version_id");
1293+
ApiResponse response = api.deleteBackedUpAssets(assetId, new String[]{firstAssetVersion}, ObjectUtils.emptyMap());
1294+
1295+
assertNotNull(response);
1296+
assertEquals(response.get("asset_id"), assetId);
1297+
List<String> deletedVersionIds = (List<String>) response.get("deleted_version_ids");
1298+
assertEquals(deletedVersionIds.get(0), firstAssetVersion);
1299+
}
1300+
}
12811301
}

cloudinary-test-common/src/main/java/com/cloudinary/test/helpers/Feature.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
public class Feature {
44
public static final String ALL = "all";
55
public static final String DYNAMIC_FOLDERS = "dynamic_folders";
6+
public static final String BACKEDUP_ASSETS = "backedup_assets";
67
}

0 commit comments

Comments
 (0)