1
1
package org .ohdsi .webapi .statistic .service ;
2
2
3
3
import org .apache .commons .lang3 .tuple .ImmutablePair ;
4
- import org .apache .commons .lang3 .tuple .Pair ;
5
4
import org .ohdsi .webapi .statistic .dto .AccessTrendDto ;
6
5
import org .ohdsi .webapi .statistic .dto .AccessTrendsDto ;
7
6
import org .ohdsi .webapi .statistic .dto .EndpointDto ;
22
21
import java .text .SimpleDateFormat ;
23
22
import java .time .LocalDate ;
24
23
import java .time .ZoneId ;
25
- import java .util .ArrayList ;
26
24
import java .util .HashMap ;
27
25
import java .util .List ;
28
26
import java .util .Map ;
29
- import java .util .Objects ;
30
27
import java .util .Optional ;
31
28
import java .util .Set ;
32
- import java .util .regex .Matcher ;
33
29
import java .util .regex .Pattern ;
34
30
import java .util .stream .Collectors ;
35
31
import java .util .stream .Stream ;
@@ -117,26 +113,26 @@ public StatisticService() {
117
113
logFileDateFormat = new SimpleDateFormat (dateString );
118
114
}
119
115
120
- public SourceExecutionsDto getSourceExecutions (LocalDate startDate , LocalDate endDate , String sourceKey , String userID ) {
116
+ public SourceExecutionsDto getSourceExecutions (LocalDate startDate , LocalDate endDate , String sourceKey , boolean showUserInformation ) {
121
117
Set <Path > paths = getLogPaths (startDate , endDate );
122
118
List <SourceExecutionDto > executions = paths .stream ()
123
- .flatMap (path -> extractSourceExecutions (path , sourceKey , userID ).stream ())
119
+ .flatMap (path -> extractSourceExecutions (path , sourceKey , showUserInformation ).stream ())
124
120
.collect (Collectors .toList ());
125
121
return new SourceExecutionsDto (executions );
126
122
}
127
123
128
- public AccessTrendsDto getAccessTrends (LocalDate startDate , LocalDate endDate , List <EndpointDto > endpoints , String userID ) {
124
+ public AccessTrendsDto getAccessTrends (LocalDate startDate , LocalDate endDate , List <EndpointDto > endpoints , boolean showUserInformation ) {
129
125
Set <Path > paths = getLogPaths (startDate , endDate );
130
126
List <AccessTrendDto > trends = paths .stream ()
131
- .flatMap (path -> extractAccessTrends (path , endpoints , userID ).stream ())
127
+ .flatMap (path -> extractAccessTrends (path , endpoints , showUserInformation ).stream ())
132
128
.collect (Collectors .toList ());
133
129
return new AccessTrendsDto (trends );
134
130
}
135
131
136
- private List <SourceExecutionDto > extractSourceExecutions (Path path , String sourceKey , String userID ) {
132
+ private List <SourceExecutionDto > extractSourceExecutions (Path path , String sourceKey , boolean showUserInformation ) {
137
133
try (Stream <String > stream = Files .lines (path )) {
138
134
return stream
139
- .map (str -> getMatchedExecution (str , sourceKey , userID ))
135
+ .map (str -> getMatchedExecution (str , sourceKey , showUserInformation ))
140
136
.filter (Optional ::isPresent )
141
137
.map (Optional ::get )
142
138
.collect (Collectors .toList ());
@@ -146,14 +142,15 @@ private List<SourceExecutionDto> extractSourceExecutions(Path path, String sourc
146
142
}
147
143
}
148
144
149
- private List <AccessTrendDto > extractAccessTrends (Path path , List <EndpointDto > endpoints , String userID ) {
145
+ private List <AccessTrendDto > extractAccessTrends (Path path , List <EndpointDto > endpoints , boolean showUserInformation ) {
150
146
List <Pattern > patterns = endpoints .stream ()
151
147
.map (endpointPair -> {
152
148
String method = endpointPair .getMethod ();
153
149
String endpoint = endpointPair .getUrlPattern ().replaceAll ("\\ {\\ }" , ".*" );
150
+ String userId = endpointPair .getUserId ();
154
151
String regexpStr = ENDPOINT_REGEXP .replace ("{METHOD_PLACEHOLDER}" , method );
155
152
regexpStr = regexpStr .replace ("{ENDPOINT_PLACEHOLDER}" , endpoint );
156
- regexpStr = regexpStr .replace ("{USERID_PLACEHOLDER}" , userID );
153
+ regexpStr = regexpStr .replace ("{USERID_PLACEHOLDER}" , userId );
157
154
158
155
return Pattern .compile (regexpStr );
159
156
})
@@ -176,12 +173,12 @@ private List<AccessTrendDto> extractAccessTrends(Path path, List<EndpointDto> en
176
173
}
177
174
}
178
175
179
- private Optional <SourceExecutionDto > getMatchedExecution (String str , String sourceKey , String userID ) {
176
+ private Optional <SourceExecutionDto > getMatchedExecution (String str , String sourceKey , boolean showUserInformation ) {
180
177
return patternMap .entrySet ().stream ()
181
178
.map (entry -> new ImmutablePair <>(entry .getKey (), entry .getValue ().matcher (str )))
182
179
.filter (pair -> pair .getValue ().matches ())
183
180
.filter (pair -> sourceKey == null || (sourceKey != null && sourceKey .equals (pair .getValue ().group (2 ))))
184
- .map (pair -> new SourceExecutionDto (pair .getValue ().group (2 ), pair .getKey (), LocalDate .parse (pair .getValue ().group (1 )), userID ))
181
+ .map (pair -> new SourceExecutionDto (pair .getValue ().group (2 ), pair .getKey (), LocalDate .parse (pair .getValue ().group (1 )), pair . getValue (). group ( 3 ) ))
185
182
.findFirst ();
186
183
}
187
184
0 commit comments