@@ -42,7 +42,7 @@ public enum ResponseFormat {
42
42
43
43
private static final List <String []> ACCESS_TRENDS_CSV_RESULT_HEADER = new ArrayList <String []>() {{
44
44
add (new String []{"Date" , "Endpoint" , "UserID" });
45
- }};
45
+ }};
46
46
47
47
public StatisticController (StatisticService service ) {
48
48
this .service = service ;
@@ -64,7 +64,7 @@ public Response executionStatistics(ExecutionStatisticsRequest executionStatisti
64
64
LocalDate .parse (executionStatisticsRequest .getEndDate (), formatter ), executionStatisticsRequest .getSourceKey (), showUserInformation );
65
65
66
66
if (ResponseFormat .CSV .equals (executionStatisticsRequest .getResponseFormat ())) {
67
- return prepareExecutionResultResponse (sourceExecutions .getExecutions (), "execution_statistics.zip" );
67
+ return prepareExecutionResultResponse (sourceExecutions .getExecutions (), "execution_statistics.zip" , showUserInformation );
68
68
} else {
69
69
return Response .ok (sourceExecutions ).build ();
70
70
}
@@ -86,29 +86,29 @@ public Response accessStatistics(AccessTrendsStatisticsRequest accessTrendsStati
86
86
LocalDate .parse (accessTrendsStatisticsRequest .getEndDate (), formatter ), accessTrendsStatisticsRequest .getEndpoints (), showUserInformation );
87
87
88
88
if (ResponseFormat .CSV .equals (accessTrendsStatisticsRequest .getResponseFormat ())) {
89
- return prepareAccessTrendsResponse (trends .getTrends (), "execution_trends.zip" );
89
+ return prepareAccessTrendsResponse (trends .getTrends (), "execution_trends.zip" , showUserInformation );
90
90
} else {
91
91
return Response .ok (trends ).build ();
92
92
}
93
93
}
94
94
95
- private Response prepareExecutionResultResponse (List <SourceExecutionDto > executions , String filename ) {
95
+ private Response prepareExecutionResultResponse (List <SourceExecutionDto > executions , String filename , boolean showUserInformation ) {
96
+ updateExecutionStatisticsHeader (showUserInformation );
96
97
List <String []> data = executions .stream ()
97
- .flatMap (execution ->
98
- new ArrayList <String []>() {{
99
- add (new String []{execution .getExecutionDate ().toString (), execution .getSourceName (), execution .getExecutionName ()});
100
- }}.stream ()
98
+ .map (execution -> showUserInformation
99
+ ? new String []{execution .getExecutionDate (), execution .getSourceName (), execution .getExecutionName (), execution .getUserID ()}
100
+ : new String []{execution .getExecutionDate (), execution .getSourceName (), execution .getExecutionName ()}
101
101
)
102
102
.collect (Collectors .toList ());
103
103
return prepareResponse (data , filename , EXECUTION_STATISTICS_CSV_RESULT_HEADER );
104
104
}
105
105
106
- private Response prepareAccessTrendsResponse (List <AccessTrendDto > trends , String filename ) {
106
+ private Response prepareAccessTrendsResponse (List <AccessTrendDto > trends , String filename , boolean showUserInformation ) {
107
+ updateAccessTrendsHeader (showUserInformation );
107
108
List <String []> data = trends .stream ()
108
- .flatMap (trend ->
109
- new ArrayList <String []>() {{
110
- add (new String []{trend .getExecutionDate ().toString (), trend .getEndpointName (), trend .getUserID ()});
111
- }}.stream ()
109
+ .map (trend -> showUserInformation
110
+ ? new String []{trend .getExecutionDate ().toString (), trend .getEndpointName (), trend .getUserID ()}
111
+ : new String []{trend .getExecutionDate ().toString (), trend .getEndpointName ()}
112
112
)
113
113
.collect (Collectors .toList ());
114
114
return prepareResponse (data , filename , ACCESS_TRENDS_CSV_RESULT_HEADER );
@@ -133,6 +133,24 @@ private Response prepareResponse(List<String[]> data, String filename, List<Stri
133
133
}
134
134
}
135
135
136
+ private void updateExecutionStatisticsHeader (boolean showUserInformation ) {
137
+ EXECUTION_STATISTICS_CSV_RESULT_HEADER .clear ();
138
+ if (showUserInformation ) {
139
+ EXECUTION_STATISTICS_CSV_RESULT_HEADER .add (new String []{"Date" , "Source" , "Execution Type" , "User ID" });
140
+ } else {
141
+ EXECUTION_STATISTICS_CSV_RESULT_HEADER .add (new String []{"Date" , "Source" , "Execution Type" });
142
+ }
143
+ }
144
+
145
+ private void updateAccessTrendsHeader (boolean showUserInformation ) {
146
+ ACCESS_TRENDS_CSV_RESULT_HEADER .clear ();
147
+ if (showUserInformation ) {
148
+ ACCESS_TRENDS_CSV_RESULT_HEADER .add (new String []{"Date" , "Endpoint" , "UserID" });
149
+ } else {
150
+ ACCESS_TRENDS_CSV_RESULT_HEADER .add (new String []{"Date" , "Endpoint" });
151
+ }
152
+ }
153
+
136
154
public static final class ExecutionStatisticsRequest {
137
155
// Format - yyyy-MM-dd
138
156
String startDate ;
0 commit comments