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

RESTWS-953:Support setting values of type "Location" #617

Merged
merged 2 commits into from
Aug 12, 2024
Merged

Conversation

mogoodrich
Copy link
Member

Description of what I changed

Issue I worked on

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

Checklist: I completed these to help reviewers :)

  • 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

@coveralls
Copy link

coveralls commented Aug 12, 2024

Coverage Status

coverage: 47.536% (-0.05%) from 47.582%
when pulling 58fd2a9 on RESTWS-953
into 1390386 on master.


//We want clients to be able to fetch a coded value in one rest call
//and set the returned payload as the obs value
return;
Copy link
Member Author

Choose a reason for hiding this comment

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

I was reluctant to refactor this too much because I wasn't sure how good the test coverage was, but the nested if/else block were confusing and this change was going to make them even more confusing, so I removed the top-level if/else and had each block just return instead.

}

// if there is a potential uuid, see if there is a matching location and set
if (RestUtil.isUuid(potentialLocationUuid)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't strictly need to do a uuid check, but otherwise we'd we calling a getLocation.getLocationByUuid for any value text passed it, which seemed like it could be a performance hit.

return;
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

End of the stuff I added. The stuff below should be the same, just with one less if/then block.

@@ -936,4 +940,8 @@ public static Class<?> getSupportedClass(Resource resource) {
.supportedClass();
}
}

public static boolean isUuid(String str) {
return StringUtils.isNotBlank(str) && UUID_REGEX.matcher(str).matches();
Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't find any existing standard util methods for this (besides doing a UUID.toString() in a try/catch block, which was ugly) so I just grabbed a regex I found online.

Copy link
Member

Choose a reason for hiding this comment

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

I've definitely seen other implementations of this in OpenMRS code, can't remember where off-hand...

Copy link
Member

Choose a reason for hiding this comment

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

There are a few lying around, but they often run up against the issue that we've been allowing invalid UUIDs for years (e.g., every single "uuid" in CIEL is, in fact, not a "valid UUID"). Usually these implementations hang around until someone complains and we basically end up with a check that says "is this string 36 characters long"? Here is one version and a slight variant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, right, @ibacher regarding the invalid uuid formats for concepts. Hopefully shouldn't matter for this case, since it is regarding to locations, but makes sense to standardized on a single util method, will fix.

}
return;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the start of the stuff I added to handle location

Copy link
Member

@mseaton mseaton left a comment

Choose a reason for hiding this comment

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

LGTM, a few minor comments but nothing mandatory

Location location = Context.getLocationService().getLocationByUuid(potentialLocationUuid);
if (location != null) {
obs.setValueText(location.getLocationId().toString());
obs.setComment("org.openmrs.Location");
Copy link
Member

Choose a reason for hiding this comment

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

Fine, but could also do "Location.class.getName()"

@@ -936,4 +940,8 @@ public static Class<?> getSupportedClass(Resource resource) {
.supportedClass();
}
}

public static boolean isUuid(String str) {
return StringUtils.isNotBlank(str) && UUID_REGEX.matcher(str).matches();
Copy link
Member

Choose a reason for hiding this comment

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

I've definitely seen other implementations of this in OpenMRS code, can't remember where off-hand...

@mogoodrich
Copy link
Member Author

Thanks @mseaton ... I am merging so we can test some already-merged code that relies on this, but @ibacher @dkayiwa definitely interested in a post-commit review.

@mogoodrich mogoodrich merged commit 4f3e8ec into master Aug 12, 2024
1 check passed
@mogoodrich mogoodrich deleted the RESTWS-953 branch August 12, 2024 16:14
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.

4 participants