Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __Breaking Changes:__
__New Features and Enhancements:__

__Bug Fixes:__
- Fix `url` for `BoxFileRequest.Info` object ([#906](https://github.com/box/box-java-sdk/pull/906))


## 2.55.1 [2021-07-30]
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/box/sdk/BoxAPIConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class BoxAPIConnection {
private static final String REVOKE_URL_STRING = "https://api.box.com/oauth2/revoke";
private static final String DEFAULT_BASE_URL = "https://api.box.com/2.0/";
private static final String DEFAULT_BASE_UPLOAD_URL = "https://upload.box.com/api/2.0/";
private static final String DEFAULT_BASE_APP_URL = "https://app.box.com";

private static final String AS_USER_HEADER = "As-User";
private static final String BOX_NOTIFICATIONS_HEADER = "Box-Notifications";
Expand Down Expand Up @@ -75,6 +76,7 @@ public class BoxAPIConnection {
private String revokeURL;
private String baseURL;
private String baseUploadURL;
private String baseAppURL;
private boolean autoRefresh;
private int maxRetryAttempts;
private int connectTimeout;
Expand Down Expand Up @@ -129,6 +131,7 @@ public BoxAPIConnection(String clientID, String clientSecret, String accessToken
this.revokeURL = REVOKE_URL_STRING;
this.baseURL = DEFAULT_BASE_URL;
this.baseUploadURL = DEFAULT_BASE_UPLOAD_URL;
this.baseAppURL = DEFAULT_BASE_APP_URL;
this.autoRefresh = true;
this.maxRetryAttempts = BoxGlobalSettings.getMaxRetryAttempts();
this.connectTimeout = BoxGlobalSettings.getConnectTimeout();
Expand Down Expand Up @@ -363,6 +366,22 @@ public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}

/**
* Gets the base App url. Used for e.g. file requests.
* @return the base App Url.
*/
public String getBaseAppUrl() {
return this.baseAppURL;
}

/**
* Sets the base App url. Used for e.g. file requests.
* @param baseAppURL a base App Url.
*/
public void setBaseAppUrl(String baseAppURL) {
this.baseAppURL = baseAppURL;
}

/**
* Gets an access token that can be used to authenticate an API request. This method will automatically refresh the
* access token if it has expired since the last call to <code>getAccessToken()</code>.
Expand Down
55 changes: 44 additions & 11 deletions src/main/java/com/box/sdk/BoxFileRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public BoxFileRequest.Info getInfo() {
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
return new Info(responseJSON);
return new Info(responseJSON, this.getAPI().getBaseAppUrl());
}

/**
Expand All @@ -62,7 +62,7 @@ public BoxFileRequest.Info copyInfo(String folderId) {
request.setBody(body.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject jsonObject = JsonObject.readFrom(response.getJSON());
return new Info(jsonObject);
return new Info(jsonObject, this.getAPI().getBaseAppUrl());
}

/**
Expand Down Expand Up @@ -90,7 +90,7 @@ public BoxFileRequest.Info copyInfo(BoxFileRequest.Info info, String folderId) {
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject jsonObject = JsonObject.readFrom(response.getJSON());
info.update(jsonObject);
return new Info(jsonObject);
return new Info(jsonObject, this.getAPI().getBaseAppUrl());
}

/**
Expand Down Expand Up @@ -145,6 +145,8 @@ public class Info extends BoxResource.Info {
private Date updatedAt;
private BoxUser.Info updatedBy;
private URL url;
private String path;
private String baseUrl;

/**
* Constructs an empty Info object.
Expand All @@ -167,8 +169,14 @@ public Info(String json) {
*
* @param jsonObject the parsed JSON object.
*/
Info(JsonObject jsonObject) {
Info(JsonObject jsonObject, String fileRequestBaseUrl) {
super(jsonObject);
try {
this.baseUrl = fileRequestBaseUrl;
this.url = new URL(this.baseUrl + this.path);
} catch (MalformedURLException e) {
throw new BoxAPIException("Couldn't construct url for file request", e);
}
}

@Override
Expand Down Expand Up @@ -360,12 +368,42 @@ public BoxUser.Info getUpdatedBy() {
/**
* Gets the URL can be shared with users to let them upload files to the associated folder.
*
* @return the date at which this task is due.
* @return the URL for files upload.
*/
public URL getUrl() {
return this.url;
}

/**
* Gets the base URL for the upload files link.
*
* @return the base url including protocol and hostname.
*/
public String getBaseUrl() {
return this.baseUrl;
}

/**
* Gets the URL containing only the path (e.g. "/f/123456789") shared with users to let
* them upload files to the associated folder.
*
* @return the path of the URL for files upload.
*/
public String getPath() {
return this.path;
}

/**
* Sets the base URL for the upload files link. Can throw an exception if format of the URL is invalid.
*
* @param baseUrl the base url including protocol and hostname.
* @throws MalformedURLException when baseUrl format is invalid.
*/
public void setBaseUrl(String baseUrl) throws MalformedURLException {
this.baseUrl = baseUrl;
this.url = new URL(this.baseUrl + this.path);
}

@Override
void parseJSONMember(JsonObject.Member member) {
super.parseJSONMember(member);
Expand Down Expand Up @@ -409,12 +447,7 @@ void parseJSONMember(JsonObject.Member member) {
BoxUser user = new BoxUser(getAPI(), userID);
this.createdBy = user.new Info(userJSON);
} else if (memberName.equals("url")) {
try {
String urlString = value.asString();
this.url = new URL(urlString);
} catch (MalformedURLException e) {
throw new BoxAPIException("Couldn't parse url for file request", e);
}
this.path = value.asString();
}
} catch (Exception e) {
throw new BoxDeserializationException(memberName, value.toString(), e);
Expand Down
2 changes: 1 addition & 1 deletion src/test/Fixtures/BoxFileRequest/CopyFileRequest200.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
"login": "ceo@example.com",
"name": "Aaron Levie"
},
"url": "https://cloud.app.box.com/f/19e57f40ace247278a8e3d336678c64a"
"url": "/f/19e57f40ace247278a8e3d336678c64a"
}
2 changes: 1 addition & 1 deletion src/test/Fixtures/BoxFileRequest/GetFileRequest200.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
"login": "ceo@example.com",
"name": "Aaron Levie"
},
"url": "https://cloud.app.box.com/f/19e57f40ace247278a8e3d336678c64a"
"url": "/f/19e57f40ace247278a8e3d336678c64a"
}
2 changes: 1 addition & 1 deletion src/test/Fixtures/BoxFileRequest/UpdateFileRequest200.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
"login": "ceo@example.com",
"name": "Aaron Levie"
},
"url": "https://cloud.app.box.com/f/19e57f40ace247278a8e3d336678c64a"
"url": "/f/19e57f40ace247278a8e3d336678c64a"
}
2 changes: 2 additions & 0 deletions src/test/java/com/box/sdk/BoxFileRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public void getFileRequestSucceeds() throws IOException {

Assert.assertEquals("Following documents are requested for your process", fileRequestInfo.getDescription());
Assert.assertEquals("Please upload documents", fileRequestInfo.getTitle());
Assert.assertEquals(this.api.getBaseAppUrl()
+ fileRequestInfo.getPath(), fileRequestInfo.getUrl().toString());
}

@Test
Expand Down