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?
}
}
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());
}
Aggregations