public User editUser(Long userId, String password, long bitmap) {
    if (password.isEmpty()) {
      return null;
    }

    Privileges privileges = new Privileges(bitmap);
    EntityTransaction transaction = startSaveTransaction();

    User user = getUserById(userId);
    if (user != null) {
      user.setPassword(password);
      user.setCategoryRead(privileges.isCategoryRead());
      user.setCategoryWrite(privileges.isCategoryWrite());
      user.setCategoryDelete(privileges.isCategoryDelete());
      user.setItemRead(privileges.isItemRead());
      user.setItemWrite(privileges.isItemWrite());
      user.setItemDelete(privileges.isItemDelete());
      user.setItemCommentRead(privileges.isItemCommentRead());
      user.setItemCommentWrite(privileges.isItemCommentWrite());
      user.setItemCommentDelete(privileges.isItemCommentDelete());
      user.setUserPromote(privileges.isUserPromote());
      user.setUserDemote(privileges.isUserDemote());
      user.setUserDelete(privileges.isUserDelete());
    }

    try {
      entityManager.persist(user);
      transaction.commit();
      return user;
    } catch (Exception e) {
      transaction.rollback();
    }

    return null;
  }
  public User createUser(String username, String password, long bitmap) {
    if (username.isEmpty() || password.isEmpty()) {
      return null;
    }

    Privileges privileges = new Privileges(bitmap);
    EntityTransaction transaction = startSaveTransaction();

    User user =
        new User(
            username,
            password,
            privileges.isCategoryRead(),
            privileges.isCategoryWrite(),
            privileges.isCategoryDelete(),
            privileges.isItemRead(),
            privileges.isItemWrite(),
            privileges.isItemDelete(),
            privileges.isItemCommentRead(),
            privileges.isItemCommentWrite(),
            privileges.isItemCommentDelete(),
            privileges.isUserPromote(),
            privileges.isUserDemote(),
            privileges.isUserDelete());

    try {
      entityManager.persist(user);
      transaction.commit();
      return user;
    } catch (Exception e) {
      transaction.rollback();
    }

    return null;
  }