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  
23  import org.eclipse.microprofile.openapi.annotations.media.Schema;
24  
25  import com.fasterxml.jackson.annotation.JsonInclude;
26  
27  import de.kaiserpfalzedv.commons.api.resources.HasName;
28  import de.kaiserpfalzedv.commons.api.resources.HasTimestamps;
29  import de.kaiserpfalzedv.commons.api.resources.History;
30  import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
31  import jakarta.validation.constraints.Pattern;
32  import jakarta.validation.constraints.Size;
33  import lombok.AllArgsConstructor;
34  import lombok.Builder;
35  import lombok.Getter;
36  import lombok.NoArgsConstructor;
37  import lombok.ToString;
38  import lombok.extern.jackson.Jacksonized;
39  
40  
41  /**
42   * A single history entry. Basic data is the timestamp, the status and the message.
43   *
44   * @author klenkes74 {@literal <rlichti@kaiserpfalz-edv.de>}
45   * @since 2.0.0  2021-05-24
46   */
47  @Jacksonized
48  @Builder(toBuilder = true)
49  @AllArgsConstructor
50  @NoArgsConstructor
51  @Getter
52  @ToString
53  @JsonInclude(JsonInclude.Include.NON_ABSENT)
54  @Schema(
55          name = "History",
56          description = "A single history entry of a change."
57  )
58  public class HistoryImpl implements History {
59      /** serial version of this class. */
60      private static final long serialVersionUID = 0L;
61  
62      @Schema(
63              name = "TimeStamp",
64              description = "The timestamp of the change.",
65              required = true,
66              defaultValue = "now",
67              pattern = HasTimestamps.VALID_PATTERN,
68              minLength = HasTimestamps.VALID_LENGTH,
69              maxLength = HasTimestamps.VALID_LENGTH
70      )
71      @Builder.Default
72      @Pattern(regexp = HasTimestamps.VALID_PATTERN, message = HasTimestamps.VALID_PATTERN_MSG)
73      private final OffsetDateTime timeStamp = OffsetDateTime.now(ZoneOffset.UTC);
74  
75      @Schema(
76              name = "Status",
77              description = "The resource status after the change.",
78              required = true,
79              defaultValue = "not-specified",
80              pattern = HasName.VALID_NAME_PATTERN,
81              minLength = HasName.VALID_NAME_MIN_LENGTH,
82              maxLength = HasName.VALID_NAME_MAX_LENGTH
83      )
84      @Builder.Default
85      @Size(min = HasName.VALID_NAME_MIN_LENGTH, max = HasName.VALID_NAME_MAX_LENGTH, message = HasName.VALID_NAME_LENGTH_MSG)
86      @Pattern(regexp = HasName.VALID_NAME_PATTERN, message = HasName.VALID_NAME_PATTERN_MSG)
87      private final String status = "not-specified";
88  
89      @Schema(
90              name = "Message",
91              description = "The human readable description of the change.",
92              nullable = true
93      )
94      @Builder.Default
95      private final String message = null;
96  
97  
98      @SuppressWarnings({"MethodDoesntCallSuperMethod","java:S1182","java:S2975"})
99      @Override
100     @SuppressFBWarnings(value = "CN_IDIOM_NO_SUPER_CALL", justification = "Using the lombok builder.")
101     public History clone() {
102         return this.toBuilder().build();
103     }
104 }