Skip to content

Commit bd49799

Browse files
nitzanjAmir Tocker
authored andcommitted
Add method deleteDerivedResourcesByTransformations to Admin Api
1 parent 3bf53e4 commit bd49799

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,19 @@ public ApiResponse deleteResources(Iterable<String> publicIds, Map options) thro
140140
if (options == null) options = ObjectUtils.emptyMap();
141141
String resourceType = ObjectUtils.asString(options.get("resource_type"), "image");
142142
String type = ObjectUtils.asString(options.get("type"), "upload");
143-
Map params = ObjectUtils.only(options, "keep_original", "invalidate", "next_cursor");
143+
Map params = ObjectUtils.only(options, "keep_original", "invalidate", "next_cursor", "transformations");
144+
params.put("public_ids", publicIds);
145+
return callApi(HttpMethod.DELETE, Arrays.asList("resources", resourceType, type), params, options);
146+
}
147+
148+
public ApiResponse deleteDerivedResourcesByTransformations(Iterable<String> publicIds, List<Transformation> transformations, Map options) throws Exception {
149+
if (options == null) options = ObjectUtils.emptyMap();
150+
String resourceType = ObjectUtils.asString(options.get("resource_type"), "image");
151+
String type = ObjectUtils.asString(options.get("type"), "upload");
152+
Map params = ObjectUtils.only(options, "invalidate", "next_cursor");
153+
params.put("keep_original", true);
144154
params.put("public_ids", publicIds);
155+
params.put("transformations", Util.buildEager(transformations));
145156
return callApi(HttpMethod.DELETE, Arrays.asList("resources", resourceType, type), params, options);
146157
}
147158

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
@@ -281,6 +281,26 @@ public void test08DeleteDerived() throws Exception {
281281
assertEquals(derived.size(), 0);
282282
}
283283

284+
@Test()
285+
public void testDeleteDerivedByTransformation() throws Exception {
286+
// should allow deleting resources
287+
String public_id = "api_test_123";
288+
List<Transformation> transformations = new ArrayList<Transformation>();
289+
transformations.add(new Transformation().angle(90));
290+
transformations.add(new Transformation().width(120));
291+
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", public_id, "tags", UPLOAD_TAGS, "eager", transformations));
292+
Map resource = api.resource(public_id, ObjectUtils.emptyMap());
293+
assertNotNull(resource);
294+
List derived = ((List) resource.get("derived"));
295+
assertTrue(derived.size() == 2);
296+
api.deleteDerivedResourcesByTransformations(ObjectUtils.asArray(public_id), ObjectUtils.asArray(transformations), ObjectUtils.emptyMap());
297+
298+
resource = api.resource(public_id, ObjectUtils.emptyMap());
299+
assertNotNull(resource);
300+
derived = ((List) resource.get("derived"));
301+
assertTrue(derived.size() == 0);
302+
}
303+
284304
@Test(expected = NotFound.class)
285305
public void test09DeleteResources() throws Exception {
286306
// should allow deleting resources

0 commit comments

Comments
 (0)