Skip to content

Commit af3f682

Browse files
hernaldourbinaoleg-odysseus
authored andcommitted
ATL-8: Adding userInformation to the response
1 parent 01c0d51 commit af3f682

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

src/main/java/org/ohdsi/webapi/statistic/controller/StatisticController.java

+31-13
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public enum ResponseFormat {
4242

4343
private static final List<String[]> ACCESS_TRENDS_CSV_RESULT_HEADER = new ArrayList<String[]>() {{
4444
add(new String[]{"Date", "Endpoint", "UserID"});
45-
}};
45+
}};
4646

4747
public StatisticController(StatisticService service) {
4848
this.service = service;
@@ -64,7 +64,7 @@ public Response executionStatistics(ExecutionStatisticsRequest executionStatisti
6464
LocalDate.parse(executionStatisticsRequest.getEndDate(), formatter), executionStatisticsRequest.getSourceKey(), showUserInformation);
6565

6666
if (ResponseFormat.CSV.equals(executionStatisticsRequest.getResponseFormat())) {
67-
return prepareExecutionResultResponse(sourceExecutions.getExecutions(), "execution_statistics.zip");
67+
return prepareExecutionResultResponse(sourceExecutions.getExecutions(), "execution_statistics.zip", showUserInformation);
6868
} else {
6969
return Response.ok(sourceExecutions).build();
7070
}
@@ -86,29 +86,29 @@ public Response accessStatistics(AccessTrendsStatisticsRequest accessTrendsStati
8686
LocalDate.parse(accessTrendsStatisticsRequest.getEndDate(), formatter), accessTrendsStatisticsRequest.getEndpoints(), showUserInformation);
8787

8888
if (ResponseFormat.CSV.equals(accessTrendsStatisticsRequest.getResponseFormat())) {
89-
return prepareAccessTrendsResponse(trends.getTrends(), "execution_trends.zip");
89+
return prepareAccessTrendsResponse(trends.getTrends(), "execution_trends.zip", showUserInformation);
9090
} else {
9191
return Response.ok(trends).build();
9292
}
9393
}
9494

95-
private Response prepareExecutionResultResponse(List<SourceExecutionDto> executions, String filename) {
95+
private Response prepareExecutionResultResponse(List<SourceExecutionDto> executions, String filename, boolean showUserInformation) {
96+
updateExecutionStatisticsHeader(showUserInformation);
9697
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()}
101101
)
102102
.collect(Collectors.toList());
103103
return prepareResponse(data, filename, EXECUTION_STATISTICS_CSV_RESULT_HEADER);
104104
}
105105

106-
private Response prepareAccessTrendsResponse(List<AccessTrendDto> trends, String filename) {
106+
private Response prepareAccessTrendsResponse(List<AccessTrendDto> trends, String filename, boolean showUserInformation) {
107+
updateAccessTrendsHeader(showUserInformation);
107108
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()}
112112
)
113113
.collect(Collectors.toList());
114114
return prepareResponse(data, filename, ACCESS_TRENDS_CSV_RESULT_HEADER);
@@ -133,6 +133,24 @@ private Response prepareResponse(List<String[]> data, String filename, List<Stri
133133
}
134134
}
135135

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+
136154
public static final class ExecutionStatisticsRequest {
137155
// Format - yyyy-MM-dd
138156
String startDate;

src/main/java/org/ohdsi/webapi/statistic/dto/AccessTrendDto.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
public class AccessTrendDto {
66
private String endpointName;
7-
private LocalDate executionDate;
7+
private String executionDate;
88
private String userID;
99

10-
public AccessTrendDto(String endpointName, LocalDate executionDate, String userID) {
10+
public AccessTrendDto(String endpointName, String executionDate, String userID) {
1111
this.endpointName = endpointName;
1212
this.executionDate = executionDate;
1313
this.userID = userID;
@@ -21,11 +21,11 @@ public void setEndpointName(String endpointName) {
2121
this.endpointName = endpointName;
2222
}
2323

24-
public LocalDate getExecutionDate() {
24+
public String getExecutionDate() {
2525
return executionDate;
2626
}
2727

28-
public void setExecutionDate(LocalDate executionDate) {
28+
public void setExecutionDate(String executionDate) {
2929
this.executionDate = executionDate;
3030
}
3131

src/main/java/org/ohdsi/webapi/statistic/dto/SourceExecutionDto.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
public class SourceExecutionDto {
77
private String sourceName;
88
private String executionName;
9-
private LocalDate executionDate;
9+
private String executionDate;
1010
private String userID;
1111

12-
public SourceExecutionDto(String sourceName, String executionName, LocalDate executionDate, String userID) {
12+
public SourceExecutionDto(String sourceName, String executionName, String executionDate, String userID) {
1313
this.sourceName = sourceName;
1414
this.executionName = executionName;
1515
this.executionDate = executionDate;
@@ -32,11 +32,11 @@ public void setExecutionName(String executionName) {
3232
this.executionName = executionName;
3333
}
3434

35-
public LocalDate getExecutionDate() {
35+
public String getExecutionDate() {
3636
return executionDate;
3737
}
3838

39-
public void setExecutionDate(LocalDate executionDate) {
39+
public void setExecutionDate(String executionDate) {
4040
this.executionDate = executionDate;
4141
}
4242

src/main/java/org/ohdsi/webapi/statistic/service/StatisticService.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,25 @@ public class StatisticService {
5858
// Duplicate log entries can exist because sometimes ccontroller methods are called from other controller methods
5959
// These regular expressions let us to choose only needed log entries
6060
private static final Pattern COHORT_GENERATION_REGEXP =
61-
Pattern.compile("^.*(\\d{4}-\\d{2}-\\d{2})T\\d{2}:\\d{2}:\\d{2}.*GET\\s/WebAPI/cohortdefinition/\\d+/generate/(.+)\\s-\\s.*status::String,startDate::Date,endDate::Date.*$");
61+
Pattern.compile("^.*(\\d{4}-\\d{2}-\\d{2})T\\d{2}:\\d{2}:\\d{2}.*-\\s-\\s-\\s([\\w-]+)\\s.*GET\\s/WebAPI/cohortdefinition/\\d+/generate/(.+)\\s-\\s.*status::String,startDate::Date,endDate::Date.*$");
6262

6363
private static final Pattern CHARACTERIZATION_GENERATION_REGEXP =
64-
Pattern.compile("^.*(\\d{4}-\\d{2}-\\d{2})T\\d{2}:\\d{2}:\\d{2}.*POST\\s/WebAPI/cohort-characterization/\\d+/generation/(.+)\\s-\\s.*status::String,startDate::Date,endDate::Date.*$");
64+
Pattern.compile("^.*(\\d{4}-\\d{2}-\\d{2})T\\d{2}:\\d{2}:\\d{2}.*-\\s-\\s-\\s([\\w-]+)\\s.*POST\\s/WebAPI/cohort-characterization/\\d+/generation/(.+)\\s-\\s.*status::String,startDate::Date,endDate::Date.*$");
6565

6666
private static final Pattern PATHWAY_GENERATION_REGEXP =
67-
Pattern.compile("^.*(\\d{4}-\\d{2}-\\d{2})T\\d{2}:\\d{2}:\\d{2}.*POST\\s/WebAPI/pathway-analysis/\\d+/generation/(.+)\\s-\\s.*status::String,startDate::Date,endDate::Date.*$");
67+
Pattern.compile("^.*(\\d{4}-\\d{2}-\\d{2})T\\d{2}:\\d{2}:\\d{2}.*-\\s-\\s-\\s([\\w-]+)\\s.*POST\\s/WebAPI/pathway-analysis/\\d+/generation/(.+)\\s-\\s.*status::String,startDate::Date,endDate::Date.*$");
6868

6969
private static final Pattern IR_GENERATION_REGEXP =
70-
Pattern.compile("^.*(\\d{4}-\\d{2}-\\d{2})T\\d{2}:\\d{2}:\\d{2}.*GET\\s/WebAPI/ir/\\d+/execute/(.+)\\s-\\s.*status::String,startDate::Date,endDate::Date.*$");
70+
Pattern.compile("^.*(\\d{4}-\\d{2}-\\d{2})T\\d{2}:\\d{2}:\\d{2}.*-\\s-\\s-\\s([\\w-]+)\\s.*GET\\s/WebAPI/ir/\\d+/execute/(.+)\\s-\\s.*status::String,startDate::Date,endDate::Date.*$");
7171

7272
private static final Pattern PLE_GENERATION_REGEXP =
73-
Pattern.compile("^.*(\\d{4}-\\d{2}-\\d{2})T\\d{2}:\\d{2}:\\d{2}.*POST\\s/WebAPI/estimation/\\d+/generation/(.+)\\s-\\s.*status::String,startDate::Date,endDate::Date.*$");
73+
Pattern.compile("^.*(\\d{4}-\\d{2}-\\d{2})T\\d{2}:\\d{2}:\\d{2}.*-\\s-\\s-\\s([\\w-]+)\\s.*POST\\s/WebAPI/estimation/\\d+/generation/(.+)\\s-\\s.*status::String,startDate::Date,endDate::Date.*$");
7474

7575
private static final Pattern PLP_GENERATION_REGEXP =
76-
Pattern.compile("^.*(\\d{4}-\\d{2}-\\d{2})T\\d{2}:\\d{2}:\\d{2}.*POST\\s/WebAPI/prediction/\\d+/generation/(.+)\\s-\\s.*status::String,startDate::Date,endDate::Date.*$");
76+
Pattern.compile("^.*(\\d{4}-\\d{2}-\\d{2})T\\d{2}:\\d{2}:\\d{2}.*-\\s-\\s-\\s([\\w-]+)\\s.*POST\\s/WebAPI/prediction/\\d+/generation/(.+)\\s-\\s.*status::String,startDate::Date,endDate::Date.*$");
7777

7878
private static final String ENDPOINT_REGEXP =
79-
"^.*(\\d{4}-\\d{2}-\\d{2})T(\\d{2}:\\d{2}:\\d{2}).*-\\s([\\w.-]+)\\s.*-\\s({METHOD_PLACEHOLDER}\\s.*{ENDPOINT_PLACEHOLDER})\\s-.*$";
79+
"^.*(\\d{4}-\\d{2}-\\d{2})T(\\d{2}:\\d{2}:\\d{2}).*-\\s-\\s-\\s([\\w-]+)\\s.*-\\s({METHOD_PLACEHOLDER}\\s.*{ENDPOINT_PLACEHOLDER})\\s-.*$";
8080

8181
private static final String COHORT_GENERATION_NAME = "Cohort Generation";
8282

@@ -162,7 +162,7 @@ private List<AccessTrendDto> extractAccessTrends(Path path, List<EndpointDto> en
162162
return patterns.stream()
163163
.map(pattern -> pattern.matcher(str))
164164
.filter(Matcher::matches)
165-
.map(matcher -> new AccessTrendDto(matcher.group(4), LocalDate.parse(matcher.group(1)), showUserInformation ? matcher.group(3) : null))
165+
.map(matcher -> new AccessTrendDto(matcher.group(4), matcher.group(1), showUserInformation ? matcher.group(3) : null))
166166
.findFirst();
167167
})
168168
.filter(Optional::isPresent)
@@ -178,8 +178,8 @@ private Optional<SourceExecutionDto> getMatchedExecution(String str, String sour
178178
return patternMap.entrySet().stream()
179179
.map(entry -> new ImmutablePair<>(entry.getKey(), entry.getValue().matcher(str)))
180180
.filter(pair -> pair.getValue().matches())
181-
.filter(pair -> sourceKey == null || (sourceKey != null && sourceKey.equals(pair.getValue().group(2))))
182-
.map(pair -> new SourceExecutionDto(pair.getValue().group(2), pair.getKey(), LocalDate.parse(pair.getValue().group(1)), showUserInformation ? pair.getValue().group(1) : null))
181+
.filter(pair -> sourceKey == null || (sourceKey != null && sourceKey.equals(pair.getValue().group(3))))
182+
.map(pair -> new SourceExecutionDto(pair.getValue().group(3), pair.getKey(), pair.getValue().group(1), showUserInformation ? pair.getValue().group(2) : null))
183183
.findFirst();
184184
}
185185

0 commit comments

Comments
 (0)