Skip to content

Commit

Permalink
Implement trash operation to retrieve recently deleted assets from By…
Browse files Browse the repository at this point in the history
…nder (#116)

* implement trash operations to be able to retrieve deleted assets from bynder api

* adjust formatting by replacing tabs with spaces
  • Loading branch information
jdickel committed Jan 19, 2024
1 parent 9d99e16 commit 4ba653d
Show file tree
Hide file tree
Showing 11 changed files with 421 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/bynder/sdk/api/BynderApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,8 @@ Observable<Response<WorkflowGroup>> updateWorkflowGroup(@Path("id") String group

@DELETE("api/workflow/groups/{id}/")
Observable<Response<Void>> deleteWorkflowGroup(@Path("id") String groupId);

@GET("api/trash/media/")
Observable<Response<List<DeletedMedia>>> getRecentlyRemovedMediaList(@QueryMap Map<String, String> params);

}
105 changes: 105 additions & 0 deletions src/main/java/com/bynder/sdk/model/DeletedMedia.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2017 Bynder B.V. All rights reserved.
*
* Licensed under the MIT License. See LICENSE file in the project root for full license
* information.
*/
package com.bynder.sdk.model;

import java.util.Map;

import com.bynder.sdk.api.BynderApi;
import com.google.gson.annotations.SerializedName;

/**
* Media model returned by {@link BynderApi#getRecentlyRemovedMediaList(Map)}.
*/
public class DeletedMedia {

/**
* Media id.
*/
private String id;
/**
* Media name.
*/
private String name;
/**
* Date removed.
*/
private String dateRemoved;
/**
* Date created.
*/
private String dateCreated;
/**
* Username of the user triggering the deletion.
*/
private String username;
/**
* UserID of the user triggering the deletion.
*/
private String userId;
/**
* Public URL of the media item when available.
*/
@SerializedName(value = "S3_filepointer")
private String publicUrl;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDateRemoved() {
return dateRemoved;
}

public void setDateRemoved(String dateRemoved) {
this.dateRemoved = dateRemoved;
}

public String getDateCreated() {
return dateCreated;
}

public void setDateCreated(String dateCreated) {
this.dateCreated = dateCreated;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}

public String getPublicUrl() {
return publicUrl;
}

public void setPublicUrl(String publicUrl) {
this.publicUrl = publicUrl;
}

}
88 changes: 88 additions & 0 deletions src/main/java/com/bynder/sdk/query/DeletedMediaQuery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2017 Bynder B.V. All rights reserved.
*
* Licensed under the MIT License. See LICENSE file in the project root for full license
* information.
*/
package com.bynder.sdk.query;

import com.bynder.sdk.query.decoder.ApiField;

/**
* Query to filter deleted media results.
*/
public class DeletedMediaQuery {

/**
* Limit of results per request. Example: 20. Default: 10.
*/
@ApiField
private Integer limit;
/**
* Page to be retrieved.
*/
@ApiField
private Integer page;
/**
* Retrieve assets removed after this date.
* You can only retrieve the removed assets from the last 30 days.
*/
@ApiField
private String dateRemoved;
/**
* Desired field to sort the returned list of results.
*/
@ApiField
private OrderField field;
/**
* Desired order for the returned list of results.
*/
@ApiField
private Order order;

public Integer getLimit() {
return limit;
}

public DeletedMediaQuery setLimit(Integer limit) {
this.limit = limit;
return this;
}

public Integer getPage() {
return page;
}

public DeletedMediaQuery setPage(Integer page) {
this.page = page;
return this;
}

public String getDateRemoved() {
return dateRemoved;
}

public DeletedMediaQuery setDateRemoved(String dateRemoved) {
this.dateRemoved = dateRemoved;
return this;
}

public OrderField getField() {
return field;
}

public DeletedMediaQuery setField(OrderField field) {
this.field = field;
return this;
}

public Order getOrder() {
return order;
}

public DeletedMediaQuery setOrder(Order order) {
this.order = order;
return this;
}

}
26 changes: 26 additions & 0 deletions src/main/java/com/bynder/sdk/query/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2017 Bynder B.V. All rights reserved.
*
* Licensed under the MIT License. See LICENSE file in the project root for full license
* information.
*/
package com.bynder.sdk.query;

/**
* Enum used to define how API results should be ordered.
*/
public enum Order {

ASC("asc"), DESC("desc");

private final String name;

Order(final String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/bynder/sdk/query/OrderField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2017 Bynder B.V. All rights reserved.
*
* Licensed under the MIT License. See LICENSE file in the project root for full license
* information.
*/
package com.bynder.sdk.query;

/**
* Enum used to define by which field the API results should be ordered.
*/
public enum OrderField {

DATE_CREATED("media.dateCreated"), DATE_REMOVED("media.dateRemoved"), NAME("media.name"),
USERNAME("media.username");

private final String name;

OrderField(final String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}
}
53 changes: 35 additions & 18 deletions src/main/java/com/bynder/sdk/service/asset/AssetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public interface AssetService {
/**
* Get Metaproperties.
*
* @param metapropertyQuery Information about if media count should be included in the
* metaproperty options or not.
* @return {@link Observable} with Map of String, {@link Metaproperty} key/value pairs.
* @param metapropertyQuery Information about if media count should be included
* in the metaproperty options or not.
* @return {@link Observable} with Map of String, {@link Metaproperty} key/value
* pairs.
*/
Observable<Response<Map<String, Metaproperty>>> getMetaproperties(
MetapropertyQuery metapropertyQuery);
Observable<Response<Map<String, Metaproperty>>> getMetaproperties(MetapropertyQuery metapropertyQuery);

/**
* Gets a list of media using query information.
Expand All @@ -58,37 +58,42 @@ Observable<Response<Map<String, Metaproperty>>> getMetaproperties(
Observable<Response<List<Media>>> getMediaList(MediaQuery mediaQuery);

/**
* Gets all the information for a specific media. This is needed to get the media items of a
* media asset.
* Gets all the information for a specific media. This is needed to get the
* media items of a media asset.
*
* @param mediaInfoQuery Information about the media we want to get the information from.
* @param mediaInfoQuery Information about the media we want to get the
* information from.
* @return {@link Observable} with {@link Media} information.
*/
Observable<Response<Media>> getMediaInfo(MediaInfoQuery mediaInfoQuery);

/**
* Modifies the metadata of a media asset.
*
* @param mediaModifyQuery Information with the media asset metadata new values to be
* modified.
* @param mediaModifyQuery Information with the media asset metadata new values
* to be modified.
* @return {@link Observable} with the request {@link Response} information.
*/
Observable<Response<Void>> modifyMedia(MediaModifyQuery mediaModifyQuery);

/**
* Deletes a media asset.
*
* @param mediaDeleteQuery Information to identify the media asset we want to delete.
* @param mediaDeleteQuery Information to identify the media asset we want to
* delete.
* @return {@link Observable} with the request {@link Response} information.
*/
Observable<Response<Void>> deleteMedia(MediaDeleteQuery mediaDeleteQuery);

/**
* Gets the download file URL for a specific media asset file. If the media item id was not
* specified, it will return the download URL of the media specified by media id.
* Gets the download file URL for a specific media asset file. If the media item
* id was not specified, it will return the download URL of the media specified
* by media id.
*
* @param mediaDownloadQuery Information with the media we want to get the URL from.
* @return {@link Observable} with the {@link DownloadUrl} information of the media asset file.
* @param mediaDownloadQuery Information with the media we want to get the URL
* from.
* @return {@link Observable} with the {@link DownloadUrl} information of the
* media asset file.
*/
Observable<Response<DownloadUrl>> getMediaDownloadUrl(MediaDownloadQuery mediaDownloadQuery);

Expand All @@ -103,7 +108,8 @@ Observable<Response<Map<String, Metaproperty>>> getMetaproperties(
/**
* Gets all the media assets usage records.
*
* @param usageQuery Information about the asset usage we want to get the information from.
* @param usageQuery Information about the asset usage we want to get the
* information from.
* @return {@link Observable} with list of {@link Usage}.
*/
Observable<Response<List<Usage>>> getUsage(UsageQuery usageQuery);
Expand Down Expand Up @@ -141,6 +147,18 @@ Observable<Response<Map<String, Metaproperty>>> getMetaproperties(
*/
Observable<UploadProgress> uploadFileWithProgress(UploadQuery uploadQuery);

/**
* Get a list of recently removed assets. <br>
* <br>
* Warning: You can only retrieve the removed assets from the last 30 days.<br>
* Warning: Requires the trash.assets security role.
*
* @param deletedMediaQuery Information about the deleted media we want to get
* the information from.
* @return {@link Observable} with list of {@link DeletedMedia}
*/
Observable<Response<List<DeletedMedia>>> getRecentlyRemovedMediaList(DeletedMediaQuery deletedMediaQuery);

/**
* Builder class used to create a new instance of {@link AssetService}.
*/
Expand All @@ -149,8 +167,7 @@ class Builder {
private Builder() {
}

public static AssetService create(final BynderApi bynderApi,
final QueryDecoder queryDecoder) {
public static AssetService create(final BynderApi bynderApi, final QueryDecoder queryDecoder) {
return new AssetServiceImpl(bynderApi, queryDecoder);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,13 @@ public Observable<UploadAdditionalMediaResponse> uploadAdditionalFile(final Uplo
public Observable<UploadProgress> uploadFileWithProgress(final UploadQuery uploadQuery) {
return fileUploader.uploadFileWithProgress(uploadQuery);
}

/**
* Check {@link AssetService} for more information.
*/
@Override
public Observable<Response<List<DeletedMedia>>> getRecentlyRemovedMediaList(final DeletedMediaQuery deletedMediaQuery) {
Map<String, String> params = queryDecoder.decode(deletedMediaQuery);
return bynderApi.getRecentlyRemovedMediaList(params);
}
}
Loading

0 comments on commit 4ba653d

Please sign in to comment.