File size: 3,170 Bytes
9373c61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5cfe5c4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.dalab.policyengine.model;

import java.time.Instant;
import java.util.Map;
import java.util.UUID;

import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

import jakarta.persistence.*;

@Entity
@Table(name = "policy_evaluations")
public class PolicyEvaluation {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(columnDefinition = "UUID")
    private UUID id;

    @Column(nullable = false, columnDefinition = "UUID")
    private UUID policyId;

    @Column(nullable = false, length = 255) // External asset ID from da-catalog or other source
    private String targetAssetId;

    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private PolicyEvaluationStatus status;

    // Store details about the evaluation, e.g., which rules passed/failed, input facts snapshot
    @JdbcTypeCode(SqlTypes.JSON)
    @Column(columnDefinition = "jsonb")
    private Map<String, Object> evaluationDetails;

    // Store actions that were triggered as a result of this evaluation
    @JdbcTypeCode(SqlTypes.JSON)
    @Column(columnDefinition = "jsonb")
    private Map<String, Object> triggeredActions;

    @Column(nullable = false)
    private Instant evaluatedAt;

    @Column(columnDefinition = "UUID")
    private UUID evaluationTriggeredByUserId; // Optional: if triggered by a user action

    // Getters and Setters

    public UUID getId() {
        return id;
    }

    public void setId(UUID id) {
        this.id = id;
    }

    public UUID getPolicyId() {
        return policyId;
    }

    public void setPolicyId(UUID policyId) {
        this.policyId = policyId;
    }

    public String getTargetAssetId() {
        return targetAssetId;
    }

    public void setTargetAssetId(String targetAssetId) {
        this.targetAssetId = targetAssetId;
    }

    public PolicyEvaluationStatus getStatus() {
        return status;
    }

    public void setStatus(PolicyEvaluationStatus status) {
        this.status = status;
    }

    public Map<String, Object> getEvaluationDetails() {
        return evaluationDetails;
    }

    public void setEvaluationDetails(Map<String, Object> evaluationDetails) {
        this.evaluationDetails = evaluationDetails;
    }

    public Map<String, Object> getTriggeredActions() {
        return triggeredActions;
    }

    public void setTriggeredActions(Map<String, Object> triggeredActions) {
        this.triggeredActions = triggeredActions;
    }

    public Instant getEvaluatedAt() {
        return evaluatedAt;
    }

    public void setEvaluatedAt(Instant evaluatedAt) {
        this.evaluatedAt = evaluatedAt;
    }

    public UUID getEvaluationTriggeredByUserId() {
        return evaluationTriggeredByUserId;
    }

    public void setEvaluationTriggeredByUserId(UUID evaluationTriggeredByUserId) {
        this.evaluationTriggeredByUserId = evaluationTriggeredByUserId;
    }

    @PrePersist
    protected void onPersist() {
        if (evaluatedAt == null) {
            evaluatedAt = Instant.now();
        }
    }
}