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

Implement GET DownloadStatus endpoint #52 #54

Merged
merged 3 commits into from
Jan 16, 2025

Conversation

patrick-austin
Copy link

@patrick-austin patrick-austin commented Dec 4, 2024

Should be independent of other changes.

  • Add endpoint in UserResource to check Downloads status by id.
  • Add function in DownloadRepository for the above.

Closes #52
Closes #53

* the request.
*/
public List<DownloadStatus> getStatuses(String userName, List<Long> downloadIds) throws NotFoundException {
StringBuilder stringBuilder = new StringBuilder();

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)

Copy link
Author

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).

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.

Copy link
Author

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,

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?

Copy link
Author

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);

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.

Copy link
Author

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.

@patrick-austin patrick-austin merged commit a4bc2fc into 36_queuing Jan 16, 2025
1 check passed
@patrick-austin patrick-austin deleted the 52_get_download_status branch January 16, 2025 14:06
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