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
16
17
18
19
20
21
22
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 }