| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.core.organization.entity; | 
  | 17 |  |   | 
  | 18 |  |  import java.util.Date; | 
  | 19 |  |  import java.util.List; | 
  | 20 |  |   | 
  | 21 |  |  import javax.persistence.CascadeType; | 
  | 22 |  |  import javax.persistence.Column; | 
  | 23 |  |  import javax.persistence.Entity; | 
  | 24 |  |  import javax.persistence.Id; | 
  | 25 |  |  import javax.persistence.JoinColumn; | 
  | 26 |  |  import javax.persistence.ManyToOne; | 
  | 27 |  |  import javax.persistence.NamedQueries; | 
  | 28 |  |  import javax.persistence.NamedQuery; | 
  | 29 |  |  import javax.persistence.OneToMany; | 
  | 30 |  |  import javax.persistence.Table; | 
  | 31 |  |  import javax.persistence.Temporal; | 
  | 32 |  |  import javax.persistence.TemporalType; | 
  | 33 |  |   | 
  | 34 |  |  import org.kuali.student.common.util.UUIDHelper; | 
  | 35 |  |  import org.kuali.student.core.entity.AttributeOwner; | 
  | 36 |  |  import org.kuali.student.core.entity.MetaEntity; | 
  | 37 |  |   | 
  | 38 |  |  @Entity | 
  | 39 |  |  @Table(name = "KSOR_ORG_ORG_RELTN") | 
  | 40 |  |  @NamedQueries( { | 
  | 41 |  |                  @NamedQuery(name = "OrgOrgRelation.getAllDescendants", query = "SELECT oor.relatedOrg.id FROM OrgOrgRelation oor " | 
  | 42 |  |                                  + " WHERE oor.org.id = :orgId " | 
  | 43 |  |                                  + "   AND oor.type.orgHierarchy.id = :orgHierarchy" | 
  | 44 |  |                                  + "   AND oor.org.effectiveDate<=CURRENT_TIMESTAMP  " | 
  | 45 |  |                                  + "   AND (oor.org.expirationDate IS NULL OR oor.org.expirationDate>=CURRENT_TIMESTAMP)"), | 
  | 46 |  |                  @NamedQuery(name = "OrgOrgRelation.getAncestors", query = "SELECT oor.org.id FROM OrgOrgRelation oor " | 
  | 47 |  |                                  + " WHERE oor.relatedOrg.id = :orgId " | 
  | 48 |  |                  + "   AND oor.type.orgHierarchy.id = :orgHierarchy" | 
  | 49 |  |                  + "   AND oor.relatedOrg.effectiveDate<=CURRENT_TIMESTAMP  " | 
  | 50 |  |                  + "   AND (oor.relatedOrg.expirationDate IS NULL OR oor.relatedOrg.expirationDate>=CURRENT_TIMESTAMP)"), | 
  | 51 |  |                  @NamedQuery(name = "OrgOrgRelation.getOrgOrgRelationsByIdList", query = "SELECT oor FROM OrgOrgRelation oor WHERE oor.id IN (:idList)"), | 
  | 52 |  |                  @NamedQuery(name = "OrgOrgRelation.OrgOrgRelation", query = "SELECT oor FROM OrgOrgRelation oor WHERE oor.org.id = :orgId"), | 
  | 53 |  |                  @NamedQuery(name = "OrgOrgRelation.getOrgOrgRelationsByRelatedOrg", query = "SELECT oor FROM OrgOrgRelation oor WHERE oor.relatedOrg.id = :relatedOrgId"), | 
  | 54 |  |                  @NamedQuery(name = "OrgOrgRelation.getOrgTreeInfo", query = "SELECT NEW org.kuali.student.core.organization.dto.OrgTreeInfo(oor.relatedOrg.id, oor.org.id, oor.relatedOrg.longName) " | 
  | 55 |  |                                  + "   FROM OrgOrgRelation oor " | 
  | 56 |  |                                  + "  WHERE oor.org.id = :orgId " | 
  | 57 |  |                                  + "    AND oor.type.orgHierarchy.id = :orgHierarchyId "  | 
  | 58 |  |                  + "   AND oor.relatedOrg.effectiveDate<=CURRENT_TIMESTAMP  " | 
  | 59 |  |                  + "   AND (oor.relatedOrg.expirationDate IS NULL OR oor.relatedOrg.expirationDate>=CURRENT_TIMESTAMP)"), | 
  | 60 |  |                  @NamedQuery(name = "OrgOrgRelation.hasOrgOrgRelation", query = "SELECT COUNT(oor) " | 
  | 61 |  |                                  + "  FROM OrgOrgRelation oor " | 
  | 62 |  |                                  + " WHERE oor.org.id = :orgId " | 
  | 63 |  |                                  + "   AND oor.relatedOrg.id = :comparisonOrgId " | 
  | 64 |  |                                  + "   AND oor.type.id = :orgOrgRelationTypeKey") }) | 
  | 65 | 0 |  public class OrgOrgRelation extends MetaEntity implements | 
  | 66 |  |                  AttributeOwner<OrgOrgRelationAttribute> { | 
  | 67 |  |          @Id | 
  | 68 |  |          @Column(name = "ID") | 
  | 69 |  |          private String id; | 
  | 70 |  |   | 
  | 71 |  |          @ManyToOne | 
  | 72 |  |          @JoinColumn(name = "ORG") | 
  | 73 |  |          private Org org; | 
  | 74 |  |   | 
  | 75 |  |          @ManyToOne | 
  | 76 |  |          @JoinColumn(name = "RELATED_ORG") | 
  | 77 |  |          private Org relatedOrg; | 
  | 78 |  |   | 
  | 79 |  |          @Temporal(TemporalType.TIMESTAMP) | 
  | 80 |  |          @Column(name = "EFF_DT") | 
  | 81 |  |          private Date effectiveDate; | 
  | 82 |  |   | 
  | 83 |  |          @Temporal(TemporalType.TIMESTAMP) | 
  | 84 |  |          @Column(name = "EXPIR_DT") | 
  | 85 |  |          private Date expirationDate; | 
  | 86 |  |   | 
  | 87 |  |          @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") | 
  | 88 |  |          private List<OrgOrgRelationAttribute> attributes; | 
  | 89 |  |   | 
  | 90 |  |          @ManyToOne | 
  | 91 |  |          @JoinColumn(name = "TYPE") | 
  | 92 |  |          private OrgOrgRelationType type; | 
  | 93 |  |   | 
  | 94 |  |          @Column(name = "ST") | 
  | 95 |  |          private String state; | 
  | 96 |  |   | 
  | 97 |  |           | 
  | 98 |  |   | 
  | 99 |  |   | 
  | 100 |  |          @Override | 
  | 101 |  |          public void onPrePersist() { | 
  | 102 | 0 |                  this.id = UUIDHelper.genStringUUID(this.id); | 
  | 103 | 0 |          } | 
  | 104 |  |   | 
  | 105 |  |          public String getId() { | 
  | 106 | 0 |                  return id; | 
  | 107 |  |          } | 
  | 108 |  |   | 
  | 109 |  |          public void setId(String id) { | 
  | 110 | 0 |                  this.id = id; | 
  | 111 | 0 |          } | 
  | 112 |  |   | 
  | 113 |  |          public Org getOrg() { | 
  | 114 | 0 |                  return org; | 
  | 115 |  |          } | 
  | 116 |  |   | 
  | 117 |  |          public void setOrg(Org org) { | 
  | 118 | 0 |                  this.org = org; | 
  | 119 | 0 |          } | 
  | 120 |  |   | 
  | 121 |  |          public Org getRelatedOrg() { | 
  | 122 | 0 |                  return relatedOrg; | 
  | 123 |  |          } | 
  | 124 |  |   | 
  | 125 |  |          public void setRelatedOrg(Org relatedOrg) { | 
  | 126 | 0 |                  this.relatedOrg = relatedOrg; | 
  | 127 | 0 |          } | 
  | 128 |  |   | 
  | 129 |  |          public Date getEffectiveDate() { | 
  | 130 | 0 |                  return effectiveDate; | 
  | 131 |  |          } | 
  | 132 |  |   | 
  | 133 |  |          public void setEffectiveDate(Date effectiveDate) { | 
  | 134 | 0 |                  this.effectiveDate = effectiveDate; | 
  | 135 | 0 |          } | 
  | 136 |  |   | 
  | 137 |  |          public Date getExpirationDate() { | 
  | 138 | 0 |                  return expirationDate; | 
  | 139 |  |          } | 
  | 140 |  |   | 
  | 141 |  |          public void setExpirationDate(Date expirationDate) { | 
  | 142 | 0 |                  this.expirationDate = expirationDate; | 
  | 143 | 0 |          } | 
  | 144 |  |   | 
  | 145 |  |          @Override | 
  | 146 |  |          public List<OrgOrgRelationAttribute> getAttributes() { | 
  | 147 | 0 |                  return attributes; | 
  | 148 |  |          } | 
  | 149 |  |   | 
  | 150 |  |          @Override | 
  | 151 |  |          public void setAttributes(List<OrgOrgRelationAttribute> attributes) { | 
  | 152 | 0 |                  this.attributes = attributes; | 
  | 153 | 0 |          } | 
  | 154 |  |   | 
  | 155 |  |          public OrgOrgRelationType getType() { | 
  | 156 | 0 |                  return type; | 
  | 157 |  |          } | 
  | 158 |  |   | 
  | 159 |  |          public void setType(OrgOrgRelationType type) { | 
  | 160 | 0 |                  this.type = type; | 
  | 161 | 0 |          } | 
  | 162 |  |   | 
  | 163 |  |          public String getState() { | 
  | 164 | 0 |                  return state; | 
  | 165 |  |          } | 
  | 166 |  |   | 
  | 167 |  |          public void setState(String state) { | 
  | 168 | 0 |                  this.state = state; | 
  | 169 | 0 |          } | 
  | 170 |  |   | 
  | 171 |  |  } |