Coverage Report - org.kuali.student.r2.core.class1.enumerationmanagement.model.EnumerationEntity
 
Classes in this File Line Coverage Branch Coverage Complexity
EnumerationEntity
0%
0/50
0%
0/10
1.333
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.r2.core.class1.enumerationmanagement.model;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import javax.persistence.AttributeOverride;
 22  
 import javax.persistence.AttributeOverrides;
 23  
 import javax.persistence.CascadeType;
 24  
 import javax.persistence.Column;
 25  
 import javax.persistence.Entity;
 26  
 import javax.persistence.OneToMany;
 27  
 import javax.persistence.Table;
 28  
 
 29  
 import org.kuali.student.common.entity.KSEntityConstants;
 30  
 import org.kuali.student.r2.common.dto.AttributeInfo;
 31  
 import org.kuali.student.r2.common.dto.RichTextInfo;
 32  
 import org.kuali.student.r2.common.entity.AttributeOwner;
 33  
 import org.kuali.student.r2.common.entity.MetaEntity;
 34  
 import org.kuali.student.r2.common.infc.Attribute;
 35  
 import org.kuali.student.r2.core.enumerationmanagement.dto.EnumerationInfo;
 36  
 import org.kuali.student.r2.core.enumerationmanagement.infc.Enumeration;
 37  
 
 38  
 @Entity
 39  
 @Table(name = "KSEN_ENUM_T")
 40  
 @AttributeOverrides({
 41  
     @AttributeOverride(name="id", column=@Column(name="ENUM_KEY"))})
 42  
 public class EnumerationEntity extends MetaEntity implements AttributeOwner<EnumerationAttributeEntity> {
 43  
 
 44  
     @Column(name = "NAME")
 45  
     private String name;
 46  
 
 47  
     @Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
 48  
     private String formatted;
 49  
 
 50  
     @Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH, nullable = false)
 51  
     private String plain;
 52  
     
 53  
     @Column(name = "ENUM_TYPE", nullable = false)
 54  
     private String enumerationType;
 55  
 
 56  
     @Column(name = "ENUM_STATE", nullable = false)
 57  
     private String enumerationState;
 58  
 
 59  0
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
 60  
     private List<EnumerationAttributeEntity> attributes = new ArrayList<EnumerationAttributeEntity>();
 61  
 
 62  0
     public EnumerationEntity() {}
 63  
 
 64  
     public EnumerationEntity(Enumeration enumeration) {
 65  0
         super(enumeration);
 66  0
         this.setId(enumeration.getKey());
 67  0
         this.setName(enumeration.getName());
 68  0
         if (enumeration.getDescr() != null) {
 69  0
             this.setDescrFormatted(enumeration.getDescr().getFormatted());
 70  0
             this.setDescrPlain(enumeration.getDescr().getPlain());
 71  
         }
 72  0
         if (enumeration.getStateKey() != null) {
 73  0
             this.setEnumerationState(enumeration.getStateKey());
 74  
         }
 75  0
         this.setAttributes(new ArrayList<EnumerationAttributeEntity>());
 76  0
         if (null != enumeration.getAttributes()) {
 77  0
             for (Attribute att : enumeration.getAttributes()) {
 78  0
                 this.getAttributes().add(new EnumerationAttributeEntity(att, this));
 79  
             }
 80  
         }
 81  0
     }
 82  
 
 83  
     public String getName() {
 84  0
         return name;
 85  
     }
 86  
 
 87  
     public void setName(String name) {
 88  0
         this.name = name;
 89  0
     }
 90  
 
 91  
     public String getDescrFormatted() {
 92  0
         return formatted;
 93  
     }
 94  
 
 95  
     public void setDescrFormatted(String formatted) {
 96  0
         this.formatted = formatted;
 97  0
     }
 98  
 
 99  
     public String getDescrPlain() {
 100  0
         return plain;
 101  
     }
 102  
 
 103  
     public void setDescrPlain(String plain) {
 104  0
         this.plain = plain;
 105  0
     }
 106  
     
 107  
     public String getEnumerationType() {
 108  0
         return enumerationType;
 109  
     }
 110  
 
 111  
     public void setEnumerationType(String enumerationType) {
 112  0
         this.enumerationType = enumerationType;
 113  0
     }
 114  
 
 115  
     public String getEnumerationState() {
 116  0
         return enumerationState;
 117  
     }
 118  
 
 119  
     public void setEnumerationState(String enumerationState) {
 120  0
         this.enumerationState = enumerationState;
 121  0
     }
 122  
 
 123  
     @Override
 124  
     public void setAttributes(List<EnumerationAttributeEntity> attributes) {
 125  0
         this.attributes = attributes;
 126  0
     }
 127  
 
 128  
     @Override
 129  
     public List<EnumerationAttributeEntity> getAttributes() {
 130  0
         return attributes;
 131  
     }
 132  
 
 133  
     public EnumerationInfo toDto() {
 134  0
         EnumerationInfo enumeration = new EnumerationInfo();
 135  0
         enumeration.setKey(getId());
 136  0
         enumeration.setName(name);
 137  0
         enumeration.setTypeKey(enumerationType);
 138  0
         enumeration.setStateKey(enumerationState);
 139  0
         enumeration.setMeta(super.toDTO());
 140  
 
 141  0
         RichTextInfo rti = new RichTextInfo();
 142  0
         rti.setPlain(getDescrPlain());
 143  0
         rti.setFormatted(getDescrFormatted());
 144  0
         enumeration.setDescr(rti);
 145  
 
 146  0
         List<AttributeInfo> enumerations = new ArrayList<AttributeInfo>();
 147  0
         for (EnumerationAttributeEntity att : getAttributes()) {
 148  0
             AttributeInfo attInfo = att.toDto();
 149  0
             enumerations.add(attInfo);
 150  0
         }
 151  0
         enumeration.setAttributes(enumerations);
 152  
         
 153  0
         return enumeration;
 154  
     }
 155  
 
 156  
 }