Search in sources :

Example 1 with UserUpdateEvent

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;
}
Also used : UserUpdateEvent(de.symeda.sormas.backend.user.event.UserUpdateEvent) User(de.symeda.sormas.backend.user.User)

Example 2 with UserUpdateEvent

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);
    }
}
Also used : UserUpdateEvent(de.symeda.sormas.backend.user.event.UserUpdateEvent)

Example 3 with UserUpdateEvent

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));
    }
}
Also used : UserUpdateEvent(de.symeda.sormas.backend.user.event.UserUpdateEvent) User(de.symeda.sormas.backend.user.User) PasswordResetEvent(de.symeda.sormas.backend.user.event.PasswordResetEvent)

Example 4 with UserUpdateEvent

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));
    }
}
Also used : UserUpdateEvent(de.symeda.sormas.backend.user.event.UserUpdateEvent) UserRoleValidationException(de.symeda.sormas.api.user.UserRole.UserRoleValidationException) ValidationException(javax.validation.ValidationException)

Example 5 with UserUpdateEvent

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;
}
Also used : UserSyncResult(de.symeda.sormas.api.user.UserSyncResult) UserUpdateEvent(de.symeda.sormas.backend.user.event.UserUpdateEvent)

Aggregations

UserUpdateEvent (de.symeda.sormas.backend.user.event.UserUpdateEvent)6 UserRoleValidationException (de.symeda.sormas.api.user.UserRole.UserRoleValidationException)2 User (de.symeda.sormas.backend.user.User)2 ValidationException (javax.validation.ValidationException)2 UserSyncResult (de.symeda.sormas.api.user.UserSyncResult)1 PasswordResetEvent (de.symeda.sormas.backend.user.event.PasswordResetEvent)1 UserCreateEvent (de.symeda.sormas.backend.user.event.UserCreateEvent)1