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.History;
29  import de.kaiserpfalzedv.commons.api.resources.TimeStampPattern;
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              example = TimeStampPattern.VALID_EXAMPLE,
68              pattern = TimeStampPattern.VALID_PATTERN,
69              minLength = TimeStampPattern.VALID_LENGTH,
70              maxLength = TimeStampPattern.VALID_LENGTH
71      )
72      @Builder.Default
73      @Pattern(regexp = TimeStampPattern.VALID_PATTERN, message = TimeStampPattern.VALID_PATTERN_MSG)
74      private final OffsetDateTime timeStamp = OffsetDateTime.now(ZoneOffset.UTC);
75  
76      @Schema(
77              name = "Status",
78              description = "The resource status after the change.",
79              required = true,
80              defaultValue = "not-specified",
81              example = HasName.VALID_NAME_EXAMPLE,
82              pattern = HasName.VALID_NAME_PATTERN,
83              minLength = HasName.VALID_NAME_MIN_LENGTH,
84              maxLength = HasName.VALID_NAME_MAX_LENGTH
85      )
86      @Builder.Default
87      @Size(min = HasName.VALID_NAME_MIN_LENGTH, max = HasName.VALID_NAME_MAX_LENGTH, message = HasName.VALID_NAME_LENGTH_MSG)
88      @Pattern(regexp = HasName.VALID_NAME_PATTERN, message = HasName.VALID_NAME_PATTERN_MSG)
89      private final String status = "not-specified";
90  
91      @Schema(
92              name = "Message",
93              description = "The human readable description of the change.",
94              nullable = true
95      )
96      @Builder.Default
97      private final String message = null;
98  
99  
100     @SuppressWarnings("MethodDoesntCallSuperMethod")
101     @Override
102     @SuppressFBWarnings(value = "CN_IDIOM_NO_SUPER_CALL", justification = "Using the lombok builder.")
103     public History clone() {
104         return this.toBuilder().build();
105     }
106 }