Skip to content

Commit 0a3826d

Browse files
committed
feat: update database schema and properties for v11 release
1 parent 57462dc commit 0a3826d

32 files changed

+286
-454
lines changed

backend/src/main/java/com/park/utmstack/domain/index_template/IndexTemplate.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
import com.fasterxml.jackson.annotation.JsonInclude;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import lombok.Getter;
6+
import lombok.Setter;
57

68
import java.util.ArrayList;
79
import java.util.Arrays;
810
import java.util.List;
911

12+
@Setter
13+
@Getter
1014
@JsonInclude(JsonInclude.Include.NON_NULL)
1115
public class IndexTemplate {
1216

@@ -24,30 +28,6 @@ private IndexTemplate(List<String> indexPatterns, Integer priority, Template tem
2428
this.template = template;
2529
}
2630

27-
public List<String> getIndexPatterns() {
28-
return indexPatterns;
29-
}
30-
31-
public void setIndexPatterns(List<String> indexPatterns) {
32-
this.indexPatterns = indexPatterns;
33-
}
34-
35-
public Integer getPriority() {
36-
return priority;
37-
}
38-
39-
public void setPriority(Integer priority) {
40-
this.priority = priority;
41-
}
42-
43-
public Template getTemplate() {
44-
return template;
45-
}
46-
47-
public void setTemplate(Template template) {
48-
this.template = template;
49-
}
50-
5131
public static Builder builder() {
5232
return new Builder();
5333
}

backend/src/main/java/com/park/utmstack/domain/index_template/IndexTemplateSettings.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import com.fasterxml.jackson.annotation.JsonInclude;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import lombok.Getter;
56

7+
@Getter
68
@JsonInclude(value = JsonInclude.Include.NON_NULL)
79
public class IndexTemplateSettings {
810

@@ -18,34 +20,18 @@ public class IndexTemplateSettings {
1820
@JsonProperty("number_of_replicas")
1921
private Integer numberOfReplicas;
2022

21-
public String getIndexPolicyId() {
22-
return indexPolicyId;
23-
}
24-
2523
public void setIndexPolicyId(String indexPolicyId) {
2624
this.indexPolicyId = indexPolicyId;
2725
}
2826

29-
public Integer getTotalFieldsLimit() {
30-
return totalFieldsLimit;
31-
}
32-
3327
public void setTotalFieldsLimit(Integer totalFieldsLimit) {
3428
this.totalFieldsLimit = totalFieldsLimit;
3529
}
3630

37-
public Integer getNumberOfShards() {
38-
return numberOfShards;
39-
}
40-
4131
public void setNumberOfShards(Integer numberOfShards) {
4232
this.numberOfShards = numberOfShards;
4333
}
4434

45-
public Integer getNumberOfReplicas() {
46-
return numberOfReplicas;
47-
}
48-
4935
public void setNumberOfReplicas(Integer numberOfReplicas) {
5036
this.numberOfReplicas = numberOfReplicas;
5137
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.park.utmstack.domain.index_template;
22

3+
import lombok.Getter;
4+
5+
@Getter
36
public class Template {
47
private final IndexTemplateSettings settings = new IndexTemplateSettings();
58

6-
public IndexTemplateSettings getSettings() {
7-
return settings;
8-
}
99
}

backend/src/main/java/com/park/utmstack/service/impl/UtmAlertServiceImpl.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,25 @@ public void convertToIncident(List<String> alertIds, String incidentName, Intege
329329

330330
Instant incidentCreationDate = Instant.now();
331331
String incidentCreatedBy = SecurityUtils.getCurrentUserLogin().orElse("system");
332+
String formattedDate = incidentCreationDate.toString();
333+
334+
String script = String.format(
335+
"ctx._source.isIncident = true; " +
336+
"if (ctx._source.incidentDetail == null) { " +
337+
"ctx._source.incidentDetail = [:]; " +
338+
"} " +
339+
"ctx._source.incidentDetail.incidentName = '%s'; " +
340+
"ctx._source.incidentDetail.incidentId = '%s'; " +
341+
"ctx._source.incidentDetail.creationDate = '%s'; " +
342+
"ctx._source.incidentDetail.createdBy = '%s'; " +
343+
"ctx._source.incidentDetail.source = '%s';",
344+
incidentName.replace("'", "\\'"),
345+
incidentId,
346+
formattedDate,
347+
incidentCreatedBy,
348+
incidentSource
349+
);
332350

333-
String script = String.format("ctx._source.isIncident=true;" +
334-
"if(ctx._source.incidentDetail == null) {" +
335-
"ctx._source.incidentDetail = new HashMap();}" +
336-
"ctx._source.incidentDetail.incidentName=\"%1$s\";" +
337-
"ctx._source.incidentDetail.incidentId=\"%2$s\";" +
338-
"ctx._source.incidentDetail.creationDate=\"%3$s\";" +
339-
"ctx._source.incidentDetail.createdBy=\"%4$s\";" +
340-
"ctx._source.incidentDetail.source=\"%5$s\";",
341-
incidentName, incidentId, incidentCreationDate, incidentCreatedBy, incidentSource);
342351

343352
List<FilterType> filters = new ArrayList<>();
344353
filters.add(new FilterType(Constants.alertIdKeyword, OperatorType.IS_ONE_OF_TERMS, alertIds));

backend/src/main/java/com/park/utmstack/service/incident/UtmIncidentService.java

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ public UtmIncident changeStatus(UtmIncident utmIncident) {
9494
try {
9595
log.debug("Request to save UtmIncident : {}", utmIncident);
9696
String oldIncident = ResolveIncidentStatus.incidentLabel(utmIncidentRepository.
97-
findById(utmIncident.getId())
98-
.orElseThrow(() -> new RuntimeException("Incident not found")));
97+
findById(utmIncident.getId())
98+
.orElseThrow(() -> new RuntimeException("Incident not found")));
9999

100100
UtmIncident incident = utmIncidentRepository.save(utmIncident);
101101
List<UtmIncidentAlert> alerts = utmIncidentAlertService.findAllByIncidentId(incident.getId());
@@ -136,34 +136,30 @@ public UtmIncident changeStatus(UtmIncident utmIncident) {
136136
*/
137137
public UtmIncident createIncident(NewIncidentDTO newIncidentDTO) {
138138
final String ctx = CLASSNAME + ".createIncident";
139-
try {
140-
validateAlertsNotAlreadyLinked(newIncidentDTO.getAlertList(), ctx);
141139

142-
UtmIncident utmIncident = new UtmIncident();
143-
utmIncident.setIncidentName(newIncidentDTO.getIncidentName());
144-
utmIncident.setIncidentDescription(newIncidentDTO.getIncidentDescription());
145-
utmIncident.setIncidentStatus(IncidentStatusEnum.OPEN);
146-
Integer severity = newIncidentDTO.getAlertList().stream()
140+
validateAlertsNotAlreadyLinked(newIncidentDTO.getAlertList(), ctx);
141+
142+
UtmIncident utmIncident = new UtmIncident();
143+
utmIncident.setIncidentName(newIncidentDTO.getIncidentName());
144+
utmIncident.setIncidentDescription(newIncidentDTO.getIncidentDescription());
145+
utmIncident.setIncidentStatus(IncidentStatusEnum.OPEN);
146+
Integer severity = newIncidentDTO.getAlertList().stream()
147147
.mapToInt(RelatedIncidentAlertsDTO::getAlertSeverity).max().orElse(0);
148-
utmIncident.setIncidentSeverity(severity);
149-
utmIncident.setIncidentAssignedTo(newIncidentDTO.getIncidentAssignedTo());
150-
utmIncident.setIncidentCreatedDate(new Date().toInstant());
148+
utmIncident.setIncidentSeverity(severity);
149+
utmIncident.setIncidentAssignedTo(newIncidentDTO.getIncidentAssignedTo());
150+
utmIncident.setIncidentCreatedDate(new Date().toInstant());
151151

152-
UtmIncident savedIncident = utmIncidentRepository.save(utmIncident);
152+
UtmIncident savedIncident = utmIncidentRepository.save(utmIncident);
153153

154-
saveRelatedAlerts(newIncidentDTO.getAlertList(), savedIncident.getId());
154+
saveRelatedAlerts(newIncidentDTO.getAlertList(), savedIncident.getId());
155155

156-
sendIncidentsEmail(newIncidentDTO.getAlertList().stream().map(RelatedIncidentAlertsDTO::getAlertId).collect(Collectors.toList()), savedIncident);
156+
sendIncidentsEmail(newIncidentDTO.getAlertList().stream().map(RelatedIncidentAlertsDTO::getAlertId).collect(Collectors.toList()), savedIncident);
157157

158-
String historyMessage = String.format("Incident created with %d alerts", newIncidentDTO.getAlertList().size());
159-
utmIncidentHistoryService.createHistory(IncidentHistoryActionEnum.INCIDENT_CREATED, savedIncident.getId(), "Incident Created", historyMessage);
158+
String historyMessage = String.format("Incident created with %d alerts", newIncidentDTO.getAlertList().size());
159+
utmIncidentHistoryService.createHistory(IncidentHistoryActionEnum.INCIDENT_CREATED, savedIncident.getId(), "Incident Created", historyMessage);
160+
161+
return savedIncident;
160162

161-
return savedIncident;
162-
} catch (Exception e) {
163-
String msg = ctx + ": " + e.getMessage();
164-
eventService.createEvent(msg, ApplicationEventType.ERROR);
165-
throw new RuntimeException(msg);
166-
}
167163
}
168164

169165
/**
@@ -174,33 +170,29 @@ public UtmIncident createIncident(NewIncidentDTO newIncidentDTO) {
174170
*/
175171
public UtmIncident addAlertsIncident(@Valid AddToIncidentDTO addToIncidentDTO) {
176172
final String ctx = CLASSNAME + ".addAlertsIncident";
177-
try {
178-
log.debug("Request to add alert to UtmIncident : {}", addToIncidentDTO);
179173

180-
List<RelatedIncidentAlertsDTO> alertIds = addToIncidentDTO.getAlertList();
174+
log.debug("Request to add alert to UtmIncident : {}", addToIncidentDTO);
181175

182-
String alertsIds = alertIds.stream().map(RelatedIncidentAlertsDTO::getAlertId).collect(Collectors.joining(","));
183-
Map<String, Object> extra = Map.of(
184-
"alertIds", alertsIds,
185-
"source", "service"
186-
);
187-
String attemptMsg = String.format("Attempt to add %d alerts to incident %d", addToIncidentDTO.getAlertList().size(), addToIncidentDTO.getIncidentId());
188-
eventService.createEvent(attemptMsg, ApplicationEventType.INCIDENT_ALERT_ADD_ATTEMPT, extra);
176+
List<RelatedIncidentAlertsDTO> alertIds = addToIncidentDTO.getAlertList();
189177

190-
validateAlertsNotAlreadyLinked(addToIncidentDTO.getAlertList(), ctx);
191-
UtmIncident utmIncident = utmIncidentRepository.findById(addToIncidentDTO.getIncidentId()).orElseThrow(() -> new RuntimeException(ctx + ": Incident not found"));
192-
saveRelatedAlerts(addToIncidentDTO.getAlertList(), utmIncident.getId());
193-
String historyMessage = String.format("New %d alerts added to incident", addToIncidentDTO.getAlertList().size());
194-
utmIncidentHistoryService.createHistory(IncidentHistoryActionEnum.INCIDENT_ALERT_ADD, utmIncident.getId(), "New alerts added to incident", historyMessage);
178+
String alertsIds = alertIds.stream().map(RelatedIncidentAlertsDTO::getAlertId).collect(Collectors.joining(","));
179+
Map<String, Object> extra = Map.of(
180+
"alertIds", alertsIds,
181+
"source", "service"
182+
);
183+
String attemptMsg = String.format("Attempt to add %d alerts to incident %d", addToIncidentDTO.getAlertList().size(), addToIncidentDTO.getIncidentId());
184+
eventService.createEvent(attemptMsg, ApplicationEventType.INCIDENT_ALERT_ADD_ATTEMPT, extra);
195185

196-
eventService.createEvent(historyMessage, ApplicationEventType.INCIDENT_ALERTS_ADDED, extra);
186+
validateAlertsNotAlreadyLinked(addToIncidentDTO.getAlertList(), ctx);
187+
UtmIncident utmIncident = utmIncidentRepository.findById(addToIncidentDTO.getIncidentId()).orElseThrow(() -> new RuntimeException(ctx + ": Incident not found"));
188+
saveRelatedAlerts(addToIncidentDTO.getAlertList(), utmIncident.getId());
189+
String historyMessage = String.format("New %d alerts added to incident", addToIncidentDTO.getAlertList().size());
190+
utmIncidentHistoryService.createHistory(IncidentHistoryActionEnum.INCIDENT_ALERT_ADD, utmIncident.getId(), "New alerts added to incident", historyMessage);
191+
192+
eventService.createEvent(historyMessage, ApplicationEventType.INCIDENT_ALERTS_ADDED, extra);
193+
194+
return utmIncident;
197195

198-
return utmIncident;
199-
} catch (Exception e) {
200-
String msg = ctx + ": " + e.getMessage();
201-
eventService.createEvent(msg, ApplicationEventType.ERROR);
202-
throw new RuntimeException(msg);
203-
}
204196
}
205197

206198
@Async
@@ -289,7 +281,7 @@ private void sendIncidentsEmail(List<String> alertIds, UtmIncident utmIncident)
289281
return;
290282

291283
String[] addressToNotify = Constants.CFG.get(Constants.PROP_ALERT_ADDRESS_TO_NOTIFY_INCIDENTS)
292-
.replace(" ", "").split(",");
284+
.replace(" ", "").split(",");
293285

294286
mailService.sendIncidentEmail(Arrays.asList(addressToNotify), alerts, utmIncident);
295287

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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="20251106001" author="Manuel">
8+
<comment>Update Incidents menu position to appear before Tagging rules</comment>
9+
10+
<!-- Update Tagging rules position from 1 to 2 -->
11+
<update tableName="utm_menu">
12+
<column name="position" valueNumeric="2"/>
13+
<where>id = 314 AND parent_id = 300</where>
14+
</update>
15+
16+
<!-- Keep Incidents position at 1 (already set, but ensuring it's correct) -->
17+
<update tableName="utm_menu">
18+
<column name="position" valueNumeric="1"/>
19+
<where>id = 402 AND parent_id = 300</where>
20+
</update>
21+
22+
<rollback>
23+
<update tableName="utm_menu">
24+
<column name="position" valueNumeric="1"/>
25+
<where>id = 314 AND parent_id = 300</where>
26+
</update>
27+
<update tableName="utm_menu">
28+
<column name="position" valueNumeric="1"/>
29+
<where>id = 402 AND parent_id = 300</where>
30+
</update>
31+
</rollback>
32+
</changeSet>
33+
34+
</databaseChangeLog>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,5 +255,7 @@
255255

256256
<include file="/config/liquibase/changelog/20251017001_create_api_keys_table.xml" relativeToChangelogFile="false"/>
257257

258+
<include file="/config/liquibase/changelog/20251106001_update_incident_menu_position.xml" relativeToChangelogFile="false"/>
259+
258260

259261
</databaseChangeLog>

user-auditor/pom.xml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
34
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
45
<modelVersion>4.0.0</modelVersion>
6+
57
<parent>
68
<groupId>org.springframework.boot</groupId>
79
<artifactId>spring-boot-starter-parent</artifactId>
810
<version>2.7.14</version>
911
<relativePath/>
1012
</parent>
13+
1114
<groupId>com.utmstack</groupId>
1215
<artifactId>user-auditor</artifactId>
1316
<version>1.0.0</version>
1417
<name>user-auditor</name>
1518
<description>userAuditor</description>
19+
1620
<properties>
1721
<java.version>11</java.version>
1822
</properties>
23+
1924
<dependencies>
25+
<!-- Spring Boot starters -->
2026
<dependency>
2127
<groupId>org.springframework.boot</groupId>
2228
<artifactId>spring-boot-starter-data-jpa</artifactId>
@@ -27,29 +33,41 @@
2733
</exclusion>
2834
</exclusions>
2935
</dependency>
36+
3037
<dependency>
3138
<groupId>org.springframework.boot</groupId>
3239
<artifactId>spring-boot-starter-web</artifactId>
3340
</dependency>
41+
42+
<!-- PostgreSQL -->
3443
<dependency>
3544
<groupId>org.postgresql</groupId>
3645
<artifactId>postgresql</artifactId>
3746
<version>42.7.2</version>
3847
</dependency>
48+
49+
<!-- Lombok actualizado -->
3950
<dependency>
4051
<groupId>org.projectlombok</groupId>
4152
<artifactId>lombok</artifactId>
42-
<optional>true</optional>
53+
<version>1.18.30</version>
54+
<scope>provided</scope>
4355
</dependency>
56+
57+
<!-- Liquibase -->
4458
<dependency>
4559
<groupId>org.liquibase</groupId>
4660
<artifactId>liquibase-core</artifactId>
4761
</dependency>
62+
63+
<!-- OpenSearch Connector -->
4864
<dependency>
4965
<groupId>com.utmstack</groupId>
5066
<artifactId>opensearch-connector</artifactId>
5167
<version>1.0.0</version>
5268
</dependency>
69+
70+
<!-- JSON API -->
5371
<dependency>
5472
<groupId>jakarta.json</groupId>
5573
<artifactId>jakarta.json-api</artifactId>
@@ -59,6 +77,19 @@
5977

6078
<build>
6179
<plugins>
80+
<!-- Compiler Plugin -->
81+
<plugin>
82+
<groupId>org.apache.maven.plugins</groupId>
83+
<artifactId>maven-compiler-plugin</artifactId>
84+
<version>3.11.0</version>
85+
<configuration>
86+
<source>11</source>
87+
<target>11</target>
88+
<encoding>UTF-8</encoding>
89+
</configuration>
90+
</plugin>
91+
92+
<!-- Spring Boot plugin -->
6293
<plugin>
6394
<groupId>org.springframework.boot</groupId>
6495
<artifactId>spring-boot-maven-plugin</artifactId>

0 commit comments

Comments
 (0)