From c5af83fa6a73ce3733c0625a4b19274f11959353 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Mon, 17 Jun 2024 16:41:44 -0400 Subject: [PATCH 1/4] RESTWS-942 - Obs for a Concept Numeric with allowDecimal = false should not return a decimal as a value (#612) --- .../resource/openmrs1_11/ObsResource1_11.java | 22 ++++++++++++++++++ .../openmrs1_11/ObsResource1_11Test.java | 23 +++++++++++++++++++ .../resource/openmrs1_8/ObsResource1_8.java | 13 ++++++++--- .../openmrs1_9/ObsResource1_9Test.java | 12 +++++----- 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java index c5dca8ed0..14626f497 100644 --- a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java +++ b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java @@ -12,7 +12,11 @@ import io.swagger.models.Model; import io.swagger.models.ModelImpl; import io.swagger.models.properties.StringProperty; +import org.apache.commons.lang.BooleanUtils; +import org.openmrs.Concept; +import org.openmrs.ConceptNumeric; import org.openmrs.Obs; +import org.openmrs.api.db.hibernate.HibernateUtil; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.PropertySetter; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -92,4 +96,22 @@ public static void setFormFieldNamespace(Obs obs, Object namespace) { public String getResourceVersion() { return RestConstants1_11.RESOURCE_VERSION; } + + /** + * @return a Double if the ConceptNumeric is configured as allowDecimal, but an Integer otherwise + * This changes the implementation from the pre-1.11 field named precise. + */ + protected Number getValueNumeric(Obs obs) { + if (obs.getValueNumeric() == null) { + return null; + } + Concept concept = HibernateUtil.getRealObjectFromProxy(obs.getConcept()); + if (concept instanceof ConceptNumeric) { + ConceptNumeric conceptNumeric = (ConceptNumeric) concept; + if (BooleanUtils.isFalse(conceptNumeric.getAllowDecimal())) { + return obs.getValueNumeric().intValue(); + } + } + return obs.getValueNumeric(); + } } diff --git a/omod-1.11/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11Test.java b/omod-1.11/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11Test.java index 9d525cbdf..3be6db0ea 100644 --- a/omod-1.11/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11Test.java +++ b/omod-1.11/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11Test.java @@ -9,9 +9,14 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11; +import org.junit.Assert; +import org.junit.Test; +import org.openmrs.ConceptNumeric; import org.openmrs.Obs; import org.openmrs.api.context.Context; +import org.openmrs.module.webservices.rest.SimpleObject; import org.openmrs.module.webservices.rest.web.RestTestConstants1_8; +import org.openmrs.module.webservices.rest.web.representation.Representation; import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest; public class ObsResource1_11Test extends BaseDelegatingResourceTest { @@ -44,4 +49,22 @@ public String getDisplayProperty() { public String getUuidProperty() { return RestTestConstants1_8.OBS_UUID; } + + @Test + public void asRepresentation_shouldReturnNumericValueBasedOnConceptNumericAllowDecimal() { + Obs obs = getObject(); + obs.setValueNumeric(20.0); + ConceptNumeric cn = Context.getConceptService().getConceptNumeric(5497); + obs.setConcept(cn); + cn.setAllowDecimal(true); + SimpleObject rep = getResource().asRepresentation(getObject(), Representation.DEFAULT); + Object value = rep.get("value"); + Assert.assertEquals(20.0, value); + Assert.assertEquals(Double.class, value.getClass()); + cn.setAllowDecimal(false); + rep = getResource().asRepresentation(getObject(), Representation.DEFAULT); + value = rep.get("value"); + Assert.assertEquals(20, value); + Assert.assertEquals(Integer.class, value.getClass()); + } } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java index 1ed900c8b..00a5900e1 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java @@ -278,7 +278,7 @@ public String getDisplayString(Obs obs) { * @return */ @PropertyGetter("value") - public static Object getValue(Obs obs) throws ConversionException { + public Object getValue(Obs obs) throws ConversionException { if (obs.isComplex()) { //Note that complex obs value is handled by ObsComplexValueController1_8 SimpleObject so = new SimpleObject(); @@ -322,13 +322,20 @@ public static Object getValue(Obs obs) throws ConversionException { } } - + if (obs.getValueNumeric() != null) { - return obs.getValueNumeric(); + return getValueNumeric(obs); } return null; } + + /** + * @return the valueNumeric from the obs + */ + protected Number getValueNumeric(Obs obs) { + return obs.getValueNumeric(); + } /** * Sets the members of an obs group diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ObsResource1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ObsResource1_9Test.java index f4e637738..ec560b4ce 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ObsResource1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ObsResource1_9Test.java @@ -220,7 +220,7 @@ public void setValue_shouldReturnUuidForConceptTrue() throws Exception { Obs obs = new Obs(); obs.setConcept(Context.getConceptService().getConceptByUuid(BOOLEAN_CONCEPT_UUID)); ObsResource1_8.setValue(obs, trueConcept); - assertEquals(trueConcept, ObsResource1_8.getValue(obs)); + assertEquals(trueConcept, new ObsResource1_8().getValue(obs)); } @Test @@ -232,7 +232,7 @@ public void setValue_shouldReturnDrug() throws Exception { String drugUuid = "3cfcf118-931c-46f7-8ff6-7b876f0d4202"; Drug drug = Context.getConceptService().getDrugByUuid(drugUuid); ObsResource1_8.setValue(obs, drugUuid); - assertEquals(drug, ObsResource1_8.getValue(obs)); + assertEquals(drug, new ObsResource1_8().getValue(obs)); } @Test @@ -240,7 +240,7 @@ public void setValue_shouldReturnUuidForConceptFalse() throws Exception { Obs obs = new Obs(); obs.setConcept(Context.getConceptService().getConceptByUuid(BOOLEAN_CONCEPT_UUID)); ObsResource1_8.setValue(obs, falseConcept); - assertEquals(falseConcept, ObsResource1_8.getValue(obs)); + assertEquals(falseConcept, new ObsResource1_8().getValue(obs)); } @Test(expected = ConversionException.class) @@ -255,7 +255,7 @@ public void setValue_shouldReturnUuidForPrimitiveTrue() throws Exception { Obs obs = new Obs(); obs.setConcept(Context.getConceptService().getConceptByUuid(BOOLEAN_CONCEPT_UUID)); ObsResource1_8.setValue(obs, true); - assertEquals(trueConcept, ObsResource1_8.getValue(obs)); + assertEquals(trueConcept, new ObsResource1_8().getValue(obs)); } @Test @@ -263,7 +263,7 @@ public void setValue_shouldReturnUuidForPrimitiveFalse() throws Exception { Obs obs = new Obs(); obs.setConcept(Context.getConceptService().getConceptByUuid(BOOLEAN_CONCEPT_UUID)); ObsResource1_8.setValue(obs, false); - assertEquals(falseConcept, ObsResource1_8.getValue(obs)); + assertEquals(falseConcept, new ObsResource1_8().getValue(obs)); } private void clearAndSetValue(Obs obs, ObsType type, Object value) { @@ -287,6 +287,6 @@ public void setConvertedProperties_shouldAllowAnyPropertyOrder() throws Exceptio propertyMap.put("obsDatetime", "2013-12-09T00:00:00.000+0100"); resource.setConvertedProperties(obs, propertyMap, resource.getUpdatableProperties(), false); - org.springframework.util.Assert.isTrue(((Double) ObsResource1_8.getValue(obs)) == 10.0); + org.springframework.util.Assert.isTrue(((Double) new ObsResource1_8().getValue(obs)) == 10.0); } } From 9fd0263128ce89f87c501bb6c847a77d11e8480a Mon Sep 17 00:00:00 2001 From: openmrs-bot Date: Tue, 18 Jun 2024 15:11:07 +0000 Subject: [PATCH 2/4] [maven-release-plugin] prepare release 2.44.0 --- integration-tests/pom.xml | 2 +- omod-1.10/pom.xml | 2 +- omod-1.11/pom.xml | 2 +- omod-1.12/pom.xml | 2 +- omod-1.8/pom.xml | 2 +- omod-1.9/pom.xml | 2 +- omod-2.0/pom.xml | 2 +- omod-2.1/pom.xml | 2 +- omod-2.2/pom.xml | 2 +- omod-2.3/pom.xml | 2 +- omod-2.4/pom.xml | 2 +- omod-common/pom.xml | 2 +- omod/pom.xml | 2 +- pom.xml | 4 ++-- 14 files changed, 15 insertions(+), 15 deletions(-) diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 320aabbcd..f70eb0c96 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.44.0 webservices.rest-integration-tests jar diff --git a/omod-1.10/pom.xml b/omod-1.10/pom.xml index 8f1f99fce..222e78794 100644 --- a/omod-1.10/pom.xml +++ b/omod-1.10/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.44.0 webservices.rest-omod-1.10 jar diff --git a/omod-1.11/pom.xml b/omod-1.11/pom.xml index dddcb3843..ea286e128 100644 --- a/omod-1.11/pom.xml +++ b/omod-1.11/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.44.0 webservices.rest-omod-1.11 jar diff --git a/omod-1.12/pom.xml b/omod-1.12/pom.xml index fb6670c2c..b6463c267 100644 --- a/omod-1.12/pom.xml +++ b/omod-1.12/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.44.0 webservices.rest-omod-1.12 jar diff --git a/omod-1.8/pom.xml b/omod-1.8/pom.xml index cdad25989..9d857f965 100644 --- a/omod-1.8/pom.xml +++ b/omod-1.8/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.44.0 webservices.rest-omod-1.8 jar diff --git a/omod-1.9/pom.xml b/omod-1.9/pom.xml index 1af38f67f..f7fe895ab 100644 --- a/omod-1.9/pom.xml +++ b/omod-1.9/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.44.0 webservices.rest-omod-1.9 jar diff --git a/omod-2.0/pom.xml b/omod-2.0/pom.xml index 1dbc19f7c..4e87923d6 100644 --- a/omod-2.0/pom.xml +++ b/omod-2.0/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.44.0 webservices.rest-omod-2.0 jar diff --git a/omod-2.1/pom.xml b/omod-2.1/pom.xml index 38f2110ce..0e3f32bed 100644 --- a/omod-2.1/pom.xml +++ b/omod-2.1/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.44.0 webservices.rest-omod-2.1 jar diff --git a/omod-2.2/pom.xml b/omod-2.2/pom.xml index 729e37a60..c6b0ea209 100644 --- a/omod-2.2/pom.xml +++ b/omod-2.2/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.44.0 webservices.rest-omod-2.2 jar diff --git a/omod-2.3/pom.xml b/omod-2.3/pom.xml index 3f0d67476..f782e7e34 100644 --- a/omod-2.3/pom.xml +++ b/omod-2.3/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.44.0 webservices.rest-omod-2.3 jar diff --git a/omod-2.4/pom.xml b/omod-2.4/pom.xml index 78a239735..c54e0e6ef 100644 --- a/omod-2.4/pom.xml +++ b/omod-2.4/pom.xml @@ -3,7 +3,7 @@ webservices.rest org.openmrs.module - 2.44.0-SNAPSHOT + 2.44.0 4.0.0 diff --git a/omod-common/pom.xml b/omod-common/pom.xml index 0b135e521..0ad0c36ac 100644 --- a/omod-common/pom.xml +++ b/omod-common/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.44.0 webservices.rest-omod-common jar diff --git a/omod/pom.xml b/omod/pom.xml index aab184439..888c9641b 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.44.0 webservices.rest-omod jar diff --git a/pom.xml b/pom.xml index b734d08d2..589aec072 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.44.0 pom Rest Web Services Parent project for the Rest Web Services Module @@ -15,7 +15,7 @@ scm:git:git@github.com:openmrs/openmrs-module-webservices.rest.git scm:git:git@github.com:openmrs/openmrs-module-webservices.rest.git https://github.com/openmrs/openmrs-module-webservices.rest/ - HEAD + 2.44.0 From ff78c3ab8adc3ca31485cb1f858ad16496c8475d Mon Sep 17 00:00:00 2001 From: openmrs-bot Date: Tue, 18 Jun 2024 15:11:10 +0000 Subject: [PATCH 3/4] [maven-release-plugin] prepare for next development iteration --- integration-tests/pom.xml | 2 +- omod-1.10/pom.xml | 2 +- omod-1.11/pom.xml | 2 +- omod-1.12/pom.xml | 2 +- omod-1.8/pom.xml | 2 +- omod-1.9/pom.xml | 2 +- omod-2.0/pom.xml | 2 +- omod-2.1/pom.xml | 2 +- omod-2.2/pom.xml | 2 +- omod-2.3/pom.xml | 2 +- omod-2.4/pom.xml | 2 +- omod-common/pom.xml | 2 +- omod/pom.xml | 2 +- pom.xml | 4 ++-- 14 files changed, 15 insertions(+), 15 deletions(-) diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index f70eb0c96..addba8f33 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0 + 2.45.0-SNAPSHOT webservices.rest-integration-tests jar diff --git a/omod-1.10/pom.xml b/omod-1.10/pom.xml index 222e78794..1f5124358 100644 --- a/omod-1.10/pom.xml +++ b/omod-1.10/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0 + 2.45.0-SNAPSHOT webservices.rest-omod-1.10 jar diff --git a/omod-1.11/pom.xml b/omod-1.11/pom.xml index ea286e128..1e7e8c04f 100644 --- a/omod-1.11/pom.xml +++ b/omod-1.11/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0 + 2.45.0-SNAPSHOT webservices.rest-omod-1.11 jar diff --git a/omod-1.12/pom.xml b/omod-1.12/pom.xml index b6463c267..8fe7929b2 100644 --- a/omod-1.12/pom.xml +++ b/omod-1.12/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0 + 2.45.0-SNAPSHOT webservices.rest-omod-1.12 jar diff --git a/omod-1.8/pom.xml b/omod-1.8/pom.xml index 9d857f965..5ee535590 100644 --- a/omod-1.8/pom.xml +++ b/omod-1.8/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0 + 2.45.0-SNAPSHOT webservices.rest-omod-1.8 jar diff --git a/omod-1.9/pom.xml b/omod-1.9/pom.xml index f7fe895ab..198d8fc91 100644 --- a/omod-1.9/pom.xml +++ b/omod-1.9/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0 + 2.45.0-SNAPSHOT webservices.rest-omod-1.9 jar diff --git a/omod-2.0/pom.xml b/omod-2.0/pom.xml index 4e87923d6..510c47f7a 100644 --- a/omod-2.0/pom.xml +++ b/omod-2.0/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0 + 2.45.0-SNAPSHOT webservices.rest-omod-2.0 jar diff --git a/omod-2.1/pom.xml b/omod-2.1/pom.xml index 0e3f32bed..ab7fccf71 100644 --- a/omod-2.1/pom.xml +++ b/omod-2.1/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0 + 2.45.0-SNAPSHOT webservices.rest-omod-2.1 jar diff --git a/omod-2.2/pom.xml b/omod-2.2/pom.xml index c6b0ea209..3ede534b6 100644 --- a/omod-2.2/pom.xml +++ b/omod-2.2/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0 + 2.45.0-SNAPSHOT webservices.rest-omod-2.2 jar diff --git a/omod-2.3/pom.xml b/omod-2.3/pom.xml index f782e7e34..03b416069 100644 --- a/omod-2.3/pom.xml +++ b/omod-2.3/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0 + 2.45.0-SNAPSHOT webservices.rest-omod-2.3 jar diff --git a/omod-2.4/pom.xml b/omod-2.4/pom.xml index c54e0e6ef..959fbf09e 100644 --- a/omod-2.4/pom.xml +++ b/omod-2.4/pom.xml @@ -3,7 +3,7 @@ webservices.rest org.openmrs.module - 2.44.0 + 2.45.0-SNAPSHOT 4.0.0 diff --git a/omod-common/pom.xml b/omod-common/pom.xml index 0ad0c36ac..6ae78c967 100644 --- a/omod-common/pom.xml +++ b/omod-common/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0 + 2.45.0-SNAPSHOT webservices.rest-omod-common jar diff --git a/omod/pom.xml b/omod/pom.xml index 888c9641b..e0cd4bfff 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0 + 2.45.0-SNAPSHOT webservices.rest-omod jar diff --git a/pom.xml b/pom.xml index 589aec072..76649b8e4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.openmrs.module webservices.rest - 2.44.0 + 2.45.0-SNAPSHOT pom Rest Web Services Parent project for the Rest Web Services Module @@ -15,7 +15,7 @@ scm:git:git@github.com:openmrs/openmrs-module-webservices.rest.git scm:git:git@github.com:openmrs/openmrs-module-webservices.rest.git https://github.com/openmrs/openmrs-module-webservices.rest/ - 2.44.0 + HEAD From 57b2e5ed9ce59201a351093ea68e62de408799ff Mon Sep 17 00:00:00 2001 From: Yasindu Dissanayake <23ug1-0099@sltc.ac.lk> Date: Tue, 9 Jul 2024 17:00:41 +0530 Subject: [PATCH 4/4] (chore) O3-3551: Use latest Actions in GH Actions (#614) --- .github/workflows/maven.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 5cd382ca2..b383af10b 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -21,13 +21,14 @@ jobs: JAVA_VERSION: ${{ matrix.java-version }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: java-version: ${{ matrix.java-version }} + distribution: 'temurin' - name: Cache local Maven repository - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}