Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report paging #482

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 9 additions & 6 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,10 @@ public ResponseEntity<List<ReporterModel>> getParentNodesReport(@Parameter(descr
@Parameter(description = "Node uuid") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "Node only report") @RequestParam(value = "nodeOnlyReport", required = false, defaultValue = "true") boolean nodeOnlyReport,
@Parameter(description = "The report Type") @RequestParam(name = "reportType") StudyService.ReportType reportType,
@Parameter(description = "Severity levels") @RequestParam(name = "severityLevels", required = false) Set<String> severityLevels) {
@Parameter(description = "Severity levels") @RequestParam(name = "severityLevels", required = false) Set<String> severityLevels,
@Parameter(description = "Pagination parameters") Pageable pageable) {
studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getParentNodesReport(nodeUuid, nodeOnlyReport, reportType, severityLevels));
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getParentNodesReport(nodeUuid, nodeOnlyReport, reportType, severityLevels, pageable));
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/report", produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -1017,9 +1018,10 @@ public ResponseEntity<List<ReporterModel>> getNodeReport(@Parameter(description
@Parameter(description = "Node uuid") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "The report Id") @RequestParam(name = "reportId", required = false) String reportId,
@Parameter(description = "The report Type") @RequestParam(name = "reportType") StudyService.ReportType reportType,
@Parameter(description = "Severity levels") @RequestParam(name = "severityLevels", required = false) Set<String> severityLevels) {
@Parameter(description = "Severity levels") @RequestParam(name = "severityLevels", required = false) Set<String> severityLevels,
@Parameter(description = "Pagination parameters") Pageable pageable) {
studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getNodeReport(nodeUuid, reportId, reportType, severityLevels));
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getNodeReport(nodeUuid, reportId, reportType, severityLevels, pageable));
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/subreport", produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -1028,9 +1030,10 @@ public ResponseEntity<List<ReporterModel>> getNodeReport(@Parameter(description
public ResponseEntity<ReporterModel> getSubReport(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "Node uuid") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "The report Id") @RequestParam(name = "reportId") String reportId,
@Parameter(description = "Severity levels") @RequestParam(name = "severityLevels", required = false) Set<String> severityLevels) {
@Parameter(description = "Severity levels") @RequestParam(name = "severityLevels", required = false) Set<String> severityLevels,
@Parameter(description = "Pagination parameters") Pageable pageable) {
studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getSubReport(reportId, severityLevels));
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getSubReport(reportId, severityLevels, pageable));
}

@DeleteMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/report")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.poi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
Expand All @@ -38,6 +39,15 @@ public class ReportService {

private static final String DELIMITER = "/";

public static final String QUERY_PARAM_ERROR_ON_REPORT_NOT_FOUND = "errorOnReportNotFound";
public static final String QUERY_PARAM_REPORT_DEFAULT_NAME = "defaultName";
public static final String QUERY_PARAM_REPORT_SEVERITY_LEVEL = "severityLevels";
public static final String QUERY_PARAM_REPORT_WITH_ELEMENTS = "withElements";
public static final String QUERY_PARAM_REPORT_TASK_KEY_FILTER = "taskKeyFilter";
public static final String QUERY_PARAM_REPORT_PAGE_NUMBER = "page";
public static final String QUERY_PARAM_REPORT_PAGE_SIZE = "size";
public static final String REPORTER_ID_VALUE_KEY = "id";

private String reportServerBaseUri;

@Autowired
Expand Down Expand Up @@ -66,21 +76,25 @@ private String getSubReportsServerURI() {
return this.reportServerBaseUri + DELIMITER + REPORT_API_VERSION + DELIMITER + "subreports" + DELIMITER;
}

public ReporterModel getReport(@NonNull UUID id, @NonNull String defaultName, String reportNameFilter, StudyService.ReportNameMatchingType reportNameMatchingType, Set<String> severityLevels) {
public ReporterModel getReport(@NonNull UUID id, @NonNull String defaultName, String reportNameFilter, StudyService.ReportNameMatchingType reportNameMatchingType, Set<String> severityLevels, Pageable pageable) {
var uriBuilder = UriComponentsBuilder.fromPath("{id}")
.queryParam(QUERY_PARAM_REPORT_DEFAULT_NAME, defaultName)
.queryParam(QUERY_PARAM_REPORT_WITH_ELEMENTS, true)
.queryParam(QUERY_PARAM_REPORT_SEVERITY_LEVEL, severityLevels);
.queryParam(QUERY_PARAM_REPORT_DEFAULT_NAME, defaultName)
.queryParam(QUERY_PARAM_REPORT_WITH_ELEMENTS, true)
.queryParam(QUERY_PARAM_REPORT_SEVERITY_LEVEL, severityLevels)
.queryParam(QUERY_PARAM_REPORT_PAGE_NUMBER, pageable.getPageNumber())
.queryParam(QUERY_PARAM_REPORT_PAGE_SIZE, pageable.getPageSize());
if (!StringUtil.isBlank(reportNameFilter)) {
uriBuilder.queryParam(QUERY_PARAM_REPORT_NAME_FILTER, reportNameFilter);
uriBuilder.queryParam(QUERY_PARAM_REPORT_NAME_MATCHING_TYPE, reportNameMatchingType);
}
return reportServerCall(id, this.getReportsServerURI(), uriBuilder);
}

public ReporterModel getSubReport(@NonNull UUID id, Set<String> severityLevels) {
public ReporterModel getSubReport(@NonNull UUID id, Set<String> severityLevels, Pageable pageable) {
var uriBuilder = UriComponentsBuilder.fromPath("{id}")
.queryParam(QUERY_PARAM_REPORT_SEVERITY_LEVEL, severityLevels);
.queryParam(QUERY_PARAM_REPORT_SEVERITY_LEVEL, severityLevels)
.queryParam(QUERY_PARAM_REPORT_PAGE_NUMBER, pageable.getPageNumber())
.queryParam(QUERY_PARAM_REPORT_PAGE_SIZE, pageable.getPageSize());
return reportServerCall(id, this.getSubReportsServerURI(), uriBuilder);
}

Expand Down
22 changes: 12 additions & 10 deletions src/main/java/org/gridsuite/study/server/service/StudyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.client.elc.QueryBuilders;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Service;
Expand All @@ -70,6 +71,7 @@
import static org.gridsuite.study.server.StudyException.Type.*;
import static org.gridsuite.study.server.elasticsearch.EquipmentInfosService.EQUIPMENT_TYPE_SCORES;
import static org.gridsuite.study.server.service.NetworkModificationTreeService.ROOT_NODE_NAME;
import static org.gridsuite.study.server.service.ReportService.REPORTER_ID_VALUE_KEY;
import static org.gridsuite.study.server.utils.StudyUtils.handleHttpError;

/**
Expand Down Expand Up @@ -1770,13 +1772,13 @@ private void checkStudyContainsNode(UUID studyUuid, UUID nodeUuid) {
}

@Transactional(readOnly = true)
public ReporterModel getSubReport(String subReportId, Set<String> severityLevels) {
return reportService.getSubReport(UUID.fromString(subReportId), severityLevels);
public ReporterModel getSubReport(String subReportId, Set<String> severityLevels, Pageable pageable) {
return reportService.getSubReport(UUID.fromString(subReportId), severityLevels, pageable);
}

@Transactional(readOnly = true)
public List<ReporterModel> getNodeReport(UUID nodeUuid, String reportId, ReportType reportType, Set<String> severityLevels) {
return getSubReporters(nodeUuid, UUID.fromString(reportId), nodeUuid + "@" + reportType, ReportNameMatchingType.EXACT_MATCHING, severityLevels);
public List<ReporterModel> getNodeReport(UUID nodeUuid, String reportId, ReportType reportType, Set<String> severityLevels, Pageable pageable) {
return getSubReporters(nodeUuid, UUID.fromString(reportId), nodeUuid + "@" + reportType, ReportNameMatchingType.EXACT_MATCHING, severityLevels, pageable);
}

private Pair<String, ReportNameMatchingType> getFiltersParamaters(UUID nodeUuid, boolean nodeOnlyReport, ReportType reportType) {
Expand All @@ -1794,10 +1796,10 @@ private Pair<String, ReportNameMatchingType> getFiltersParamaters(UUID nodeUuid,
}

@Transactional(readOnly = true)
public List<ReporterModel> getParentNodesReport(UUID nodeUuid, boolean nodeOnlyReport, ReportType reportType, Set<String> severityLevels) {
public List<ReporterModel> getParentNodesReport(UUID nodeUuid, boolean nodeOnlyReport, ReportType reportType, Set<String> severityLevels, Pageable pageable) {
Pair<String, ReportNameMatchingType> filtersParameters = getFiltersParamaters(nodeUuid, nodeOnlyReport, reportType);
AbstractNode nodeInfos = networkModificationTreeService.getNode(nodeUuid);
List<ReporterModel> subReporters = getSubReporters(nodeUuid, nodeInfos.getReportUuid(), filtersParameters.getFirst(), filtersParameters.getSecond(), severityLevels);
List<ReporterModel> subReporters = getSubReporters(nodeUuid, nodeInfos.getReportUuid(), filtersParameters.getFirst(), filtersParameters.getSecond(), severityLevels, pageable);
if (subReporters.isEmpty()) {
return subReporters;
} else if (nodeOnlyReport) {
Expand All @@ -1810,21 +1812,21 @@ public List<ReporterModel> getParentNodesReport(UUID nodeUuid, boolean nodeOnlyR
if (parentUuid.isEmpty()) {
return subReporters;
}
List<ReporterModel> parentReporters = self.getParentNodesReport(parentUuid.get(), false, reportType, severityLevels);
List<ReporterModel> parentReporters = self.getParentNodesReport(parentUuid.get(), false, reportType, severityLevels, pageable);
return Stream.concat(parentReporters.stream(), subReporters.stream()).collect(Collectors.toList());
}
}

private List<ReporterModel> getSubReporters(UUID nodeUuid, UUID reportUuid, String reportNameFilter, ReportNameMatchingType reportNameMatchingType, Set<String> severityLevels) {
ReporterModel reporter = reportService.getReport(reportUuid, nodeUuid.toString(), reportNameFilter, reportNameMatchingType, severityLevels);
private List<ReporterModel> getSubReporters(UUID nodeUuid, UUID reportUuid, String reportNameFilter, ReportNameMatchingType reportNameMatchingType, Set<String> severityLevels, Pageable pageable) {
ReporterModel reporter = reportService.getReport(reportUuid, nodeUuid.toString(), reportNameFilter, reportNameMatchingType, severityLevels, pageable);
Map<String, List<ReporterModel>> subReportersByNode = new LinkedHashMap<>();
reporter.getSubReporters().forEach(subReporter -> subReportersByNode.putIfAbsent(getNodeIdFromReportKey(subReporter), new ArrayList<>()));
reporter.getSubReporters().forEach(subReporter ->
subReportersByNode.get(getNodeIdFromReportKey(subReporter)).addAll(subReporter.getSubReporters())
);
return subReportersByNode.keySet().stream().map(nodeId -> {
// For a node report, pass the reportId to the Front as taskValues, to allow direct access
Map<String, TypedValue> taskValues = Map.of("id", new TypedValue(reportUuid.toString(), "ID"));
Map<String, TypedValue> taskValues = Map.of(REPORTER_ID_VALUE_KEY, new TypedValue(reportUuid.toString(), TypedValue.UNTYPED));
ReporterModel newSubReporter = new ReporterModel(nodeId, nodeId, taskValues);
subReportersByNode.get(nodeId).forEach(newSubReporter::addSubReporter);
return newSubReporter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import java.util.*;
import java.util.stream.Stream;

import static org.gridsuite.study.server.StudyConstants.QUERY_PARAM_REPORT_DEFAULT_NAME;
import static org.gridsuite.study.server.service.ReportService.QUERY_PARAM_REPORT_DEFAULT_NAME;
import static org.gridsuite.study.server.utils.TestUtils.createModificationNodeInfo;
import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand Down Expand Up @@ -306,22 +306,22 @@ private ReporterModel getNodeReport(String reportUuid, String nodeUuid) {
private ReporterModel getNodeSimpleReport(String reportUuid, String nodeUuid) {
ReporterModel reporter = new ReporterModel(reportUuid, reportUuid);
Map<String, TypedValue> taskValues = new HashMap<>();
taskValues.put("id", new TypedValue(reportUuid, "ID"));
taskValues.put("id", new TypedValue(reportUuid, TypedValue.UNTYPED));
reporter.addSubReporter(new ReporterModel(nodeUuid, nodeUuid, taskValues));
return reporter;
}

private ReporterModel getRootNodeSimpleReport(String reportUuid) {
ReporterModel reporter = new ReporterModel(reportUuid, reportUuid);
Map<String, TypedValue> taskValues = new HashMap<>();
taskValues.put("id", new TypedValue(reportUuid, "ID"));
taskValues.put("id", new TypedValue(reportUuid, TypedValue.UNTYPED));
reporter.addSubReporter(new ReporterModel("Root", "Root", taskValues));
return reporter;
}

private ReporterModel getNodeMultipleReport(String reportUuid, String nodeUuid) {
ReporterModel reporter = new ReporterModel(reportUuid, reportUuid);
Map<String, TypedValue> taskValues = Map.of("id", new TypedValue(reportUuid, "ID"));
Map<String, TypedValue> taskValues = Map.of("id", new TypedValue(reportUuid, TypedValue.UNTYPED));
ReporterModel subReporter = new ReporterModel(MODIFICATION_NODE_UUID.toString(), MODIFICATION_NODE_UUID.toString(), taskValues);
subReporter.addSubReporter(new ReporterModel("test" + nodeUuid, "test" + nodeUuid));
reporter.addSubReporter(subReporter);
Expand Down
Loading