BED-23: Bed Tags should be uniquely identified by name#89
BED-23: Bed Tags should be uniquely identified by name#89jwnasambu wants to merge 33 commits intoopenmrs:masterfrom
Conversation
4e0b290 to
7f3559c
Compare
| return; | ||
| } | ||
|
|
||
| List<BedTag> allTags = (List<BedTag>) bedManagementService.getAllBedTags(); |
There was a problem hiding this comment.
Do we need to the cast here?
There was a problem hiding this comment.
@wikumChamith Thanks for the review. I have made a fix.
a868895 to
a4571ce
Compare
| import org.powermock.api.mockito.PowerMockito; | ||
| import org.powermock.core.classloader.annotations.PrepareForTest; | ||
| import org.powermock.modules.junit4.PowerMockRunner; |
There was a problem hiding this comment.
Can we try to avoid using PowerMock?
There was a problem hiding this comment.
@wikumChamith Kindly feel free to review my PR with the proposed changes at your convinient time please!
a4c9583 to
5d17ceb
Compare
|
|
||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.mockito.Mockito.*; |
There was a problem hiding this comment.
There was a problem hiding this comment.
@wikumChamith Thanks for the point out. I have fixed the proposed changes. Kindly feel free to review my PR at your convinient time please!
6613614 to
329bb74
Compare
|
|
||
| List<BedTag> existingTags = bedManagementService.getAllBedTags(); | ||
| for (BedTag existingTag : existingTags) { | ||
| boolean isVoidedOrExpired = existingTag.isVoided() || existingTag.getDateVoided() != null; |
There was a problem hiding this comment.
It should be sufficient just to check this:
| boolean isVoidedOrExpired = existingTag.isVoided() || existingTag.getDateVoided() != null; | |
| boolean isVoided = existingTag.getVoided(); |
There's no reasonable case where dateVoided is not null but the tag isn't voided.
There was a problem hiding this comment.
@ibacher after fixing this proposed changes, I get a build failure which I belief is because the validator treats the expired tag as active. The getVoided() method does not correctly reflect that dateVoided is set and by replacing existingTag.getVoided() with existingTag.getDateVoided() != null to properly detect expired/voided tags which solves the build failure. I stand to be corrected.
| BedTag tag = (BedTag) target; | ||
|
|
||
| if (tag.getName() == null || tag.getName().trim().isEmpty()) { | ||
| errors.rejectValue("name", "bedtag.name.required", "Name is required"); |
There was a problem hiding this comment.
The strings added here should be added to the messages.properties or else they will never properly be translatable.
api/src/test/java/org/openmrs/validator/BedTagValidatorTest.java
Outdated
Show resolved
Hide resolved
2da590a to
940e7ed
Compare
|
@ibacher I Kindly need your guidance on one of the requests please? |
70b24f8 to
c7fdf98
Compare
| if (existingTag.getDateVoided() != null) { | ||
| isVoided = true; | ||
| } |
| if (!isVoided && existingTag.getName().equals(tag.getName())) { | ||
| errors.rejectValue("name", "bedtag.name.exists"); | ||
| break; | ||
| } |
There was a problem hiding this comment.
This needs to verify that the existingTag is different from the tag that we are validating. That's why the test is failing...
e6c8513 to
ac0c752
Compare
|
@ibacher, @wikumChamith Kindly I have fixed all the proposed changes. Feel free to review my PR at your convinient time please! |
ddb1b92 to
493fc39
Compare
| import org.springframework.validation.Validator; | ||
|
|
||
| @Handler(supports = {BedTag.class}, order = 50) | ||
| public class BedTagValidator implements Validator { |
There was a problem hiding this comment.
So, this class also need to be registered as a bean in the applicationContext.xml.
| * http://license.openmrs.org | ||
| * | ||
| * Software distributed under the License is distributed on an "AS IS" | ||
|
|
There was a problem hiding this comment.
Most of the reformatting here is harmless, but this line is incorrect.
| return bedTagMapDao.getBedTagByUuid(bedTagUuid); | ||
| } | ||
|
|
||
| @Override |
There was a problem hiding this comment.
| @Override | |
| @Override |
| @Authorized(value = { "Get Bed Tags", "Get Beds" }, requireAll = true) | ||
| BedTag getBedTagByUuid(String bedTagUuid); | ||
|
|
||
| BedTag getBedTagByName(String name); |
There was a problem hiding this comment.
Shouldn't this have an @Authorized annotation? But also, I don't think it belongs in this class at all.
|
|
||
| BedTag existing = bedManagementService.getBedTagByName(tag.getName().trim()); | ||
|
|
||
| if (existing != null && existing.getDateVoided() == null && !existing.getUuid().equals(tag.getUuid())) { |
There was a problem hiding this comment.
I still think we should be checking existing.getVoided(). The dateVoided property is informational, but not the determining factor for whether a value is voided or not.
|
@dkayiwa Kindly feel free to review my PR at your convinient time please! |
|
Can you discard the formatting changes? |
|
@dkayiwa Kindly feel free to review my PR at your convinient time please! |
|
Can you remove all those formatting changes? |
|
@dkayiwa Kindly feel free to review my PR at your convinient time please! |
| this.sessionFactory = sessionFactory; | ||
| } | ||
|
|
There was a problem hiding this comment.
Can you remove all these formatting changes?
20046b3 to
958884e
Compare
|
@dkayiwa I’ve tried resolving the requested changes, but each time I update the files, more formatting changes keep appearing in the commits. Could you please advise on the best way to handle or remove these formatting changes? I tried to create a new commit but still facing the same challenge as reflected on this link https://github.com/openmrs/openmrs-module-bedmanagement/compare/master...jwnasambu:BED-23b?expand=1 |
Description of what changed
I added a BedTagValidator to enforce validation rules on BedTag objects. This prevents creating two active bed tags with the same name, while still allowing duplicate names if the bed tags is expired. The validator also checks that the name is not null/empty/whitespace and respects field length constraints.
Issued worked on
https://openmrs.atlassian.net/browse/BED-23