Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support search deleted filters #1207

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion src/main/java/com/box/sdk/BoxSearchParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class BoxSearchParameters {
private BoxMetadataFilter metadataFilter;
private String sort;
private String direction;
private Boolean includeRecentSharedLinks;
private List<String> deleterUserIds;
private DateRange deletedRange;

/**
* Creates a Box Search Parameters Objects without query set, specific for Metadata Only Searches.
Expand Down Expand Up @@ -65,6 +66,8 @@ public boolean clearParameters() {
this.metadataFilter = null;
this.sort = null;
this.direction = null;
this.deleterUserIds = null;
this.deletedRange = null;
return true;
}

Expand Down Expand Up @@ -338,6 +341,46 @@ public void setDirection(String direction) {
this.direction = direction;
}

/**
* Limits the search results to items that were deleted by the given list of users, defined as a list of comma separated user IDs.
* The trash_content parameter needs to be set to trashed_only.
*
* @return deleterUserIds.
*/
public List<String> getDeleterUserIds() {
return this.deleterUserIds;
}

/**
* Limits the search results to items that were deleted by the given list of users, defined as a list of comma separated user IDs.
* The trash_content parameter needs to be set to trashed_only.
*
* @param deleterUserIds a list of user ids.
*/
public void setDeleterUserIds(List<String> deleterUserIds) {
this.deleterUserIds = deleterUserIds;
}

/**
* Limits the search results to items that were deleted within the given date range.
* The trash_content parameter needs to be set to trashed_only.
*
* @return deletedRange.
*/
public DateRange getDeletedRange() {
return this.deletedRange;
}

/**
* Limits the search results to items that were deleted within the given date range.
* The trash_content parameter needs to be set to trashed_only.
*
* @param deletedRange a date range.
*/
public void setDeletedRange(DateRange deletedRange) {
this.deletedRange = deletedRange;
}

/**
* Checks String to see if the parameter is null.
*
Expand Down Expand Up @@ -465,6 +508,14 @@ public QueryStringBuilder getQueryParameters() {
if (!this.isNullOrEmpty(this.direction)) {
builder.appendParam("direction", this.direction);
}
//Deleter User Ids
if (!this.isNullOrEmpty(this.deleterUserIds)) {
builder.appendParam("deleter_user_ids", this.listToCSV(this.deleterUserIds));
}
//Deleted Range
if ((this.deletedRange != null)) {
congminh1254 marked this conversation as resolved.
Show resolved Hide resolved
builder.appendParam("deleted_range", this.deletedRange.buildRangeString());
}

return builder;
}
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/com/box/sdk/BoxSearchParametersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,37 @@ public void shouldCorrectlySetSortAndDirection() {
assertTrue(isCleared);
assertNull(searchParams.getSort());
}

@Test
public void shouldCorrectlySetAndGetDeleterUserIdsAndDeletedRange() {
BoxSearchParameters searchParams = new BoxSearchParameters();
searchParams.setQuery("Test Query");

searchParams.setTrashContent("trashed_only");

List<String> deleterUserIds = new ArrayList<>();
deleterUserIds.add("123");
deleterUserIds.add("456");
searchParams.setDeleterUserIds(deleterUserIds);

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
String deletedFromDateString = "2016-01-01T00:00:00Z";
String deletedToDateString = "2016-04-01T00:00:00Z";

try {
Date deletedFromDate = sdf.parse(deletedFromDateString);
Date deletedToDate = sdf.parse(deletedToDateString);
DateRange deletedRange = new DateRange(deletedFromDate, deletedToDate);
searchParams.setDeletedRange(deletedRange);
} catch (ParseException e) { /* no op */ }

QueryStringBuilder queryParams = searchParams.getQueryParameters();

assertEquals(
"?query=Test+Query&trash_content=trashed_only&deleter_user_ids=123%2C456"
+ "&deleted_range=2016-01-01T00%3A00%3A00Z%2C2016-04-01T00%3A00%3A00Z",
queryParams.toString()
);
}
}
Loading