Skip to content

Commit 903a212

Browse files
authored
Bugfix/10.4/549 improve the elastic index loading in the application (#657)
* Fixed Improve the elastic index loading in the application (#549) * Fixed Improve the elastic index loading in the application (#549) * Fixed elastic index loading in the application (#549) * Fixed elastic index loading in the application (#549) * Improve the elastic index loading in the application (657) * Improve the elastic index loading in the application (657) * Improve the elastic index loading in the application (657) * Update version.yml
1 parent b2cd8c3 commit 903a212

File tree

9 files changed

+135
-14
lines changed

9 files changed

+135
-14
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.park.utmstack.service.dto.index_pattern;
2+
3+
import com.park.utmstack.util.chart_builder.IndexPropertyType;
4+
5+
import java.util.List;
6+
7+
public class UtmIndexPatternField {
8+
String indexPattern;
9+
List<IndexPropertyType> fields;
10+
11+
public UtmIndexPatternField(){};
12+
13+
public UtmIndexPatternField(String indexPatter, List<IndexPropertyType> fields) {
14+
this.indexPattern = indexPatter;
15+
this.fields = fields;
16+
}
17+
18+
public String getIndexPattern() {
19+
return indexPattern;
20+
}
21+
22+
public void setIndexPattern(String indexPattern) {
23+
this.indexPattern = indexPattern;
24+
}
25+
26+
public List<IndexPropertyType> getFields() {
27+
return fields;
28+
}
29+
30+
public void setFields(List<IndexPropertyType> fields) {
31+
this.fields = fields;
32+
}
33+
}

backend/src/main/java/com/park/utmstack/service/index_pattern/UtmIndexPatternQueryService.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
import com.park.utmstack.domain.index_pattern.UtmIndexPattern_;
55
import com.park.utmstack.repository.index_pattern.UtmIndexPatternRepository;
66
import com.park.utmstack.service.dto.index_pattern.UtmIndexPatternCriteria;
7+
import com.park.utmstack.service.dto.index_pattern.UtmIndexPatternField;
8+
import com.park.utmstack.service.elasticsearch.ElasticsearchService;
79
import org.slf4j.Logger;
810
import org.slf4j.LoggerFactory;
911
import org.springframework.data.domain.Page;
12+
import org.springframework.data.domain.PageImpl;
1013
import org.springframework.data.domain.Pageable;
1114
import org.springframework.data.jpa.domain.Specification;
1215
import org.springframework.stereotype.Service;
1316
import org.springframework.transaction.annotation.Transactional;
1417
import tech.jhipster.service.QueryService;
1518

1619
import java.util.List;
20+
import java.util.stream.Collectors;
1721

1822
@Service
1923
@Transactional(readOnly = true)
@@ -22,8 +26,11 @@ public class UtmIndexPatternQueryService extends QueryService<UtmIndexPattern> {
2226

2327
private final UtmIndexPatternRepository indexPatternRepository;
2428

25-
public UtmIndexPatternQueryService(UtmIndexPatternRepository indexPatternRepository) {
29+
private final ElasticsearchService elasticsearchService;
30+
31+
public UtmIndexPatternQueryService(UtmIndexPatternRepository indexPatternRepository, ElasticsearchService elasticsearchService) {
2632
this.indexPatternRepository = indexPatternRepository;
33+
this.elasticsearchService = elasticsearchService;
2734
}
2835

2936
@Transactional(readOnly = true)
@@ -40,6 +47,27 @@ public Page<UtmIndexPattern> findByCriteria(UtmIndexPatternCriteria criteria, Pa
4047
return indexPatternRepository.findAll(specification, page);
4148
}
4249

50+
@Transactional(readOnly = true)
51+
public Page<UtmIndexPatternField> findWithFieldsByCriteria(UtmIndexPatternCriteria criteria, Pageable page) {
52+
log.debug("find by criteria : {}, page: {}", criteria, page);
53+
final Specification<UtmIndexPattern> specification = createSpecification(criteria);
54+
55+
Page<UtmIndexPattern> indexPatterns = indexPatternRepository.findAll(specification, page);
56+
57+
List<UtmIndexPatternField> utmIndexPatternFields = indexPatterns.getContent().stream()
58+
.map(index -> {
59+
try {
60+
return new UtmIndexPatternField(index.getPattern(), elasticsearchService.getIndexProperties(index.getPattern()));
61+
} catch (Exception e) {
62+
log.error("Error fetching index properties for pattern: {}", index.getPattern(), e);
63+
return new UtmIndexPatternField(index.getPattern(), null);
64+
}
65+
}).collect(Collectors.toList());
66+
67+
return new PageImpl<>(utmIndexPatternFields, page, indexPatterns.getTotalElements());
68+
}
69+
70+
4371
private Specification<UtmIndexPattern> createSpecification(UtmIndexPatternCriteria criteria) {
4472
Specification<UtmIndexPattern> specification = Specification.where(null);
4573
if (criteria != null) {

backend/src/main/java/com/park/utmstack/web/rest/index_pattern/UtmIndexPatternResource.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.park.utmstack.service.UtmStackService;
66
import com.park.utmstack.service.application_events.ApplicationEventService;
77
import com.park.utmstack.service.dto.index_pattern.UtmIndexPatternCriteria;
8+
import com.park.utmstack.service.dto.index_pattern.UtmIndexPatternField;
89
import com.park.utmstack.service.index_pattern.UtmIndexPatternQueryService;
910
import com.park.utmstack.service.index_pattern.UtmIndexPatternService;
1011
import com.park.utmstack.web.rest.util.HeaderUtil;
@@ -128,6 +129,23 @@ public ResponseEntity<List<UtmIndexPattern>> getAllUtmIndexPatterns(UtmIndexPatt
128129
}
129130
}
130131

132+
@GetMapping("/utm-index-patterns/fields")
133+
public ResponseEntity<List<UtmIndexPatternField>> getAllUtmIndexPatternsWithFields(UtmIndexPatternCriteria criteria,
134+
Pageable pageable) {
135+
final String ctx = CLASSNAME + ".getAllUtmIndexPatternsWithFields";
136+
try {
137+
Page<UtmIndexPatternField> page = indexPatternQueryService.findWithFieldsByCriteria(criteria, pageable);
138+
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/utm-index-patterns-fields");
139+
return ResponseEntity.ok().headers(headers).body(page.getContent());
140+
} catch (Exception e) {
141+
String msg = ctx + ": " + e.getMessage();
142+
log.error(msg);
143+
applicationEventService.createEvent(msg, ApplicationEventType.ERROR);
144+
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).headers(
145+
HeaderUtil.createFailureAlert(null, null, msg)).body(null);
146+
}
147+
}
148+
131149
/**
132150
* GET /utm-index-patterns/:id : get the "id" utmIndexPattern.
133151
*

frontend/src/app/dashboard/dashboard-overview/dashboard-overview.component.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import {HttpResponse} from '@angular/common/http';
12
import {Component, OnDestroy, OnInit} from '@angular/core';
23
import {ActivatedRoute} from '@angular/router';
34
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
45
import {NgxSpinnerService} from 'ngx-spinner';
56
import {Subject} from 'rxjs';
6-
import {takeUntil} from 'rxjs/operators';
7+
import {filter, map, takeUntil} from 'rxjs/operators';
78
// tslint:disable-next-line:max-line-length
89
import {UtmModulesEnum} from '../../app-module/shared/enum/utm-module.enum';
910
import {UtmModulesService} from '../../app-module/shared/services/utm-modules.service';
@@ -32,7 +33,9 @@ import {LocalFieldService} from '../../shared/services/elasticsearch/local-field
3233
import {ExportPdfService} from '../../shared/services/util/export-pdf.service';
3334
import {ChartSerieValueType} from '../../shared/types/chart-reponse/chart-serie-value.type';
3435
import {ElasticFilterType} from '../../shared/types/filter/elastic-filter.type';
36+
import {UtmIndexPattern} from '../../shared/types/index-pattern/utm-index-pattern';
3537
import {buildFormatInstantFromDate} from '../../shared/util/utm-time.util';
38+
import {UtmIndexPatternFields} from "../../shared/types/index-pattern/utm-index-pattern-fields";
3639

3740
@Component({
3841
selector: 'app-dashboard-overview',
@@ -248,14 +251,16 @@ export class DashboardOverviewComponent implements OnInit, OnDestroy {
248251
synchronizeFields() {
249252
this.accountService.identity(true).then(value => {
250253
if (value) {
251-
this.indexPatternService.query({page: 0, size: 2000}).subscribe(responsePatterns => {
252-
for (const pattern of responsePatterns.body) {
253-
this.indexPatternFieldService.getElasticIndexField({indexPattern: pattern.pattern})
254-
.subscribe(responseFields => {
255-
this.localFieldService.setPatternStoredFields(pattern.pattern, responseFields.body);
254+
this.indexPatternService.queryWithFields({page: 0, size: 2000, 'isActive.equals': true})
255+
.pipe(
256+
map(response => response.body))
257+
.subscribe((values: UtmIndexPatternFields[]) => {
258+
values.forEach(value => {
259+
if (value.fields && value.fields.length > 0) {
260+
this.localFieldService.setPatternStoredFields(value.indexPattern, value.fields);
261+
}
256262
});
257-
}
258-
});
263+
});
259264
}
260265
});
261266
}

frontend/src/app/shared/components/layout/header/header-menu-navigation/header-menu-navigation.component.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import {Component, OnInit} from '@angular/core';
1+
import {Component, OnDestroy, OnInit} from '@angular/core';
22
import {Router} from '@angular/router';
33
import {NgxSpinnerService} from 'ngx-spinner';
4+
import {Subject} from 'rxjs';
45
import {HttpCancelService} from '../../../../../blocks/service/httpcancel.service';
56
import {DashboardBehavior} from '../../../../behaviors/dashboard.behavior';
67
import {MenuBehavior} from '../../../../behaviors/menu.behavior';
@@ -10,18 +11,20 @@ import {ActiveAdModuleActiveService} from '../../../../services/active-modules/a
1011
import {MenuService} from '../../../../services/menu/menu.service';
1112
import {Menu} from '../../../../types/menu/menu.model';
1213
import {stringParamToQueryParams} from '../../../../util/query-params-to-filter.util';
14+
import { takeUntil } from 'rxjs/operators';
1315

1416
@Component({
1517
selector: 'app-header-menu-navigation',
1618
templateUrl: './header-menu-navigation.component.html',
1719
styleUrls: ['./header-menu-navigation.component.scss']
1820
})
19-
export class HeaderMenuNavigationComponent implements OnInit {
21+
export class HeaderMenuNavigationComponent implements OnInit, OnDestroy {
2022
menus: Menu[] = [];
2123
defaultStructureMenu: Menu[] = [];
2224
searching = false;
2325
iconPath = SYSTEM_MENU_ICONS_PATH;
2426
active: number;
27+
destroy$: Subject<void> = new Subject<void>();
2528

2629
constructor(private adModuleActiveService: ActiveAdModuleActiveService,
2730
private navBehavior: NavBehavior,
@@ -35,6 +38,14 @@ export class HeaderMenuNavigationComponent implements OnInit {
3538

3639
ngOnInit() {
3740
this.loadMenus();
41+
42+
this.navBehavior.$nav
43+
.pipe(takeUntil(this.destroy$))
44+
.subscribe( value => {
45+
if (value) {
46+
this.loadMenus();
47+
}
48+
});
3849
}
3950

4051
/**
@@ -50,7 +61,6 @@ export class HeaderMenuNavigationComponent implements OnInit {
5061
}
5162

5263
loadMenus() {
53-
this.menus = [];
5464
this.menuService.getMenuStructure(true).subscribe(reponse => {
5565
this.menus = reponse.body;
5666
this.defaultStructureMenu = reponse.body;
@@ -118,4 +128,9 @@ export class HeaderMenuNavigationComponent implements OnInit {
118128
return false;
119129
}
120130
}
131+
132+
ngOnDestroy() {
133+
this.destroy$.next();
134+
this.destroy$.complete();
135+
}
121136
}

frontend/src/app/shared/services/elasticsearch/index-pattern.service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Observable} from 'rxjs';
44
import {SERVER_API_URL} from '../../../app.constants';
55
import {UtmIndexPattern} from '../../types/index-pattern/utm-index-pattern';
66
import {createRequestOption} from '../../util/request-util';
7+
import {UtmIndexPatternFields} from "../../types/index-pattern/utm-index-pattern-fields";
78

89
@Injectable({
910
providedIn: 'root'
@@ -34,6 +35,14 @@ export class IndexPatternService {
3435
});
3536
}
3637

38+
queryWithFields(req?: any): Observable<HttpResponse<UtmIndexPatternFields[]>> {
39+
const options = createRequestOption(req);
40+
return this.http.get<UtmIndexPatternFields[]>(`${this.resourceUrl}/fields`, {
41+
params: options,
42+
observe: 'response'
43+
});
44+
}
45+
3746
delete(indexPattern: number): Observable<HttpResponse<any>> {
3847
return this.http.delete(`${this.resourceUrl}/${indexPattern}`, {observe: 'response'});
3948
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {ElasticSearchFieldInfoType} from '../elasticsearch/elastic-search-field-info.type';
2+
3+
export class UtmIndexPatternFields {
4+
indexPattern: string;
5+
fields: ElasticSearchFieldInfoType[];
6+
7+
constructor(indexPattern: string, fields: ElasticSearchFieldInfoType[]) {
8+
this.indexPattern = indexPattern;
9+
this.fields = fields;
10+
}
11+
}

frontend/src/app/shared/types/index-pattern/utm-index-pattern.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ export class UtmIndexPattern {
33
pattern: string;
44
patternSystem?: boolean;
55
patternModule?: string;
6+
active?: boolean;
67

7-
constructor(id: number, pattern: string, patternSystem: boolean, patternModule?: string) {
8+
constructor(id: number, pattern: string, patternSystem: boolean, patternModule?: string, active?: boolean) {
89
this.id = id;
910
this.pattern = pattern;
1011
this.patternSystem = patternSystem;
1112
this.patternModule = patternModule;
13+
this.active = active;
1214
}
1315
}

version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version: 10.4.2
1+
version: 10.4.3

0 commit comments

Comments
 (0)