1 package de.dlr.shepard.data.timeseries.io;
2
3 import de.dlr.shepard.common.util.HasId;
4 import de.dlr.shepard.context.semantic.entities.SemanticAnnotation;
5 import de.dlr.shepard.data.timeseries.model.Timeseries;
6 import de.dlr.shepard.data.timeseries.model.enums.DataPointValueType;
7 import jakarta.validation.constraints.NotBlank;
8 import java.util.List;
9 import lombok.Data;
10 import lombok.NoArgsConstructor;
11 import org.eclipse.microprofile.openapi.annotations.media.Schema;
12
13
14
15
16
17
18
19 @Schema(name = "TimeseriesEntity")
20 @Data
21 @NoArgsConstructor(force = true)
22 public class TimeseriesIO {
23
24 @NotBlank
25 private final long id;
26
27 @NotBlank
28 private final long containerId;
29
30 @NotBlank
31 private final DataPointValueType valueType;
32
33 @NotBlank
34 private final String measurement;
35
36 @NotBlank
37 private final String device;
38
39 @NotBlank
40 private final String location;
41
42 @NotBlank
43 private final String symbolicName;
44
45 @NotBlank
46 private final String field;
47
48 @Schema(readOnly = true, required = true)
49 private long[] semanticAnnotationIds;
50
51 public TimeseriesIO(Timeseries timeseries) {
52 this.id = timeseries.getTimeseriesId();
53 this.containerId = timeseries.getContainer().getId();
54 this.valueType = timeseries.getValueType();
55 this.measurement = timeseries.getTimeseriesTuple().getMeasurement();
56 this.device = timeseries.getTimeseriesTuple().getDevice();
57 this.location = timeseries.getTimeseriesTuple().getLocation();
58 this.symbolicName = timeseries.getTimeseriesTuple().getSymbolicName();
59 this.field = timeseries.getTimeseriesTuple().getField();
60 this.semanticAnnotationIds = extractIds(timeseries.getAnnotations());
61 }
62
63 protected static long[] extractIds(List<SemanticAnnotation> annotations) {
64 return annotations.stream().map(SemanticAnnotation::getId).mapToLong(Long::longValue).toArray();
65 }
66
67 @Override
68 public boolean equals(Object o) {
69 if (this == o) return true;
70 if (!(o instanceof TimeseriesIO)) return false;
71 TimeseriesIO other = (TimeseriesIO) o;
72 return (
73 HasId.areEqualSets(semanticAnnotationIds, other.semanticAnnotationIds) &&
74 id == other.id &&
75 containerId == other.containerId &&
76 valueType.equals(other.valueType) &&
77 measurement.equals(other.measurement) &&
78 device.equals(other.device) &&
79 location.equals(other.location) &&
80 symbolicName.equals(other.symbolicName) &&
81 field.equals(other.field)
82 );
83 }
84 }