Search in sources :

Example 1 with UserAgentInfo

use of org.finos.waltz.model.user_agent_info.UserAgentInfo in project waltz by khartec.

the class UserAgentInfoHarness method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    UserAgentInfoDao userLoginDao = ctx.getBean(UserAgentInfoDao.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<UserAgentInfo> infos = userLoginDao.findLoginsForUser("admin", 10);
    System.out.println(infos);
    userLoginDao.save(infos.get(0));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) UserAgentInfoDao(org.finos.waltz.data.user_agent_info.UserAgentInfoDao) DSLContext(org.jooq.DSLContext) UserAgentInfo(org.finos.waltz.model.user_agent_info.UserAgentInfo)

Example 2 with UserAgentInfo

use of org.finos.waltz.model.user_agent_info.UserAgentInfo 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

UserAgentInfo (org.finos.waltz.model.user_agent_info.UserAgentInfo)2 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 UserAgentInfoDao (org.finos.waltz.data.user_agent_info.UserAgentInfoDao)1 ImmutableUserAgentInfo (org.finos.waltz.model.user_agent_info.ImmutableUserAgentInfo)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 DSLContext (org.jooq.DSLContext)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Service (org.springframework.stereotype.Service)1