Skip to content

Commit

Permalink
Massage path for easier parsing/categorizing later
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanrdoherty committed Sep 27, 2024
1 parent 79d118e commit 3fe3958
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
37 changes: 35 additions & 2 deletions Service/src/main/java/org/gusdb/wdk/service/PageViewLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,44 @@ public class PageViewLogger {

private static final Logger LOG = Logger.getLogger(PageViewLogger.class);

public static void logPageView(String projectId, User user, String pagePath) {
private static final String CLIENT_PREFIX = "/web-client";

public static void logPageView(String projectId, User user, String submittedPath) {
LOG.info(
TAB + user.getUserId() +
TAB + (user.isGuest() ? "guest" : "registered") +
TAB + projectId +
TAB + pagePath);
TAB + trimWebappAndClientApp(submittedPath));
}

// a -> a
// a/ -> a
// webapp/app -> /web-client
// webapp/app/ -> /web-client
// webapp/app/blah -> /web-client/blah
private static String trimWebappAndClientApp(String submittedPath) {
String[] segments = submittedPath.split("/");
switch (segments.length) {
case 0:
// unrecognized path; don't legitimize with client prefix
return "/";
case 1:
// unrecognized path; don't legitimize with client prefix
return "/" + segments[0];
default:
// start with base URL of the webapp, then add remaining segments
String newPath = CLIENT_PREFIX;
for (int i = 2; i < segments.length; i++) {
newPath += "/" + segments[i];
}
return newPath;
}
}

public static void main(String[] args) {
String[] tests = new String[] { "a", "a/", "webapp/app", "webapp/app/", "webapp/app/blah" };
for (String test : tests) {
System.out.println(test + " = " + trimWebappAndClientApp(test));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ public StreamingOutput getMetrics() {
@Path("/metrics/count-page-view/{clientPath:.+}")
@Produces(MediaType.APPLICATION_JSON)
public Response registerVisit(@PathParam("clientPath") String clientPath) {
clientPath = "/" + clientPath; // reprepend '/'
LOG.trace("Registered visit to " + clientPath);
PageViewLogger.logPageView(getWdkModel().getProjectId(), getRequestingUser(), clientPath);
return Response.noContent().build();
}
Expand Down

0 comments on commit 3fe3958

Please sign in to comment.