Spaces:
Build error
Build error
| package com.dalab.policyengine.model; | |
| import java.time.Instant; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import java.util.Map; | |
| import java.util.UUID; | |
| import org.hibernate.annotations.JdbcTypeCode; | |
| import org.hibernate.type.SqlTypes; | |
| import jakarta.persistence.CascadeType; | |
| import jakarta.persistence.CollectionTable; | |
| import jakarta.persistence.Column; | |
| import jakarta.persistence.ElementCollection; | |
| import jakarta.persistence.Entity; | |
| import jakarta.persistence.EnumType; | |
| import jakarta.persistence.Enumerated; | |
| import jakarta.persistence.FetchType; | |
| import jakarta.persistence.GeneratedValue; | |
| import jakarta.persistence.GenerationType; | |
| import jakarta.persistence.Id; | |
| import jakarta.persistence.JoinColumn; | |
| import jakarta.persistence.OneToMany; | |
| import jakarta.persistence.PrePersist; | |
| import jakarta.persistence.PreUpdate; | |
| import jakarta.persistence.Table; | |
| import jakarta.validation.constraints.NotBlank; | |
| import jakarta.validation.constraints.NotNull; | |
| import jakarta.validation.constraints.Size; | |
| /** | |
| * Entity representing an event subscription configuration. | |
| * Users can subscribe to specific types of events and configure | |
| * notification preferences and action triggers. | |
| */ | |
| public class EventSubscription { | |
| private UUID id; | |
| private String name; | |
| private String description; | |
| private UUID userId; | |
| private EventSubscriptionStatus status = EventSubscriptionStatus.ACTIVE; | |
| /** | |
| * Event types to subscribe to (e.g., POLICY_VIOLATION, ASSET_DISCOVERED, COMPLIANCE_ISSUE) | |
| */ | |
| private List<EventType> eventTypes = new ArrayList<>(); | |
| /** | |
| * Event severity levels to include (e.g., HIGH, MEDIUM, LOW) | |
| */ | |
| private List<EventSeverity> severities = new ArrayList<>(); | |
| /** | |
| * Source services to monitor (e.g., da-catalog, da-discovery, da-compliance) | |
| */ | |
| private List<String> sourceServices = new ArrayList<>(); | |
| /** | |
| * Filter conditions for events (MVEL expressions) | |
| */ | |
| private List<EventRule> rules = new ArrayList<>(); | |
| /** | |
| * Notification preferences and action configurations | |
| */ | |
| private Map<String, Object> notificationConfig; // e.g., { "email": true, "slack": { "channel": "#alerts" } } | |
| /** | |
| * Action configurations to trigger when events match | |
| */ | |
| private Map<String, Object> actionConfig; // e.g., { "autoQuarantine": true, "escalateTo": "admin" } | |
| private Instant createdAt; | |
| private Instant updatedAt; | |
| private UUID createdByUserId; | |
| private UUID updatedByUserId; | |
| // Constructors | |
| public EventSubscription() {} | |
| public EventSubscription(String name, UUID userId) { | |
| this.name = name; | |
| this.userId = userId; | |
| } | |
| // Getters and Setters | |
| public UUID getId() { | |
| return id; | |
| } | |
| public void setId(UUID id) { | |
| this.id = id; | |
| } | |
| public String getName() { | |
| return name; | |
| } | |
| public void setName(String name) { | |
| this.name = name; | |
| } | |
| public String getDescription() { | |
| return description; | |
| } | |
| public void setDescription(String description) { | |
| this.description = description; | |
| } | |
| public UUID getUserId() { | |
| return userId; | |
| } | |
| public void setUserId(UUID userId) { | |
| this.userId = userId; | |
| } | |
| public EventSubscriptionStatus getStatus() { | |
| return status; | |
| } | |
| public void setStatus(EventSubscriptionStatus status) { | |
| this.status = status; | |
| } | |
| public List<EventType> getEventTypes() { | |
| return eventTypes; | |
| } | |
| public void setEventTypes(List<EventType> eventTypes) { | |
| this.eventTypes = eventTypes != null ? eventTypes : new ArrayList<>(); | |
| } | |
| public void addEventType(EventType eventType) { | |
| if (this.eventTypes == null) { | |
| this.eventTypes = new ArrayList<>(); | |
| } | |
| this.eventTypes.add(eventType); | |
| } | |
| public void removeEventType(EventType eventType) { | |
| if (this.eventTypes != null) { | |
| this.eventTypes.remove(eventType); | |
| } | |
| } | |
| public List<EventSeverity> getSeverities() { | |
| return severities; | |
| } | |
| public void setSeverities(List<EventSeverity> severities) { | |
| this.severities = severities != null ? severities : new ArrayList<>(); | |
| } | |
| public void addSeverity(EventSeverity severity) { | |
| if (this.severities == null) { | |
| this.severities = new ArrayList<>(); | |
| } | |
| this.severities.add(severity); | |
| } | |
| public void removeSeverity(EventSeverity severity) { | |
| if (this.severities != null) { | |
| this.severities.remove(severity); | |
| } | |
| } | |
| public List<String> getSourceServices() { | |
| return sourceServices; | |
| } | |
| public void setSourceServices(List<String> sourceServices) { | |
| this.sourceServices = sourceServices != null ? sourceServices : new ArrayList<>(); | |
| } | |
| public void addSourceService(String sourceService) { | |
| if (this.sourceServices == null) { | |
| this.sourceServices = new ArrayList<>(); | |
| } | |
| this.sourceServices.add(sourceService); | |
| } | |
| public void removeSourceService(String sourceService) { | |
| if (this.sourceServices != null) { | |
| this.sourceServices.remove(sourceService); | |
| } | |
| } | |
| public List<EventRule> getRules() { | |
| return rules; | |
| } | |
| public void setRules(List<EventRule> rules) { | |
| this.rules = rules != null ? rules : new ArrayList<>(); | |
| this.rules.forEach(rule -> rule.setSubscription(this)); | |
| } | |
| public void addRule(EventRule rule) { | |
| if (this.rules == null) { | |
| this.rules = new ArrayList<>(); | |
| } | |
| this.rules.add(rule); | |
| rule.setSubscription(this); | |
| } | |
| public void removeRule(EventRule rule) { | |
| if (this.rules != null) { | |
| this.rules.remove(rule); | |
| rule.setSubscription(null); | |
| } | |
| } | |
| public Map<String, Object> getNotificationConfig() { | |
| return notificationConfig; | |
| } | |
| public void setNotificationConfig(Map<String, Object> notificationConfig) { | |
| this.notificationConfig = notificationConfig; | |
| } | |
| public Map<String, Object> getActionConfig() { | |
| return actionConfig; | |
| } | |
| public void setActionConfig(Map<String, Object> actionConfig) { | |
| this.actionConfig = actionConfig; | |
| } | |
| public Instant getCreatedAt() { | |
| return createdAt; | |
| } | |
| public void setCreatedAt(Instant createdAt) { | |
| this.createdAt = createdAt; | |
| } | |
| public Instant getUpdatedAt() { | |
| return updatedAt; | |
| } | |
| public void setUpdatedAt(Instant updatedAt) { | |
| this.updatedAt = updatedAt; | |
| } | |
| public UUID getCreatedByUserId() { | |
| return createdByUserId; | |
| } | |
| public void setCreatedByUserId(UUID createdByUserId) { | |
| this.createdByUserId = createdByUserId; | |
| } | |
| public UUID getUpdatedByUserId() { | |
| return updatedByUserId; | |
| } | |
| public void setUpdatedByUserId(UUID updatedByUserId) { | |
| this.updatedByUserId = updatedByUserId; | |
| } | |
| protected void onCreate() { | |
| createdAt = Instant.now(); | |
| updatedAt = Instant.now(); | |
| } | |
| protected void onUpdate() { | |
| updatedAt = Instant.now(); | |
| } | |
| public boolean equals(Object o) { | |
| if (this == o) return true; | |
| if (!(o instanceof EventSubscription)) return false; | |
| EventSubscription that = (EventSubscription) o; | |
| return id != null && id.equals(that.getId()); | |
| } | |
| public int hashCode() { | |
| return getClass().hashCode(); | |
| } | |
| public String toString() { | |
| return "EventSubscription{" + | |
| "id=" + id + | |
| ", name='" + name + '\'' + | |
| ", userId=" + userId + | |
| ", status=" + status + | |
| ", eventTypes=" + eventTypes + | |
| ", severities=" + severities + | |
| '}'; | |
| } | |
| } |