-
Notifications
You must be signed in to change notification settings - Fork 1
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
Implement GET DownloadStatus endpoint #52 #54
Conversation
* the request. | ||
*/ | ||
public List<DownloadStatus> getStatuses(String userName, List<Long> downloadIds) throws NotFoundException { | ||
StringBuilder stringBuilder = new StringBuilder(); |
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 think this section creating the comma separated list can be replaced with:
String commaSepString = String.join(",", downloadIds);
(I think there is a similar section in another PR which I didn't comment on so I need to go back and try to find that)
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.
String.join()
requires the second argument to be a CharSequence
or Iterable<? extends CharSequence>
- but we have a List<Long>
, and Long
doesn't extend CharSequence
. To use String.join
I think we'd need to first iterate over every id, get the String
value, then join (unless there's a neater/more efficient way of casting):
List<String> stringDownloadIds = new ArrayList<>();
downloadIds.forEach(downloadId -> {
stringDownloadIds.add(downloadId.toString());
});
String joinedDownloadIds = String.join(",", stringDownloadIds);
I guess it's 2 lines shorter (so maybe looks nicer?) but I can only assume it's less efficient because we're looping twice . Let me know if you still prefer it and I can make the change (or not).
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 think I prefer the shorter version as it's much simpler despite the slight inefficiency of looping twice.
It could be simplified even further using a standard for-each loop:
List<String> stringDownloadIds = new ArrayList<>();
for (Long downloadId : downloadIds) {
stringDownloadIds.add(downloadId.toString());
}
String joinedDownloadIds = String.join(",", stringDownloadIds);
which gets rid of the (I find) rather awkward syntax of Lambda expressions.
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.
Sure, I can't see the inefficiency actually mattering/bottlenecking here, so happy to go for whatever is clearest to someone else reading the code
(I do actually like lambdas though... 😬 )
@GET | ||
@Path("/downloads/status") | ||
@Produces({ MediaType.APPLICATION_JSON }) | ||
public Response getDownloadStatuses(@QueryParam("facilityName") String facilityName, |
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.
As with other PRs, can the facility name be made optional?
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 think this one should be optional once it's merged onto the changes from #47 - it's using a QueryParam
so can be left out, and the update FacilityMap
functions will handle null
values by returning the configured default.
download.setStatus(DownloadStatus.COMPLETE); | ||
download = downloadRepository.save(download); | ||
downloadIds.add(download.getId()); | ||
Response response = userResource.getDownloadStatuses("LILS", sessionId, downloadIds); |
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 feel like as the download IDs is a list, the test ought to have more than one item in it.
And if the status were set different on those Downloads then it would also be possible to check that the statuses are returned in an order matching the request.
So that the code doesn't get too repetitive with creating the downloads, it might be nice to make use of the createDownload method that you created in one of the other PRs.
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.
Yes it would ensure it properly tests the String joining stuff above as well. Will refactor the dummyDownload functions from StatusCheckTest
to TestHelpers
so we can use them here as well.
Should be independent of other changes.
Closes #52
Closes #53