Expose LocationService.getAllChildLocations() via REST#406
Expose LocationService.getAllChildLocations() via REST#406reagan-meant wants to merge 1 commit intoopenmrs:masterfrom
Conversation
| Set<Location> descendants=new HashSet<>(); | ||
| Location location = Context.getLocationService().getLocationByUuid(uuid); | ||
| if (location == null) | ||
| location = Context.getLocationService().getLocation(uuid); |
There was a problem hiding this comment.
Will Context.getLocationService().getLocation(uuid) always return a location ?
|
@reagan-meant You should add the ticket id in your commit message https://wiki.openmrs.org/display/docs/Pull+Request+Tips |
359e7ad to
0006b5a
Compare
0006b5a to
28ac980
Compare
f9c73bb to
2a4407f
Compare
|
@ibacher could you review this? |
ibacher
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Probably isn't the version of StringUtil you want.
|
|
||
| @Override | ||
| public PageableResult search(RequestContext context) throws ResponseException { | ||
| Set<Location> descendants=new HashSet<>(); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Why are we not using if-else here??
| } | ||
| } | ||
| return new EmptySearchResult(); | ||
| } |
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 --amendI 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 --amendI ran
mvn clean packageright before creating this pull request andadded 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