diff --git a/java-shim-sdk/src/main/java/org/openmhealth/shim/common/mapper/JsonNodeMappingSupport.java b/java-shim-sdk/src/main/java/org/openmhealth/shim/common/mapper/JsonNodeMappingSupport.java index c283df19..0d03d763 100644 --- a/java-shim-sdk/src/main/java/org/openmhealth/shim/common/mapper/JsonNodeMappingSupport.java +++ b/java-shim-sdk/src/main/java/org/openmhealth/shim/common/mapper/JsonNodeMappingSupport.java @@ -5,6 +5,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.math.BigDecimal; import java.time.*; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; @@ -83,6 +84,7 @@ public static String asRequiredString(JsonNode parentNode, String path) { } // TODO add tests + /** * @param parentNode a parent node * @param path the path to a child node @@ -108,6 +110,7 @@ public static Long asRequiredLong(JsonNode parentNode, String path) { } // TODO add tests + /** * @param parentNode a parent node * @param path the path to a child node @@ -397,6 +400,17 @@ public static Optional asOptionalInteger(JsonNode parentNode, String pa return asOptionalValue(parentNode, path, JsonNode::isIntegralNumber, JsonNode::intValue); } + /** + * @param parentNode a parent node + * @param path the path to a child node + * @return the value of the child node as a Big Decimal, or an empty optional if the child doesn't exist or if the + * value of the child node isn't numeric + */ + public static Optional asOptionalBigDecimal(JsonNode parentNode, String path) { + + return asOptionalValue(parentNode, path, JsonNode::isNumber, JsonNode::decimalValue); + } + /** * @param parentNode a parent node * @param path the path to a child node diff --git a/shim-server/src/main/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapper.java b/shim-server/src/main/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapper.java index d8c3cf3d..35e38d9f 100644 --- a/shim-server/src/main/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapper.java +++ b/shim-server/src/main/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapper.java @@ -46,7 +46,6 @@ * @author Emerson Farrugia * @author Danilo Bonilla * @author Chris Schaefbauer - * * @see API documentation */ public class JawbonePhysicalActivityDataPointMapper extends JawboneDataPointMapper { @@ -100,7 +99,8 @@ protected Optional getMeasure(JsonNode workoutNode) { PhysicalActivity.Builder builder = new PhysicalActivity.Builder(activityName); - asOptionalInteger(workoutNode, "details.meters") + + asOptionalBigDecimal(workoutNode, "details.meters") .ifPresent(distance -> builder.setDistance(new LengthUnitValue(METER, distance))); Optional endTimestamp = asOptionalLong(workoutNode, "time_completed"); @@ -152,7 +152,7 @@ public String getActivityName(@Nullable String title, @Nullable Integer workoutT */ public SelfReportedIntensity asSelfReportedIntensity(int intensityValue) { - switch (intensityValue) { + switch ( intensityValue ) { case 1: return LIGHT; case 2: diff --git a/shim-server/src/test/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapperUnitTests.java b/shim-server/src/test/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapperUnitTests.java index 81f3cce4..123b7769 100644 --- a/shim-server/src/test/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapperUnitTests.java +++ b/shim-server/src/test/java/org/openmhealth/shim/jawbone/mapper/JawbonePhysicalActivityDataPointMapperUnitTests.java @@ -101,7 +101,7 @@ public void asDataPointsShouldReturnCorrectMissingSensedDataPoints() { List> dataPoints = mapper.asDataPoints(singletonList(responseNode)); PhysicalActivity expectedPhysicalActivity = new PhysicalActivity.Builder("Bike") - .setDistance(new LengthUnitValue(METER, 1188)) + .setDistance(new LengthUnitValue(METER, 6318.2688961)) .setEffectiveTimeFrame( TimeInterval.ofEndDateTimeAndDuration(OffsetDateTime.parse("2015-04-29T16:07:07-04:00"), new DurationUnitValue(SECOND, 343))) diff --git a/shim-server/src/test/resources/org/openmhealth/shim/jawbone/mapper/jawbone-workouts.json b/shim-server/src/test/resources/org/openmhealth/shim/jawbone/mapper/jawbone-workouts.json index ac9c7763..c6e4ba47 100644 --- a/shim-server/src/test/resources/org/openmhealth/shim/jawbone/mapper/jawbone-workouts.json +++ b/shim-server/src/test/resources/org/openmhealth/shim/jawbone/mapper/jawbone-workouts.json @@ -48,7 +48,7 @@ "goal": 0, "intensity": null, "km": 1.188, - "meters": 1188, + "meters": 6318.2688961, "place_acc": 0, "steps": 0, "time": 343,