From 8964cd19e25f100e815a5d48266cddd9fdcb78ea Mon Sep 17 00:00:00 2001 From: Guillaume Duval Date: Tue, 29 Oct 2024 14:06:36 +0100 Subject: [PATCH 1/2] [RHCLOUD-35901] Drop status table --- .../db/migration/V1.105.0__RHCLOUD-35901_drop_status_table.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 database/src/main/resources/db/migration/V1.105.0__RHCLOUD-35901_drop_status_table.sql diff --git a/database/src/main/resources/db/migration/V1.105.0__RHCLOUD-35901_drop_status_table.sql b/database/src/main/resources/db/migration/V1.105.0__RHCLOUD-35901_drop_status_table.sql new file mode 100644 index 0000000000..92b83c16ef --- /dev/null +++ b/database/src/main/resources/db/migration/V1.105.0__RHCLOUD-35901_drop_status_table.sql @@ -0,0 +1 @@ +DROP TABLE status; From f8735aa904307e0a090ffccfaf55c86246173eab Mon Sep 17 00:00:00 2001 From: Guillaume Duval Date: Wed, 6 Nov 2024 10:19:49 +0100 Subject: [PATCH 2/2] [RHCLOUD-35901] Drop status table --- .../db/converters/StatusConverter.java | 27 ------- .../notifications/models/CurrentStatus.java | 73 ------------------- .../cloud/notifications/models/Status.java | 6 -- .../MaintenanceWithTimeInterval.java | 30 -------- .../MaintenanceWithTimeIntervalValidator.java | 25 ------- .../cloud/notifications/db/DbCleaner.java | 5 -- 6 files changed, 166 deletions(-) delete mode 100644 backend/src/main/java/com/redhat/cloud/notifications/db/converters/StatusConverter.java delete mode 100644 backend/src/main/java/com/redhat/cloud/notifications/models/CurrentStatus.java delete mode 100644 backend/src/main/java/com/redhat/cloud/notifications/models/Status.java delete mode 100644 backend/src/main/java/com/redhat/cloud/notifications/models/validation/MaintenanceWithTimeInterval.java delete mode 100644 backend/src/main/java/com/redhat/cloud/notifications/models/validation/MaintenanceWithTimeIntervalValidator.java diff --git a/backend/src/main/java/com/redhat/cloud/notifications/db/converters/StatusConverter.java b/backend/src/main/java/com/redhat/cloud/notifications/db/converters/StatusConverter.java deleted file mode 100644 index 0792ca1215..0000000000 --- a/backend/src/main/java/com/redhat/cloud/notifications/db/converters/StatusConverter.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.redhat.cloud.notifications.db.converters; - -import com.redhat.cloud.notifications.models.Status; -import jakarta.persistence.AttributeConverter; -import jakarta.persistence.Converter; - -@Converter -public class StatusConverter implements AttributeConverter { - - @Override - public String convertToDatabaseColumn(Status status) { - if (status == null) { - return null; - } else { - return status.name(); - } - } - - @Override - public Status convertToEntityAttribute(String name) { - if (name == null) { - return null; - } else { - return Status.valueOf(name); - } - } -} diff --git a/backend/src/main/java/com/redhat/cloud/notifications/models/CurrentStatus.java b/backend/src/main/java/com/redhat/cloud/notifications/models/CurrentStatus.java deleted file mode 100644 index ad071ed2d5..0000000000 --- a/backend/src/main/java/com/redhat/cloud/notifications/models/CurrentStatus.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.redhat.cloud.notifications.models; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.annotation.JsonNaming; -import com.redhat.cloud.notifications.db.converters.StatusConverter; -import com.redhat.cloud.notifications.models.validation.MaintenanceWithTimeInterval; -import jakarta.persistence.Column; -import jakarta.persistence.Convert; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import jakarta.validation.constraints.NotNull; - -import java.time.LocalDateTime; - -import static com.fasterxml.jackson.annotation.JsonFormat.Shape.STRING; -import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; -import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; - -@Entity -@Table(name = "status") -@JsonNaming(SnakeCaseStrategy.class) -@MaintenanceWithTimeInterval -public class CurrentStatus { - - /* - * We don't need this field in the Java code but Hibernate needs each @Entity to have a field annotated with @Id. - * This field has a real purpose in the database though: it is used to guarantee that the status table will never - * contain more than one row. This is done with a combination of PK and CHECK SQL constraints. - */ - @Id - @JsonIgnore - private boolean preventMultipleRows = true; - - @NotNull - @Convert(converter = StatusConverter.class) - @Column(name = "value") - public Status status; - - @JsonInclude(NON_NULL) - @JsonFormat(shape = STRING) - private LocalDateTime startTime; - - @JsonInclude(NON_NULL) - @JsonFormat(shape = STRING) - private LocalDateTime endTime; - - public Status getStatus() { - return status; - } - - public void setStatus(Status status) { - this.status = status; - } - - public LocalDateTime getStartTime() { - return startTime; - } - - public void setStartTime(LocalDateTime startTime) { - this.startTime = startTime; - } - - public LocalDateTime getEndTime() { - return endTime; - } - - public void setEndTime(LocalDateTime endTime) { - this.endTime = endTime; - } -} diff --git a/backend/src/main/java/com/redhat/cloud/notifications/models/Status.java b/backend/src/main/java/com/redhat/cloud/notifications/models/Status.java deleted file mode 100644 index 849b84bdea..0000000000 --- a/backend/src/main/java/com/redhat/cloud/notifications/models/Status.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.redhat.cloud.notifications.models; - -public enum Status { - UP, - MAINTENANCE -} diff --git a/backend/src/main/java/com/redhat/cloud/notifications/models/validation/MaintenanceWithTimeInterval.java b/backend/src/main/java/com/redhat/cloud/notifications/models/validation/MaintenanceWithTimeInterval.java deleted file mode 100644 index c32424bdaf..0000000000 --- a/backend/src/main/java/com/redhat/cloud/notifications/models/validation/MaintenanceWithTimeInterval.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.redhat.cloud.notifications.models.validation; - -import com.redhat.cloud.notifications.models.CurrentStatus; -import com.redhat.cloud.notifications.models.Status; -import jakarta.validation.Constraint; -import jakarta.validation.Payload; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Checks that {@link CurrentStatus#startTime} and {@link CurrentStatus#endTime} are not {@code null} and valid when - * {@link CurrentStatus#status CurrentStatus#status} is equal to {@link Status#MAINTENANCE MAINTENANCE}. - */ -@Retention(RUNTIME) -@Target(TYPE) -@Constraint(validatedBy = MaintenanceWithTimeIntervalValidator.class) -@Documented -public @interface MaintenanceWithTimeInterval { - - String message() default "A valid time interval is mandatory for the maintenance status"; - - Class[] groups() default {}; - - Class[] payload() default {}; -} diff --git a/backend/src/main/java/com/redhat/cloud/notifications/models/validation/MaintenanceWithTimeIntervalValidator.java b/backend/src/main/java/com/redhat/cloud/notifications/models/validation/MaintenanceWithTimeIntervalValidator.java deleted file mode 100644 index c6701ae6ed..0000000000 --- a/backend/src/main/java/com/redhat/cloud/notifications/models/validation/MaintenanceWithTimeIntervalValidator.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.redhat.cloud.notifications.models.validation; - -import com.redhat.cloud.notifications.models.CurrentStatus; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; - -import static com.redhat.cloud.notifications.models.Status.MAINTENANCE; - -public class MaintenanceWithTimeIntervalValidator implements ConstraintValidator { - - @Override - public boolean isValid(CurrentStatus value, ConstraintValidatorContext context) { - if (value.getStatus() == MAINTENANCE) { - // The time interval is mandatory for maintenance. - if (value.getStartTime() == null || value.getEndTime() == null) { - return false; - } - // The time interval must be valid. - if (value.getStartTime().isAfter(value.getEndTime())) { - return false; - } - } - return true; - } -} diff --git a/backend/src/test/java/com/redhat/cloud/notifications/db/DbCleaner.java b/backend/src/test/java/com/redhat/cloud/notifications/db/DbCleaner.java index 80fcc3ad73..74939b9078 100644 --- a/backend/src/test/java/com/redhat/cloud/notifications/db/DbCleaner.java +++ b/backend/src/test/java/com/redhat/cloud/notifications/db/DbCleaner.java @@ -14,7 +14,6 @@ import com.redhat.cloud.notifications.models.InstantEmailTemplate; import com.redhat.cloud.notifications.models.IntegrationTemplate; import com.redhat.cloud.notifications.models.NotificationHistory; -import com.redhat.cloud.notifications.models.Status; import com.redhat.cloud.notifications.models.WebhookProperties; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; @@ -86,9 +85,5 @@ public void clean() { eventType.setDisplayName(DEFAULT_EVENT_TYPE_DISPLAY_NAME); eventType.setDescription(DEFAULT_EVENT_TYPE_DESCRIPTION); applicationRepository.createEventType(eventType); - - entityManager.createQuery("UPDATE CurrentStatus SET status = :status") - .setParameter("status", Status.UP) - .executeUpdate(); } }