public void removeUser(String user) { if (Equals(user, "u1")) { throw new UserException("admin cannot be removed"); } SubscribedUser subscribedUser = DBSubscribedUser.getInstance().getSubscribedUser(user); if (subscribedUser == null) { throw new UserException("user to be removed does not exist"); } try { Session session = dbSession.getSessionOfSubscribedUser(subscribedUser); if (session != null) { if (session.getState() is LoggedIn) { session.logout(); session.setSubscribedUser(null); } } } catch (DoesntExistException) { } LinkedList <StoreRole> toDelete = new LinkedList <StoreRole>(); LinkedList <Store> toDeleteStore = new LinkedList <Store>(); foreach (StoreRole role in subscribedUser.getStoreRoles()) { role.removeAllAppointedBy(); Store store = role.getStore(); SubscribedUser appointedBySubscribedUser = role.getAppointedBy(); toDelete.AddFirst(role); if (appointedBySubscribedUser != null) { StoreRole appointedByStoreRole = store.getStoreRole(role.getAppointedBy()); store.removeStoreRole(role); appointedByStoreRole.removeRoleAppointedByMe(role); } if (role is StoreOwner && role.getStore().getNumberOfOwners() == 1) { closeStore(role.getStore()); } //DBStore.getInstance().removeStoreRole(role); } foreach (StoreRole sr in toDelete) { DBStore.getInstance().removeStoreRole(sr); subscribedUser.removeStoreRole(sr); sr.getStore().removeStoreRole(sr); } dbSubscribedUser.remove(subscribedUser); }
public void removeUser(String user) { if (Equals(user, "admin")) { throw new UserException("admin cannot be removed"); } SubscribedUser subscribedUser = DBSubscribedUser.getInstance().getSubscribedUser(user); if (subscribedUser == null) { throw new UserException("user to be removed does not exist"); } Session session = dbSession.getSessionOfSubscribedUser(subscribedUser); if (session != null) { if (session.getState() is LoggedIn) { session.logout(); } } foreach (StoreRole role in subscribedUser.getStoreRoles()) { role.removeAllAppointedBy(); Store store = role.getStore(); SubscribedUser appointedBySubscribedUser = role.getAppointedBy(); if (appointedBySubscribedUser != null) { StoreRole appointedByStoreRole = store.getStoreRole(role.getAppointedBy()); store.removeStoreRole(appointedByStoreRole); appointedByStoreRole.removeRoleAppointedByMe(role); } if (role is StoreOwner && role.getStore().getNumberOfOwners() == 0) { closeStore(role.getStore()); } DBStore.getInstance().removeStoreRole(role); } session.setSubscribedUser(null); dbSubscribedUser.remove(subscribedUser); }