Search in sources :

Example 1 with UserSignUpEvent

use of com.networknt.portal.usermanagement.model.common.event.UserSignUpEvent 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 UserSignUpEvent

use of com.networknt.portal.usermanagement.model.common.event.UserSignUpEvent in project light-portal by networknt.

the class UserQueryWorkFlowTest method testCreateEvent.

/*

    public static DataSource ds;

    static {
        ds = (DataSource) SingletonServiceFactory.getBean(DataSource.class);
        try (Connection connection = ds.getConnection()) {
            // Runscript doesn't work need to execute batch here.
            String schemaResourceName = "/user_management_ddl.sql";
            InputStream in = UserQueryWorkFlowTest.class.getResourceAsStream(schemaResourceName);

            if (in == null) {
                throw new RuntimeException("Failed to load resource: " + schemaResourceName);
            }
            InputStreamReader reader = new InputStreamReader(in);
            RunScript.execute(connection, reader);

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    private UserRepository userRepository = (UserRepository) SingletonServiceFactory.getBean(UserRepository.class);
    private static PasswordSecurity passwordSecurity = (PasswordSecurity)SingletonServiceFactory.getBean(PasswordSecurity.class);
    private UserService service = new UserServiceImpl(passwordSecurity, null, userRepository);



    @Test
    public void testCreate() {
        UserDto userDto = new UserDto("aaa.bbb@gmail.com", "testUser");
        userDto.setHost("google");
        userDto.setPassword("12345678");
        userDto.getContactData().setFirstName("test2");
        userDto.getContactData().setLastName("bbb2");
        userDto.getContactData().setGender(Gender.MALE);
        AddressData address = new AddressData();
        address.setCountry(Country.CA);
        address.setState(State.AK);
        address.setCity("BaBa");
        address.setAddressType(AddressType.SHIPPING);
        address.setAddressLine1("222 Bay Street");
        userDto.getContactData().addAddresses(address);
        try {
            User user = service.fromUserDto(userDto, "2222-3333-5555-6666");
            service.signup(user, userDto.getPassword());
            //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:8080/v1/user/token/" + user.getId() + "?token=" + token.get().getId());
            }

        } catch (Exception e) {
            System.out.println("error:" + e.getMessage());

            //TODO handler excption, add log info?
        }

    }
*/
@Test
public void testCreateEvent() throws Exception {
    String eventType = "com.networknt.portal.usermanagement.model.common.event.UserSignUpEvent";
    Class<Event> eventClass = toEventClass(eventType);
    String str = "{\"userDto\":{\"screenName\":\"testUser\",\"contactData\":{\"email\":\"aaa.bbb@gmail.com\",\"firstName\":\"test2\",\"lastName\":\"bbb2\",\"addresses\":[{\"country\":\"CA\",\"state\":\"AK\",\"city\":\"BaBa\",\"addressLine1\":\"222 Bay Street\",\"addressType\":\"SHIPPING\"}],\"gender\":\"MALE\"},\"timezone\":\"CANADA_EASTERN\",\"locale\":\"English (Canada)\",\"password\":\"12345678\",\"host\":\"google\",\"emailChange\":false,\"passwordReset\":false,\"screenNameChange\":false}}";
    System.out.println(str);
    UserSignUpEvent event1 = JSonMapper.fromJson(str, (Class<UserSignUpEvent>) Class.forName(eventType));
    System.out.println(event1.toString());
    System.out.println(event1.getUserDto());
    Assert.assertNotNull(event1.getUserDto().getHost());
}
Also used : UserSignUpEvent(com.networknt.portal.usermanagement.model.common.event.UserSignUpEvent) Event(com.networknt.eventuate.common.Event) EndOfCurrentEventsReachedEvent(com.networknt.eventuate.common.EndOfCurrentEventsReachedEvent) UserSignUpEvent(com.networknt.portal.usermanagement.model.common.event.UserSignUpEvent) Test(org.junit.Test)

Aggregations

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