File tree Expand file tree Collapse file tree 4 files changed +36
-11
lines changed
backend/src/main/java/com/park/utmstack
domain/alert_response_rule Expand file tree Collapse file tree 4 files changed +36
-11
lines changed Original file line number Diff line number Diff line change @@ -41,14 +41,7 @@ public class UtmAlertResponseActionTemplate implements Serializable {
4141 @ Column (name = "system_owner" , nullable = false )
4242 private Boolean systemOwner ;
4343
44- @ ManyToMany
45- @ JoinTable (
46- name = "utm_alert_response_rule_template" ,
47- joinColumns = @ JoinColumn (name = "rule_id" ),
48- inverseJoinColumns = @ JoinColumn (name = "template_id" )
49- )
50- private List <UtmAlertResponseActionTemplate > utmAlertResponseActionTemplates = new ArrayList <>();
51-
52-
44+ @ ManyToMany (mappedBy = "utmAlertResponseActionTemplates" )
45+ private List <UtmAlertResponseRule > utmAlertResponseRules = new ArrayList <>();
5346}
5447
Original file line number Diff line number Diff line change @@ -109,4 +109,30 @@ public UtmAlertResponseRule(UtmAlertResponseRuleDTO dto) {
109109 }
110110 }
111111
112+ public void mergeInto (UtmAlertResponseRule target ) {
113+ target .setRuleName (this .getRuleName ());
114+ target .setRuleDescription (this .getRuleDescription ());
115+ target .setRuleCmd (this .getRuleCmd ());
116+ target .setRuleActive (this .getRuleActive ());
117+ target .setAgentPlatform (this .getAgentPlatform ());
118+ target .setDefaultAgent (this .getDefaultAgent ());
119+ target .setExcludedAgents (this .getExcludedAgents ());
120+ target .setRuleConditions (this .getRuleConditions ());
121+
122+ if (!this .getUtmAlertResponseActionTemplates ().isEmpty ()) {
123+ List <UtmAlertResponseActionTemplate > targetActions = target .getUtmAlertResponseActionTemplates ();
124+ targetActions .clear ();
125+ targetActions .addAll (this .getUtmAlertResponseActionTemplates ().stream ().map (templateDto -> {
126+ UtmAlertResponseActionTemplate template = new UtmAlertResponseActionTemplate ();
127+ template .setId (templateDto .getId ());
128+ template .setTitle (templateDto .getTitle ());
129+ template .setDescription (templateDto .getDescription ());
130+ template .setCommand (templateDto .getCommand ());
131+ return template ;
132+ }).collect (Collectors .toList ()));
133+ }
134+
135+ }
136+
137+
112138}
Original file line number Diff line number Diff line change @@ -93,9 +93,12 @@ public UtmAlertResponseRule save(UtmAlertResponseRule alertResponseRule) {
9393 final String ctx = CLASSNAME + ".save" ;
9494 try {
9595 if (alertResponseRule .getId () != null ) {
96+ String alertRuleId = String .valueOf (alertResponseRule .getId ());
9697 UtmAlertResponseRule current = alertResponseRuleRepository .findById (alertResponseRule .getId ())
97- .orElseThrow (() -> new RuntimeException (String .format ("Incident response rule with ID: %1$s not found" , alertResponseRule .getId ())));
98- alertResponseRuleHistoryRepository .save (new UtmAlertResponseRuleHistory (new UtmAlertResponseRuleDTO (current )));
98+ .orElseThrow (() -> new RuntimeException (String .format ("Incident response rule with ID: %1$s not found" , alertRuleId )));
99+ alertResponseRule .mergeInto (current );
100+ alertResponseRuleHistoryRepository .save (new UtmAlertResponseRuleHistory (new UtmAlertResponseRuleDTO (alertResponseRule )));
101+ alertResponseRule = current ;
99102 }
100103
101104 if (alertResponseRule .getUtmAlertResponseActionTemplates () != null ) {
Original file line number Diff line number Diff line change 33import com .fasterxml .jackson .annotation .JsonProperty ;
44import com .google .gson .Gson ;
55import com .google .gson .reflect .TypeToken ;
6+ import com .park .utmstack .domain .alert_response_rule .UtmAlertResponseActionTemplate ;
67import com .park .utmstack .domain .alert_response_rule .UtmAlertResponseRule ;
78import com .park .utmstack .domain .chart_builder .types .query .FilterType ;
89import lombok .Data ;
910import lombok .NoArgsConstructor ;
11+ import org .springframework .util .CollectionUtils ;
1012import org .springframework .util .StringUtils ;
1113
1214import javax .validation .constraints .*;
@@ -95,4 +97,5 @@ public UtmAlertResponseRuleDTO(UtmAlertResponseRule rule) {
9597 }
9698
9799 }
100+
98101}
You can’t perform that action at this time.
0 commit comments