Skip to content

Commit 8b23188

Browse files
committed
feat: refactor UtmLogstashPipeline class to use Lombok annotations and improve default value handling
1 parent 34cb954 commit 8b23188

File tree

4 files changed

+31
-101
lines changed

4 files changed

+31
-101
lines changed
Lines changed: 14 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
package com.park.utmstack.domain.logstash_pipeline;
22

3+
import com.park.utmstack.domain.application_modules.UtmModule;
34
import com.park.utmstack.service.logstash_pipeline.enums.PipelineStatus;
5+
import lombok.*;
6+
47
import org.hibernate.annotations.GenericGenerator;
58

69
import javax.persistence.*;
710
import javax.validation.constraints.Size;
811
import java.io.Serializable;
912

10-
/**
11-
* A UtmLogstashPipeline.
12-
*/
1313
@Entity
1414
@Table(name = "utm_logstash_pipeline")
15+
@Getter
16+
@Setter
17+
@NoArgsConstructor
18+
@AllArgsConstructor
19+
@Builder
1520
public class UtmLogstashPipeline implements Serializable {
1621

1722
private static final long serialVersionUID = 1L;
@@ -48,103 +53,14 @@ public class UtmLogstashPipeline implements Serializable {
4853
@Column(name = "events_out")
4954
private Long eventsOut;
5055

56+
@OneToOne
57+
@JoinColumn(name = "module_name", referencedColumnName = "module_name", insertable = false, updatable = false)
58+
private UtmModule utmModule;
5159

52-
public UtmLogstashPipeline(){}
53-
public UtmLogstashPipeline(Long id, String pipelineId,
54-
String pipelineName,
55-
String pipelineStatus,
56-
String moduleName,
57-
Boolean systemOwner,
58-
String pipelineDescription,
59-
Boolean pipelineInternal,
60-
Long eventsOut) {
61-
this.id = id;
62-
this.pipelineId = pipelineId;
63-
this.pipelineName = pipelineName;
64-
this.pipelineStatus = pipelineStatus;
65-
this.moduleName = moduleName;
66-
this.systemOwner = systemOwner;
67-
this.pipelineDescription = pipelineDescription;
68-
this.pipelineInternal = pipelineInternal==null?false:pipelineInternal;
69-
this.eventsOut = eventsOut==null?0L:eventsOut;
70-
}
71-
72-
public Long getId() {
73-
return id;
74-
}
75-
76-
public void setId(Long id) {
77-
this.id = id;
78-
}
79-
80-
public String getPipelineId() {
81-
return pipelineId;
82-
}
83-
84-
public void setPipelineId(String pipelineId) {
85-
this.pipelineId = pipelineId;
86-
}
87-
88-
public String getPipelineName() {
89-
return pipelineName;
90-
}
91-
92-
public void setPipelineName(String pipelineName) {
93-
this.pipelineName = pipelineName;
94-
}
95-
96-
public String getPipelineStatus() {
97-
return pipelineStatus;
98-
}
99-
100-
public void setPipelineStatus(String pipelineStatus) {
101-
this.pipelineStatus = pipelineStatus;
102-
}
103-
104-
public String getModuleName() {
105-
return moduleName;
106-
}
107-
108-
public void setModuleName(String moduleName) {
109-
this.moduleName = moduleName;
110-
}
111-
112-
public Boolean getSystemOwner() {
113-
return systemOwner;
114-
}
115-
116-
public void setSystemOwner(Boolean systemOwner) {
117-
this.systemOwner = systemOwner;
118-
}
119-
120-
public String getPipelineDescription() {
121-
return pipelineDescription;
122-
}
123-
124-
public void setPipelineDescription(String pipelineDescription) {
125-
this.pipelineDescription = pipelineDescription;
126-
}
127-
128-
public Boolean getPipelineInternal() {
129-
return pipelineInternal;
130-
}
131-
132-
public void setPipelineInternal(Boolean pipelineInternal) {
133-
this.pipelineInternal = pipelineInternal;
134-
}
135-
136-
public Long getEventsOut() {
137-
return eventsOut;
138-
}
139-
140-
public void setEventsOut(Long eventsOut) {
141-
this.eventsOut = eventsOut;
142-
}
143-
144-
public void setDefaults(){
60+
public void setDefaults() {
14561
this.systemOwner = false;
146-
this.pipelineInternal = this.pipelineInternal==null?false:this.pipelineInternal;
147-
this.eventsOut = this.eventsOut==null?0L:this.eventsOut;
62+
this.pipelineInternal = this.pipelineInternal == null ? false : this.pipelineInternal;
63+
this.eventsOut = this.eventsOut == null ? 0L : this.eventsOut;
14864
this.pipelineStatus = PipelineStatus.PIPELINE_STATUS_DOWN.get();
14965
}
15066
}

backend/src/main/java/com/park/utmstack/service/dto/logstash_pipeline/UtmLogstashPipelineDTO.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public UtmLogstashPipelineDTO(UtmLogstashPipeline pipeline) {
5555

5656
@JsonIgnore
5757
public UtmLogstashPipeline getPipeline(UtmLogstashPipeline utmLogstashPipeline) {
58-
if (utmLogstashPipeline==null) utmLogstashPipeline = new UtmLogstashPipeline();
58+
if (utmLogstashPipeline==null){
59+
utmLogstashPipeline = new UtmLogstashPipeline();
60+
utmLogstashPipeline.setDefaults();
61+
}
5962
utmLogstashPipeline.setId(this.getId());
6063
utmLogstashPipeline.setPipelineName(this.getPipelineName());
6164
utmLogstashPipeline.setModuleName(this.getModuleName());

backend/src/main/java/com/park/utmstack/service/logstash_pipeline/UtmLogstashPipelineService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.springframework.transaction.annotation.Transactional;
4444
import org.springframework.util.StringUtils;
4545

46+
import javax.sql.DataSource;
4647
import java.time.Duration;
4748
import java.time.Instant;
4849
import java.time.format.DateTimeFormatter;
@@ -70,13 +71,15 @@ public class UtmLogstashPipelineService {
7071
private final ElasticsearchService elasticsearchService;
7172

7273
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
74+
private final DataSource dataSource;
7375

74-
public UtmLogstashPipelineService(UtmLogstashPipelineRepository utmLogstashPipelineRepository, RestTemplateService restTemplateService, UtmGroupLogstashPipelineFiltersRepository utmGroupLogstashPipelineFiltersRepository, UtmLogstashFilterRepository utmLogstashFilterRepository, OpensearchClientBuilder client, ElasticsearchService elasticsearchService) {
76+
public UtmLogstashPipelineService(UtmLogstashPipelineRepository utmLogstashPipelineRepository, RestTemplateService restTemplateService, UtmGroupLogstashPipelineFiltersRepository utmGroupLogstashPipelineFiltersRepository, UtmLogstashFilterRepository utmLogstashFilterRepository, OpensearchClientBuilder client, ElasticsearchService elasticsearchService, DataSource dataSource) {
7577
this.utmLogstashPipelineRepository = utmLogstashPipelineRepository;
7678
this.restTemplateService = restTemplateService;
7779
this.utmGroupLogstashPipelineFiltersRepository = utmGroupLogstashPipelineFiltersRepository;
7880
this.utmLogstashFilterRepository = utmLogstashFilterRepository;
7981
this.elasticsearchService = elasticsearchService;
82+
this.dataSource = dataSource;
8083
}
8184

8285
/**
@@ -326,7 +329,13 @@ public void pipelineStatus() {
326329

327330
try {
328331
activeByServer.forEach((p) -> {
329-
StatisticDocument pipeLine = this.getStatisticsDataType(Constants.STATISTICS_INDEX_PATTERN, p.getPipelineName());
332+
String dataType = p.getPipelineName();
333+
Set<UtmLogstashFilter> filters = p.getUtmModule() != null ? p.getUtmModule().getFilters() : null;
334+
dataType = Optional.ofNullable(filters)
335+
.flatMap(fs -> fs.stream().findFirst())
336+
.map(f -> f.getDatatype().getDataType())
337+
.orElse(dataType);
338+
StatisticDocument pipeLine = this.getStatisticsDataType(Constants.STATISTICS_INDEX_PATTERN, dataType);
330339

331340
if (!Objects.isNull(pipeLine)) {
332341
p.setEventsOut(pipeLine.getCount());

backend/src/main/java/com/park/utmstack/web/rest/logstash_pipeline/UtmLogstashPipelineResource.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.park.utmstack.web.rest.errors.BadRequestAlertException;
1313
import com.park.utmstack.web.rest.util.HeaderUtil;
1414
import com.park.utmstack.web.rest.vm.UtmLogstashPipelineVM;
15+
import io.swagger.v3.oas.annotations.Hidden;
1516
import org.slf4j.Logger;
1617
import org.slf4j.LoggerFactory;
1718
import org.springdoc.api.annotations.ParameterObject;
@@ -33,6 +34,7 @@
3334
* REST controller for managing {@link UtmLogstashPipeline}.
3435
*/
3536
@RestController
37+
@Hidden
3638
@RequestMapping("/api")
3739
public class UtmLogstashPipelineResource {
3840

0 commit comments

Comments
 (0)