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

Application usage statistics #2387

Merged
merged 15 commits into from
Mar 18, 2025
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import org.ohdsi.webapi.statistic.service.StatisticService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;

import javax.ws.rs.Consumes;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
Expand All @@ -30,12 +31,14 @@

@Controller
@Path("/statistic/")
@ConditionalOnProperty(value = "audit.trail.enabled", havingValue = "true")
public class StatisticController {

private static final Logger log = LoggerFactory.getLogger(StatisticController.class);

private StatisticService service;

@Value("${audit.trail.enabled}")
private boolean auditTrailEnabled;

public enum ResponseFormat {
CSV, JSON
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both CSV and JSON output formats should be supported

Expand Down Expand Up @@ -70,6 +73,9 @@ public StatisticController(StatisticService service) {
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response executionStatistics(ExecutionStatisticsRequest executionStatisticsRequest) {
if (!auditTrailEnabled) {
throw new NotFoundException("Audit Trail functionality should be enabled (audit.trail.enabled) to serve this endpoint");
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
boolean showUserInformation = executionStatisticsRequest.isShowUserInformation();

Expand All @@ -92,6 +98,9 @@ public Response executionStatistics(ExecutionStatisticsRequest executionStatisti
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response accessStatistics(AccessTrendsStatisticsRequest accessTrendsStatisticsRequest) {
if (!auditTrailEnabled) {
throw new NotFoundException("Audit Trail functionality should be enabled (audit.trail.enabled) to serve this endpoint");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NotFound results in a 404, correct? We said that it would be confusing if someone looked at an api and attempted to call an endpoint and it was not found. I think we mentioned raising an error, such that it could return an HTTP 500 or some other HTTP code that represents an error other than 'not found'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misread your passage, corrected to the internal server error

}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
boolean showUserInformation = accessTrendsStatisticsRequest.isShowUserInformation();

Expand Down
Loading