-
Notifications
You must be signed in to change notification settings - Fork 187
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: Getting collaborators allows to specify fields #1178
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,8 +130,14 @@ protected static BoxCollaboration.Info create( | |
* @param api the API connection to use. | ||
* @return a collection of pending collaboration infos. | ||
*/ | ||
public static Collection<Info> getPendingCollaborations(BoxAPIConnection api) { | ||
URL url = PENDING_COLLABORATIONS_URL.build(api.getBaseURL()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is PENDING_COLLABORATIONS_URL used now anywhere? Seems not. Constant to be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is public field. Removing it can break someone else code. I'm suggesting leaving it. |
||
public static Collection<Info> getPendingCollaborations(BoxAPIConnection api, String... fields) { | ||
QueryStringBuilder queryBuilder = new QueryStringBuilder(); | ||
queryBuilder.appendParam("status", "pending"); | ||
if (fields.length > 0) { | ||
queryBuilder.appendParam("fields", fields); | ||
} | ||
URL url = COLLABORATIONS_URL_TEMPLATE.buildWithQuery(api.getBaseURL(), queryBuilder.toString()); | ||
|
||
|
||
BoxJSONRequest request = new BoxJSONRequest(api, url, "GET"); | ||
try (BoxJSONResponse response = request.send()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,7 +274,7 @@ public BoxTask.Info addTask(BoxTask.Action action, String message, Date dueAt, | |
* @return the temporary download URL | ||
*/ | ||
public URL getDownloadURL() { | ||
URL url = CONTENT_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); | ||
URL url = getDownloadUrl(); | ||
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET"); | ||
request.setFollowRedirects(false); | ||
|
||
|
@@ -305,7 +305,7 @@ public void download(OutputStream output) { | |
* @param listener a listener for monitoring the download's progress. | ||
*/ | ||
public void download(OutputStream output, ProgressListener listener) { | ||
URL url = CONTENT_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); | ||
URL url = getDownloadUrl(); | ||
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET"); | ||
BoxAPIResponse response = request.send(); | ||
writeStream(response, output, listener); | ||
|
@@ -342,7 +342,7 @@ public void downloadRange(OutputStream output, long rangeStart, long rangeEnd) { | |
* @param listener a listener for monitoring the download's progress. | ||
*/ | ||
public void downloadRange(OutputStream output, long rangeStart, long rangeEnd, ProgressListener listener) { | ||
URL url = CONTENT_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); | ||
URL url = getDownloadUrl(); | ||
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET"); | ||
if (rangeEnd > 0) { | ||
request.addHeader("Range", String.format("bytes=%s-%s", rangeStart, rangeEnd)); | ||
|
@@ -352,6 +352,14 @@ public void downloadRange(OutputStream output, long rangeStart, long rangeEnd, P | |
writeStream(request.send(), output, listener); | ||
} | ||
|
||
/** | ||
* Can be used to override the URL used for file download. | ||
* @return URL for file downalod | ||
*/ | ||
protected URL getDownloadUrl() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This of our internal use when we want to change download URL |
||
return CONTENT_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); | ||
} | ||
|
||
@Override | ||
public BoxFile.Info copy(BoxFolder destination) { | ||
return this.copy(destination, null); | ||
|
@@ -516,6 +524,11 @@ public void getRepresentationContent(String representationHint, String assetPath | |
String repContentURLString = null; | ||
while (repContentURLString == null) { | ||
repContentURLString = this.pollRepInfo(representation.getInfo().getUrl()); | ||
try { | ||
Thread.sleep(100); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this sleep ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is basically infinite loop that is doing as many requests as it can. Only thing that can slow it down is rate limiter. This seems like a least we could improve. |
||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
this.makeRepresentationContentRequest(repContentURLString, assetPath, output); | ||
|
@@ -649,7 +662,7 @@ public boolean canUploadVersion(String name) { | |
*/ | ||
public boolean canUploadVersion(String name, long fileSize) { | ||
|
||
URL url = CONTENT_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); | ||
URL url = getDownloadUrl(); | ||
lukaszsocha2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "OPTIONS"); | ||
|
||
JsonObject preflightInfo = new JsonObject(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"total_count": 1, | ||
"total_count": 2, | ||
"entries": [ | ||
{ | ||
"type": "collaboration", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"total_count": 2, | ||
"entries": [ | ||
{ | ||
"type": "collaboration", | ||
"id": "12345", | ||
"item": { | ||
"type": "folder", | ||
"id": "3333", | ||
"sequence_id": "1", | ||
"etag": "1", | ||
"name": "Test Folder" | ||
}, | ||
"can_view_path": false | ||
}, | ||
{ | ||
"type": "collaboration", | ||
"id": "124783", | ||
"item": { | ||
"type": "folder", | ||
"id": "3333", | ||
"sequence_id": "1", | ||
"etag": "1", | ||
"name": "Test Folder" | ||
}, | ||
"can_view_path": true | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails sometimes so retrying usually solves issue.