Skip to content

Commit 16373e1

Browse files
feat: Add measurement unit resource identifier to data explorer field config (#3685)
1 parent 7f1d18d commit 16373e1

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

streampipes-measurement-units/src/main/java/org/apache/streampipes/units/UnitProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public enum UnitProvider {
3030

3131
INSTANCE;
3232

33+
private static final String RESOURCE_URI_PREFIX = "http://qudt.org/vocab/unit#";
34+
3335
private final List<Unit> availableUnitTypes = new ArrayList<>();
3436
private final List<Unit> availableUnits = new ArrayList<>();
3537

@@ -54,6 +56,10 @@ public Unit getUnit(String resourceUri) {
5456
return factory.getUnit(resourceUri);
5557
}
5658

59+
public Unit getUnitByIdentifier(String unitIdentifier) {
60+
return getUnit(RESOURCE_URI_PREFIX + unitIdentifier);
61+
}
62+
5763
public List<Unit> getUnitsByType(URI type) {
5864
return availableUnits
5965
.stream()

streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/MeasurementUnitResource.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ public ResponseEntity<List<Unit>> getAllMeasurementUnits() {
4040
return ok(UnitProvider.INSTANCE.getAvailableUnits());
4141
}
4242

43-
@GetMapping(path = "/{measurementResourceUri}", produces = MediaType.APPLICATION_JSON_VALUE)
43+
/**
44+
* Returns the measurement unit information for a given unit identifier.
45+
* @param unitIdentifier The identifier of the measurement unit to retrieve,
46+
* consisting of the unit's ID without the QUDT URI prefix.
47+
* @return ResponseEntity containing the Unit object if found, or an error response if not found.
48+
*/
49+
@GetMapping(path = "/{unitIdentifier}", produces = MediaType.APPLICATION_JSON_VALUE)
4450
public ResponseEntity<Unit> getMeasurementUnitInfo(
45-
@PathVariable("measurementResourceUri") String measurementResourceUri) {
46-
return ok(UnitProvider.INSTANCE.getUnit(measurementResourceUri));
51+
@PathVariable("unitIdentifier") String unitIdentifier) {
52+
return ok(UnitProvider.INSTANCE.getUnitByIdentifier(unitIdentifier));
4753
}
4854
}

ui/projects/streampipes/platform-services/src/lib/apis/measurement-units.service.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { Injectable } from '@angular/core';
2020
import { HttpClient } from '@angular/common/http';
2121
import { PlatformServicesCommons } from './commons.service';
2222
import { Observable } from 'rxjs';
23-
import { map } from 'rxjs/operators';
23+
import { MeasurementUnit } from '../model/measurement-unit/MeasurementUnit';
2424

2525
@Injectable({
2626
providedIn: 'root',
@@ -31,15 +31,25 @@ export class MeasurementUnitsService {
3131
private platformServicesCommons: PlatformServicesCommons,
3232
) {}
3333

34-
getAllMeasurementUnits(): Observable<any> {
35-
return this.http
36-
.get(
37-
this.platformServicesCommons.apiBasePath + '/measurement-units',
38-
)
39-
.pipe(
40-
map(response => {
41-
return response;
42-
}),
34+
getAllMeasurementUnits(): Observable<MeasurementUnit[]> {
35+
return this.http.get<MeasurementUnit[]>(
36+
`${this.platformServicesCommons.apiBasePath}/measurement-units`,
37+
);
38+
}
39+
40+
getMeasurementUnitInfo(
41+
measurementResourceUri: string,
42+
): Observable<MeasurementUnit> {
43+
const unitIdentifier = measurementResourceUri.split('#').pop();
44+
45+
if (!unitIdentifier) {
46+
throw new Error(
47+
'Invalid measurementResourceUri: missing unit identifier',
4348
);
49+
}
50+
51+
return this.http.get<MeasurementUnit>(
52+
`${this.platformServicesCommons.apiBasePath}/measurement-units/${unitIdentifier}`,
53+
);
4454
}
4555
}

ui/projects/streampipes/platform-services/src/lib/model/datalake/data-lake-query-config.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface DataExplorerFieldCharacteristics {
2828
export interface DataExplorerField {
2929
runtimeName: string;
3030
aggregation?: string;
31+
measurementUnitResourceId?: string;
3132
measure: string;
3233
fullDbName: string;
3334
sourceIndex: number;

ui/src/app/data-explorer-shared/services/data-explorer-field-provider-service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ export class DataExplorerFieldProviderService {
116116
semanticTypes: [property.semanticType],
117117
},
118118
};
119+
if (property instanceof EventPropertyPrimitive) {
120+
field.measurementUnitResourceId = property.measurementUnit;
121+
}
119122
provider.allFields.push(field);
120123

121124
if (field.fieldCharacteristics.numeric) {

0 commit comments

Comments
 (0)