Ejemplo n.º 1
0
  /**
   * 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;
  }
 /**
  * Deletes the authorization after removing it from any groups that might be referring to it
  *
  * @param em the entity manager reference
  * @param id the ID for authorizatino entity
  * @throws PersistenceException if there were any errors deleting the authorization
  */
 static void deleteAuthorization(EntityManager em, long id) throws PersistenceException {
   Authorization auth = em.find(Authorization.class, id);
   // may return null, if this entity is not saved, in which
   // case don't do anything.
   if (auth == null) {
     return;
   }
   // Iterate through all groups and remove the authorization from them
   Set<SummaryGroup> groups = auth.getGroups();
   if (groups != null) {
     for (SummaryGroup g : groups) {
       Group group = new SingleGroupQuery(g.getId()).fetch();
       Set<Authorization> auths = group.getAuthorizations();
       HashSet<Authorization> updated = new HashSet<Authorization>();
       for (Authorization a : auths) {
         if (a.getId() != auth.getId()) {
           updated.add(a);
         }
       }
       group.setAuthorizations(updated);
       group.save();
     }
   }
   em.remove(em.getReference(Authorization.class, auth.getId()));
 }
Ejemplo n.º 3
0
 /**
  * Return <code>true</code> if <code>other</code> is the same Group as this object, <code>false
  * </code> otherwise
  *
  * @param obj object to compare to
  * @return <code>true</code> if object passed in represents the same group as this object
  */
 @Override
 public boolean equals(Object obj) {
   if (obj == null) {
     return false;
   }
   Class<?> objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj);
   if (getClass() != objClass) {
     return false;
   }
   final Group other = (Group) obj;
   return this.getID().equals(other.getID());
 }
Ejemplo n.º 4
0
 public static Group findOrCreate(String name) {
   Group it = Group.find("name", name).first();
   if (it == null) {
     it = new Group(name);
   }
   return it;
 }
  public static void update(Long idGroup, List<SqlRow> gpms) {
    Group group = Group.findById(idGroup);
    if (group == null) return;

    Ebean.beginTransaction();
    try {
      deleteForGroup(idGroup);

      Integer i = 1;
      for (SqlRow man : gpms) {
        Profile prof = Profile.lastProfileByGpmId(man.getLong("gpm"));
        if (prof == null) continue;

        CacheClassifier cc =
            new CacheClassifier(
                group,
                i++,
                prof.gpm.idGpm,
                prof.name,
                prof.image,
                (prof.gender == null) ? null : prof.gender.value,
                (prof.relationshipStatus == null) ? null : prof.relationshipStatus.status,
                prof.nFollowers);
        if (cc.name == null || cc.name.isEmpty())
          cc.name = Profile.getLastNotEmptyField(prof.gpm.id, "name");
        cc.save();
      }

      Ebean.commitTransaction();
    } finally {
      Ebean.endTransaction();
    }
  }
Ejemplo n.º 6
0
 public List<Group> getGroups() {
   List<Group> allGroups = Group.findAll();
   List<Group> answer = new ArrayList<Group>();
   for (Group g : allGroups) {
     for (User u : g.members) {
       if (u.equals(this)) {
         answer.add(g);
         break;
       }
     }
   }
   return answer;
 }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
 public void setGroup(Group group) {
   this.group = group;
   if (!group.getClients().contains(this)) group.getClients().add(this);
 }
 public static List<CacheClassifier> findByGroup(Long id) {
   return find.where().eq("group", Group.findById(id)).orderBy("position").findList();
 }