-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
Luke-Sikina
commented
Apr 20, 2023
- 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)) { |
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.
!= 200
is a bit flawed imo. I think all 2xx codes are valid.
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)); | ||
} |
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.
We do this check like 3 different ways. I tried to normalize it a bit.
String composedURL = HttpClientUtil.composeURL(properties.getTargetPicsureUrl(), pathName); | ||
HttpResponse response = HttpClientUtil.retrievePostResponse(composedURL, headers, payload); | ||
if (HttpClientUtil.is2xx(response)) { |
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.
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, |
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.
Don't know why we were templating half of this.
response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); | ||
throwResponseError(response, targetPicsureUrl); | ||
HttpClientUtil.throwResponseError(response, properties.getTargetPicsureUrl()); |
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.
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)) { |
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.
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); |
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.
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) { |
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.
Wow this version of httpclient is old
- Added coverage to AggregateDataSharingResourceRS - Made a helper class for those tests - Fixed a marshalling bug
* 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
* 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
* 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