exceptionfactory commented on code in PR #9959:
URL: https://github.com/apache/nifi/pull/9959#discussion_r2134134920
##########
nifi-extension-bundles/nifi-atlassian-bundle/nifi-atlassian-extensions/src/main/java/org/apache/nifi/atlassian/bitbucket/BitbucketRepositoryClient.java:
##########
@@ -348,39 +348,53 @@ private Iterator<JsonNode> getFiles(final String branch,
final String resolvedPa
// retrieve source data
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/src/{commit}/{path}
final URI uri =
getUriBuilder().addPathSegment("src").addPathSegment(lastCommit.get()).addPathSegment(resolvedPath).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing content
for repository [%s] on branch %s at path %s", repoName, branch, resolvedPath);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(
- String.format("Error while listing content for repository
[%s] on branch %s at path %s: %s", repoName, branch, resolvedPath,
getErrorMessage(response)));
- }
-
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
- }
- return jsonResponse.get("values").elements();
+ return paginateAndCollect(uri.toString(), errorMessage);
}
private Iterator<JsonNode> getListCommits(final String branch, final
String path) throws FlowRegistryException {
// retrieve latest commit for that branch
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/commits/{branch}
final URI uri =
getUriBuilder().addPathSegment("commits").addPathSegment(branch).addQueryParameter("path",
path).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing commits
for repository [%s] on branch %s", repoName, branch);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(String.format("Error while listing
commits for repository [%s] on branch %s: %s", repoName, branch,
getErrorMessage(response)));
- }
+ return paginateAndCollect(uri.toString(), errorMessage);
+ }
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
+ private Iterator<JsonNode> paginateAndCollect(final String url, final
String errorMessage) throws FlowRegistryException {
+ final List<JsonNode> allValues = new ArrayList<>();
+ String newUrl = url;
+ while (newUrl != null) {
+ HttpResponseEntity response = webClient.getWebClientService()
Review Comment:
```suggestion
final HttpResponseEntity response =
webClient.getWebClientService()
```
##########
nifi-extension-bundles/nifi-atlassian-bundle/nifi-atlassian-extensions/src/main/java/org/apache/nifi/atlassian/bitbucket/BitbucketRepositoryClient.java:
##########
@@ -348,39 +348,53 @@ private Iterator<JsonNode> getFiles(final String branch,
final String resolvedPa
// retrieve source data
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/src/{commit}/{path}
final URI uri =
getUriBuilder().addPathSegment("src").addPathSegment(lastCommit.get()).addPathSegment(resolvedPath).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing content
for repository [%s] on branch %s at path %s", repoName, branch, resolvedPath);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(
- String.format("Error while listing content for repository
[%s] on branch %s at path %s: %s", repoName, branch, resolvedPath,
getErrorMessage(response)));
- }
-
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
- }
- return jsonResponse.get("values").elements();
+ return paginateAndCollect(uri.toString(), errorMessage);
}
private Iterator<JsonNode> getListCommits(final String branch, final
String path) throws FlowRegistryException {
// retrieve latest commit for that branch
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/commits/{branch}
final URI uri =
getUriBuilder().addPathSegment("commits").addPathSegment(branch).addQueryParameter("path",
path).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing commits
for repository [%s] on branch %s", repoName, branch);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(String.format("Error while listing
commits for repository [%s] on branch %s: %s", repoName, branch,
getErrorMessage(response)));
- }
+ return paginateAndCollect(uri.toString(), errorMessage);
+ }
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
+ private Iterator<JsonNode> paginateAndCollect(final String url, final
String errorMessage) throws FlowRegistryException {
+ final List<JsonNode> allValues = new ArrayList<>();
+ String newUrl = url;
+ while (newUrl != null) {
+ HttpResponseEntity response = webClient.getWebClientService()
+ .get()
+ .uri(URI.create(newUrl))
+ .header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue())
+ .retrieve();
+
+ if (response.statusCode() != HttpURLConnection.HTTP_OK) {
+ throw new FlowRegistryException(String.format(errorMessage +
": %s", getErrorMessage(response)));
+ }
+
+ JsonNode root;
+ try {
+ root = objectMapper.readTree(response.body());
+ } catch (IOException e) {
+ throw new FlowRegistryException("Could not parse Bitbucket API
response", e);
Review Comment:
Recommend including the request URI in this message.
##########
nifi-extension-bundles/nifi-atlassian-bundle/nifi-atlassian-extensions/src/main/java/org/apache/nifi/atlassian/bitbucket/BitbucketRepositoryClient.java:
##########
@@ -348,39 +348,53 @@ private Iterator<JsonNode> getFiles(final String branch,
final String resolvedPa
// retrieve source data
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/src/{commit}/{path}
final URI uri =
getUriBuilder().addPathSegment("src").addPathSegment(lastCommit.get()).addPathSegment(resolvedPath).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing content
for repository [%s] on branch %s at path %s", repoName, branch, resolvedPath);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(
- String.format("Error while listing content for repository
[%s] on branch %s at path %s: %s", repoName, branch, resolvedPath,
getErrorMessage(response)));
- }
-
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
- }
- return jsonResponse.get("values").elements();
+ return paginateAndCollect(uri.toString(), errorMessage);
}
private Iterator<JsonNode> getListCommits(final String branch, final
String path) throws FlowRegistryException {
// retrieve latest commit for that branch
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/commits/{branch}
final URI uri =
getUriBuilder().addPathSegment("commits").addPathSegment(branch).addQueryParameter("path",
path).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing commits
for repository [%s] on branch %s", repoName, branch);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(String.format("Error while listing
commits for repository [%s] on branch %s: %s", repoName, branch,
getErrorMessage(response)));
- }
+ return paginateAndCollect(uri.toString(), errorMessage);
+ }
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
+ private Iterator<JsonNode> paginateAndCollect(final String url, final
String errorMessage) throws FlowRegistryException {
+ final List<JsonNode> allValues = new ArrayList<>();
+ String newUrl = url;
+ while (newUrl != null) {
+ HttpResponseEntity response = webClient.getWebClientService()
+ .get()
+ .uri(URI.create(newUrl))
+ .header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue())
+ .retrieve();
+
+ if (response.statusCode() != HttpURLConnection.HTTP_OK) {
+ throw new FlowRegistryException(String.format(errorMessage +
": %s", getErrorMessage(response)));
Review Comment:
This combination of string formatting and concatenation is a bit hard to
read. Since the method is private, the input `errorMessage` could be passed as
`errorMessageFormat` with a `%s` placeholder, and then this could be simplified
to `errorMessageFormat.formatted(getErrorMessage(response))`. Although I also
recommend declaring `final String responseErrorMessage =
getErrorMessage(response)` for readability.
##########
nifi-extension-bundles/nifi-atlassian-bundle/nifi-atlassian-extensions/src/main/java/org/apache/nifi/atlassian/bitbucket/BitbucketRepositoryClient.java:
##########
@@ -348,39 +348,53 @@ private Iterator<JsonNode> getFiles(final String branch,
final String resolvedPa
// retrieve source data
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/src/{commit}/{path}
final URI uri =
getUriBuilder().addPathSegment("src").addPathSegment(lastCommit.get()).addPathSegment(resolvedPath).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing content
for repository [%s] on branch %s at path %s", repoName, branch, resolvedPath);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(
- String.format("Error while listing content for repository
[%s] on branch %s at path %s: %s", repoName, branch, resolvedPath,
getErrorMessage(response)));
- }
-
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
- }
- return jsonResponse.get("values").elements();
+ return paginateAndCollect(uri.toString(), errorMessage);
}
private Iterator<JsonNode> getListCommits(final String branch, final
String path) throws FlowRegistryException {
// retrieve latest commit for that branch
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/commits/{branch}
final URI uri =
getUriBuilder().addPathSegment("commits").addPathSegment(branch).addQueryParameter("path",
path).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing commits
for repository [%s] on branch %s", repoName, branch);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(String.format("Error while listing
commits for repository [%s] on branch %s: %s", repoName, branch,
getErrorMessage(response)));
- }
+ return paginateAndCollect(uri.toString(), errorMessage);
+ }
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
+ private Iterator<JsonNode> paginateAndCollect(final String url, final
String errorMessage) throws FlowRegistryException {
+ final List<JsonNode> allValues = new ArrayList<>();
+ String newUrl = url;
Review Comment:
Recommend naming this `nextUrl` for clarity:
```suggestion
String nextUrl = url;
```
##########
nifi-extension-bundles/nifi-atlassian-bundle/nifi-atlassian-extensions/src/main/java/org/apache/nifi/atlassian/bitbucket/BitbucketRepositoryClient.java:
##########
@@ -348,39 +348,53 @@ private Iterator<JsonNode> getFiles(final String branch,
final String resolvedPa
// retrieve source data
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/src/{commit}/{path}
final URI uri =
getUriBuilder().addPathSegment("src").addPathSegment(lastCommit.get()).addPathSegment(resolvedPath).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing content
for repository [%s] on branch %s at path %s", repoName, branch, resolvedPath);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(
- String.format("Error while listing content for repository
[%s] on branch %s at path %s: %s", repoName, branch, resolvedPath,
getErrorMessage(response)));
- }
-
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
- }
- return jsonResponse.get("values").elements();
+ return paginateAndCollect(uri.toString(), errorMessage);
}
private Iterator<JsonNode> getListCommits(final String branch, final
String path) throws FlowRegistryException {
// retrieve latest commit for that branch
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/commits/{branch}
final URI uri =
getUriBuilder().addPathSegment("commits").addPathSegment(branch).addQueryParameter("path",
path).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing commits
for repository [%s] on branch %s", repoName, branch);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(String.format("Error while listing
commits for repository [%s] on branch %s: %s", repoName, branch,
getErrorMessage(response)));
- }
+ return paginateAndCollect(uri.toString(), errorMessage);
+ }
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
+ private Iterator<JsonNode> paginateAndCollect(final String url, final
String errorMessage) throws FlowRegistryException {
Review Comment:
It looks like the `URI` should be passed in, instead of the `String`, and
then the `nextUrl` should converted to a URI
##########
nifi-extension-bundles/nifi-atlassian-bundle/nifi-atlassian-extensions/src/main/java/org/apache/nifi/atlassian/bitbucket/BitbucketRepositoryClient.java:
##########
@@ -348,39 +348,53 @@ private Iterator<JsonNode> getFiles(final String branch,
final String resolvedPa
// retrieve source data
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/src/{commit}/{path}
final URI uri =
getUriBuilder().addPathSegment("src").addPathSegment(lastCommit.get()).addPathSegment(resolvedPath).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing content
for repository [%s] on branch %s at path %s", repoName, branch, resolvedPath);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(
- String.format("Error while listing content for repository
[%s] on branch %s at path %s: %s", repoName, branch, resolvedPath,
getErrorMessage(response)));
- }
-
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
- }
- return jsonResponse.get("values").elements();
+ return paginateAndCollect(uri.toString(), errorMessage);
}
private Iterator<JsonNode> getListCommits(final String branch, final
String path) throws FlowRegistryException {
// retrieve latest commit for that branch
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/commits/{branch}
final URI uri =
getUriBuilder().addPathSegment("commits").addPathSegment(branch).addQueryParameter("path",
path).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing commits
for repository [%s] on branch %s", repoName, branch);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(String.format("Error while listing
commits for repository [%s] on branch %s: %s", repoName, branch,
getErrorMessage(response)));
- }
+ return paginateAndCollect(uri.toString(), errorMessage);
+ }
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
+ private Iterator<JsonNode> paginateAndCollect(final String url, final
String errorMessage) throws FlowRegistryException {
+ final List<JsonNode> allValues = new ArrayList<>();
+ String newUrl = url;
+ while (newUrl != null) {
+ HttpResponseEntity response = webClient.getWebClientService()
+ .get()
+ .uri(URI.create(newUrl))
+ .header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue())
+ .retrieve();
+
+ if (response.statusCode() != HttpURLConnection.HTTP_OK) {
+ throw new FlowRegistryException(String.format(errorMessage +
": %s", getErrorMessage(response)));
+ }
+
+ JsonNode root;
+ try {
+ root = objectMapper.readTree(response.body());
+ } catch (IOException e) {
Review Comment:
```suggestion
} catch (final IOException e) {
```
##########
nifi-extension-bundles/nifi-atlassian-bundle/nifi-atlassian-extensions/src/main/java/org/apache/nifi/atlassian/bitbucket/BitbucketRepositoryClient.java:
##########
@@ -348,39 +348,53 @@ private Iterator<JsonNode> getFiles(final String branch,
final String resolvedPa
// retrieve source data
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/src/{commit}/{path}
final URI uri =
getUriBuilder().addPathSegment("src").addPathSegment(lastCommit.get()).addPathSegment(resolvedPath).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing content
for repository [%s] on branch %s at path %s", repoName, branch, resolvedPath);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(
- String.format("Error while listing content for repository
[%s] on branch %s at path %s: %s", repoName, branch, resolvedPath,
getErrorMessage(response)));
- }
-
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
- }
- return jsonResponse.get("values").elements();
+ return paginateAndCollect(uri.toString(), errorMessage);
}
private Iterator<JsonNode> getListCommits(final String branch, final
String path) throws FlowRegistryException {
// retrieve latest commit for that branch
//
https://api.bitbucket.org/2.0/repositories/{workspace}/{repoName}/commits/{branch}
final URI uri =
getUriBuilder().addPathSegment("commits").addPathSegment(branch).addQueryParameter("path",
path).build();
- final HttpResponseEntity response =
this.webClient.getWebClientService().get().uri(uri).header(AUTHORIZATION_HEADER,
authToken.getAuthzHeaderValue()).retrieve();
+ final String errorMessage = String.format("Error while listing commits
for repository [%s] on branch %s", repoName, branch);
- if (response.statusCode() != HttpURLConnection.HTTP_OK) {
- throw new FlowRegistryException(String.format("Error while listing
commits for repository [%s] on branch %s: %s", repoName, branch,
getErrorMessage(response)));
- }
+ return paginateAndCollect(uri.toString(), errorMessage);
+ }
- final JsonNode jsonResponse;
- try {
- jsonResponse = this.objectMapper.readTree(response.body());
- } catch (IOException e) {
- throw new FlowRegistryException("Could not parse response from
Bitbucket API", e);
+ private Iterator<JsonNode> paginateAndCollect(final String url, final
String errorMessage) throws FlowRegistryException {
Review Comment:
For clarity, recommend adjusting the method name:
```suggestion
private Iterator<JsonNode> getPagedResponseValues(final String url,
final String errorMessage) throws FlowRegistryException {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]