Example #1
0
 public Organisation createChildOrg(String orgId, String title, Session session) {
   Organisation o = new Organisation();
   o.setOrganisation(this);
   if (orgId != null) {
     orgId = orgId.trim();
     if (orgId.length() == 0) {
       orgId = null;
     }
   }
   o.setOrgId(orgId);
   o.setTitle(title);
   o.setCreatedDate(new Date());
   o.setModifiedDate(new Date());
   if (this.getChildOrgs() == null) {
     this.setChildOrgs(new ArrayList<>());
   }
   this.getChildOrgs().add(o);
   session.save(o);
   if (o.getOrgId() == null || o.getOrgId().trim().length() == 0) {
     findUniqueOrgId(o, session);
     session.save(o);
   }
   SubOrg.updateSubOrgs(o, session);
   return o;
 }
Example #2
0
  /**
   * Updates the organisation reference and also any SubOrg links
   *
   * @param newParent
   * @param session
   */
  public void setOrganisation(Organisation newParent, Session session) {
    log.info("setOrganisation: this=" + getOrgId());
    Organisation oldParent = this.getOrganisation();
    if (oldParent != null) {
      oldParent.getChildOrgs().remove(this);
    }
    if (newParent != null) {
      if (newParent.getChildOrgs() == null) {
        newParent.setChildOrgs(new ArrayList<Organisation>());
      }
      newParent.getChildOrgs().add(this);
    }

    this.organisation = newParent;

    if (oldParent != null && oldParent != newParent) {
      log.info("update subs");
      SubOrg.updateSubOrgs(this, SessionManager.session());
    }
    if (oldParent != null) {
      session.save(oldParent);
    }
    if (newParent != null) {
      session.save(newParent);
    }
    session.save(this);
    log.info("finished move");
  }