Search in sources :

Example 6 with UserDto

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

the class UserQueryWorkflow method update.

@EventHandlerMethod
public void update(DispatchedEvent<UserUpdatedEvent> de) {
    String id = de.getEntityId();
    UserDto user = de.getEvent().getUserDto();
    User userResult = null;
    try {
        if (user.isEmailChange()) {
            userResult = service.changeEmail(id, user.getContactData().getEmail());
        } else if (user.isPasswordReset()) {
            userResult = service.changePassword(id, user.getPassword());
        } else if (user.isScreenNameChange()) {
            userResult = service.changeScreenName(id, user.getScreenName());
        } else {
            userResult = service.fromUserDto(user);
            userResult.setId(id);
            userResult = service.update(userResult);
        }
    } catch (NoSuchUserException e) {
        logger.info("No Such User Error", id, e.getMessage());
    } catch (InvalidEmailException e) {
        logger.info("Invalid Email Error", id, e.getMessage());
    } catch (Exception e) {
        logger.info("Error on update user:", id, e.getMessage());
    }
}
Also used : User(com.networknt.portal.usermanagement.model.common.model.user.User) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) NoSuchUserException(com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException) InvalidEmailException(com.networknt.portal.usermanagement.model.common.exception.InvalidEmailException) InvalidEmailException(com.networknt.portal.usermanagement.model.common.exception.InvalidEmailException) NoSuchUserException(com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException) EventHandlerMethod(com.networknt.eventuate.common.EventHandlerMethod)

Example 7 with UserDto

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

the class UpdateUserById method handle.

@Override
public ByteBuffer handle(HttpServerExchange exchange, Object input) {
    ObjectMapper mapper = new ObjectMapper();
    String id = ((Map<String, String>) input).get("id");
    System.out.println("id:" + id);
    String result;
    try {
        String json = mapper.writeValueAsString(input);
        System.out.println("hybrid input:" + json);
        UserDto user = mapper.readValue(json, UserDto.class);
        System.out.println("user:" + user.getScreenName());
        User userResult;
        if (user.isEmailChange()) {
            userResult = service.changeEmail(id, user.getContactData().getEmail());
        } else if (user.isPasswordReset()) {
            userResult = service.changePassword(id, user.getPassword());
        } else if (user.isScreenNameChange()) {
            userResult = service.changeScreenName(id, user.getScreenName());
        } else {
            userResult = service.fromUserDto(user);
            userResult.setId(id);
            userResult = service.update(userResult);
        }
        if (userResult == null) {
            result = "no user changed;";
        } else {
            result = Config.getInstance().getMapper().writeValueAsString(service.toUserDto(userResult));
        }
    } catch (Exception e) {
        result = e.getMessage();
    // TODO handler Exception, add log info?
    }
    System.out.println("result:" + result);
    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) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with UserDto

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

the class UserServiceImpl method toUserDto.

@Override
public UserDto toUserDto(User user) {
    UserDto userDto = new UserDto(user.getContactData().getEmail(), user.getScreenName());
    userDto.setContactData(user.getContactData());
    return userDto;
}
Also used : UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto)

Example 9 with UserDto

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

the class UserIdPutHandler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    String id = exchange.getQueryParameters().get("id").getFirst();
    ObjectMapper mapper = new ObjectMapper();
    Map s = (Map) exchange.getAttachment(BodyHandler.REQUEST_BODY);
    String json = mapper.writeValueAsString(s);
    UserDto user = mapper.readValue(json, UserDto.class);
    CompletableFuture<User> result = service.update(id, user).thenApply((e) -> {
        User m = new User();
        m.setId(e.getEntityId());
        m.setHost(e.getAggregate().getUser().getHost());
        m.setScreenName(e.getAggregate().getUser().getScreenName());
        m.getContactData().setEmail(e.getAggregate().getUser().getContactData().getEmail());
        return m;
    });
    exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
    exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(result.get()));
}
Also used : User(com.networknt.portal.usermanagement.restcommand.model.User) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) HttpString(io.undertow.util.HttpString) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpString(io.undertow.util.HttpString)

Example 10 with UserDto

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

the class UserPostHandler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    // add a new object
    Map s = (Map) exchange.getAttachment(BodyHandler.REQUEST_BODY);
    String json = mapper.writeValueAsString(s);
    UserDto userDto = mapper.readValue(json, UserDto.class);
    if (verifyEmail(userDto.getContactData().getEmail())) {
        CompletableFuture<User> result = service.add(userDto).thenApply((e) -> {
            User m = new User();
            m.setId(e.getEntityId());
            m.setPassword(e.getAggregate().getUser().getPassword());
            m.setHost(e.getAggregate().getUser().getHost());
            m.setScreenName(e.getAggregate().getUser().getScreenName());
            m.getContactData().setEmail(e.getAggregate().getUser().getContactData().getEmail());
            return m;
        });
        exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
        exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(result.get()));
    } else {
        exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
        exchange.getResponseSender().send("email has been taken by other user");
    }
}
Also used : User(com.networknt.portal.usermanagement.restcommand.model.User) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) HttpString(io.undertow.util.HttpString) HashMap(java.util.HashMap) OptionMap(org.xnio.OptionMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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