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 java.util.Objects;
10 import lombok.Data;
11 import lombok.NoArgsConstructor;
12 import org.eclipse.microprofile.openapi.annotations.media.Schema;
13
14
15
16
17
18
19
20 @Schema(name = "TimeseriesEntity")
21 @Data
22 @NoArgsConstructor(force = true)
23 public final class TimeseriesIO {
24
25 @NotBlank
26 private final long id;
27
28 @NotBlank
29 private final long containerId;
30
31 @NotBlank
32 private final DataPointValueType valueType;
33
34 @NotBlank
35 private final String measurement;
36
37 @NotBlank
38 private final String device;
39
40 @NotBlank
41 private final String location;
42
43 @NotBlank
44 private final String symbolicName;
45
46 @NotBlank
47 private final String field;
48
49 @Schema(readOnly = true, required = true)
50 private final long[] semanticAnnotationIds;
51
52 public TimeseriesIO(Timeseries timeseries) {
53 this.id = timeseries.getTimeseriesId();
54 this.containerId = timeseries.getContainer().getId();
55 this.valueType = timeseries.getValueType();
56 this.measurement = timeseries.getTimeseriesTuple().getMeasurement();
57 this.device = timeseries.getTimeseriesTuple().getDevice();
58 this.location = timeseries.getTimeseriesTuple().getLocation();
59 this.symbolicName = timeseries.getTimeseriesTuple().getSymbolicName();
60 this.field = timeseries.getTimeseriesTuple().getField();
61 this.semanticAnnotationIds = extractIds(timeseries.getAnnotations());
62 }
63
64 private static long[] extractIds(List<SemanticAnnotation> annotations) {
65 return annotations.stream().map(SemanticAnnotation::getId).mapToLong(Long::longValue).toArray();
66 }
67
68 @Override
69 public boolean equals(Object o) {
70 if (o == null || getClass() != o.getClass()) return false;
71 TimeseriesIO that = (TimeseriesIO) o;
72 return (
73 id == that.id &&
74 containerId == that.containerId &&
75 valueType == that.valueType &&
76 Objects.equals(measurement, that.measurement) &&
77 Objects.equals(device, that.device) &&
78 Objects.equals(location, that.location) &&
79 Objects.equals(symbolicName, that.symbolicName) &&
80 Objects.equals(field, that.field) &&
81 Objects.deepEquals(semanticAnnotationIds, that.semanticAnnotationIds)
82 );
83 }
84
85 @Override
86 public int hashCode() {
87 return Objects.hash(
88 id,
89 containerId,
90 valueType,
91 measurement,
92 device,
93 location,
94 symbolicName,
95 field,
96 HasId.hashcodeHelper(semanticAnnotationIds)
97 );
98 }
99 }