@Override
    public boolean deleteUser(final UserRef userRef) {
        Objects.requireNonNull(userRef);
        final Integer userCount = JooqUtil.transactionResult(securityDbConnProvider, txnContext -> {
            final String userInfoStr = userRef.toInfoString();
            final String userUuid = userRef.getUuid();

            final User user = getByUuid(txnContext, userUuid)
                    .orElseThrow(() -> new RuntimeException(LogUtil.message(
                            "User {} does not exist", userInfoStr)));

            // First ensure the stroom_user_archive record is up-to-date before we delete
            // the user, so we have the latest picture of the various names of the user.
            insertOrUpdateStroomUserArchiveRecord(txnContext, userUuid);

            // Now remove the user from any groups it is a member of
            int count = txnContext.deleteFrom(STROOM_USER_GROUP)
                    .where(STROOM_USER_GROUP.USER_UUID.eq(userUuid))
                    .execute();
            LOGGER.debug("Removed {} group memberships for user {}", count, userInfoStr);

            count = appPermissionDaoImpl.deletePermissionsForUser(txnContext, userUuid);
            LOGGER.debug("Removed {} app permission records for user {}", count, userInfoStr);

            count = documentPermissionDaoImpl.deletePermissionsForUser(txnContext, userUuid);
            LOGGER.debug("Removed {} doc permission records for user {}", count, userInfoStr);

            count = apiKeyDaoImpl.deleteByOwner(txnContext, userUuid);
            LOGGER.debug("Removed {} API key records for user {}", count, userInfoStr);

            count = txnContext.deleteFrom(STROOM_USER)
                    .where(STROOM_USER.UUID.eq(userUuid))
                    .execute();
            LOGGER.debug("Deleted {} record(s) for user {}", count, userInfoStr);

            if (count == 0 || count > 1) {
                throw new RuntimeException(LogUtil.message(
                        "Deleted {} records for user {} but expected to delete exactly one.", count, userInfoStr));
            }

            LOGGER.info("Deleted user - subjectId: '{}', displayName: '{}', userUuid: {}",
                    user.getSubjectId(), user.getDisplayName(), userUuid);
            return count;
        });
        return userCount > 0;
    }
IMPORTANT - This must be called after any insert/update to STROOM_USER (and
as part of the same txn) to ensure STROOM_USER_ARCHIVE is up-to-date.
NOT to be called after a delete statement as we want to preserve the details
of deleted users.
stroom-security/stroom-security-impl-db/src/main/java/stroom/security/impl/db/UserDaoImpl.java