use of org.finos.waltz.web.json.BrowserInfo in project waltz by khartec.
the class UserAgentInfoEndpoint method register.
@Override
public void register() {
String findForUserPath = WebUtilities.mkPath(BASE_URL, "user", ":userName");
String recordLoginPath = WebUtilities.mkPath(BASE_URL);
ListRoute<UserAgentInfo> findForUserRoute = ((request, response) -> {
String userName = request.params("userName");
String limitStr = request.queryParams("limit");
int limit = limitStr == null || limitStr.equals("") ? DEFAULT_LIMIT : Integer.parseInt(limitStr);
return userAgentInfoService.findLoginsForUser(userName, limit);
});
DatumRoute<Integer> recordLoginRoute = (request, response) -> {
BrowserInfo browserInfo = WebUtilities.readBody(request, BrowserInfo.class);
UserAgentInfo userAgentInfo = ImmutableUserAgentInfo.builder().userName(WebUtilities.getUsername(request)).userAgent(request.userAgent()).operatingSystem(browserInfo.operatingSystem()).resolution(browserInfo.resolution()).loginTimestamp(DateTimeUtilities.nowUtc()).ipAddress(request.ip()).build();
return userAgentInfoService.save(userAgentInfo);
};
EndpointUtilities.getForList(findForUserPath, findForUserRoute);
EndpointUtilities.postForDatum(recordLoginPath, recordLoginRoute);
}
Aggregations