Search in sources :

Example 1 with EventHandlerMethod

use of com.networknt.eventuate.common.EventHandlerMethod in project light-portal by networknt.

the class UserQueryWorkflow method create.

@EventHandlerMethod
public void create(DispatchedEvent<UserSignUpEvent> de) {
    UserSignUpEvent event = de.getEvent();
    String id = de.getEntityId();
    UserDto userDto = event.getUserDto();
    Int128 eventId = de.getEventId();
    logger.info("**************** account version={}, {}", id, eventId);
    String json = JSonMapper.toJson(userDto);
    try {
        User user = service.fromUserDto(userDto, id);
        service.signup(user, userDto.getPassword(), true);
        // TODO remove the following implemetation after confirm email implemented
        Optional<ConfirmationToken> token = user.getConfirmationTokens().stream().findFirst();
        if (token.isPresent()) {
            // TODO send email
            System.out.println("Link in the email:\n" + "http://localhost:8081/v1/user/token/" + user.getId() + "?token=" + token.get().getId());
        }
    } catch (Exception e) {
        System.out.println("error:" + e.getMessage());
        logger.error("user signup failed:", userDto + " error:" + e.getMessage());
    // TODO handler excption, add log info?
    }
}
Also used : User(com.networknt.portal.usermanagement.model.common.model.user.User) ConfirmationToken(com.networknt.portal.usermanagement.model.common.model.user.ConfirmationToken) UserDto(com.networknt.portal.usermanagement.model.common.domain.UserDto) UserSignUpEvent(com.networknt.portal.usermanagement.model.common.event.UserSignUpEvent) Int128(com.networknt.eventuate.common.Int128) 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 2 with EventHandlerMethod

use of com.networknt.eventuate.common.EventHandlerMethod 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 3 with EventHandlerMethod

use of com.networknt.eventuate.common.EventHandlerMethod in project light-portal by networknt.

the class UserQueryWorkflow method action.

@EventHandlerMethod
public void action(DispatchedEvent<UserConfirmedEvent> de) {
    String id = de.getEntityId();
    String token = de.getEvent().getTokenId();
    System.out.println("token:" + token);
    try {
        User user = service.confirmEmail(token);
    } catch (Exception e) {
        logger.info("Error on active user:", id, e.getMessage());
    }
}
Also used : User(com.networknt.portal.usermanagement.model.common.model.user.User) InvalidEmailException(com.networknt.portal.usermanagement.model.common.exception.InvalidEmailException) NoSuchUserException(com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException) EventHandlerMethod(com.networknt.eventuate.common.EventHandlerMethod)

Aggregations

EventHandlerMethod (com.networknt.eventuate.common.EventHandlerMethod)3 InvalidEmailException (com.networknt.portal.usermanagement.model.common.exception.InvalidEmailException)3 NoSuchUserException (com.networknt.portal.usermanagement.model.common.exception.NoSuchUserException)3 User (com.networknt.portal.usermanagement.model.common.model.user.User)3 UserDto (com.networknt.portal.usermanagement.model.common.domain.UserDto)2 Int128 (com.networknt.eventuate.common.Int128)1 UserSignUpEvent (com.networknt.portal.usermanagement.model.common.event.UserSignUpEvent)1 ConfirmationToken (com.networknt.portal.usermanagement.model.common.model.user.ConfirmationToken)1