这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@wikumChamith
Copy link
Member

Updated module to Java 21 and Platform 2.7.3. Replaced WebUtils#getTargetPage, which was removed in newer Spring versions, with a custom implementation.

Ticket: https://openmrs.atlassian.net/browse/LUI-200

@wikumChamith wikumChamith requested a review from dkayiwa April 7, 2025 06:40
@wikumChamith wikumChamith changed the title Migrate to platform 2.7.3 and Java 21 Migrate to Platform 2.7.3 and Java 21 Apr 7, 2025
*/
protected int getTargetPage(HttpServletRequest request, int currentPage) {
return WebUtils.getTargetPage(request, PARAM_TARGET, currentPage);
Enumeration<String> parameterNames = request.getParameterNames();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind pointing me to where you got this implementation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda based this on the original implementation

    public static int getTargetPage(ServletRequest request, String paramPrefix, int currentPage) {
        Enumeration<String> paramNames = request.getParameterNames();

        while(paramNames.hasMoreElements()) {
            String paramName = (String)paramNames.nextElement();
            if (paramName.startsWith(paramPrefix)) {
                for(int i = 0; i < SUBMIT_IMAGE_SUFFIXES.length; ++i) {
                    String suffix = SUBMIT_IMAGE_SUFFIXES[i];
                    if (paramName.endsWith(suffix)) {
                        paramName = paramName.substring(0, paramName.length() - suffix.length());
                    }
                }

                return Integer.parseInt(paramName.substring(paramPrefix.length()));
            }
        }

        return currentPage;
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you get that from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just going to the source using the IDE.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That one includes a logic to remove the submit button image suffixes. I did not include that here. Should I add that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which version of spring did you copy it from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version the module was using: Spring 4.1.4 RELEASE

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the code

@dkayiwa
Copy link
Member

dkayiwa commented Apr 7, 2025

You would need to create a branch of the module for older platform versions.
Do not forget to also update the version in the pom.xml files.

@wikumChamith
Copy link
Member Author

You would need to create a branch of the module for older platform versions. Do not forget to also update the version in the pom.xml files.

I created the 1.x branch and also updated the development version to 2.0.0-SNAPSHOT: 53c7372

@wikumChamith
Copy link
Member Author

@dkayiwa don't merge this yet, I just noticed this is not running all the tests correctly.

@wikumChamith
Copy link
Member Author

@dkayiwa don't merge this yet, I just noticed this is not running all the tests correctly.

We can get the tests to run by either removing the parent element or updating the maven-parent artifact and setting the version to the latest snapshot of that artifact:
openmrs/openmrs-contrib-maven-parent-module#7

cc: @ibacher

@dkayiwa
Copy link
Member

dkayiwa commented Apr 8, 2025

I created the 1.x branch and also updated the development version to 2.0.0-SNAPSHOT: 53c7372

I have switched the bamboo CI build from the master to the 1.x branch.

@wikumChamith
Copy link
Member Author

@dkayiwa I'm running into an issue with the findCountAndPatients_shouldMatchPatientWithIdentifiersThatContainNoDigit test. The method getCountOfPatients doesn't return a match for the search query unless I set the includeVoided argument to true—even though the patient identifier being searched for isn’t voided. I was also able to reproduce the same behavior in core by writing a test directly there

@dkayiwa
Copy link
Member

dkayiwa commented Apr 9, 2025

Is the test failure triggered by simply switching the platform version?

@wikumChamith
Copy link
Member Author

Is the test failure triggered by simply switching the platform version?

Yeah

@wikumChamith
Copy link
Member Author

@dkayiwa I fixed the test errors.

omod/pom.xml Outdated
<scope>test</scope>
</dependency>

<dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need these bytebuddy dependencies?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we need it for Mockito. I think after we migrate the Core to a newer version of Mockito we could remove this from here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What error do you get when you remove them from just here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ERROR] ConceptFormBackingObject_shouldCopyNumericAttributes  Time elapsed: 0.175 s  <<< ERROR!
org.mockito.exceptions.base.MockitoException: 

Mockito cannot mock this class: class org.openmrs.ConceptNumeric.

If you're not sure why you're getting this error, please report to the mailing list.


Java               : 21
JVM vendor name    : Amazon.com Inc.
JVM vendor version : 21.0.6+7-LTS
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 21.0.6+7-LTS
JVM info           : mixed mode, sharing
OS name            : Linux
OS version         : 6.1.0-32-amd64


You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.

Underlying exception : org.mockito.exceptions.base.MockitoException: Could not modify all classes [interface org.openmrs.OpenmrsObject, class java.lang.Object, class org.openmrs.ConceptNumeric, interface org.openmrs.Auditable, interface java.io.Serializable, interface org.openmrs.customdatatype.Customizable, class org.openmrs.Concept, interface org.openmrs.Changeable, class org.openmrs.BaseOpenmrsObject, interface org.openmrs.Creatable, interface org.openmrs.Attributable, interface org.openmrs.Retireable]
	at org.openmrs.web.controller.concept.ConceptFormControllerTest.ConceptFormBackingObject_shouldCopyNumericAttributes(ConceptFormControllerTest.java:25)
Caused by: org.mockito.exceptions.base.MockitoException: Could not modify all classes [interface org.openmrs.OpenmrsObject, class java.lang.Object, class org.openmrs.ConceptNumeric, interface org.openmrs.Auditable, interface java.io.Serializable, interface org.openmrs.customdatatype.Customizable, class org.openmrs.Concept, interface org.openmrs.Changeable, class org.openmrs.BaseOpenmrsObject, interface org.openmrs.Creatable, interface org.openmrs.Attributable, interface org.openmrs.Retireable]
	at org.openmrs.web.controller.concept.ConceptFormControllerTest.ConceptFormBackingObject_shouldCopyNumericAttributes(ConceptFormControllerTest.java:25)
Caused by: java.lang.IllegalStateException: 

Byte Buddy could not instrument all classes within the mock's type hierarchy

This problem should never occur for javac-compiled classes. This problem has been observed for classes that are:
 - Compiled by older versions of scalac
 - Classes that are part of the Android distribution
	at org.openmrs.web.controller.concept.ConceptFormControllerTest.ConceptFormBackingObject_shouldCopyNumericAttributes(ConceptFormControllerTest.java:25)
Caused by: java.lang.IllegalArgumentException: Java 21 (65) is not supported by the current version of Byte Buddy which officially supports Java 20 (64) - update Byte Buddy or set net.bytebuddy.experimental as a VM property
	at org.openmrs.web.controller.concept.ConceptFormControllerTest.ConceptFormBackingObject_shouldCopyNumericAttributes(ConceptFormControllerTest.java:25)


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see my comment about removing them from only that file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you referring to "mockito-inline"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need it to do static mocks without using powermock.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What i mean is, i put a comment in a specific file to remove the bytebuddy dependencies from only that file. Can you do that and commit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh ok. I updated that and it is working now :)

<concept_description concept_description_id="5090" concept_id="5090" description="Patient&apos;s height in kilograms." locale="en" creator="1" date_created="2004-08-12 00:00:00.0" uuid="18ae66c9-cd2e-429d-9c6d-29bd5805dcf8"/>
<concept_name concept_id="5090" name="HEIGHT (KG)" locale="en" creator="1" date_created="2004-08-12 00:00:00.0" concept_name_id="1439" voided="false" uuid="4302daf5-acc8-4173-b766-bed42ae79e06" concept_name_type="FULLY_SPECIFIED" locale_preferred="0"/>
<concept_numeric concept_id="5090" hi_normal="250.0" low_critical="0.0" units="cm" precise="true"/>
<concept_numeric concept_id="5090" hi_normal="250.0" low_critical="0.0" units="cm" display_precision="true" allow_decimal="true" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need the display_precision?


//will be sending the alert via ajax, so we need to escape js special chars
model.put("alertMessage", JavaScriptUtils.javaScriptEscape(alertMessage));
if(alertMessage != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Remove any image button suffixes (like .x or .y)
if (param.endsWith(suffix)) {
param = param.substring(0, param.length() - suffix.length());
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not have this break in the original code.

try {
return Integer.parseInt(pageStr);
}
catch (NumberFormatException e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code does not catch this exception.

@wikumChamith
Copy link
Member Author

@dkayiwa I updated the PR.

<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.17.4</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add scope here?

@dkayiwa dkayiwa merged commit e13bb24 into openmrs:master Apr 11, 2025
1 check passed
@dkayiwa
Copy link
Member

dkayiwa commented Apr 30, 2025

@wikumChamith basing on the approach which have taken for the addresshierarchy module, is there anything that prevents us from running or compiling this on Java 8 too?

@wikumChamith
Copy link
Member Author

@wikumChamith basing on the approach which have taken for the addresshierarchy module, is there anything that prevents us from running or compiling this on Java 8 too?

No. We can support both Java 21 and Java 8 for this module.

@dkayiwa
Copy link
Member

dkayiwa commented Apr 30, 2025

So can we do the needful?

@wikumChamith
Copy link
Member Author

So can we do the needful?

@dkayiwa PR: #214

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants