In the fifth week of the Google Summer of Code (GSoC) coding period, I made significant progress on several fronts. Here is a detailed breakdown them:
Addressing Mentor Feedback for PRs
Switching to the new Date and Time API
As part of this PR, tests were requested by my mentors to ensure the reliability and correctness of the code.
To address my mentors' request for tests, I initially examined the calling method, which was responsible for sending data to a Google form.
However, due to the specific nature of its functionality, I struggled to identify a suitable approach for writing tests.
To overcome the challenge, I resorted to an unconventional hack.
I extracted the relevant code block from checkIfOneWeekFromLastReport() and created a separate public method to encapsulate it. This extracted code block was as follows:
My mentor advised me to not because making a method public only for the sake of tests is not good. So I decided to go back and write tests using Java reflections to access private members of the class.
After I added the tests this PR got merged: https://github.com/openmrs/openmrs-sdk/commit/c7db8a1fd5f9c48a65cce2348ff6383257dd29bb
Using Java 8 Optional Class
Using Optional classes is something new for me. Initially, I perceived Optional as a replacement for if (val == null) statements with if (val.isPresent()). However, my mentor shared two invaluable articles that shed light on the true potential of Optional. These articles provided a comprehensive guide on best practices and effective use cases, enabling me to enhance my code accordingly
Here is a summary of the key takeaways from those articles
-
Never assign null to an optional variable. Instead of assigning null to an Optional variable, initialize it with an empty Optional using the Optional.empty() method.
-
Don't call get() directly on an Optional. Always check for the presence of a value using the isPresent() method before calling get(). Alternatively, you can use the orElse() method to provide a default value.
-
When using Optional, avoid using null directly. If you need a null reference, use the orElse(null) method instead.
-
Avoid using isPresent() and get() pairs for setting and returning a value. Instead, use the orElse() method to provide a default value.
-
Avoid using orElse() for returning a computed value. Instead, use orElseGet() with a Supplier to provide a computed value only when necessary.
-
Throw an exception in the absence of a value. Use orElseThrow() to throw an exception if no value is present in the Optional.
-
Throw explicit exceptions when no value is present. Use orElseThrow() with a custom exception supplier to throw a specific exception with relevant information.
-
Use ifPresent() to perform an action only when a value is present in the Optional. Avoid using isPresent() and get() for this purpose.
-
Use ifPresentOrElse() to execute an empty-based action if a value is not present in the Optional.
-
Return another Optional when no value is present. Use the or() method to return a different Optional if no value is present in the current Optional.
After reading this article I made changes to the code accordingly.
Updating the SDK to Java 11:
So our initial plan for this GSOC project was to update the SDK to use Java 8. After some considerations I decided that using Java 11 is going to be better than Java 8.
So with mentor's permissions I updated the SDK to use Java 11.
PR: https://github.com/openmrs/openmrs-sdk/pull/230
Updating Maven to the Latest Version:
Upgrading the SDK to the latest version of Maven is necessary to improve its reliability and performance. I updated all the maven plugins to latest version in this PR: https://github.com/openmrs/openmrs-sdk/pull/231/files
Enhancing the Documentation System:
The output from mvn openmrs-sdk:help is outdated. To make it up to date I had to
- Update the documentation with the current capabilities of plugins.
- Add documentation to the plugins that are currently not included in the documentation.
This was a meticulous and comprehensive task that involved reviewing each plugin's and parameter's functionality and updating the documentation accordingly.
Here is the PR for this: https://github.com/openmrs/openmrs-sdk/pull/232](https://github.com/openmrs/openmrs-sdk/pull/232
Bumping the SDK Version to 5.0.0-SNAPSHOT:
As we were having both the master branch and the 4.0.X branch producing the same version of the snapshot artifacts, we decided to bump the SDK version of the master branch to 5.0.0-SNAPSHOT.
PR: https://github.com/openmrs/openmrs-sdk/pull/229
Future
Because of some recent changes, we are having some trouble building the O3 front end. My main objective now is to find a way to mitigate these errors and add O3 support to the build-distro plugin. Thank you for reading,