O3-5662: Migrate SequentialReceiptNumberGeneratorService to OpenMRS Service - #185
Conversation
There was a problem hiding this comment.
Hello @EDSONZ-WASSWA thanks alot for working on this , but try fixing some few things here :
The previous IObjectDataServiceTest base class provided CRUD test coverage via createEntity, updateEntityFields, assertEntity, and getTestEntityCount. These have been removed without replacement.
Could you add explicit tests for the new service methods? Something like:
@test
public void save_shouldPersistModel() {
SequentialReceiptNumberGeneratorModel model = new SequentialReceiptNumberGeneratorModel();
// set required fields...
SequentialReceiptNumberGeneratorModel saved = service.save(model);
assertNotNull(saved.getId());
}
@test
public void getAll_shouldReturnSavedModels() {
List results = service.getAll();
assertNotNull(results);
// assert expected count from test dataset
}
@test
public void purge_shouldDeleteModel() {
SequentialReceiptNumberGeneratorModel model = service.getAll().get(0);
service.purge(model);
assertFalse(service.getAll().contains(model));
}
note : This ensures we don't lose coverage for basic persistence operations during the migration.
Thank you @Josephkagimu1 for the review |
|
|
@Josephkagimu1 I have made update, look at them and see |
| */ | ||
| @Transactional | ||
| public class SequentialReceiptNumberGeneratorServiceImpl extends BaseObjectDataServiceImpl<SequentialReceiptNumberGeneratorModel, BasicEntityAuthorizationPrivileges> implements ISequentialReceiptNumberGeneratorService { | ||
| public class SequentialReceiptNumberGeneratorServiceImpl extends BaseObjectDataServiceImpl<SequentialReceiptNumberGeneratorModel, BasicEntityAuthorizationPrivileges> implements SequentialReceiptNumberGeneratorService { |
There was a problem hiding this comment.
nit: The interface no longer extends IObjectDataService, but this impl still extends BaseObjectDataServiceImpl. This creates an inconsistent inheritance — the impl inherits methods (like getAll(), save()) from the base class and re-declares them on the interface separately.
Consider either:
Replacing extends BaseObjectDataServiceImpl<...> with extends BaseOpenmrsService and injecting the repository directly, or
Keeping the current inheritance but adding a code comment explaining why BaseObjectDataServiceImpl is still needed (e.g., reusing its DAO logic).
| public interface ISequentialReceiptNumberGeneratorService extends IObjectDataService<SequentialReceiptNumberGeneratorModel> { | ||
| public interface SequentialReceiptNumberGeneratorService extends OpenmrsService { | ||
|
|
||
| void setRepository(BaseHibernateRepository repository); |
There was a problem hiding this comment.
=> void setRepository(BaseHibernateRepository repository);
This line isnt necessary , removing it would be better , but thanks for the work .
There was a problem hiding this comment.
Add the save() test after the getOnly_shouldReturnTheFirstModel() test in SequentialReceiptNumberGeneratorServiceTest.java. That's around line ~160.
Add this save test :
@test
public void save_shouldSaveModelSuccessfully() {
SequentialReceiptNumberGeneratorModel model = service.getOnly();
model.setCashierPrefix("UP");
SequentialReceiptNumberGeneratorModel saved = service.save(model);
Context.flushSession();
Assert.assertEquals("UP", saved.getCashierPrefix());
}
Every thing else LGTM . @EDSONZ-WASSWA
|
nit: Consider adding a test for service.save(model) in a follow-up — currently only GroupSequence save is tested, not the model itself. |



Summary
This Pr now migrates
SequentialReceiptNumberGeneratorServiceto the standardOpenMRS service pattern, I tried to be consistent with how other services in this
module are structured.
Changes Made
Interface (
SequentialReceiptNumberGeneratorService)ISequentialReceiptNumberGeneratorService— dropsthe
Iprefix per standard Java and OpenMRS naming conventionsOpenmrsServiceinstead of the legacyIObjectDataService<SequentialReceiptNumberGeneratorModel>(
setRepository,getAll,purge) that do not belong on apurpose-built service interface
save(SequentialReceiptNumberGeneratorModel)as an explicit,documented method with proper
@throwsJavadoc@shouldJavadoc tags that referencedNullPointerException— changed toIllegalArgumentExceptionImplementation (
SequentialReceiptNumberGeneratorServiceImpl)BaseOpenmrsServiceinstead of the legacyBaseObjectDataServiceImplgetPrivileges()andvalidate()overrides that onlyexisted to satisfy the old base class
@Transactionaldeclared at class level;readOnly = trueoverrides applied only to read methods
IllegalArgumentExceptionconsistently — previously
saveSequenceandpurgeSequencethrew
NullPointerExceptionsavefor consistencySpring Context (
moduleApplicationContext.xml)serviceContextregistration fromISequentialReceiptNumberGeneratorServicetoSequentialReceiptNumberGeneratorServiceConsumers I Updated
SequentialReceiptNumberGenerator.javaAbstractSequentialReceiptNumberGenerator.javaSequentialReceiptNumberGeneratorController.javaSequentialReceiptNumberGenerator2xController.javaTests (
SequentialReceiptNumberGeneratorServiceTest)ISequentialReceiptNumberGeneratorServiceTestIObjectDataServiceTesttoBaseModuleContextTestthe old base was tied to the genericservice layer being replaced
Context.getService()in@BeforecreateEntity,updateEntityFields,assertEntity,getTestEntityCount)that only existed to satisfy the old test base class
NullPointerExceptionnow correctly expect
IllegalArgumentExceptiongetOnly_shouldReturnANewModelIfNoneHasBeenDefinedwhich depended on
service.purge(model)a method no longeron the service interface
Tests
All tests pass:
SequentialReceiptNumberGeneratorServiceTestSequentialReceiptNumberGeneratorTestRelated Issue
https://openmrs.atlassian.net/browse/O3-5662
please @NethmiRodrigo @wikumChamith please have a look at this PR thank you