Skip to content

Commit effc434

Browse files
author
RTLcoil
authored
Add support for restoring deleted datasource entries (#207)
1 parent 827ea3d commit effc434

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,18 @@ public ApiResponse deleteDatasourceEntries(String fieldExternalId, List<String>
653653
return callApi(HttpMethod.DELETE, uri, Collections.singletonMap("external_ids", entriesExternalId), Collections.emptyMap());
654654
}
655655

656+
/**
657+
* Restore deleted data source entries for a given field
658+
* @param fieldExternalId The id of the field to operate
659+
* @param entriesExternalId The ids of all the entries to restore from the data source
660+
* @return The datasource entries state after restore
661+
* @throws Exception
662+
*/
663+
public ApiResponse restoreDatasourceEntries(String fieldExternalId, List<String> entriesExternalId) throws Exception {
664+
List<String> uri = Arrays.asList("metadata_fields", fieldExternalId, "datasource_restore");
665+
return callApi(HttpMethod.POST, uri, Collections.singletonMap("external_ids", entriesExternalId), Collections.singletonMap("content_type", "json"));
666+
}
667+
656668
/**
657669
* Delete a field definition.
658670
* @param fieldExternalId The id of the field to delete

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ public void testDeleteDatasourceEntries() throws Exception {
158158
assertNotNull(result);
159159
}
160160

161+
@Test
162+
public void testRestoreDatasourceEntries() throws Exception {
163+
SetMetadataField setField = createSetField("testRestoreDatasourceEntries");
164+
ApiResponse fieldResult = addFieldToAccount(setField);
165+
String fieldExternalId = fieldResult.get("external_id").toString();
166+
api.deleteDatasourceEntries(fieldExternalId, Collections.singletonList("id1"));
167+
ApiResponse result = api.restoreDatasourceEntries(fieldExternalId, Collections.singletonList("id1"));
168+
assertNotNull(result);
169+
}
170+
161171
@Test
162172
public void testUploadWithMetadata() throws Exception {
163173
StringMetadataField field = newFieldInstance("testUploadWithMetadata");

0 commit comments

Comments
 (0)