use of de.symeda.sormas.backend.user.event.UserUpdateEvent in project SORMAS-Project by hzi-braunschweig.
the class StartupShutdownService method createAndPersistDefaultUser.
private User createAndPersistDefaultUser(UserRole userRole, String firstName, String lastName, DataHelper.Pair<String, String> usernameAndPassword, Consumer<User> userModificator) {
User user = MockDataGenerator.createUser(userRole, firstName, lastName, usernameAndPassword.getElement1());
user.setUserName(usernameAndPassword.getElement0());
userModificator.accept(user);
userService.persist(user);
userUpdateEvent.fire(new UserUpdateEvent(user));
return user;
}
use of de.symeda.sormas.backend.user.event.UserUpdateEvent in project SORMAS-Project by hzi-braunschweig.
the class StartupShutdownService method syncUser.
/**
* Triggers the user sync asynchronously to not block the deployment step
*/
private void syncUser(User user) {
String shortUuid = DataHelper.getShortUuid(user.getUuid());
logger.debug("Synchronizing user {}", shortUuid);
try {
UserUpdateEvent event = new UserUpdateEvent(user);
event.setExceptionCallback(exceptionMessage -> logger.error("Could not synchronize user {} due to {}", shortUuid, exceptionMessage));
this.userUpdateEvent.fireAsync(event);
} catch (Throwable e) {
logger.error(MessageFormat.format("Unexpected exception when synchronizing user {0}", shortUuid), e);
}
}
use of de.symeda.sormas.backend.user.event.UserUpdateEvent in project SORMAS-Project by hzi-braunschweig.
the class StartupShutdownService method createOrUpdateDefaultUser.
private void createOrUpdateDefaultUser(Set<UserRole> userRoles, String username, String password, String firstName, String lastName) {
if (StringUtils.isAnyBlank(username, password)) {
logger.debug("Invalid user details. Will not create/update default user");
return;
}
User existingUser = userService.getByUserName(username);
if (existingUser == null) {
if (!DataHelper.isNullOrEmpty(password)) {
User newUser = MockDataGenerator.createUser(userRoles, firstName, lastName, password);
newUser.setUserName(username);
userService.persist(newUser);
userUpdateEvent.fire(new UserUpdateEvent(newUser));
}
} else if (!DataHelper.equal(existingUser.getPassword(), PasswordHelper.encodePassword(password, existingUser.getSeed()))) {
existingUser.setSeed(PasswordHelper.createPass(16));
existingUser.setPassword(PasswordHelper.encodePassword(password, existingUser.getSeed()));
userService.persist(existingUser);
passwordResetEvent.fire(new PasswordResetEvent(existingUser));
}
}
use of de.symeda.sormas.backend.user.event.UserUpdateEvent in project SORMAS-Project by hzi-braunschweig.
the class UserFacadeEjb method updateActiveState.
private void updateActiveState(List<String> userUuids, boolean active) {
List<User> users = userService.getByUuids(userUuids);
for (User user : users) {
User oldUser;
try {
oldUser = (User) BeanUtils.cloneBean(user);
} catch (Exception e) {
throw new IllegalArgumentException("Invalid bean access", e);
}
user.setActive(active);
userService.ensurePersisted(user);
userUpdateEvent.fire(new UserUpdateEvent(oldUser, user));
}
}
use of de.symeda.sormas.backend.user.event.UserUpdateEvent in project SORMAS-Project by hzi-braunschweig.
the class UserFacadeEjb method syncUser.
@Override
public UserSyncResult syncUser(String uuid) {
User user = userService.getByUuid(uuid);
UserSyncResult userSyncResult = new UserSyncResult();
userSyncResult.setSuccess(true);
UserUpdateEvent event = new UserUpdateEvent(user);
event.setExceptionCallback(exceptionMessage -> {
userSyncResult.setSuccess(false);
userSyncResult.setErrorMessage(exceptionMessage);
});
this.userUpdateEvent.fire(event);
return userSyncResult;
}
Aggregations