Extract method in FiltersJSONResolver#getResponse

This commit is contained in:
Risto Lahtela 2021-01-31 11:07:58 +02:00
parent ae416cc49f
commit bf835c3b2e

View File

@ -80,26 +80,28 @@ public class FiltersJSONResolver implements Resolver {
} }
private Response getResponse() { private Response getResponse() {
List<DateObj<Integer>> data = dbSystem.getDatabase().query(TPSQueries.fetchViewPreviewGraphData(serverInfo.getServerUUID()));
Long earliestStart = dbSystem.getDatabase().query(SessionQueries.earliestSessionStart());
data.add(0, new DateObj<>(earliestStart, 1));
boolean displayGaps = true;
List<Double[]> viewPoints = graphs.line().lineGraph(Lists.map(data, Point::fromDateObj), displayGaps).getPoints()
.stream().map(point -> {
if (point.getY() == null) point.setY(0.0);
return point.toArray();
}).collect(Collectors.toList());
return Response.builder() return Response.builder()
.setMimeType(MimeType.JSON) .setMimeType(MimeType.JSON)
.setJSONContent(new FilterResponseJSON( .setJSONContent(new FilterResponseJSON(
filters.getFilters(), filters.getFilters(),
new ViewJSON(formatters), new ViewJSON(formatters),
viewPoints fetchViewGraphPoints()
)).build(); )).build();
} }
private List<Double[]> fetchViewGraphPoints() {
List<DateObj<Integer>> data = dbSystem.getDatabase().query(TPSQueries.fetchViewPreviewGraphData(serverInfo.getServerUUID()));
Long earliestStart = dbSystem.getDatabase().query(SessionQueries.earliestSessionStart());
data.add(0, new DateObj<>(earliestStart, 1));
boolean displayGaps = true;
return graphs.line().lineGraph(Lists.map(data, Point::fromDateObj), displayGaps).getPoints()
.stream().map(point -> {
if (point.getY() == null) point.setY(0.0);
return point.toArray();
}).collect(Collectors.toList());
}
/** /**
* JSON serialization class. * JSON serialization class.
*/ */