View Javadoc
1   /*
2    * Copyright (c) 2022-2023. Roland T. Lichti, Kaiserpfalz EDV-Service.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <https://www.gnu.org/licenses/>.
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   * ResourceStatus -- The state of the managed resource.
41   *
42   * @author klenkes74 {@literal <rlichti@kaiserpfalz-edv.de>}
43   * @since 2.0.0  2021-05-24
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  }