Search in sources :

Example 11 with UserDto

use of com.networknt.portal.usermanagement.model.common.domain.UserDto in project light-portal by networknt.

the class UserGetHandler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    List<User> users = service.getUser();
    List<UserDto> result = users.stream().map(e -> service.toUserDto(e)).collect(Collectors.toList());
    exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
    exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(result));
// exchange.endExchange();
}
Also used : PasswordSecurity(com.networknt.portal.usermanagement.model.common.crypto.PasswordSecurity) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) HttpServerExchange(io.undertow.server.HttpServerExchange) HashMap(java.util.HashMap) SingletonServiceFactory(com.networknt.service.SingletonServiceFactory) Collectors(java.util.stream.Collectors) HttpHandler(io.undertow.server.HttpHandler) HttpString(io.undertow.util.HttpString) List(java.util.List) UserServiceImpl(com.networknt.portal.usermanagement.model.auth.service.UserServiceImpl) UserRepository(com.networknt.portal.usermanagement.model.common.model.user.UserRepository) Map(java.util.Map) User(com.networknt.portal.usermanagement.model.common.model.user.User) Config(com.networknt.config.Config) UserService(com.networknt.portal.usermanagement.model.auth.service.UserService) User(com.networknt.portal.usermanagement.model.common.model.user.User) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) HttpString(io.undertow.util.HttpString)

Example 12 with UserDto

use of com.networknt.portal.usermanagement.model.common.domain.UserDto in project light-portal by networknt.

the class UserIdPutHandlerTest method testUserIdPutHandlerTestEmailChange.

@Test
public void testUserIdPutHandlerTestEmailChange() throws ClientException, ApiException {
    final Http2Client client = Http2Client.getInstance();
    final CountDownLatch latch = new CountDownLatch(1);
    final ClientConnection connection;
    try {
        connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true) : OptionMap.EMPTY).get();
    } catch (Exception e) {
        throw new ClientException(e);
    }
    final AtomicReference<ClientResponse> reference = new AtomicReference<>();
    UserDto userDto = new UserDto("aaa.bbb2@gmail.com", "testUser");
    userDto.setEmailChange(true);
    String json = JSonMapper.toJson(userDto);
    System.out.println(json);
    try {
        ClientRequest request = new ClientRequest().setPath("/v1/user/1233333").setMethod(Methods.PUT);
        request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
        request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
        connection.sendRequest(request, client.createClientCallback(reference, latch, json));
        latch.await();
    } catch (Exception e) {
        logger.error("Exception: ", e);
        throw new ClientException(e);
    } finally {
        IoUtils.safeClose(connection);
    }
    int statusCode = reference.get().getResponseCode();
    String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
    System.out.println("response:" + body);
    Assert.assertEquals(200, statusCode);
    Assert.assertNotNull(body);
}
Also used : ClientResponse(io.undertow.client.ClientResponse) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) ClientException(com.networknt.exception.ClientException) SQLException(java.sql.SQLException) ApiException(com.networknt.exception.ApiException) ClientConnection(io.undertow.client.ClientConnection) Http2Client(com.networknt.client.Http2Client) ClientException(com.networknt.exception.ClientException) ClientRequest(io.undertow.client.ClientRequest) Test(org.junit.Test)

Example 13 with UserDto

use of com.networknt.portal.usermanagement.model.common.domain.UserDto in project light-portal by networknt.

the class UserIdPutHandlerTest method testUserIdPutHandlerTestPasswordReset.

@Test
public void testUserIdPutHandlerTestPasswordReset() throws ClientException, ApiException {
    final Http2Client client = Http2Client.getInstance();
    final CountDownLatch latch = new CountDownLatch(1);
    final ClientConnection connection;
    try {
        connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true) : OptionMap.EMPTY).get();
    } catch (Exception e) {
        throw new ClientException(e);
    }
    final AtomicReference<ClientResponse> reference = new AtomicReference<>();
    UserDto userDto = new UserDto("aaa.bbb@gmail.com", "testUser");
    userDto.setPassword("new_password");
    userDto.setPasswordReset(true);
    String json = JSonMapper.toJson(userDto);
    System.out.println(json);
    try {
        ClientRequest request = new ClientRequest().setPath("/v1/user/1233333").setMethod(Methods.PUT);
        request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
        request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
        connection.sendRequest(request, client.createClientCallback(reference, latch, json));
        latch.await();
    } catch (Exception e) {
        logger.error("Exception: ", e);
        throw new ClientException(e);
    } finally {
        IoUtils.safeClose(connection);
    }
    int statusCode = reference.get().getResponseCode();
    String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
    System.out.println("response:" + body);
    Assert.assertEquals(200, statusCode);
    Assert.assertNotNull(body);
}
Also used : ClientResponse(io.undertow.client.ClientResponse) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) ClientException(com.networknt.exception.ClientException) SQLException(java.sql.SQLException) ApiException(com.networknt.exception.ApiException) ClientConnection(io.undertow.client.ClientConnection) Http2Client(com.networknt.client.Http2Client) ClientException(com.networknt.exception.ClientException) ClientRequest(io.undertow.client.ClientRequest) Test(org.junit.Test)

Example 14 with UserDto

use of com.networknt.portal.usermanagement.model.common.domain.UserDto in project light-portal by networknt.

the class GetNewUser method handle.

@Override
public ByteBuffer handle(HttpServerExchange exchange, Object input) {
    ObjectMapper mapper = new ObjectMapper();
    ResponseResult response = new ResponseResult();
    String result = "[Ok!]";
    try {
        String json = mapper.writeValueAsString(input);
        UserDto userDto = mapper.readValue(json, UserDto.class);
        User user = service.fromUserDto(userDto);
        System.out.println("user:" + user.getScreenName());
        service.signup(user, userDto.getPassword(), false);
        response.setCompleted(true);
        response.setMessage("created User:" + user.getScreenName());
        result = Config.getInstance().getMapper().writeValueAsString(response);
    } catch (Exception e) {
        result = e.getMessage();
    }
    return NioUtils.toByteBuffer(result);
}
Also used : User(com.networknt.portal.usermanagement.model.common.model.user.User) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 15 with UserDto

use of com.networknt.portal.usermanagement.model.common.domain.UserDto in project light-portal by networknt.

the class UserGetHandler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    List<User> users = service.getUser();
    List<UserDto> result = users.stream().map(e -> service.toUserDto(e)).collect(Collectors.toList());
    exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
    exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(result));
// //     exchange.endExchange();
}
Also used : PasswordSecurity(com.networknt.portal.usermanagement.model.common.crypto.PasswordSecurity) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) HttpServerExchange(io.undertow.server.HttpServerExchange) HashMap(java.util.HashMap) SingletonServiceFactory(com.networknt.service.SingletonServiceFactory) Collectors(java.util.stream.Collectors) HttpHandler(io.undertow.server.HttpHandler) HttpString(io.undertow.util.HttpString) List(java.util.List) UserServiceImpl(com.networknt.portal.usermanagement.model.auth.service.UserServiceImpl) UserRepository(com.networknt.portal.usermanagement.model.common.model.user.UserRepository) Map(java.util.Map) User(com.networknt.portal.usermanagement.model.common.model.user.User) Config(com.networknt.config.Config) UserService(com.networknt.portal.usermanagement.model.auth.service.UserService) User(com.networknt.portal.usermanagement.model.common.model.user.User) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) HttpString(io.undertow.util.HttpString)

Aggregations

UserDto (com.networknt.portal.usermanagement.model.common.domain.UserDto)15 User (com.networknt.portal.usermanagement.model.common.model.user.User)8 Map (java.util.Map)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 HttpString (io.undertow.util.HttpString)6 HashMap (java.util.HashMap)5 Http2Client (com.networknt.client.Http2Client)4 ApiException (com.networknt.exception.ApiException)4 ClientException (com.networknt.exception.ClientException)4 NoSuchUserException (com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException)4 ClientConnection (io.undertow.client.ClientConnection)4 ClientRequest (io.undertow.client.ClientRequest)4 ClientResponse (io.undertow.client.ClientResponse)4 URI (java.net.URI)4 SQLException (java.sql.SQLException)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Test (org.junit.Test)4 Config (com.networknt.config.Config)2 EventHandlerMethod (com.networknt.eventuate.common.EventHandlerMethod)2