RESTWS-702 : Add support for unvoiding/unretiring resources#373
RESTWS-702 : Add support for unvoiding/unretiring resources#373dkayiwa merged 1 commit intoopenmrs:masterfrom
Conversation
|
Hi @Ruhanga I was skimming really quick through your code and I see you have named your method unDelete. I think undelete is simply one word hence the method names do not need to be camelized they way you did. My two cents ( or just one 😄 ) |
| * @return unvoided/unretired object | ||
| * @since 2.2.0 | ||
| */ | ||
| Object unDelete(String uuid, RequestContext context) throws ResponseException; |
There was a problem hiding this comment.
should be capitalized like undelete (no capital D). E.g. for consistency with unvoid, unretire, etc.
There was a problem hiding this comment.
I made changes accordingly
| * @return Object | ||
| */ | ||
|
|
||
| // TODO make this method an abstruct method when all subclasses have overriden it |
There was a problem hiding this comment.
Can't merge code that has a TODO in it. Remove this comment (and the blank lines).
If there is no base implementation of this the method should be abstract, just like delete. Are there many other resources that would need this fixed?
There was a problem hiding this comment.
I deleted the TODO and empty line but left the default implementation in place because I think this will help the end user trouble shoot problems that may come with existing resources that may not be part of the rest.webservices module and don't have their own implementation for this already.
| return RestUtil.updated(response, updated); | ||
|
|
||
| if (post.get("deleted") != null && "false".equals(post.get("deleted")) && post.size() == 1) { | ||
| //This branching provides for unvoiding or unretiring a resource |
There was a problem hiding this comment.
This comment is obvious from context, so you don't need to explicitly state this.
| protected Object unDelete(Encounter enc, RequestContext context) { | ||
| Encounter unvoidedEnc = null; | ||
| if (!enc.isVoided()) { | ||
| unvoidedEnc = Context.getEncounterService().getEncounter(enc.getEncounterId()); |
There was a problem hiding this comment.
You already have "Encounter enc" passed into the method. Why do you need to fetch it again? Can't you just do
if (enc.isVoided()) {
// unvoid it
}
return // convert
There was a problem hiding this comment.
Thank you for this observation, I have adjusted the code accordingly.
|
I am going ahead to include the rest of the resources that are |
|
What I have done -Included remaining resources to unvoid/unretire that are unretireable including MetaData related resources
|
|
@Ruhanga did you address all the changes requested by @djazayeri ? |
|
@dkayiwa , yes I addressed the requests for changes from @djazayeri . |
| * org.openmrs.module.webservices.rest.web.RequestContext) | ||
| */ | ||
| @Override | ||
| public Object unDelete(String uuid, RequestContext context) throws ResponseException { |
There was a problem hiding this comment.
Didn't i see comments about renaming these methods?
There was a problem hiding this comment.
@Ruhanga can you please squash your commits into one?
There was a problem hiding this comment.
Thank you @samuelmale , commits have been squashed into one.
| * @return Object | ||
| */ | ||
| protected T undelete(T delegate, RequestContext context) throws ResponseException { | ||
| //Default implimentation of this method if not overriden by sub-class is to raise an |
There was a problem hiding this comment.
Can you fix this typo "implimentation"?
There was a problem hiding this comment.
Thank you @samuelmale , I've got this resolved.
| * @param context | ||
| * @throws ResponseException | ||
| * @return unvoided/unretired object | ||
| * @since 2.2.0 |
There was a problem hiding this comment.
Thank you very much for pointing out this @dkayiwa , it was supposed to be 2.25.0 (release version to contain these changes). I have updated the commit to reflect the correction. I initially thought the version to be compared against openmrs-core.
| * Undeletes the specified resource, which in the OpenMRS context means either unvoiding or | ||
| * unretiring it | ||
| * | ||
| * @param uuid |
There was a problem hiding this comment.
Did you just forget to document these params?
There was a problem hiding this comment.
You mean uuid and context ? If so what in their documentation is missing?
There was a problem hiding this comment.
That was quick, the description is missing. But This is how the other params I have seen in this module being documented.
There was a problem hiding this comment.
Did you do some googling about javadoc?
There was a problem hiding this comment.
Definitely yes, and in this case I had to remind myself. Good convention is to include the @params's description. Gona do just that. Thank you @dkayiwa .
| conceptClass.setDateRetired(new Date()); | ||
| conceptClass.setRetireReason("random reason"); | ||
| service.saveConceptClass(conceptClass); | ||
| Assert.assertTrue(conceptClass.isRetired()); |
There was a problem hiding this comment.
Will the above assertion fail if line 105 is commented out?
There was a problem hiding this comment.
Definitely not, what was in my mind though was conceptClass = service.saveConceptClass(conceptClass);. I am refactoring to reflect this.
| return RestUtil.updated(response, undeletedRes); | ||
| } | ||
| else { | ||
| Updatable res = (Updatable) restService.getResourceByName(buildResourceName(resource)); |
There was a problem hiding this comment.
What happens if you have the deleted property together with others?
There was a problem hiding this comment.
Also what happens when the property deleted has a value of true?
There was a problem hiding this comment.
An Exception similar to all other invalid properties is thrown, i.e conversion Exception.
There was a problem hiding this comment.
Do you have a test to confirm so?
There was a problem hiding this comment.
This test should be part of work done earlier since this is not the first time this possibility exists.
|
Did you confirm that you have added this for all resources and a corresponding test for each? |
| public void shouldUnRetireAnEncounterType() throws Exception { | ||
| EncounterType encounterType = service.getEncounterTypeByUuid(getUuid()); | ||
| encounterType.setRetired(true); | ||
| encounterType.setRetiredBy(Context.getAuthenticatedUser()); |
There was a problem hiding this comment.
I guess you do not need to set retiredBy, retireReason, and dateRetired.
There was a problem hiding this comment.
Yes, thank you for pointing out this @dkayiwa , these methods are deprecated apart from setRetireReason().
| obj.setRetiredBy(Context.getAuthenticatedUser()); | ||
| obj.setDateRetired(new Date()); | ||
| obj.setRetireReason("random reason"); | ||
| service.savePersonAttributeType(obj); |
There was a problem hiding this comment.
What happens if you comment out the above line?
| relationshipType.setRetiredBy(Context.getAuthenticatedUser()); | ||
| relationshipType.setDateRetired(new Date()); | ||
| relationshipType.setRetireReason("random reason"); | ||
| service.saveRelationshipType(relationshipType); |
There was a problem hiding this comment.
What happens if you comment out the above line?
| patientIdentifierType.setRetiredBy(Context.getAuthenticatedUser()); | ||
| patientIdentifierType.setDateRetired(new Date()); | ||
| patientIdentifierType.setRetireReason("random reason"); | ||
| service.savePatientIdentifierType(patientIdentifierType); |
There was a problem hiding this comment.
What happens when the above line is commented out?
Am now asking this same question for the third time. Do you take time to review your changes?
There was a problem hiding this comment.
Apologies on this @dkayiwa , I think I have been following my not up-to date list of the changes and resources affected as I have made on this pull request. The next commit will consider everything is fine. Thank you very much.
| * Undeletes the specified resource, which in the OpenMRS context means either unvoiding or | ||
| * unretiring it | ||
| * | ||
| * @param uuid Uuid to the delegate to unvoid/unretire |
There was a problem hiding this comment.
Delegate in my thinking as I have seen it being used with respect to this module, is a domain object.
There was a problem hiding this comment.
What has that got to do with the API consumer?
There was a problem hiding this comment.
I think to make this doc safe, I'l replace "delegate" with "resource" instead.
|
|
||
| @Test | ||
| public void shouldUnVoidAVisit() throws Exception { | ||
| Visit visit = service.getVisitByUuid(RestTestConstants1_9.VISIT_UUID); |
There was a problem hiding this comment.
Can you try void an existing visit in any of the datasets used for VisitServiceTest in the core platform?
There was a problem hiding this comment.
I think it's not possible since this setting is in a Web and Module context sensitive environment. Unless I duplicate the datasets into this module.
There was a problem hiding this comment.
When documenting, avoid exposing internal implementation details to the client.
There was a problem hiding this comment.
Thank you @dkayiwa , I've taken note of this.
| program.setRetireReason("random reason"); | ||
| program = service.saveProgram(program); | ||
| Assert.assertTrue(program.isRetired()); | ||
|
|
There was a problem hiding this comment.
Can you first make a REST call and confirm that it is indeed retired?
There was a problem hiding this comment.
I have used Service.get.......ByUuid() which is implicitly called on any GET request for a given resource as suggested somewhere on this PR.
| public void shouldUnRetireAPersonAttributeType() throws Exception { | ||
|
|
||
| final String nonRetiredAttribute = "a0f5521c-dbbd-4c10-81b2-1b7ab18330df"; | ||
| PersonAttributeType obj = service.getPersonAttributeTypeByUuid(nonRetiredAttribute); |
There was a problem hiding this comment.
Just a variable name. Meaning comes from its type definition → PersonAttributeType .
There was a problem hiding this comment.
Can you do some googling about good variable names?
There was a problem hiding this comment.
Thank you @dkayiwa , this helped as it usually does. I going to rename this for better meaning.
| PatientIdentifierType patientIdentifierType = service.getPatientIdentifierTypeByUuid(getUuid()); | ||
| patientIdentifierType.setRetired(true); | ||
| patientIdentifierType.setRetireReason("random reason"); | ||
| patientIdentifierType = service.savePatientIdentifierType(patientIdentifierType); |
There was a problem hiding this comment.
Generally, instead of asserting using the returned object, i would prefer fetching it afresh using getPatientIdentifierTypeByUuid and then assert that it is retired
There was a problem hiding this comment.
I agree @dkayiwa . Let me refactor to reflect these changes.
|
@Ruhanga did you try run your changes and test using an interface like this to unretire a concept? |
|
@dkayiwa , this was not implemented for the |
|
Do we have a ticket for it? |
|
@dkayiwa , there's actually never been any ticket for or against this, I guess I have to create or rather seek consent from talk to create a ticket that addresses the Unretiring of a |
|
@Ruhanga did you try run your changes and test using an interface like this https://demo.openmrs.org/openmrs/module/webservices/rest/test.htm to unretire a patient? |
|
Okay, I hadn't @dkayiwa . Let me hard test these changes on a running instance. Thank you. |
|
@dkayiwa , for the far I have gone unretiring a resource is possible including the |
|
Can you share some screenshots on the JIRA ticket? |
|
Cool @dkayiwa . |
RESTWS-702 Add support for unvoiding/unretiring resources
Description of what I changed
Updated "
Deletable" interface to also support:undelete(String uuid, RequestContext context) throws ResponseException;Made
DelegatingCrudeResourceclass to implement this method (undelete(String uuid, RequestContext context) throws ResponseException;)Updated
BaseDelegatingResourceclass to have a protectedunDelete(Object, RequestContext)which temporarily/by-default provides for an alternative message for the classes that have not yet overridden this method. This pattern follows the design used bydelete(Object, String, RequestContext) throws ResponseException;method in the same class.Overrode the
unDelete(Object, RequestContext)for the following Resources:->
PatientResource1_8->
PersonResource1_8->
ObsResource1_8->
OrderResource1_8->
EncounterResource1_8I am welcoming comments and enhancements on resources connected to
VoidableOpenmrs Objects to include.Issue I worked on
see https://issues.openmrs.org/browse/RESTWS-702
Checklist: I completed these to help reviewers :)
My pull request only contains ONE single commit
My IDE is configured to follow the code style of this project.
I have added tests to cover my changes.
I ran
mvn clean packageright before creating this pull request andadded all formatting changes to my commit.
All new and existing tests passed.
My pull request is based on the latest changes of the master branch.