Skip to content

Expose LocationService.getAllChildLocations() via REST#406

Closed
reagan-meant wants to merge 1 commit intoopenmrs:masterfrom
reagan-meant:RESTWS-315
Closed

Expose LocationService.getAllChildLocations() via REST#406
reagan-meant wants to merge 1 commit intoopenmrs:masterfrom
reagan-meant:RESTWS-315

Conversation

@reagan-meant
Copy link

RESTWS-315:Expose LocationService.getAllChildLocations() via REST
Added a new method to expose the getDescendants method of Location class via RESTservices
https://issues.openmrs.org/browse/RESTWS-315

Description of what I changed

Issue I worked on

see https://issues.openmrs.org/browse/RESTWS-

Checklist: I completed these to help reviewers :)

  • My pull request only contains ONE single commit
    (the number above, next to the 'Commits' tab is 1).

    No? -> read here on how to squash multiple commits into one

  • My IDE is configured to follow the code style of this project.

    No? Unsure? -> configure your IDE, format the code and add the changes with git add . && git commit --amend

  • I have added tests to cover my changes. (If you refactored
    existing code that was well tested you do not have to add tests)

    No? -> write tests and add them to this commit git add . && git commit --amend

  • I ran mvn clean package right before creating this pull request and
    added all formatting changes to my commit.

    No? -> execute above command

  • All new and existing tests passed.

    No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.

  • My pull request is based on the latest changes of the master branch.

    No? Unsure? -> execute command git pull --rebase upstream master

Set<Location> descendants=new HashSet<>();
Location location = Context.getLocationService().getLocationByUuid(uuid);
if (location == null)
location = Context.getLocationService().getLocation(uuid);
Copy link
Contributor

Choose a reason for hiding this comment

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

Will Context.getLocationService().getLocation(uuid) always return a location ?

@ODORA0
Copy link
Member

ODORA0 commented Sep 8, 2019

@reagan-meant You should add the ticket id in your commit message https://wiki.openmrs.org/display/docs/Pull+Request+Tips

@gracepotma
Copy link

@ibacher could you review this?

Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

Thanks for this! I've added some small comments, but this looks like it's probably worth having.

import org.openmrs.module.webservices.rest.web.response.ResponseException;
import org.springframework.stereotype.Component;

import ca.uhn.hl7v2.util.StringUtil;
Copy link
Member

Choose a reason for hiding this comment

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

Probably isn't the version of StringUtil you want.


@Override
public PageableResult search(RequestContext context) throws ResponseException {
Set<Location> descendants=new HashSet<>();
Copy link
Member

Choose a reason for hiding this comment

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

Could you clean up the indentation and spacing here to conform to the usual OMRS standards?

public class LocationDescendantSearchHandler2_0 implements SearchHandler {

private final SearchConfig searchConfig = new SearchConfig("first", RestConstants.VERSION_1 + "/location",
Arrays.asList("2.0.*", "2.1.*", "2.2.*", "2.3.*"), Arrays.asList(new SearchQuery.Builder(
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be updated to take account of 2.4.* and 2.5.*


@Override
public PageableResult search(RequestContext context) throws ResponseException {
Set<Location> descendants=new HashSet<>();
Copy link
Member

Choose a reason for hiding this comment

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

Why are we allocating a new HashSet<> here at all? it looks like we always overwrite this with descendants = location.getDescendantLocations(). I'm also a bit confused as to why we declare that variable here at all instead of just on line 58?

@Override
public PageableResult search(RequestContext context) throws ResponseException {
Set<Location> descendants=new HashSet<>();
List<Location> temp=new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

Can we name this something better than "temp"? Even "result" or "searchResults" are more descriptive.

if (location == null) {
location = Context.getLocationService().getLocation(parentUuid);
}
if(location != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Why are we not using if-else here??

Comment on lines +63 to +66
}
}
return new EmptySearchResult();
}
Copy link
Member

Choose a reason for hiding this comment

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

Fix the indentation.

@dkayiwa dkayiwa closed this Apr 3, 2023
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.

7 participants