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