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

[ALS-4412] - Implement query ID API endpoints #111

Merged
merged 4 commits into from
May 25, 2023

Conversation

Luke-Sikina
Copy link
Member

  • Implement proxy query, queryStatus, and queryResult methods
  • Deduplicate code
  • Fix 2xx predicates that I broke
  • Make logging more consistent
  • Check for 2xx response codes, not just 200
  • Deduplicate constructor code
  • Make some constants final

- Make logging more consistent
- Check for 2xx response codes, not just 200
- Deduplicate constructor code
- Make some constants final
- Implement proxy query, queryStatus, and queryResult methods
- Deduplicate code
- Fix 2xx predicates
if (response.getStatusLine().getStatusCode() != 200) {
String composedURL = HttpClientUtil.composeURL(properties.getTargetPicsureUrl(), pathName);
HttpResponse response = HttpClientUtil.retrievePostResponse(composedURL, headers, payload);
if (HttpClientUtil.is2xx(response)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!= 200 is a bit flawed imo. I think all 2xx codes are valid.

Comment on lines 155 to 161
if (searchRequest == null) {
if (searchRequest == null || searchRequest.getQuery() == null) {
throw new ProtocolException(ProtocolException.MISSING_DATA);
}
Object search = searchRequest.getQuery();
if (search == null) {
throw new ProtocolException((ProtocolException.MISSING_DATA));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do this check like 3 different ways. I tried to normalize it a bit.

Comment on lines 158 to 160
String composedURL = HttpClientUtil.composeURL(properties.getTargetPicsureUrl(), pathName);
HttpResponse response = HttpClientUtil.retrievePostResponse(composedURL, headers, payload);
if (HttpClientUtil.is2xx(response)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normalizing this pattern across endpoints so I can pull it out later.

logger.error(
composedURL + " calling resource with id " + resourceUUID + " did not return a 200: {} {} ",
"{} calling resource with id {} did not return a 200: {} {} ", composedURL, resourceUUID,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know why we were templating half of this.

response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
throwResponseError(response, targetPicsureUrl);
HttpClientUtil.throwResponseError(response, properties.getTargetPicsureUrl());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to qualify these static methods. One step closer to actual DI, and it makes it a bit easier to grok.

}


HttpEntity entity = response.getEntity();
String entityString = EntityUtils.toString(entity, "UTF-8");
String responseString = entityString;

if(expectedResultType.equals("COUNT")) {
if("COUNT".equals(expectedResultType)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lead with constant values in equals. 1 less way to get npes

throw new ApplicationException(
"Error encoding search for resource with id " + searchRequest.getResourceUUID());
}
checkQuery(searchRequest);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not thrilled about all the exception based control flow, but we'll leave that for another PR.

@@ -46,6 +46,10 @@ public class HttpClientUtil {

private static final Logger logger = LoggerFactory.getLogger(HttpClientUtil.class);

public static boolean is2xx(HttpResponse response) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow this version of httpclient is old

- Added coverage to AggregateDataSharingResourceRS
- Made a helper class for those tests
- Fixed a marshalling bug
@Luke-Sikina Luke-Sikina merged commit 005b9db into release/gic-institution May 25, 2023
@Luke-Sikina Luke-Sikina deleted the gic-query-api branch May 25, 2023 14:28
@Luke-Sikina Luke-Sikina restored the gic-query-api branch July 26, 2023 15:14
Luke-Sikina added a commit that referenced this pull request Jul 26, 2023
* Refactoring AggDataSharingResourceRS

- Make logging more consistent
- Check for 2xx response codes, not just 200
- Deduplicate constructor code
- Make some constants final

* [ALS-4412] - Implement query ID API endpoints

- Implement proxy query, queryStatus, and queryResult methods
- Deduplicate code
- Fix 2xx predicates

* Unit tests + bug fixes

- Added coverage to AggregateDataSharingResourceRS
- Made a helper class for those tests
- Fixed a marshalling bug

* Do not persist to common area repo
Luke-Sikina added a commit that referenced this pull request Jul 26, 2023
* Refactoring AggDataSharingResourceRS

- Make logging more consistent
- Check for 2xx response codes, not just 200
- Deduplicate constructor code
- Make some constants final
- Fix 2xx predicates

* Unit tests + bug fixes

- Added coverage to AggregateDataSharingResourceRS
- Made a helper class for those tests
- Fixed a marshalling bug

* Do not persist to common area repo
Luke-Sikina added a commit that referenced this pull request Jul 27, 2023
* Refactoring AggDataSharingResourceRS

- Make logging more consistent
- Check for 2xx response codes, not just 200
- Deduplicate constructor code
- Make some constants final
- Fix 2xx predicates

* Unit tests + bug fixes

- Added coverage to AggregateDataSharingResourceRS
- Made a helper class for those tests
- Fixed a marshalling bug

* Do not persist to common area repo
@Luke-Sikina Luke-Sikina deleted the gic-query-api branch July 27, 2023 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants