1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.kaiserpfalzedv.commons.core.resources;
19
20 import java.time.OffsetDateTime;
21 import java.time.ZoneOffset;
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.eclipse.microprofile.openapi.annotations.media.Schema;
26
27 import com.fasterxml.jackson.annotation.JsonInclude;
28 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
29
30 import de.kaiserpfalzedv.commons.api.resources.Status;
31 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
32 import lombok.AllArgsConstructor;
33 import lombok.Builder;
34 import lombok.Getter;
35 import lombok.RequiredArgsConstructor;
36 import lombok.ToString;
37 import lombok.extern.jackson.Jacksonized;
38
39
40
41
42
43
44
45 @Jacksonized
46 @SuppressFBWarnings(value = "EI_EXPOSE_REF2", justification = "Use of lombok provided builder.")
47 @Builder(toBuilder = true)
48 @AllArgsConstructor
49 @RequiredArgsConstructor
50 @Getter
51 @ToString(onlyExplicitlyIncluded = true)
52 @JsonInclude(JsonInclude.Include.NON_ABSENT)
53 @JsonPropertyOrder({"observedGeneration,history"})
54 @Schema(name = "ResourceStatus", description = "The status of a resource.")
55 public class StatusImpl implements Status {
56 private static final long serialVersionUID = 0L;
57
58 @Builder.Default
59 @ToString.Include
60 private final Integer observedGeneration = 0;
61
62
63 @Builder.Default
64 @ToString.Include
65 @SuppressFBWarnings(value = {"EI_EXPOSE_REP","EI_EXPOSE_REP2"}, justification = "lombok provided @Getter are created")
66 private List<HistoryImpl> history = new ArrayList<>();
67
68 @Override
69 public StatusImpl addHistory(final String status, final String message) {
70 this.getHistory().add(
71 HistoryImpl.builder()
72 .status(status)
73 .timeStamp(OffsetDateTime.now(ZoneOffset.UTC))
74 .message(message)
75 .build()
76 );
77
78 return this;
79 }
80
81 @SuppressWarnings("MethodDoesntCallSuperMethod")
82 @SuppressFBWarnings(value = "CN_IDIOM_NO_SUPER_CALL", justification = "Using the lombok builder.")
83 @Override
84 public StatusImpl clone() {
85 return this.toBuilder().build();
86 }
87 }