AM-241: Adopt Hibernate Envers auditing for appointment module - #194
AM-241: Adopt Hibernate Envers auditing for appointment module#194Binayak490-cyber wants to merge 5 commits into
Conversation
|
Hi @druchniewicz, Raised PR-1 (prerequisite) for this ticket: https://openmrs.atlassian.net/browse/AM-241 This PR now upgrades the OpenMRS platform version from 2.4.2 → 2.8.4 to align the Bahmni Appointments module with the latest omrs-core version running on the dev3 reference server. Once this PR is reviewed and merged, we can proceed with PR-2 - enabling Hibernate Envers auditing (@Audited annotations + _AUD shadow tables + Liquibase changelog) as the main deliverable of this ticket https://openmrs.atlassian.net/browse/AM-241 which is as we planned to proceed. Please check it out now…! |
Hi @Binayak490-cyber I think you can enable the Hibernate envers auditing in this PR. I think it comes down to mark all required entities as @Audited. After that you can create an appointment and check if new entry in appointment audit table appears - I think this will be the best test |
Hi @druchniewicz, thanks for the feedback! So it means that I will add the @Audited annotations to all the required entities directly in this PR itself, so both the platform upgrade and the Hibernate Envers auditing will be delivered together in PR #194...? |
@Binayak490-cyber yes exactly. AM-241 is about adopting appointment module to use hibernate envers auditing so it should all be done in scope of this ticket. Upgrading OMRS version is just a part of this ticket because without it we won't be able to enable auditing in appointments module |
|
Hi @druchniewicz, now I added the Hibernate Envers auditing (commit Changes:
One thing to say, Note: Envers is off by default in OpenMRS. To activate on a live server, add |
| </createIndex> | ||
| </changeSet> | ||
|
|
||
| <!-- Hibernate Envers auditing tables (AM-241) --> |
There was a problem hiding this comment.
I think audit tables creation should not be done this way. I think it should work out of the box when you start the application with hibernate.integration.envers.enabled=true the same like all others tables. We don't have liquibase migrations for every single table in OpenMRS, it is done automatically by Envers. It looks for @Audited tables and creates audit tables for them.
What's more these migrations are wrong because you create tables with hardcoded "_AUD" suffix what is wrong
There was a problem hiding this comment.
Yes @druchniewicz you are correct - removed all the manual Liquibase changesets for the AUD tables. Envers will create them automatically when hibernate.integration.envers.enabled=true is set, the same way it handles all other audited tables in OpenMRS. The @Audited annotations on the entities are all that's needed. I actually added it while testing but forgot to remove it while committing it.
… them automatically
|
Any update @druchniewicz...? |
I should be able to verify it today |
|
@Binayak490-cyber at the first glance seems it looks good. Audit tables are created and when I change something in patient appointment new entry is saved in patient_appointment_aud table. Surprising thing is that I can see these entities in Audit log web page: but results are empty when I select e.g. org.openmrs.module.appointments.model.Appointment even though I have data in these appointment audit tables. AI gives me hints that it can be related to NotAudited annotations in appointments module. @Binayak490-cyber can you deploy auditlog module from this my PR - openmrs/openmrs-module-auditlogweb#31 and test on that?
Another important thing that I noticed - default suffix for audit tables is "_audit" so for patient_appointment table audit table will be "patient_appointment_audit" <- created by Envers BUT appointments module already provides own patient_appointment_table so there is a name collision and there can be an issue like This is a quite specific case and probably we have to use custom suffix different than "_audit", but probably in most of cases there will be such "_audit" suffix used. Can you check if we can somehow handle it? At least catch issues like these and not to break whole migration process? |
…ng patient_appointment_audit table
@druchniewicz, Fixed the name collision - added |
@Binayak490-cyber good idea to use custom name for Appointment entity to not clash with the existing |
|
@druchniewicz, found the root cause of the empty Appointment audit results which you also said and I also think that this was only the prime reason for that. Two fields were missing @NotAudited: provider - commented out in HBM but still visible to Envers (no DB column) Regarding my previous commit - I intentionally held back the @NotAudited fix to avoid breaking anything without live server verification, since you had the environment running and I am facing some issues while running the server. Could you please re-test it on your end? |
@druchniewicz, I think the issue which I am facing to run and deploy the audit log module is related to java versions, my JAVA_HOME is setup with java 17 or more as all other repositories of OpenMRS where I have worked, all requires that only but the bahmni openmrs-module-appointments still runs on java 8 but my desktop is not yet configured for java 8, so I think my all modules for this repo is configured and built upon java 17 or more and therefore I am facing the issue while running and deploying the audit appointment log module of Bahmni. |
@Binayak490-cyber I think it should not be a problem, I'm currently using java21 and I can deploy auditlog module, appointments module and others. You may probably have problems when you build module and tests fail. Please use |
@druchniewicz, yes I think that as there are many extensions installed in my IDE, like metals and many more which is overwriting and breaking the openmrs module updates and dependencies and I think that due to the broken dependencies and as you said the failing tests for that when doing mvn clean install -DskipTests is the issue for this. |
@Binayak490-cyber audit log PR has been merged so you can just use version from the main branch - https://github.com/openmrs/openmrs-module-auditlogweb |
Okk @druchniewicz. |
@Binayak490-cyber were you able to set it up locally and test it? |
|
@Binayak490-cyber reminder |




Summary
openmrs.platform.versionfrom2.4.2to2.8.4to match the dev3 reference server (prerequisite for Envers)Changes
Platform upgrade fixes:
pom.xml: bumpopenmrs.platform.version2.4.2→2.8.4api/pom.xml,atom-feed/pom.xml,omod/pom.xml: explicitly declarePowerMockandjavax.maildependencies (no longer transitive inopenmrs-test 2.8.x)DefaultAppointmentStatusChangeValidator: wrapgetGlobalProperty()with proxy privilege (AdministrationServicenow requires privilege in2.8.x)appointmentTestData.xml: move test appointments frompatient_id=1topatient_id=2(Hibernate 5 in2.8.xis strict about Person/Patient session cache)AtomFeedAdviceActivatorComponentTest: addorg.openmrs.logging.*to@PowerMockIgnore(newOpenmrsConfigurationFactoryin2.8.xcauses NPE)Hibernate Envers auditing:
@AuditedtoAppointment,AppointmentServiceDefinition,AppointmentServiceType,AppointmentProvider,AppointmentRecurringPattern,Speciality@NotAuditedon collection fields pointing to non-audited entitiesrevision_entity+ 6_AUDshadow tablesAppointmentEnversAuditITverifying Envers schema creation and error-free savesNote: Envers is disabled by default in OpenMRS. To activate on a live server, set
hibernate.integration.envers.enabled=trueinopenmrs-runtime.properties.Test plan
mvn clean package -Dmaven.test.skip=true→ BUILD SUCCESSmvn clean package(Java 8, mirrors CI) → BUILD SUCCESS, 0 failures