View Javadoc

1   package org.kuali.student.r2.common.entity;
2   
3   import javax.persistence.Column;
4   import javax.persistence.JoinColumn;
5   import javax.persistence.ManyToOne;
6   import javax.persistence.MappedSuperclass;
7   import javax.persistence.Table;
8   import javax.persistence.UniqueConstraint;
9   
10  import org.kuali.student.r1.common.entity.KSEntityConstants;
11  import org.kuali.student.r2.common.dto.AttributeInfo;
12  import org.kuali.student.r2.common.infc.Attribute;
13  
14  @MappedSuperclass
15  // 9/06/2012 nwright commented this out as the contract DOES specify that you can have 2 entries with the same key
16  // This was a deliberate change from how R1 Dynamic Attributes worked at the request of an implementing institution 
17  // The design change was to allow dynamic attributes could implement a list of values more naturally by repeating keys
18  //
19  // Also constraints defined here as annotations have no effect except on unit tests because this 
20  // constraint does not exist in the schemas created by DBAs and generated via IMPEX
21  // this would make the unit tests be out of sync with the actual implementation
22  //@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"ATTR_KEY", "OWNER_ID"})})
23  public abstract class BaseAttributeEntity<T extends AttributeOwner<?>> extends BaseEntity {
24  
25      @Column(name = "ATTR_KEY")
26      private String key;
27  
28      @Column(name = "ATTR_VALUE", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
29      private String value;
30  
31      @ManyToOne
32      @JoinColumn (name="OWNER_ID")
33      private T owner;
34  
35      public BaseAttributeEntity() {}
36  
37  
38      public BaseAttributeEntity(Attribute att, T owner) {
39          this.setId(att.getId());
40  
41          this.fromDto(att);
42  
43          this.owner = owner;
44      }
45  
46      public String getKey() {
47          return key;
48      }
49  
50      public void setKey(String key) {
51          this.key = key;
52      }
53  
54      public String getValue() {
55          return value;
56      }
57  
58      public void setValue(String value) {
59          this.value = value;
60      }
61  
62  
63  
64      public T getOwner() {
65  		return owner;
66  	}
67  
68  
69  	public void setOwner(T owner) {
70  		this.owner = owner;
71  	}
72  
73  
74      public AttributeInfo toDto() {
75          AttributeInfo attributeInfo = new AttributeInfo();
76          attributeInfo.setId(this.getId());
77          attributeInfo.setKey(this.getKey());
78          attributeInfo.setValue(this.getValue());
79          return attributeInfo;
80      }
81  
82      public void fromDto(Attribute info) {
83  
84      	setKey(info.getKey());
85      	setValue(info.getValue());
86  	}
87  
88      @Override
89  	public String toString() {
90  		StringBuilder builder = new StringBuilder();
91  		builder.append("BaseAttributeEntityNew [id=");
92  		builder.append(getId());
93  		builder.append(", key=");
94  		builder.append(key);
95  		builder.append(", value=");
96  		builder.append(value);
97  		builder.append(", owner=");
98  		builder.append(owner);
99  		builder.append("]");
100 		return builder.toString();
101     }
102 
103 }