Skip to content

Commit 61a5c90

Browse files
authored
Add restore by asset ids api call
1 parent a8284eb commit 61a5c90

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,14 @@ public ApiResponse restore(Iterable<String> publicIds, Map options) throws Excep
393393
return response;
394394
}
395395

396+
public ApiResponse restoreByAssetIds(Iterable<String> assetIds, Map options) throws Exception {
397+
if (options == null)
398+
options = ObjectUtils.emptyMap();
399+
Map params = new HashMap<String, Object>();
400+
params.put("asset_ids", assetIds);
401+
return callApi(HttpMethod.POST, Arrays.asList("resources", "restore"), params, options);
402+
}
403+
396404
public ApiResponse uploadMappings(Map options) throws Exception {
397405
if (options == null)
398406
options = ObjectUtils.emptyMap();

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,32 @@ public void testRestore() throws Exception {
971971
assertEquals(resource.get("bytes"), 3381);
972972
}
973973

974+
@Test
975+
public void testRestoreByAssetIds() throws Exception {
976+
977+
// Upload
978+
cloudinary.uploader().upload(SRC_TEST_IMAGE,
979+
ObjectUtils.asMap("public_id", API_TEST_RESTORE, "backup", true, "tags", UPLOAD_TAGS));
980+
Map resource = api.resource(API_TEST_RESTORE, ObjectUtils.emptyMap());
981+
assertEquals(resource.get("bytes"), 3381);
982+
983+
//Delete
984+
api.deleteResources(Collections.singletonList(API_TEST_RESTORE), ObjectUtils.emptyMap());
985+
resource = api.resource(API_TEST_RESTORE, ObjectUtils.emptyMap());
986+
String assetId = (String) resource.get("asset_id");
987+
assertEquals(resource.get("bytes"), 0);
988+
assertNotNull(assetId);
989+
assertTrue((Boolean) resource.get("placeholder"));
990+
991+
//Restore
992+
Map response = api.restoreByAssetIds(Collections.singletonList(assetId), ObjectUtils.emptyMap());
993+
Map info = (Map) response.get(assetId);
994+
assertNotNull(info);
995+
assertEquals(info.get("bytes"), 3381);
996+
resource = api.resource(API_TEST_RESTORE, ObjectUtils.emptyMap());
997+
assertEquals(resource.get("bytes"), 3381);
998+
}
999+
9741000
@Test
9751001
public void testRestoreDifferentVersionsOfDeletedAsset() throws Exception {
9761002
final String TEST_RESOURCE_PUBLIC_ID = "api_test_restore_different_versions_single_asset" + SUFFIX;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void testCreateMetadata() throws Exception {
7575

7676
@Test
7777
public void testCreateSetMetadataWithAllowDynamicListValues() throws Exception {
78-
SetMetadataField setField = createSetField("testCreateMetadata_2");
78+
SetMetadataField setField = createSetField("testCreateMetadata_4");
7979
ApiResponse result = cloudinary.api().addMetadataField(setField);
8080
assertNotNull(result);
8181
assertEquals(setField.getLabel(), result.get("label"));

0 commit comments

Comments
 (0)