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);
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) {
// TODO handler excption, add log info?
}
String result;
if (userResult == null) {
result = "no user changed;";
} else {
result = Config.getInstance().getMapper().writeValueAsString(service.toUserDto(userResult));
}
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
exchange.getResponseSender().send(result);
// exchange.endExchange();
}
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);
String result = "Ok!";
try {
User user = service.fromUserDto(userDto);
service.signup(user, userDto.getPassword(), false);
// TODO remove the following implemetation after confirm email implemented
Optional<ConfirmationToken> token = user.getConfirmationTokens().stream().findFirst();
if (token.isPresent()) {
result = "http://localhost:8080/v1/user/token/" + token.get().getId();
}
} catch (Exception e) {
result = e.getMessage();
// TODO handler excption, add log info?
}
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(result));
// exchange.endExchange();
}
use of com.networknt.portal.usermanagement.model.common.domain.UserDto in project light-portal by networknt.
the class UserIdPutHandlerTest method testUserIdPutHandlerTestUserUpdate.
@Test
public void testUserIdPutHandlerTestUserUpdate() 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.setHost("google");
userDto.setPassword("12345678");
userDto.getContactData().setFirstName("test1");
userDto.getContactData().setLastName("bbb1");
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);
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);
}
use of com.networknt.portal.usermanagement.model.common.domain.UserDto in project light-portal by networknt.
the class UserPostHandlerTest method testUserPostHandlerTest.
@Test
public void testUserPostHandlerTest() 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.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);
String json = JSonMapper.toJson(userDto);
System.out.println(json);
try {
ClientRequest request = new ClientRequest().setPath("/v1/user").setMethod(Methods.POST);
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);
Assert.assertEquals(200, statusCode);
Assert.assertNotNull(body);
}
use of com.networknt.portal.usermanagement.model.common.domain.UserDto 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?
}
}
Aggregations