HistoryImpl.java
/*
* Copyright (c) 2022-2023. Roland T. Lichti, Kaiserpfalz EDV-Service.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.kaiserpfalzedv.commons.core.resources;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import com.fasterxml.jackson.annotation.JsonInclude;
import de.kaiserpfalzedv.commons.api.resources.HasName;
import de.kaiserpfalzedv.commons.api.resources.HasTimestamps;
import de.kaiserpfalzedv.commons.api.resources.History;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;
/**
* A single history entry. Basic data is the timestamp, the status and the message.
*
* @author klenkes74 {@literal <rlichti@kaiserpfalz-edv.de>}
* @since 2.0.0 2021-05-24
*/
@Jacksonized
@Builder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Getter
@ToString
@JsonInclude(JsonInclude.Include.NON_ABSENT)
@Schema(
name = "History",
description = "A single history entry of a change."
)
public class HistoryImpl implements History {
/** serial version of this class. */
private static final long serialVersionUID = 0L;
@Schema(
name = "TimeStamp",
description = "The timestamp of the change.",
required = true,
defaultValue = "now",
pattern = HasTimestamps.VALID_PATTERN,
minLength = HasTimestamps.VALID_LENGTH,
maxLength = HasTimestamps.VALID_LENGTH
)
@Builder.Default
@Pattern(regexp = HasTimestamps.VALID_PATTERN, message = HasTimestamps.VALID_PATTERN_MSG)
private final OffsetDateTime timeStamp = OffsetDateTime.now(ZoneOffset.UTC);
@Schema(
name = "Status",
description = "The resource status after the change.",
required = true,
defaultValue = "not-specified",
pattern = HasName.VALID_NAME_PATTERN,
minLength = HasName.VALID_NAME_MIN_LENGTH,
maxLength = HasName.VALID_NAME_MAX_LENGTH
)
@Builder.Default
@Size(min = HasName.VALID_NAME_MIN_LENGTH, max = HasName.VALID_NAME_MAX_LENGTH, message = HasName.VALID_NAME_LENGTH_MSG)
@Pattern(regexp = HasName.VALID_NAME_PATTERN, message = HasName.VALID_NAME_PATTERN_MSG)
private final String status = "not-specified";
@Schema(
name = "Message",
description = "The human readable description of the change.",
nullable = true
)
@Builder.Default
private final String message = null;
@SuppressWarnings({"MethodDoesntCallSuperMethod","java:S1182","java:S2975"})
@Override
@SuppressFBWarnings(value = "CN_IDIOM_NO_SUPER_CALL", justification = "Using the lombok builder.")
public History clone() {
return this.toBuilder().build();
}
}