-
Notifications
You must be signed in to change notification settings - Fork 17
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
COH-50 : Cohort resources cannot be voided #26
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ibacher, could you please review this PR? I added some comments as well.
api/src/main/java/org/openmrs/module/cohort/api/impl/CohortTypeServiceImpl.java
Show resolved
Hide resolved
@ManojLL can you add some tests for this? |
@dkayiwa I added some tests for voidCohort method. Can you review? |
api/src/main/java/org/openmrs/module/cohort/api/impl/CohortServiceImpl.java
Outdated
Show resolved
Hide resolved
api/src/main/java/org/openmrs/module/cohort/api/impl/CohortTypeServiceImpl.java
Show resolved
Hide resolved
cohort.setVoided(true); | ||
cohort.setVoidReason(reason); | ||
|
||
for (CohortMember cohortMember : cohort.getCohortMembers()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cohort won't voided automatically. That is why manually set voided true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a test to demonstrate it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean tests in this pull request. Not a screenshot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words, tests which would fail if you removed that for loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words, tests which would fail if you removed that
for loop
If I remove for loop
tests wont fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which means that you do not have tests to demonstrate the problem that you claim to require the for loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dkayiwa I updated the test can you review ?
api/src/test/java/org/openmrs/module/cohort/api/impl/CohortServiceImplTest.java
Outdated
Show resolved
Hide resolved
cohortMember.setVoided(true); | ||
cohortMember.setVoidReason("Cohort voided"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we need these two explicit setVoided()
and setVoidReason()
calls rather than calling the service method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ibacher I thought that, it would be better to call the two explicit would be better than calling Context.getService
multiple times inside the for loop
considering the performance, that is why I use setVoided
and setVoidReasin
methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd tend to prefer the service call. You could always do:
CohortMemberService cms = Context.getService(CohortMemberService.class);
// loop
cms.voidCohortMember();
// end loop
That way, it's the CohortMemberService's responsibility to know how to void a cohort member (and also it fixes the real problem which is that calling these methods depends on Hibernate's implicit context to flush those changes to the DB whereas calling the service method will actually ensure that those changes are always written.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ibacher After rename the voidChort
method to voidCohortM
,no need to call cohortMemberservice
void method to make cohortmember
to voided. when delete a cohort
, the child cohortmember
getting Voided.
@@ -167,9 +167,11 @@ public void shouldVoidCohort() { | |||
cohortMember.setPatient(patient); | |||
cohortMember.setUuid("4834jk3-n34nm30-34nm34-348nl"); | |||
cohortMember.setCohort(cohortM); | |||
cohortM.addMemberships(cohortMember); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to write a separate test for this. The test here isn't really valid because ultimately we mock the createOrUpdate()
call...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ibacher This test is to check whether the child cohortMember
is voided when the parent cohort is deleted. So I added the cohortMember
to the cohort
and used assertions to check the cohort
and cohortMember
is voided after deleting the cohort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, what I was trying to get at is the way in which the mock changes this from how the code would run in production because the key thing about voiding the memberships is that the voiding gets written to the database, but because we've mocked the call to createOrUpdate()
nothing is getting written to a database, so, ultimately, this test ends up verifying that cohortMember.setVoided()
was called, but not that the cohortMember
was actually saved in a voided state.
@ManojLL the method needs renaming to If we want other platform AOP things to work for other methods like saveCohort, etc, we would need to rename those methods too. But any way, that would be a different ticket. |
@dkayiwa rename the |
@ManojLL do you think you can add a test? |
@ManojLL would it be easier for you to just put un mocked tests here? https://github.com/openmrs/openmrs-module-cohort/blob/master/api/src/test/java/org/openmrs/module/cohort/api/dao/CohortGenericDaoTest.java |
@dkayiwa I added tests for |
I do not see your test calling the |
@dkayiwa I updated the test |
The test that you added passes even when you do not fix the reported problem. |
@dkayiwa updated the tests, You can review. |
@Test | ||
public void shouldVoidCohortM() { | ||
CohortM cohortToVoid = dao.get(COHORT_UUID); | ||
cohortToVoid.setVoided(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you setting the void properties of the cohort and then at the same time call the voidCohort service method? It is the service method that is supposed to take care of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dkayiwa I thought that, the cohort
which is passing to the voidCoghortM
method needs be voided true.
btw I updated test.
api/src/test/java/org/openmrs/module/cohort/api/dao/CohortGenericDaoTest.java
Outdated
Show resolved
Hide resolved
api/src/test/java/org/openmrs/module/cohort/api/dao/CohortGenericDaoTest.java
Show resolved
Hide resolved
api/src/test/java/org/openmrs/module/cohort/api/dao/CohortGenericDaoTest.java
Show resolved
Hide resolved
Thank you all for getting this done. @dkayiwa @ibacher will it be possible to do a release with this fix? |
@Piumal1999 feel empowered to do the release by yourself. Here are the instructions: https://wiki.openmrs.org/display/docs/Releasing+a+Module+from+Bamboo |
Sure, I would love to. I just created a help desk ticket to get access to the bamboo dashboard. |
I’d prefer if we hold off on releasing this just yet. There’s no reason we need to do that to unblock the issue; we can just update the O3 release to use the snapshot and then, once we inevitably find another problem or two, we can fix things without all the hassle. We’ll cut a release of this the next time we need to release the 3.x RefApp (which will likely be soon anyways). |
Oh sorry @ibacher. I already did the release.
Btw, how do we change the module versions used in dev3? Is it done by updating this? |
Yes. |
Issue worked on:
https://issues.openmrs.org/browse/COH-50?filter=-1
Description
This PR fixed the issue in (COH-50) DELETE Cohort endpoint.