1 package de.dlr.shepard.context.references.timeseriesreference.endpoints; 2 3 import de.dlr.shepard.common.util.Constants; 4 import de.dlr.shepard.context.references.timeseriesreference.io.MetricsIO; 5 import de.dlr.shepard.context.references.timeseriesreference.services.TimeseriesReferenceMetricsService; 6 import de.dlr.shepard.data.timeseries.model.Timeseries; 7 import de.dlr.shepard.data.timeseries.model.enums.AggregateFunction; 8 import jakarta.enterprise.context.RequestScoped; 9 import jakarta.inject.Inject; 10 import jakarta.validation.constraints.NotBlank; 11 import jakarta.validation.constraints.NotNull; 12 import jakarta.validation.constraints.PositiveOrZero; 13 import jakarta.ws.rs.Consumes; 14 import jakarta.ws.rs.GET; 15 import jakarta.ws.rs.Path; 16 import jakarta.ws.rs.PathParam; 17 import jakarta.ws.rs.Produces; 18 import jakarta.ws.rs.QueryParam; 19 import jakarta.ws.rs.core.Context; 20 import jakarta.ws.rs.core.MediaType; 21 import jakarta.ws.rs.core.Response; 22 import jakarta.ws.rs.core.SecurityContext; 23 import java.util.List; 24 import java.util.UUID; 25 import org.eclipse.microprofile.openapi.annotations.Operation; 26 import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; 27 import org.eclipse.microprofile.openapi.annotations.media.Content; 28 import org.eclipse.microprofile.openapi.annotations.media.Schema; 29 import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; 30 import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; 31 import org.eclipse.microprofile.openapi.annotations.tags.Tag; 32 33 @Consumes(MediaType.APPLICATION_JSON) 34 @Produces(MediaType.APPLICATION_JSON) 35 @Path( 36 Constants.COLLECTIONS + 37 "/{" + 38 Constants.COLLECTION_ID + 39 "}/" + 40 Constants.DATA_OBJECTS + 41 "/{" + 42 Constants.DATA_OBJECT_ID + 43 "}/" + 44 Constants.TIMESERIES_REFERENCES 45 ) 46 @RequestScoped 47 public class TimeseriesReferenceMetricsRest { 48 49 @Inject 50 TimeseriesReferenceMetricsService timeseriesReferenceMetricsService; 51 52 @Context 53 private SecurityContext securityContext; 54 55 @GET 56 @Path("/{" + Constants.TIMESERIES_REFERENCE_ID + "}" + "/" + Constants.METRICS) 57 @Tag(name = Constants.TIMESERIES_REFERENCE) 58 @Operation(description = "Get timeseries reference metrics by reference id.") 59 @APIResponse( 60 description = "ok", 61 responseCode = "200", 62 content = @Content(schema = @Schema(type = SchemaType.ARRAY, implementation = MetricsIO.class)) 63 ) 64 @APIResponse(description = "not found", responseCode = "404") 65 @Parameter(name = Constants.COLLECTION_ID, required = true) 66 @Parameter(name = Constants.DATA_OBJECT_ID, required = true) 67 @Parameter(name = Constants.TIMESERIES_REFERENCE_ID, required = true) 68 @Parameter(name = Constants.MEASUREMENT, required = true) 69 @Parameter(name = Constants.DEVICE, required = true) 70 @Parameter(name = Constants.LOCATION, required = true) 71 @Parameter(name = Constants.SYMBOLICNAME, required = true) 72 @Parameter(name = Constants.FIELD, required = true) 73 @Parameter(name = Constants.VERSION_UID) 74 public Response getMetricsOfTimeseriesReference( 75 @PathParam(Constants.COLLECTION_ID) @NotNull @PositiveOrZero Long collectionId, 76 @PathParam(Constants.DATA_OBJECT_ID) @NotNull @PositiveOrZero Long dataObjectId, 77 @PathParam(Constants.TIMESERIES_REFERENCE_ID) @NotNull @PositiveOrZero Long timeseriesReferenceId, 78 @QueryParam(Constants.MEASUREMENT) @NotBlank String measurement, 79 @QueryParam(Constants.DEVICE) @NotBlank String device, 80 @QueryParam(Constants.LOCATION) @NotBlank String location, 81 @QueryParam(Constants.SYMBOLICNAME) @NotBlank String symbolicName, 82 @QueryParam(Constants.FIELD) @NotBlank String field, 83 @QueryParam(Constants.VERSION_UID) @org.hibernate.validator.constraints.UUID String versionUID 84 ) { 85 UUID versionUUID = null; 86 if (versionUID != null) { 87 versionUUID = UUID.fromString(versionUID); 88 } 89 Timeseries timeseries = new Timeseries(measurement, device, location, symbolicName, field); 90 91 List<MetricsIO> result = timeseriesReferenceMetricsService.getTimeseriesReferenceMetrics( 92 collectionId, 93 dataObjectId, 94 timeseriesReferenceId, 95 versionUUID, 96 timeseries 97 ); 98 99 return Response.ok(result).build(); 100 } 101 102 @GET 103 @Path("/{" + Constants.TIMESERIES_REFERENCE_ID + "}" + "/" + Constants.METRIC) 104 @Tag(name = Constants.TIMESERIES_REFERENCE) 105 @Operation(description = "Get timeseries reference metric by id.") 106 @APIResponse( 107 description = "ok", 108 responseCode = "200", 109 content = @Content(schema = @Schema(implementation = MetricsIO.class)) 110 ) 111 @APIResponse(description = "not found", responseCode = "404") 112 @Parameter(name = Constants.COLLECTION_ID, required = true) 113 @Parameter(name = Constants.DATA_OBJECT_ID, required = true) 114 @Parameter(name = Constants.TIMESERIES_REFERENCE_ID, required = true) 115 @Parameter(name = Constants.MEASUREMENT, required = true) 116 @Parameter(name = Constants.DEVICE, required = true) 117 @Parameter(name = Constants.LOCATION, required = true) 118 @Parameter(name = Constants.SYMBOLICNAME, required = true) 119 @Parameter(name = Constants.FIELD, required = true) 120 @Parameter(name = Constants.FUNCTION, required = true) 121 @Parameter(name = Constants.VERSION_UID) 122 public Response getMetricOfTimeseriesReference( 123 @PathParam(Constants.COLLECTION_ID) @NotNull @PositiveOrZero Long collectionId, 124 @PathParam(Constants.DATA_OBJECT_ID) @NotNull @PositiveOrZero Long dataObjectId, 125 @PathParam(Constants.TIMESERIES_REFERENCE_ID) @NotNull @PositiveOrZero Long timeseriesReferenceId, 126 @QueryParam(Constants.MEASUREMENT) @NotBlank String measurement, 127 @QueryParam(Constants.DEVICE) @NotBlank String device, 128 @QueryParam(Constants.LOCATION) @NotBlank String location, 129 @QueryParam(Constants.SYMBOLICNAME) @NotBlank String symbolicName, 130 @QueryParam(Constants.FIELD) @NotBlank String field, 131 @QueryParam(Constants.FUNCTION) @NotNull AggregateFunction function, 132 @QueryParam(Constants.VERSION_UID) @org.hibernate.validator.constraints.UUID String versionUID 133 ) { 134 UUID versionUUID = null; 135 if (versionUID != null) { 136 versionUUID = UUID.fromString(versionUID); 137 } 138 139 Timeseries timeseries = new Timeseries(measurement, device, location, symbolicName, field); 140 141 MetricsIO result = timeseriesReferenceMetricsService 142 .getTimeseriesReferenceMetrics( 143 collectionId, 144 dataObjectId, 145 timeseriesReferenceId, 146 versionUUID, 147 timeseries, 148 List.of(function) 149 ) 150 .get(0); 151 152 return Response.ok(result).build(); 153 } 154 }