Coverage Report - org.kuali.student.r2.core.class1.state.model.StateEntity
 
Classes in this File Line Coverage Branch Coverage Complexity
StateEntity
0%
0/55
0%
0/6
1.167
 
 1  
 package org.kuali.student.r2.core.class1.state.model;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.Date;
 5  
 import java.util.List;
 6  
 
 7  
 import javax.persistence.CascadeType;
 8  
 import javax.persistence.Column;
 9  
 import javax.persistence.Entity;
 10  
 import javax.persistence.OneToMany;
 11  
 import javax.persistence.Table;
 12  
 import javax.persistence.Temporal;
 13  
 import javax.persistence.TemporalType;
 14  
 
 15  
 import org.kuali.student.common.entity.KSEntityConstants;
 16  
 import org.kuali.student.r2.common.dto.AttributeInfo;
 17  
 import org.kuali.student.r2.common.entity.MetaEntity;
 18  
 import org.kuali.student.r2.common.infc.Attribute;
 19  
 import org.kuali.student.r2.common.util.RichTextHelper;
 20  
 import org.kuali.student.r2.core.state.dto.StateInfo;
 21  
 import org.kuali.student.r2.core.state.infc.State;
 22  
 
 23  
 @Entity
 24  
 @Table(name = "KSEN_STATE")
 25  
 // TODO: Uncomment when/if we figure out if we store xxx_KEY as such in the DB instead of as ID
 26  
 //@AttributeOverrides({
 27  
 //    @AttributeOverride(name = "id", column =
 28  
 //    @Column(name = "STATE_KEY"))})
 29  
 public class StateEntity extends MetaEntity {
 30  
 
 31  
     @Column(name = "NAME")
 32  
     private String name;
 33  
     @Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH, nullable=false)
 34  
     private String descrPlain;
 35  
     @Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
 36  
     private String descrFormatted;
 37  
     // TODO: consider storing this as a related JPA entity instead of as a string
 38  
     @Column(name = "LIFECYCLE_KEY")
 39  
     private String lifecycleKey;
 40  
     @Temporal(TemporalType.TIMESTAMP)
 41  
     @Column(name = "EFF_DT")
 42  
     private Date effectiveDate;
 43  
     @Temporal(TemporalType.TIMESTAMP)
 44  
     @Column(name = "EXPIR_DT")
 45  
     private Date expirationDate;
 46  
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
 47  
     private List<StateAttributeEntity> attributes;
 48  
 
 49  
     public String getName() {
 50  0
         return name;
 51  
     }
 52  
 
 53  
     public void setName(String name) {
 54  0
         this.name = name;
 55  0
     }
 56  
 
 57  
     public String getDescrFormatted() {
 58  0
         return descrFormatted;
 59  
     }
 60  
 
 61  
     public void setDescrFormatted(String descrFormatted) {
 62  0
         this.descrFormatted = descrFormatted;
 63  0
     }
 64  
 
 65  
     public String getDescrPlain() {
 66  0
         return descrPlain;
 67  
     }
 68  
 
 69  
     public void setDescrPlain(String descrPlain) {
 70  0
         this.descrPlain = descrPlain;
 71  0
     }
 72  
 
 73  
     public String getLifecycleKey() {
 74  0
         return lifecycleKey;
 75  
     }
 76  
 
 77  
     public void setLifecycleKey(String lifecycleKey) {
 78  0
         this.lifecycleKey = lifecycleKey;
 79  0
     }
 80  
 
 81  
     
 82  
     public Date getEffectiveDate() {
 83  0
         return effectiveDate;
 84  
     }
 85  
 
 86  
     public void setEffectiveDate(Date effectiveDate) {
 87  0
         this.effectiveDate = effectiveDate;
 88  0
     }
 89  
 
 90  
     public Date getExpirationDate() {
 91  0
         return expirationDate;
 92  
     }
 93  
 
 94  
     public void setExpirationDate(Date expirationDate) {
 95  0
         this.expirationDate = expirationDate;
 96  0
     }
 97  
 
 98  
     public List<StateAttributeEntity> getAttributes() {
 99  0
         return attributes;
 100  
     }
 101  
 
 102  
     public void setAttributes(List<StateAttributeEntity> attributes) {
 103  0
         this.attributes = attributes;
 104  0
     }
 105  
 
 106  0
     public StateEntity() {
 107  0
     }
 108  
 
 109  
     public StateEntity(State state) {
 110  0
         super();
 111  0
         this.setId(state.getKey());
 112  0
         this.lifecycleKey = state.getLifecycleKey();
 113  0
         this.fromDto(state);
 114  0
     }
 115  
 
 116  
     public void fromDto(State state) {
 117  0
         this.setName(state.getName());
 118  0
         if (state.getDescr() == null) {
 119  0
             this.descrPlain = null;
 120  0
             this.descrFormatted = null;
 121  
         } else {
 122  0
             this.descrPlain = state.getDescr().getPlain();
 123  0
             this.descrFormatted = state.getDescr().getFormatted();
 124  
         }
 125  0
         this.effectiveDate = state.getEffectiveDate();
 126  0
         this.expirationDate = state.getExpirationDate();
 127  0
         this.setAttributes(new ArrayList<StateAttributeEntity>());
 128  0
         for (Attribute att : state.getAttributes()) {
 129  0
             StateAttributeEntity attEntity = new StateAttributeEntity(att, this);
 130  0
             this.getAttributes().add(attEntity);
 131  0
         }
 132  0
     }
 133  
 
 134  
     public StateInfo toDto() {
 135  0
         StateInfo info = new StateInfo();
 136  0
         info.setKey(getId());
 137  0
         info.setLifecycleKey(lifecycleKey);
 138  0
         info.setName(name);
 139  0
         info.setDescr(new RichTextHelper().toRichTextInfo(descrPlain, descrFormatted));
 140  0
         info.setEffectiveDate(effectiveDate);
 141  0
         info.setExpirationDate(expirationDate);
 142  0
         info.setMeta(super.toDTO());
 143  0
         for (StateAttributeEntity att : getAttributes()) {
 144  0
             AttributeInfo attInfo = att.toDto();
 145  0
             info.getAttributes().add(attInfo);
 146  0
         };
 147  0
         return info;
 148  
     }
 149  
 }