@Override public void delete(Session session) { // Delete links from this to each parent if (getParentOrgLinks() != null) { for (SubOrg so : getParentOrgLinks()) { session.delete(so); } setParentOrgLinks(null); } if (getWebsites() != null) { for (Website w : getWebsites()) { w.delete(session); } } setWebsites(null); if (getGroups() != null) { for (Group g : getGroups()) { g.delete(false, session); // do a hard delete } } for (Organisation childOrg : childOrgs()) { childOrg.delete(session); } session.delete(this); Organisation parent = getOrganisation(); if (parent != null) { parent.getChildOrgs().remove(this); session.save(parent); } }
/** * Create a GroupMembership linking this profile to the given group, within the given * organisation. Is immediately saved * * <p>If a duplicate membership exists an exception is thrown * * <p>Check for existing membership by calling getGroupMembership(group, hasGruopInOrg, session) * * @param g * @param hasGroupInOrg * @param session * @return */ public GroupMembership createGroupMembership( Group g, Organisation hasGroupInOrg, Session session) { GroupMembership gm = getGroupMembership(g, hasGroupInOrg, session); if (gm != null) { return gm; } gm = new GroupMembership(); gm.setCreatedDate(new Date()); gm.setGroupEntity(g); gm.setMember(this); gm.setWithinOrg(hasGroupInOrg); gm.setModifiedDate(new Date()); session.save(gm); if (g.getGroupMemberships() == null) { g.setGroupMemberships(new ArrayList<GroupMembership>()); } g.getGroupMemberships().add(gm); // Need to create a subordinate record for each parent organisation Organisation subordinateTo = hasGroupInOrg; while (subordinateTo != null) { createSubordinate(subordinateTo, gm, session); subordinateTo = subordinateTo.getOrganisation(); } if (getMemberships() == null) { setMemberships(new ArrayList<GroupMembership>()); } getMemberships().add(gm); return gm; }
public Group group(Long id, Session session) { for (Group g : groups(session)) { if (g.getId() == id) { return g; } } return null; }
/** * Recursive method, goes up through parent orgs to find the group * * @param groupName * @param session * @return */ public Group group(String groupName, Session session) { for (Group g : groups(session)) { if (g.getName().equals(groupName)) { return g; } } return null; }
/** * Creates and adds to this Org's groups, but does not save * * @param newName * @return */ public Group createGroup(String newName) { Group g = new Group(); g.setName(newName); g.setOrganisation(this); g.setCreatedDate(new Date()); g.setModifiedDate(new Date()); if (this.getGroups() == null) { this.setGroups(new ArrayList<>()); } getGroups().add(g); return g; }
public GroupMembership getGroupMembership(Group g, Organisation hasGroupInOrg, Session session) { if (getMemberships() != null) { for (GroupMembership gm : getMemberships()) { if (gm.getGroupEntity().getId() == g.getId()) { // same group if (gm.getWithinOrg().getId() == hasGroupInOrg.getId()) { // and same org, so its a duplicate return gm; } } } } return null; }
public List<Group> groups(Session session) { return Group.findByOrg(this, session); }