Coverage Report - org.kuali.student.enrollment.class2.courseofferingset.model.SocRolloverResultEntity
 
Classes in this File Line Coverage Branch Coverage Complexity
SocRolloverResultEntity
0%
0/88
0%
0/22
1.444
 
 1  
 package org.kuali.student.enrollment.class2.courseofferingset.model;
 2  
 
 3  
 import org.kuali.student.common.entity.KSEntityConstants;
 4  
 import org.kuali.student.r2.common.dto.AttributeInfo;
 5  
 import org.kuali.student.r2.common.entity.MetaEntity;
 6  
 import org.kuali.student.r2.common.infc.Attribute;
 7  
 import org.kuali.student.r2.common.util.RichTextHelper;
 8  
 
 9  
 import javax.persistence.CascadeType;
 10  
 import javax.persistence.Column;
 11  
 import javax.persistence.Entity;
 12  
 import javax.persistence.OneToMany;
 13  
 import javax.persistence.Table;
 14  
 import java.util.ArrayList;
 15  
 import java.util.List;
 16  
 import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultInfo;
 17  
 import org.kuali.student.enrollment.courseofferingset.infc.SocRolloverResult;
 18  
 
 19  
 @Entity
 20  
 @Table(name = "KSEN_SOC_ROR")
 21  
 public class SocRolloverResultEntity extends MetaEntity {
 22  
 
 23  
     @Column(name = "SOC_ROR_TYPE", nullable = false)
 24  
     private String socRorType;
 25  
     @Column(name = "SOC_ROR_STATE", nullable = false)
 26  
     private String socRorState;
 27  
     @Column(name = "TARGET_TERM_ID")
 28  
     private String targetTermId;
 29  
     @Column(name = "ITEMS_PROCESSED")
 30  
     private Integer itemsProcessed;
 31  
     @Column(name = "ITEMS_EXPECTED")
 32  
     private Integer itemsExpected;
 33  
     @Column(name = "SOURCE_SOC_ID")
 34  
     private String sourceSocId;
 35  
     @Column(name = "TARGET_SOC_ID")
 36  
     private String targetSocId;
 37  
     @Column(name = "MESG_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
 38  
     private String mesgFormatted;
 39  
     @Column(name = "MESG_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
 40  
     private String mesgPlain;
 41  0
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "socRolloverResult")
 42  
     private List<SocRolloverResultOptionEntity> options = new ArrayList<SocRolloverResultOptionEntity>();
 43  0
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
 44  
     private List<SocRolloverResultAttributeEntity> attributes = new ArrayList<SocRolloverResultAttributeEntity>();
 45  
 
 46  0
     public SocRolloverResultEntity() {
 47  0
     }
 48  
 
 49  
     public SocRolloverResultEntity(SocRolloverResult socRolloverResult) {
 50  0
         super(socRolloverResult);
 51  0
         this.setId(socRolloverResult.getId());
 52  0
         this.setSocRorType(socRolloverResult.getTypeKey());
 53  0
         this.fromDTO(socRolloverResult);
 54  0
     }
 55  
 
 56  
     public void fromDTO(SocRolloverResult socRolloverResult) {
 57  0
         this.setSocRorState(socRolloverResult.getStateKey());
 58  0
         this.setSourceSocId(socRolloverResult.getSourceSocId());
 59  0
         this.setTargetSocId(socRolloverResult.getTargetSocId());
 60  0
         this.setTargetTermId(socRolloverResult.getTargetTermId());
 61  
         // TODO: store the option keys
 62  0
         this.setItemsProcessed(socRolloverResult.getItemsProcessed());
 63  0
         this.setItemsExpected(socRolloverResult.getItemsExpected());
 64  0
         if (socRolloverResult.getMessage() != null) {
 65  0
             this.setMesgFormatted(socRolloverResult.getMessage().getFormatted());
 66  0
             this.setMesgPlain(socRolloverResult.getMessage().getPlain());
 67  
         } else {
 68  0
             this.setMesgFormatted(null);
 69  0
             this.setMesgPlain(null);
 70  
         }
 71  
         // Add any new options to the list of options
 72  
         // Deletes of options has to occur in the updateRolloverResult method because it needs access to the entity
 73  0
         for (String optionKey : socRolloverResult.getOptionKeys()) {
 74  0
             if (!alreadyExists(optionKey)) {
 75  0
                 this.getOptions().add(new SocRolloverResultOptionEntity(optionKey, this));
 76  
             }
 77  
         }
 78  0
         this.setAttributes(new ArrayList<SocRolloverResultAttributeEntity>());
 79  0
         for (Attribute att : socRolloverResult.getAttributes()) {
 80  0
             this.getAttributes().add(new SocRolloverResultAttributeEntity(att, this));
 81  
         }
 82  0
     }
 83  
 
 84  
     private boolean alreadyExists(String optionKey) {
 85  0
         for (SocRolloverResultOptionEntity optionEntity : this.getOptions()) {
 86  0
             if (optionEntity.getOptionId().equals(optionKey)) {
 87  0
                 return true;
 88  
             }
 89  
         }
 90  0
         return false;
 91  
     }
 92  
 
 93  
     public SocRolloverResultInfo toDto() {
 94  0
         SocRolloverResultInfo socRolloverResult = new SocRolloverResultInfo();
 95  0
         socRolloverResult.setId(getId());
 96  0
         socRolloverResult.setTypeKey(socRorType);
 97  0
         socRolloverResult.setStateKey(socRorState);
 98  0
         socRolloverResult.setSourceSocId(sourceSocId);
 99  0
         socRolloverResult.setTargetTermId(targetTermId);
 100  
         // TODO: load the option keys
 101  0
         socRolloverResult.setTargetSocId(targetSocId);
 102  0
         socRolloverResult.setItemsExpected(itemsExpected);
 103  0
         socRolloverResult.setItemsProcessed(itemsProcessed);
 104  0
         socRolloverResult.setMessage(new RichTextHelper().toRichTextInfo(getMesgPlain(), getMesgFormatted()));
 105  0
         if (getOptions() != null) {
 106  0
             for (SocRolloverResultOptionEntity optionEntity : getOptions()) {
 107  0
                 String optionKey = optionEntity.getOptionId();
 108  0
                 socRolloverResult.getOptionKeys().add(optionKey);
 109  0
             }
 110  
         }
 111  0
         socRolloverResult.setMeta(super.toDTO());
 112  0
         if (getAttributes() != null) {
 113  0
             for (SocRolloverResultAttributeEntity att : getAttributes()) {
 114  0
                 AttributeInfo attInfo = att.toDto();
 115  0
                 socRolloverResult.getAttributes().add(attInfo);
 116  0
             }
 117  
         }
 118  0
         return socRolloverResult;
 119  
     }
 120  
 
 121  
     public List<SocRolloverResultAttributeEntity> getAttributes() {
 122  0
         return attributes;
 123  
     }
 124  
 
 125  
     public void setAttributes(List<SocRolloverResultAttributeEntity> attributes) {
 126  0
         this.attributes = attributes;
 127  0
     }
 128  
 
 129  
     public Integer getItemsExpected() {
 130  0
         return itemsExpected;
 131  
     }
 132  
 
 133  
     public void setItemsExpected(Integer itemsExpected) {
 134  0
         this.itemsExpected = itemsExpected;
 135  0
     }
 136  
 
 137  
     public Integer getItemsProcessed() {
 138  0
         return itemsProcessed;
 139  
     }
 140  
 
 141  
     public void setItemsProcessed(Integer itemsProcessed) {
 142  0
         this.itemsProcessed = itemsProcessed;
 143  0
     }
 144  
 
 145  
     public String getMesgFormatted() {
 146  0
         return mesgFormatted;
 147  
     }
 148  
 
 149  
     public void setMesgFormatted(String mesgFormatted) {
 150  0
         this.mesgFormatted = mesgFormatted;
 151  0
     }
 152  
 
 153  
     public String getMesgPlain() {
 154  0
         return mesgPlain;
 155  
     }
 156  
 
 157  
     public void setMesgPlain(String mesgPlain) {
 158  0
         this.mesgPlain = mesgPlain;
 159  0
     }
 160  
 
 161  
     public String getSocRorState() {
 162  0
         return socRorState;
 163  
     }
 164  
 
 165  
     public void setSocRorState(String socRorState) {
 166  0
         this.socRorState = socRorState;
 167  0
     }
 168  
 
 169  
     public String getSocRorType() {
 170  0
         return socRorType;
 171  
     }
 172  
 
 173  
     public void setSocRorType(String socRorType) {
 174  0
         this.socRorType = socRorType;
 175  0
     }
 176  
 
 177  
     public String getSourceSocId() {
 178  0
         return sourceSocId;
 179  
     }
 180  
 
 181  
     public void setSourceSocId(String sourceSocId) {
 182  0
         this.sourceSocId = sourceSocId;
 183  0
     }
 184  
 
 185  
     public String getTargetSocId() {
 186  0
         return targetSocId;
 187  
     }
 188  
 
 189  
     public void setTargetSocId(String targetSocId) {
 190  0
         this.targetSocId = targetSocId;
 191  0
     }
 192  
 
 193  
     public String getTargetTermId() {
 194  0
         return targetTermId;
 195  
     }
 196  
 
 197  
     public void setTargetTermId(String targetTermId) {
 198  0
         this.targetTermId = targetTermId;
 199  0
     }
 200  
 
 201  
     public List<SocRolloverResultOptionEntity> getOptions() {
 202  0
         if (this.options == null) {
 203  0
             this.options = new ArrayList<SocRolloverResultOptionEntity>();
 204  
         }
 205  0
         return options;
 206  
     }
 207  
 
 208  
     public void setOptions(List<SocRolloverResultOptionEntity> options) {
 209  0
         this.options = options;
 210  0
     }
 211  
 }