Search in sources :

Example 1 with BrowserInfo

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);
}
Also used : ListRoute(org.finos.waltz.web.ListRoute) UserAgentInfoService(org.finos.waltz.service.user_agent_info.UserAgentInfoService) ImmutableUserAgentInfo(org.finos.waltz.model.user_agent_info.ImmutableUserAgentInfo) Endpoint(org.finos.waltz.web.endpoints.Endpoint) DatumRoute(org.finos.waltz.web.DatumRoute) Autowired(org.springframework.beans.factory.annotation.Autowired) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) Service(org.springframework.stereotype.Service) WebUtilities(org.finos.waltz.web.WebUtilities) UserAgentInfo(org.finos.waltz.model.user_agent_info.UserAgentInfo) BrowserInfo(org.finos.waltz.web.json.BrowserInfo) EndpointUtilities(org.finos.waltz.web.endpoints.EndpointUtilities) BrowserInfo(org.finos.waltz.web.json.BrowserInfo) ImmutableUserAgentInfo(org.finos.waltz.model.user_agent_info.ImmutableUserAgentInfo) UserAgentInfo(org.finos.waltz.model.user_agent_info.UserAgentInfo) Endpoint(org.finos.waltz.web.endpoints.Endpoint)

Aggregations

Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 ImmutableUserAgentInfo (org.finos.waltz.model.user_agent_info.ImmutableUserAgentInfo)1 UserAgentInfo (org.finos.waltz.model.user_agent_info.UserAgentInfo)1 UserAgentInfoService (org.finos.waltz.service.user_agent_info.UserAgentInfoService)1 DatumRoute (org.finos.waltz.web.DatumRoute)1 ListRoute (org.finos.waltz.web.ListRoute)1 WebUtilities (org.finos.waltz.web.WebUtilities)1 Endpoint (org.finos.waltz.web.endpoints.Endpoint)1 EndpointUtilities (org.finos.waltz.web.endpoints.EndpointUtilities)1 BrowserInfo (org.finos.waltz.web.json.BrowserInfo)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1