diff --git a/kura/distrib/config/kura.build.properties b/kura/distrib/config/kura.build.properties
index dcc71216639..0c93af489b4 100644
--- a/kura/distrib/config/kura.build.properties
+++ b/kura/distrib/config/kura.build.properties
@@ -114,7 +114,7 @@ org.eclipse.kura.rest.network.configuration.provider.version=2.0.0-SNAPSHOT
org.eclipse.kura.rest.inventory.provider.version=2.0.0-SNAPSHOT
org.eclipse.kura.rest.command.provider.version=2.0.0-SNAPSHOT
org.eclipse.kura.rest.packages.provider.version=2.0.0-SNAPSHOT
-org.eclipse.kura.rest.position.provider.version=2.0.0-SNAPSHOT
+org.eclipse.kura.rest.position.provider.version=2.1.0-SNAPSHOT
org.eclipse.kura.rest.security.provider.version=2.0.0-SNAPSHOT
org.eclipse.kura.rest.identity.provider.version=2.0.0-SNAPSHOT
org.eclipse.kura.rest.service.listing.provider.version=2.0.0-SNAPSHOT
diff --git a/kura/org.eclipse.kura.rest.position.provider/META-INF/MANIFEST.MF b/kura/org.eclipse.kura.rest.position.provider/META-INF/MANIFEST.MF
index 5f36d89eb1a..7107d5008cd 100644
--- a/kura/org.eclipse.kura.rest.position.provider/META-INF/MANIFEST.MF
+++ b/kura/org.eclipse.kura.rest.position.provider/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.eclipse.kura.rest.position.provider
Bundle-SymbolicName: org.eclipse.kura.rest.position.provider;singleton:=true
-Bundle-Version: 2.0.0.qualifier
+Bundle-Version: 2.1.0.qualifier
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Bundle-ClassPath: .
Bundle-ActivationPolicy: lazy
diff --git a/kura/org.eclipse.kura.rest.position.provider/pom.xml b/kura/org.eclipse.kura.rest.position.provider/pom.xml
index 3cc099970df..0a6b6096ad5 100644
--- a/kura/org.eclipse.kura.rest.position.provider/pom.xml
+++ b/kura/org.eclipse.kura.rest.position.provider/pom.xml
@@ -30,5 +30,5 @@
org.eclipse.kura.rest.position.provider
eclipse-plugin
- 2.0.0-SNAPSHOT
+ 2.1.0-SNAPSHOT
diff --git a/kura/org.eclipse.kura.rest.position.provider/src/main/java/org/eclipse/kura/internal/rest/position/PositionRestService.java b/kura/org.eclipse.kura.rest.position.provider/src/main/java/org/eclipse/kura/internal/rest/position/PositionRestService.java
index 28b88b468bd..6d4ac29e7a5 100644
--- a/kura/org.eclipse.kura.rest.position.provider/src/main/java/org/eclipse/kura/internal/rest/position/PositionRestService.java
+++ b/kura/org.eclipse.kura.rest.position.provider/src/main/java/org/eclipse/kura/internal/rest/position/PositionRestService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2023 Eurotech and/or its affiliates and others
+ * Copyright (c) 2023, 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -84,7 +84,7 @@ public void unsetRequestHandlerRegistry(final RequestHandlerRegistry registry) {
@Produces(MediaType.APPLICATION_JSON)
public PositionDTO getPosition() {
if (positionServiceImpl.isLocked()) {
- return new PositionDTO(positionServiceImpl.getPosition());
+ return new PositionDTO(positionServiceImpl.getPosition(), positionServiceImpl.getGnssType());
}
throw DefaultExceptionHandler.toWebApplicationException(
diff --git a/kura/org.eclipse.kura.rest.position.provider/src/main/java/org/eclipse/kura/rest/position/api/PositionDTO.java b/kura/org.eclipse.kura.rest.position.provider/src/main/java/org/eclipse/kura/rest/position/api/PositionDTO.java
index 7a0aaeea9f9..8259b4d4bb7 100644
--- a/kura/org.eclipse.kura.rest.position.provider/src/main/java/org/eclipse/kura/rest/position/api/PositionDTO.java
+++ b/kura/org.eclipse.kura.rest.position.provider/src/main/java/org/eclipse/kura/rest/position/api/PositionDTO.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2023 Eurotech and/or its affiliates and others
+ * Copyright (c) 2023, 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -12,6 +12,10 @@
*******************************************************************************/
package org.eclipse.kura.rest.position.api;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.kura.position.GNSSType;
import org.osgi.util.position.Position;
public class PositionDTO {
@@ -21,8 +25,9 @@ public class PositionDTO {
private Double altitude;
private Double speed;
private Double track;
+ private Set gnssType;
- public PositionDTO(Position position) {
+ public PositionDTO(Position position, Set gnssTypeSet) {
if (position.getLongitude() != null) {
this.longitude = Math.toDegrees(position.getLongitude().getValue());
}
@@ -42,6 +47,13 @@ public PositionDTO(Position position) {
if (position.getTrack() != null) {
this.track = Math.toDegrees(position.getTrack().getValue());
}
+
+ if (gnssTypeSet != null) {
+ this.gnssType = new HashSet<>();
+ for (GNSSType type : gnssTypeSet) {
+ this.gnssType.add(type.getValue());
+ }
+ }
}
/**
@@ -78,4 +90,11 @@ public Double getSpeed() {
public Double getTrack() {
return track;
}
+
+ /*
+ * Returns the GNSS Type used to retrieve position information
+ */
+ public Set getGnssType() {
+ return gnssType;
+ }
}
diff --git a/kura/test/org.eclipse.kura.rest.position.provider.test/src/main/java/org/eclipse/kura/rest/position/provider/test/PositionRestServiceTest.java b/kura/test/org.eclipse.kura.rest.position.provider.test/src/main/java/org/eclipse/kura/rest/position/provider/test/PositionRestServiceTest.java
index 1876cedfad5..e18070f6d93 100644
--- a/kura/test/org.eclipse.kura.rest.position.provider.test/src/main/java/org/eclipse/kura/rest/position/provider/test/PositionRestServiceTest.java
+++ b/kura/test/org.eclipse.kura.rest.position.provider.test/src/main/java/org/eclipse/kura/rest/position/provider/test/PositionRestServiceTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2023 Eurotech and/or its affiliates and others
+ * Copyright (c) 2023, 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -13,34 +13,27 @@
package org.eclipse.kura.rest.position.provider.test;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.time.LocalDateTime;
import java.util.Arrays;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
import javax.ws.rs.WebApplicationException;
-import java.time.ZonedDateTime;
-import java.time.LocalDateTime;
-import org.osgi.util.position.Position;
-import org.osgi.util.measurement.Measurement;
-import org.osgi.util.measurement.Unit;
-import org.eclipse.kura.KuraException;
-import org.eclipse.kura.cloudconnection.message.KuraMessage;
-import org.eclipse.kura.message.KuraPayload;
-import org.eclipse.kura.message.KuraResponsePayload;
-import org.eclipse.kura.position.PositionService;
+
import org.eclipse.kura.internal.rest.position.PositionRestService;
-import org.eclipse.kura.rest.position.api.IsLockedDTO;
+import org.eclipse.kura.position.GNSSType;
+import org.eclipse.kura.position.PositionService;
import org.eclipse.kura.rest.position.api.DateTimeDTO;
+import org.eclipse.kura.rest.position.api.IsLockedDTO;
import org.eclipse.kura.rest.position.api.PositionDTO;
import org.junit.Test;
-import org.mockito.ArgumentCaptor;
+import org.osgi.util.measurement.Measurement;
+import org.osgi.util.measurement.Unit;
+import org.osgi.util.position.Position;
public class PositionRestServiceTest {
@@ -57,11 +50,11 @@ public class PositionRestServiceTest {
public void getPositionTest() {
givenMockedPositionService();
givenIsLocked(true);
- givenPosition(0.1, 0.2, 4.5, null, null);
+ givenPosition(0.1, 0.2, 4.5, null, null, null);
whenGetPosition();
- thenPositionIs(0.1, 0.2, 4.5, null, null);
+ thenPositionIs(0.1, 0.2, 4.5, null, null, null);
thenNoExceptionIsThrown();
}
@@ -69,11 +62,23 @@ public void getPositionTest() {
public void getPositionTestWithFullParameters() {
givenMockedPositionService();
givenIsLocked(true);
- givenPosition(0.1, 0.2, 4.5, 50.6, 9.8);
+ givenPosition(0.1, 0.2, 4.5, 50.6, 9.8, new HashSet<>(Arrays.asList(GNSSType.GPS)));
whenGetPosition();
- thenPositionIs(0.1, 0.2, 4.5, 50.6, 9.8);
+ thenPositionIs(0.1, 0.2, 4.5, 50.6, 9.8, new HashSet<>(Arrays.asList("Gps")));
+ thenNoExceptionIsThrown();
+ }
+
+ @Test
+ public void getPositionTestWithFullParametersAndMultipleGNSSTypes() {
+ givenMockedPositionService();
+ givenIsLocked(true);
+ givenPosition(0.1, 0.2, 4.5, 50.6, 9.8, new HashSet<>(Arrays.asList(GNSSType.GPS, GNSSType.GLONASS)));
+
+ whenGetPosition();
+
+ thenPositionIs(0.1, 0.2, 4.5, 50.6, 9.8, new HashSet<>(Arrays.asList("Gps", "Glonass")));
thenNoExceptionIsThrown();
}
@@ -112,7 +117,7 @@ public void getIsLockedTestFalse() {
}
@Test
- public void getPositionNoLockTest(){
+ public void getPositionNoLockTest() {
givenMockedPositionService();
givenIsLocked(false);
@@ -122,7 +127,7 @@ public void getPositionNoLockTest(){
}
@Test
- public void getLocalDateTimeNoLockTest(){
+ public void getLocalDateTimeNoLockTest() {
givenMockedPositionService();
givenIsLocked(false);
@@ -131,22 +136,25 @@ public void getLocalDateTimeNoLockTest(){
thenExceptionIsThrown();
}
-
- private void givenMockedPositionService(){
+ private void givenMockedPositionService() {
positionRestService.setPositionServiceImpl(positionService);
}
- private void givenPosition(Double longitude, Double latitude, Double altitude, Double speed, Double track) {
+ private void givenPosition(Double longitude, Double latitude, Double altitude, Double speed, Double track,
+ Set gnssTypeSet) {
Measurement latitudeMesurment = latitude != null ? new Measurement(Math.toRadians(latitude), Unit.rad) : null;
- Measurement longitudeMesurment = longitude != null ? new Measurement(Math.toRadians(longitude), Unit.rad) : null;
+ Measurement longitudeMesurment = longitude != null ? new Measurement(Math.toRadians(longitude), Unit.rad)
+ : null;
Measurement altitudeMesurment = altitude != null ? new Measurement(altitude, Unit.m) : null;
Measurement speedMesurment = speed != null ? new Measurement(speed, Unit.m_s) : null;
Measurement trackMesurment = track != null ? new Measurement(Math.toRadians(track), Unit.rad) : null;
- Position testPosition = new Position(latitudeMesurment, longitudeMesurment, altitudeMesurment, speedMesurment, trackMesurment);
+ Position testPosition = new Position(latitudeMesurment, longitudeMesurment, altitudeMesurment, speedMesurment,
+ trackMesurment);
when(positionService.getPosition()).thenReturn(testPosition);
+ when(positionService.getGnssType()).thenReturn(gnssTypeSet);
}
private void givenLocalDateTime(String zonedDateTime) {
@@ -154,7 +162,7 @@ private void givenLocalDateTime(String zonedDateTime) {
when(positionService.getDateTime()).thenReturn(testLocalDateTime);
}
- private void givenIsLocked(boolean isLocked){
+ private void givenIsLocked(boolean isLocked) {
when(positionService.isLocked()).thenReturn(isLocked);
}
@@ -167,7 +175,7 @@ private void whenGetPosition() {
}
private void whenGetLocalDateTime() {
- try{
+ try {
localDateTimeDTO = positionRestService.getLocalDateTime();
} catch (Exception e) {
testException = e;
@@ -175,43 +183,51 @@ private void whenGetLocalDateTime() {
}
private void whenGetIsLocked() {
- try{
+ try {
isLockedDTO = positionRestService.getIsLocked();
} catch (Exception e) {
testException = e;
}
}
- private void thenPositionIs(Double longitude, Double latitude, Double altitude, Double speed, Double track) {
- if (longitude != null){
+ private void thenPositionIs(Double longitude, Double latitude, Double altitude, Double speed, Double track,
+ Set gnssTypeSet) {
+
+ if (longitude != null) {
assertEquals(longitude, positionDTO.getLongitude(), 0.0);
} else {
assertNull(positionDTO.getLongitude());
}
- if (latitude != null){
+ if (latitude != null) {
assertEquals(latitude, positionDTO.getLatitude(), 0.0);
} else {
assertNull(positionDTO.getLatitude());
}
- if (altitude != null){
+ if (altitude != null) {
assertEquals(altitude, positionDTO.getAltitude(), 0.0);
} else {
assertNull(positionDTO.getAltitude());
}
- if (speed != null){
+ if (speed != null) {
assertEquals(speed, positionDTO.getSpeed(), 0.0);
} else {
assertNull(positionDTO.getSpeed());
}
- if (track != null){
+ if (track != null) {
assertEquals(track, positionDTO.getTrack(), 0.0);
} else {
assertNull(positionDTO.getTrack());
}
+
+ if (gnssTypeSet != null) {
+ assertEquals(gnssTypeSet, positionDTO.getGnssType());
+ } else {
+ assertNull(positionDTO.getGnssType());
+ }
}
private void thenLocalDateTimeIs(String zonedDateTime) {