Skip to content

Commit 15a790e

Browse files
committed
feat: add system owner field to alert response rules and update related logic
1 parent 0cf7931 commit 15a790e

10 files changed

Lines changed: 100 additions & 78 deletions

File tree

backend/src/main/java/com/park/utmstack/domain/alert_response_rule/UtmAlertResponseRule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.park.utmstack.service.dto.UtmAlertResponseRuleDTO;
66
import lombok.Getter;
77
import lombok.Setter;
8+
import org.hibernate.annotations.GenericGenerator;
89
import org.springframework.data.annotation.CreatedBy;
910
import org.springframework.data.annotation.CreatedDate;
1011
import org.springframework.data.annotation.LastModifiedBy;
@@ -30,7 +31,8 @@ public class UtmAlertResponseRule implements Serializable {
3031
private static final long serialVersionUID = 1L;
3132

3233
@Id
33-
@GeneratedValue(strategy = GenerationType.IDENTITY)
34+
@GenericGenerator(name = "CustomIdentityGenerator", strategy = "com.park.utmstack.util.CustomIdentityGenerator")
35+
@GeneratedValue(generator = "CustomIdentityGenerator")
3436
private Long id;
3537
@Column(name = "rule_name", length = 150, nullable = false)
3638
private String ruleName;
@@ -62,6 +64,9 @@ public class UtmAlertResponseRule implements Serializable {
6264
@Column(name = "last_modified_date")
6365
private Instant lastModifiedDate;
6466

67+
@Column(name = "system_owner", nullable = false)
68+
private Boolean systemOwner;
69+
6570
@OneToMany(mappedBy = "rule", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
6671
List<UtmAlertResponseRuleExecution> utmAlertResponseRuleExecutions;
6772

@@ -87,6 +92,7 @@ public UtmAlertResponseRule(UtmAlertResponseRuleDTO dto) {
8792
this.ruleActive = dto.getActive();
8893
this.agentPlatform = dto.getAgentPlatform();
8994
this.defaultAgent = dto.getDefaultAgent();
95+
this.systemOwner = dto.getSystemOwner();
9096
if (!CollectionUtils.isEmpty(dto.getExcludedAgents()))
9197
this.excludedAgents = String.join(",", dto.getExcludedAgents());
9298
else
@@ -102,6 +108,7 @@ public UtmAlertResponseRule(UtmAlertResponseRuleDTO dto) {
102108
template.setTitle(templateDto.getTitle());
103109
template.setDescription(templateDto.getDescription());
104110
template.setCommand(templateDto.getCommand());
111+
template.setSystemOwner(false);
105112
return template;
106113
})
107114
.collect(Collectors.toList());

backend/src/main/java/com/park/utmstack/repository/alert_response_rule/UtmAlertResponseRuleRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.park.utmstack.repository.alert_response_rule;
22

33
import com.park.utmstack.domain.alert_response_rule.UtmAlertResponseRule;
4+
import com.park.utmstack.domain.correlation.rules.UtmCorrelationRules;
45
import org.springframework.data.jpa.repository.JpaRepository;
56
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
67
import org.springframework.data.jpa.repository.Query;
78
import org.springframework.stereotype.Repository;
89

910
import java.util.List;
11+
import java.util.Optional;
1012

1113

1214
/**
@@ -24,4 +26,6 @@ public interface UtmAlertResponseRuleRepository extends JpaRepository<UtmAlertRe
2426

2527
List<UtmAlertResponseRule> findAllByRuleActiveIsTrue();
2628

29+
Optional<UtmAlertResponseRule> findFirstBySystemOwnerIsTrueOrderByIdDesc();
30+
2731
}

backend/src/main/java/com/park/utmstack/service/alert_response_rule/UtmAlertResponseRuleQueryService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ private Specification<UtmAlertResponseRule> createSpecification(UtmAlertResponse
8383
if (criteria.getLastModifiedDate() != null) {
8484
specification = specification.and(buildRangeSpecification(criteria.getLastModifiedDate(), UtmAlertResponseRule_.lastModifiedDate));
8585
}
86+
if (criteria.getSystemOwner() != null) {
87+
specification = specification.and(buildSpecification(criteria.getSystemOwner(), UtmAlertResponseRule_.systemOwner));
88+
}
8689
}
8790
return specification;
8891
}

backend/src/main/java/com/park/utmstack/service/alert_response_rule/UtmAlertResponseRuleService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ public class UtmAlertResponseRuleService {
7070

7171

7272

73-
public UtmAlertResponseRule save(UtmAlertResponseRule alertResponseRule) {
73+
public UtmAlertResponseRule save(UtmAlertResponseRule alertResponseRule, boolean isCreate) {
7474
final String ctx = CLASSNAME + ".save";
7575
try {
76-
if (alertResponseRule.getId() != null) {
76+
if (!isCreate) {
7777
String alertRuleId = String.valueOf(alertResponseRule.getId());
7878
UtmAlertResponseRule current = alertResponseRuleRepository.findById(alertResponseRule.getId())
7979
.orElseThrow(() -> new RuntimeException(String.format("Incident response rule with ID: %1$s not found", alertRuleId)));
@@ -357,4 +357,10 @@ public void mergeInto(UtmAlertResponseRule target, UtmAlertResponseRule source)
357357
target.getUtmAlertResponseActionTemplates().addAll(managedTemplates);
358358
}
359359
}
360+
361+
public Long getSystemSequenceNextValue() {
362+
return alertResponseRuleRepository.findFirstBySystemOwnerIsTrueOrderByIdDesc()
363+
.map(rule -> rule.getId() + 1)
364+
.orElse(1L);
365+
}
360366
}
Lines changed: 5 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package com.park.utmstack.service.dto;
22

3+
import lombok.Getter;
4+
import lombok.Setter;
35
import tech.jhipster.service.filter.BooleanFilter;
46
import tech.jhipster.service.filter.InstantFilter;
57
import tech.jhipster.service.filter.LongFilter;
68
import tech.jhipster.service.filter.StringFilter;
79

810
import java.io.Serializable;
911

12+
@Getter
13+
@Setter
1014
public class UtmAlertResponseRuleCriteria implements Serializable {
1115

1216
private static final long serialVersionUID = 1L;
@@ -19,69 +23,5 @@ public class UtmAlertResponseRuleCriteria implements Serializable {
1923
private StringFilter lastModifiedBy;
2024
private InstantFilter createdDate;
2125
private InstantFilter lastModifiedDate;
22-
23-
24-
public LongFilter getId() {
25-
return id;
26-
}
27-
28-
public void setId(LongFilter id) {
29-
this.id = id;
30-
}
31-
32-
public StringFilter getName() {
33-
return name;
34-
}
35-
36-
public void setName(StringFilter name) {
37-
this.name = name;
38-
}
39-
40-
public BooleanFilter getActive() {
41-
return active;
42-
}
43-
44-
public void setActive(BooleanFilter active) {
45-
this.active = active;
46-
}
47-
48-
public StringFilter getAgentPlatform() {
49-
return agentPlatform;
50-
}
51-
52-
public void setAgentPlatform(StringFilter agentPlatform) {
53-
this.agentPlatform = agentPlatform;
54-
}
55-
56-
public StringFilter getCreatedBy() {
57-
return createdBy;
58-
}
59-
60-
public void setCreatedBy(StringFilter createdBy) {
61-
this.createdBy = createdBy;
62-
}
63-
64-
public StringFilter getLastModifiedBy() {
65-
return lastModifiedBy;
66-
}
67-
68-
public void setLastModifiedBy(StringFilter lastModifiedBy) {
69-
this.lastModifiedBy = lastModifiedBy;
70-
}
71-
72-
public InstantFilter getCreatedDate() {
73-
return createdDate;
74-
}
75-
76-
public void setCreatedDate(InstantFilter createdDate) {
77-
this.createdDate = createdDate;
78-
}
79-
80-
public InstantFilter getLastModifiedDate() {
81-
return lastModifiedDate;
82-
}
83-
84-
public void setLastModifiedDate(InstantFilter lastModifiedDate) {
85-
this.lastModifiedDate = lastModifiedDate;
86-
}
26+
private BooleanFilter systemOwner;
8727
}

backend/src/main/java/com/park/utmstack/service/dto/UtmAlertResponseRuleDTO.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public class UtmAlertResponseRuleDTO {
6262

6363
private List<UtmAlertResponseActionTemplateDTO> actions;
6464

65+
private Boolean systemOwner;
66+
6567
public UtmAlertResponseRuleDTO(UtmAlertResponseRule rule) {
6668
this.id = rule.getId();
6769
this.name = rule.getRuleName();
@@ -81,6 +83,7 @@ public UtmAlertResponseRuleDTO(UtmAlertResponseRule rule) {
8183
this.createdDate = rule.getCreatedDate();
8284
this.lastModifiedBy = rule.getLastModifiedBy();
8385
this.lastModifiedDate = rule.getLastModifiedDate();
86+
this.systemOwner = rule.getSystemOwner();
8487

8588
if (rule.getUtmAlertResponseActionTemplates() != null) {
8689
this.actions = rule.getUtmAlertResponseActionTemplates()

backend/src/main/java/com/park/utmstack/web/rest/alert_response_rule/UtmAlertResponseRuleResource.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.park.utmstack.domain.alert_response_rule.UtmAlertResponseActionTemplate;
44
import com.park.utmstack.domain.alert_response_rule.UtmAlertResponseRule;
55
import com.park.utmstack.domain.application_events.enums.ApplicationEventType;
6+
import com.park.utmstack.service.UtmStackService;
67
import com.park.utmstack.service.alert_response_rule.UtmAlertResponseActionTemplateQueryService;
78
import com.park.utmstack.service.alert_response_rule.UtmAlertResponseRuleQueryService;
89
import com.park.utmstack.service.alert_response_rule.UtmAlertResponseRuleService;
@@ -13,6 +14,7 @@
1314
import com.park.utmstack.service.dto.UtmAlertResponseRuleDTO;
1415
import com.park.utmstack.util.ResponseUtil;
1516
import com.park.utmstack.web.rest.util.PaginationUtil;
17+
import lombok.RequiredArgsConstructor;
1618
import org.slf4j.Logger;
1719
import org.slf4j.LoggerFactory;
1820
import org.springdoc.api.annotations.ParameterObject;
@@ -30,6 +32,7 @@
3032

3133
@RestController
3234
@RequestMapping("/api")
35+
@RequiredArgsConstructor
3336
public class UtmAlertResponseRuleResource {
3437

3538
private static final String CLASSNAME = "UtmAlertResponseRuleResource";
@@ -38,17 +41,11 @@ public class UtmAlertResponseRuleResource {
3841
private final UtmAlertResponseRuleService alertResponseRuleService;
3942
private final UtmAlertResponseRuleQueryService alertResponseRuleQueryService;
4043
private final ApplicationEventService eventService;
44+
private final UtmStackService utmStackService;
4145

4246
private final UtmAlertResponseActionTemplateQueryService utmAlertResponseActionTemplateQueryService;
4347

44-
public UtmAlertResponseRuleResource(UtmAlertResponseRuleService alertResponseRuleService,
45-
UtmAlertResponseRuleQueryService alertResponseRuleQueryService,
46-
ApplicationEventService eventService, UtmAlertResponseActionTemplateQueryService utmAlertResponseActionTemplateQueryService) {
47-
this.alertResponseRuleService = alertResponseRuleService;
48-
this.alertResponseRuleQueryService = alertResponseRuleQueryService;
49-
this.eventService = eventService;
50-
this.utmAlertResponseActionTemplateQueryService = utmAlertResponseActionTemplateQueryService;
51-
}
48+
5249

5350
@PostMapping("/utm-alert-response-rules")
5451
public ResponseEntity<UtmAlertResponseRuleDTO> createAlertResponseRule(@Valid @RequestBody UtmAlertResponseRuleDTO dto) {
@@ -60,7 +57,15 @@ public ResponseEntity<UtmAlertResponseRuleDTO> createAlertResponseRule(@Valid @R
6057
eventService.createEvent(msg, ApplicationEventType.ERROR);
6158
return ResponseUtil.buildErrorResponse(HttpStatus.BAD_REQUEST, msg);
6259
}
63-
return ResponseEntity.ok(new UtmAlertResponseRuleDTO(alertResponseRuleService.save(new UtmAlertResponseRule(dto))));
60+
61+
if (utmStackService.isInDevelop()) {
62+
dto.setId(alertResponseRuleService.getSystemSequenceNextValue());
63+
dto.setSystemOwner(true);
64+
} else {
65+
dto.setSystemOwner(false);
66+
}
67+
68+
return ResponseEntity.ok(new UtmAlertResponseRuleDTO(alertResponseRuleService.save(new UtmAlertResponseRule(dto), true)));
6469
} catch (Exception e) {
6570
String msg = ctx + ": " + e.getLocalizedMessage();
6671
log.error(msg);
@@ -79,7 +84,7 @@ public ResponseEntity<UtmAlertResponseRuleDTO> updateAlertResponseRule(@Valid @R
7984
eventService.createEvent(msg, ApplicationEventType.ERROR);
8085
return ResponseUtil.buildErrorResponse(HttpStatus.BAD_REQUEST, msg);
8186
}
82-
return ResponseEntity.ok(new UtmAlertResponseRuleDTO(alertResponseRuleService.save(new UtmAlertResponseRule(dto))));
87+
return ResponseEntity.ok(new UtmAlertResponseRuleDTO(alertResponseRuleService.save(new UtmAlertResponseRule(dto), false)));
8388
} catch (Exception e) {
8489
String msg = ctx + ": " + e.getLocalizedMessage();
8590
log.error(msg);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
6+
7+
<changeSet id="20251110002" author="Manuel">
8+
<addColumn tableName="utm_alert_response_rule">
9+
<column name="system_owner" type="BOOLEAN" defaultValueBoolean="true"/>
10+
</addColumn>
11+
<update tableName="utm_alert_response_rule">
12+
<column name="system_owner" valueBoolean="true"/>
13+
</update>
14+
<addNotNullConstraint tableName="utm_alert_response_rule" columnName="system_owner" columnDataType="BOOLEAN"/>
15+
<rollback>
16+
<dropColumn tableName="utm_alert_response_rule" columnName="system_owner"/>
17+
</rollback>
18+
</changeSet>
19+
20+
</databaseChangeLog>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
6+
7+
<changeSet id="20251110003" author="Manuel">
8+
9+
<sqlFile
10+
path="config/liquibase/data/utm_alert_response_rule.sql"
11+
relativeToChangelogFile="false"
12+
splitStatements="false"
13+
stripComments="false"
14+
encoding="UTF-8"/>
15+
<sqlFile
16+
path="config/liquibase/data/utm_response_action_template.sql"
17+
relativeToChangelogFile="false"
18+
splitStatements="false"
19+
stripComments="false"
20+
encoding="UTF-8"/>
21+
22+
<sqlFile
23+
path="config/liquibase/data/utm_alert_response_rule_template.sql"
24+
relativeToChangelogFile="false"
25+
splitStatements="false"
26+
stripComments="false"
27+
encoding="UTF-8"/>
28+
</changeSet>
29+
30+
</databaseChangeLog>

backend/src/main/resources/config/liquibase/master.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,9 @@
263263

264264
<include file="/config/liquibase/changelog/20251110001_disable_correlation_rules_with_regex.xml" relativeToChangelogFile="false"/>
265265

266+
<include file="/config/liquibase/changelog/20251110002_add_system_owner_to_alert_response_rules.xml" relativeToChangelogFile="false"/>
267+
268+
<include file="/config/liquibase/changelog/20251110003_add_alert-response_rule_data.xml" relativeToChangelogFile="false"/>
269+
266270

267271
</databaseChangeLog>

0 commit comments

Comments
 (0)