Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.park.utmstack.service.chart_builder.UtmDashboardService;
import com.park.utmstack.service.chart_builder.UtmDashboardVisualizationService;
import com.park.utmstack.service.elasticsearch.ElasticsearchService;
import com.park.utmstack.service.elasticsearch.SearchUtil;
import com.park.utmstack.util.UtilPagination;
import com.park.utmstack.util.chart_builder.elasticsearch_dsl.requests.RequestDsl;
import com.park.utmstack.util.exceptions.UtmElasticsearchException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import com.park.utmstack.service.elasticsearch.SearchUtil;
import com.park.utmstack.util.TimezoneUtil;
import com.park.utmstack.util.exceptions.UtmElasticsearchException;
import com.park.utmstack.util.exceptions.UtmSerializationException;
import org.opensearch.client.opensearch._types.SortOrder;
import org.opensearch.client.opensearch._types.aggregations.*;
import org.opensearch.client.opensearch.core.SearchRequest;
import org.opensearch.client.opensearch.core.search.TrackHits;
import org.springframework.data.domain.Pageable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

Expand All @@ -34,29 +36,48 @@ public RequestDsl(UtmVisualization visualization) {
}

public SearchRequest.Builder getSearchSourceBuilder() throws UtmElasticsearchException {
return getSearchSourceBuilder(null, 10000);
}

public SearchRequest.Builder getSearchSourceBuilder(Pageable pageable, int top) throws UtmElasticsearchException {
final String ctx = CLASSNAME + ".getSearchSourceBuilder";
try {
List<FilterType> filters = visualization.getFilterType();

if (CollectionUtils.isEmpty(filters))
filters = new ArrayList<>();

searchRequestBuilder.query(SearchUtil.toQuery(filters));
prepareSearchRequest();

if (visualization.getChartType() != ChartType.LIST_CHART &&
visualization.getChartType() != ChartType.TEXT_CHART) {
if (isAggregatedChart()) {
buildAggregation();
searchRequestBuilder.size(0);
searchRequestBuilder.trackTotalHits(TrackHits.of(t -> t.enabled(true)));
} else {
searchRequestBuilder.size(10000);
applyPagination(pageable, top);
}
return searchRequestBuilder;
} catch (Exception e) {
throw new UtmElasticsearchException(ctx + ": " + e.getMessage());
}
}

private void prepareSearchRequest() throws UtmSerializationException {
List<FilterType> filters = visualization.getFilterType();
if (CollectionUtils.isEmpty(filters)) {
filters = new ArrayList<>();
}
searchRequestBuilder.query(SearchUtil.toQuery(filters));
}

private boolean isAggregatedChart() {
return visualization.getChartType() != ChartType.LIST_CHART &&
visualization.getChartType() != ChartType.TEXT_CHART;
}

private void applyPagination(Pageable pageable, int top) {
if (pageable != null && pageable.isPaged()) {
SearchUtil.applyPaginationAndSort(searchRequestBuilder, pageable, top);
} else {
searchRequestBuilder.size(10000);
}
}

public SearchRequest.Builder getSearchSourceBuilderForCount() throws UtmElasticsearchException {
final String ctx = CLASSNAME + ".getSearchSourceBuilderForCount";
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
Expand All @@ -39,6 +40,7 @@
import java.time.ZoneOffset;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
Expand Down Expand Up @@ -280,7 +282,10 @@ public ResponseEntity<Void> bulkDelete(@RequestParam List<Long> ids) {
}

@PostMapping("/utm-visualizations/run")
public ResponseEntity<List<?>> run(@RequestBody UtmVisualization visualization) throws UtmChartBuilderException {
public ResponseEntity<List<?>> run(@RequestBody UtmVisualization visualization,
@RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "size", required = false) Integer size,
@RequestParam(defaultValue = "200") int top) throws UtmChartBuilderException {
final String ctx = CLASSNAME + ".run";
try {
Assert.notNull(visualization, "Param utmVisualization must not be null");
Expand All @@ -289,7 +294,12 @@ public ResponseEntity<List<?>> run(@RequestBody UtmVisualization visualization)
return ResponseEntity.ok(Collections.emptyList());

RequestDsl requestQuery = new RequestDsl(visualization);
SearchResponse<ObjectNode> result = elasticsearchService.search(requestQuery.getSearchSourceBuilder().build(), ObjectNode.class);
SearchResponse<ObjectNode> result;
if(Objects.nonNull(page) && Objects.nonNull(size)){
result = elasticsearchService.search(requestQuery.getSearchSourceBuilder( PageRequest.of(page, size), top).build(), ObjectNode.class);
} else {
result = elasticsearchService.search(requestQuery.getSearchSourceBuilder().build(), ObjectNode.class);
}
ResponseParser<?> responseParser = responseParserFactory.instance(visualization.getChartType());
return ResponseEntity.ok().body(responseParser.parse(visualization, result));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@

ALTER TABLE utm_compliance_report_config
ADD COLUMN IF NOT EXISTS config_report_remediation TEXT;

ALTER TABLE utm_compliance_report_config
ADD COLUMN IF NOT EXISTS config_report_status TEXT;
]]>
</sql>
</changeSet>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export class ComplianceReportViewerComponent implements OnInit, AfterViewInit, O
activeSection: ComplianceStandardSectionType = null;
pageable = {
page: 0,
size: 15
size: 15,
sort: 'configReportName,desc'
};
viewportHeight: number;

Expand Down Expand Up @@ -188,7 +189,8 @@ export class ComplianceReportViewerComponent implements OnInit, AfterViewInit, O
standardId: this.activeSection.standardId,
id: this.activeSection.id,
page: this.pageable.page,
size: this.pageable.size
size: this.pageable.size,
sort: this.pageable.sort
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,3 @@ table {
margin-right: 25px !important;
margin-top: 0;
}

.table-responsive {
min-height: 400px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h5 class="card-title mb-0 text-uppercase label-header d-flex align-items-center
</div>

<!-- Tabla -->
<div class="table-responsive">
<div [ngStyle]="{'min-height': getTableHeight(), 'height': getTableHeight()}" class="table-responsive">
<table class="table mb-0">
<thead>
<tr>
Expand Down Expand Up @@ -108,7 +108,8 @@ <h5 class="card-title mb-0 text-uppercase label-header d-flex align-items-center
<div *ngIf="reportDetail" class="utm-right-container">
<div (click)="reportDetail= undefined" class="overlay overlay-lg col-md-7"></div>
<div class="card utm-right-action utm-right-action-lg ml-0">
<div [ngClass]="(reportDetail.configReportNote && reportDetail.configReportNote !== '') || reportDetail.status === 'complaint' ? 'border-left-success' : 'border-left-danger'"
<div [ngClass]="reportDetail.configReportStatus === ComplianceStatusEnum.COMPLAINT
|| (reportDetail.configReportNote && reportDetail.configReportNote !== '') ? 'border-left-success' : 'border-left-danger'"
class="title d-flex justify-content-between align-items-center border-bottom-1
border-bottom-grey-100 pl-3 pt-3 pr-3 pb-0">
<h6 class="card-title text-blue-800 font-weight-light">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {HttpErrorResponse} from '@angular/common/http';
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
EventEmitter, HostListener,
Input,
OnChanges,
OnDestroy,
Expand All @@ -12,11 +12,12 @@ import {
import {EMPTY, Observable, Subject} from 'rxjs';
import {catchError, filter, map, switchMap, takeUntil, tap} from 'rxjs/operators';
import {UtmToastService} from '../../shared/alert/utm-toast.service';
import {SortEvent} from '../../shared/directives/sortable/type/sort-event';
import {SortByType} from '../../shared/types/sort-by.type';
import {CpReportsService} from '../shared/services/cp-reports.service';
import {ComplianceReportType} from '../shared/type/compliance-report.type';
import {ComplianceStandardSectionType} from '../shared/type/compliance-standard-section.type';
import {SortEvent} from '../../shared/directives/sortable/type/sort-event';
import {ComplianceStatusEnum} from "../shared/enums/compliance-status.enum";

@Component({
selector: 'app-compliance-reports-view',
Expand Down Expand Up @@ -44,12 +45,20 @@ export class ComplianceReportsViewComponent implements OnInit, OnChanges, OnDest
destroy$: Subject<void> = new Subject();
sort = 'configReportName,desc';
search: string;
viewportHeight: number;
ComplianceStatusEnum = ComplianceStatusEnum;

constructor(private reportsService: CpReportsService,
private toastService: UtmToastService) {
}

@HostListener('window:resize', ['$event'])
onResize(event: Event) {
this.viewportHeight = window.innerHeight;
}

ngOnInit() {
this.viewportHeight = window.innerHeight;
this.reports$ = this.reportsService.onRefresh$
.pipe(takeUntil(this.destroy$),
filter(reportRefresh =>
Expand Down Expand Up @@ -111,7 +120,8 @@ export class ComplianceReportsViewComponent implements OnInit, OnChanges, OnDest
});
this.pageChange.emit({
page,
size: this.itemsPerPage
size: this.itemsPerPage,
sort: this.sort
});
}

Expand All @@ -133,6 +143,11 @@ export class ComplianceReportsViewComponent implements OnInit, OnChanges, OnDest
});
}

getTableHeight() {
console.log('getTableHeight:', 100 - ((350 / this.viewportHeight) * 100) + 'vh');
return 100 - ((350 / this.viewportHeight) * 100) + 'vh';
}

ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { HttpErrorResponse } from '@angular/common/http';
import {ChangeDetectionStrategy, Component, Input, OnDestroy, OnInit, Output} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import {EMPTY, Observable} from 'rxjs';
import {catchError, concatMap, filter, map, takeUntil, tap} from 'rxjs/operators';
import { ComplianceReportType } from '../../../shared/type/compliance-report.type';
import { HttpErrorResponse } from '@angular/common/http';
import { CpReportsService } from 'src/app/compliance/shared/services/cp-reports.service';
import { ComplianceStandardSectionType } from 'src/app/compliance/shared/type/compliance-standard-section.type';
import { UtmToastService } from 'src/app/shared/alert/utm-toast.service';
import { SortByType } from 'src/app/shared/types/sort-by.type';
import { ActivatedRoute } from '@angular/router';
import { ComplianceReportType } from '../../../shared/type/compliance-report.type';


@Component({
Expand All @@ -22,8 +22,6 @@ export class CompliancePrintViewComponent implements OnInit, OnDestroy {
reports$: Observable<ComplianceReportType[]>;
selected: number;
fields: SortByType[];

reportDetail: ComplianceReportType;
preparingPrint = true;

constructor(private reportsService: CpReportsService,
Expand All @@ -42,6 +40,8 @@ export class CompliancePrintViewComponent implements OnInit, OnDestroy {
standardId: this.section.standardId,
sectionId: this.section.id,
expandDashboard: true,
setStatus: true,
sort: params.sort,
})),
map((res) => {
return res.body.map((r, index) => {
Expand All @@ -62,13 +62,11 @@ export class CompliancePrintViewComponent implements OnInit, OnDestroy {
report.visualization = visualization;
}

ngOnDestroy(): void {
throw new Error('Method not implemented.');
}

onVisualizationLoaded(){
this.preparingPrint = false;
}


ngOnDestroy(): void {
throw new Error('Method not implemented.');
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="w-100" *ngIf="compliance$ | async as compliance">
<div class="w-100 d-flex flex-column flex-grow-1 h-100" *ngIf="compliance$ | async as compliance">
<div [ngClass]="isComplaint() ? 'border-left-success' : 'border-left-danger'">
<div class="d-flex justify-content-around align-content-center py-1" style="border-bottom: 1px solid #ccc;">
<div style="padding-left: 10px" class="w-100">
Expand Down Expand Up @@ -82,9 +82,8 @@
<span class="text-blue-800 font-weight-light mr-2">Evidence:</span>
</div>

<div *ngIf="compliance.rows.length > 0" class="alert-details w-100 d-flex justify-content-start align-items-center mb-2">
<ngx-json-viewer [expanded]="false" [json]="compliance" class="col-12"></ngx-json-viewer>
<p class="font-size-base"></p>
<div *ngIf="compliance.rows.length > 0" class="alert-details w-100 d-flex d-flex flex-column flex-grow-1 overflow-auto mb-2">
<app-utm-json-detail-view [rowDocument]="compliance.rows"></app-utm-json-detail-view>
</div>
</div>
</div>
Loading