This is an automated email from the ASF dual-hosted git repository.
riemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new 16373e11c1 feat: Add measurement unit resource identifier to data
explorer field config (#3685)
16373e11c1 is described below
commit 16373e11c1a36cbfc8fcda0fabe68365f6a50add
Author: Dominik Riemer <[email protected]>
AuthorDate: Tue Jun 24 20:01:17 2025 +0200
feat: Add measurement unit resource identifier to data explorer field
config (#3685)
---
.../org/apache/streampipes/units/UnitProvider.java | 6 +++++
.../rest/impl/MeasurementUnitResource.java | 12 ++++++---
.../src/lib/apis/measurement-units.service.ts | 30 ++++++++++++++--------
.../model/datalake/data-lake-query-config.model.ts | 1 +
.../data-explorer-field-provider-service.ts | 3 +++
5 files changed, 39 insertions(+), 13 deletions(-)
diff --git
a/streampipes-measurement-units/src/main/java/org/apache/streampipes/units/UnitProvider.java
b/streampipes-measurement-units/src/main/java/org/apache/streampipes/units/UnitProvider.java
index b2feca9330..ed5dc4a8dc 100644
---
a/streampipes-measurement-units/src/main/java/org/apache/streampipes/units/UnitProvider.java
+++
b/streampipes-measurement-units/src/main/java/org/apache/streampipes/units/UnitProvider.java
@@ -30,6 +30,8 @@ public enum UnitProvider {
INSTANCE;
+ private static final String RESOURCE_URI_PREFIX =
"http://qudt.org/vocab/unit#";
+
private final List<Unit> availableUnitTypes = new ArrayList<>();
private final List<Unit> availableUnits = new ArrayList<>();
@@ -54,6 +56,10 @@ public enum UnitProvider {
return factory.getUnit(resourceUri);
}
+ public Unit getUnitByIdentifier(String unitIdentifier) {
+ return getUnit(RESOURCE_URI_PREFIX + unitIdentifier);
+ }
+
public List<Unit> getUnitsByType(URI type) {
return availableUnits
.stream()
diff --git
a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/MeasurementUnitResource.java
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/MeasurementUnitResource.java
index 123bb17359..3f7e46b2d2 100644
---
a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/MeasurementUnitResource.java
+++
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/MeasurementUnitResource.java
@@ -40,9 +40,15 @@ public class MeasurementUnitResource extends
AbstractRestResource {
return ok(UnitProvider.INSTANCE.getAvailableUnits());
}
- @GetMapping(path = "/{measurementResourceUri}", produces =
MediaType.APPLICATION_JSON_VALUE)
+ /**
+ * Returns the measurement unit information for a given unit identifier.
+ * @param unitIdentifier The identifier of the measurement unit to retrieve,
+ * consisting of the unit's ID without the QUDT URI
prefix.
+ * @return ResponseEntity containing the Unit object if found, or an error
response if not found.
+ */
+ @GetMapping(path = "/{unitIdentifier}", produces =
MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Unit> getMeasurementUnitInfo(
- @PathVariable("measurementResourceUri") String measurementResourceUri) {
- return ok(UnitProvider.INSTANCE.getUnit(measurementResourceUri));
+ @PathVariable("unitIdentifier") String unitIdentifier) {
+ return ok(UnitProvider.INSTANCE.getUnitByIdentifier(unitIdentifier));
}
}
diff --git
a/ui/projects/streampipes/platform-services/src/lib/apis/measurement-units.service.ts
b/ui/projects/streampipes/platform-services/src/lib/apis/measurement-units.service.ts
index 733e6c079a..09869650b7 100644
---
a/ui/projects/streampipes/platform-services/src/lib/apis/measurement-units.service.ts
+++
b/ui/projects/streampipes/platform-services/src/lib/apis/measurement-units.service.ts
@@ -20,7 +20,7 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { PlatformServicesCommons } from './commons.service';
import { Observable } from 'rxjs';
-import { map } from 'rxjs/operators';
+import { MeasurementUnit } from '../model/measurement-unit/MeasurementUnit';
@Injectable({
providedIn: 'root',
@@ -31,15 +31,25 @@ export class MeasurementUnitsService {
private platformServicesCommons: PlatformServicesCommons,
) {}
- getAllMeasurementUnits(): Observable<any> {
- return this.http
- .get(
- this.platformServicesCommons.apiBasePath +
'/measurement-units',
- )
- .pipe(
- map(response => {
- return response;
- }),
+ getAllMeasurementUnits(): Observable<MeasurementUnit[]> {
+ return this.http.get<MeasurementUnit[]>(
+ `${this.platformServicesCommons.apiBasePath}/measurement-units`,
+ );
+ }
+
+ getMeasurementUnitInfo(
+ measurementResourceUri: string,
+ ): Observable<MeasurementUnit> {
+ const unitIdentifier = measurementResourceUri.split('#').pop();
+
+ if (!unitIdentifier) {
+ throw new Error(
+ 'Invalid measurementResourceUri: missing unit identifier',
);
+ }
+
+ return this.http.get<MeasurementUnit>(
+
`${this.platformServicesCommons.apiBasePath}/measurement-units/${unitIdentifier}`,
+ );
}
}
diff --git
a/ui/projects/streampipes/platform-services/src/lib/model/datalake/data-lake-query-config.model.ts
b/ui/projects/streampipes/platform-services/src/lib/model/datalake/data-lake-query-config.model.ts
index 6affdcc7ac..27dcfe1c21 100644
---
a/ui/projects/streampipes/platform-services/src/lib/model/datalake/data-lake-query-config.model.ts
+++
b/ui/projects/streampipes/platform-services/src/lib/model/datalake/data-lake-query-config.model.ts
@@ -28,6 +28,7 @@ export interface DataExplorerFieldCharacteristics {
export interface DataExplorerField {
runtimeName: string;
aggregation?: string;
+ measurementUnitResourceId?: string;
measure: string;
fullDbName: string;
sourceIndex: number;
diff --git
a/ui/src/app/data-explorer-shared/services/data-explorer-field-provider-service.ts
b/ui/src/app/data-explorer-shared/services/data-explorer-field-provider-service.ts
index 166ba89413..baed06fb53 100644
---
a/ui/src/app/data-explorer-shared/services/data-explorer-field-provider-service.ts
+++
b/ui/src/app/data-explorer-shared/services/data-explorer-field-provider-service.ts
@@ -116,6 +116,9 @@ export class DataExplorerFieldProviderService {
semanticTypes: [property.semanticType],
},
};
+ if (property instanceof EventPropertyPrimitive) {
+ field.measurementUnitResourceId = property.measurementUnit;
+ }
provider.allFields.push(field);
if (field.fieldCharacteristics.numeric) {