public User editUserPrivileges(Long userId, long bitmap, User currentUser) { User user = getUserById(userId); EntityTransaction transaction = null; if (user != null && currentUser != null) { if (!currentUser.isUserPromote() && !currentUser.isUserDemote()) { return null; } Privileges privileges = new Privileges(bitmap); transaction = startSaveTransaction(); 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; }