public void closeStoreRoles(Store store) { List <StoreRole> roles = store.getRoles(); foreach (StoreRole role in roles) { SubscribedUser sub = role.getUser(); sub.removeStoreRole(role); } }
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 remove(SubscribedUser role) { StoreRole sr = role.getStoreRole(store); if (sr == null) { throw new RoleException("user " + role.getUsername() + " doesn't have a role in store " + store.getStoreName()); } if (sr.getAppointedBy() != this.userName) { throw new RoleException("Error: User " + userName.getUsername() + " didn't appoint " + role.getUsername()); } DBStore.getInstance().removeStoreRole(sr); role.removeStoreRole(sr); store.removeStoreRole(sr); }