Coverage Report - org.kuali.student.r2.core.class1.atp.model.MilestoneEntity
 
Classes in this File Line Coverage Branch Coverage Complexity
MilestoneEntity
0%
0/100
0%
0/20
1.455
 
 1  
 package org.kuali.student.r2.core.class1.atp.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.atp.dto.MilestoneInfo;
 21  
 import org.kuali.student.r2.core.atp.infc.Milestone;
 22  
 import org.kuali.student.r2.core.class1.atp.service.impl.DateUtil;
 23  
 
 24  
 @Entity
 25  
 @Table(name = "KSEN_MSTONE")
 26  
 public class MilestoneEntity extends MetaEntity {
 27  
 
 28  
     @Column(name = "NAME")
 29  
     private String name;
 30  
 
 31  
     @Temporal(TemporalType.TIMESTAMP)
 32  
     @Column(name = "START_DT", nullable = false)
 33  
     private Date startDate;
 34  
 
 35  
     @Temporal(TemporalType.TIMESTAMP)
 36  
     @Column(name = "END_DT", nullable = true)
 37  
     private Date endDate;
 38  
 
 39  
     @Column(name = "MSTONE_TYPE", nullable = false)
 40  
     private String atpType;
 41  
 
 42  
     @Column(name = "MSTONE_STATE", nullable = false)
 43  
     private String atpState;
 44  
 
 45  
     @Column(name = "IS_ALL_DAY", nullable = false)
 46  
     private boolean isAllDay;
 47  
 
 48  
     @Column(name = "IS_INSTRCT_DAY", nullable = false)
 49  
     private boolean isInstructionalDay;
 50  
 
 51  
     @Column(name = "IS_DATE_RANGE", nullable = false)
 52  
     private boolean isDateRange;
 53  
 
 54  
     @Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
 55  
     private String descrFormatted;
 56  
 
 57  
     @Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH, nullable = false)
 58  
     private String descrPlain;
 59  
 
 60  
     @Column(name = "IS_RELATIVE", nullable = false)
 61  
     private boolean isRelative;
 62  
 
 63  
     @Column(name = "RELATIVE_ANCHOR_MSTONE_ID")
 64  
     private String relativeAnchorMilestoneId;
 65  
 
 66  
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
 67  
     private List<MilestoneAttributeEntity> attributes;
 68  
 
 69  0
     public MilestoneEntity() {
 70  0
     }
 71  
 
 72  
     public MilestoneEntity(Milestone milestone) {
 73  0
         super(milestone);
 74  0
         this.setId(milestone.getId());
 75  0
         this.atpType = milestone.getTypeKey();
 76  0
         this.fromDto(milestone);
 77  0
     }
 78  
 
 79  
     private boolean defaultFalse(Boolean b) {
 80  0
         if (b == null) {
 81  0
             return false;
 82  
         }
 83  0
         return b.booleanValue();
 84  
     }
 85  
 
 86  
     private String toYN(Boolean flag) {
 87  0
         if (flag == null) {
 88  0
             return null;
 89  
         }
 90  0
         if (flag) {
 91  0
             return "Y";
 92  
         }
 93  0
         return "N";
 94  
     }
 95  
 
 96  
     private Boolean toBoolean(String flag) {
 97  0
         if (flag == null) {
 98  0
             return false;
 99  
         }
 100  0
         if (flag.equals("Y")) {
 101  0
             return true;
 102  
         }
 103  0
         return false;
 104  
     }
 105  
 
 106  
     public String getName() {
 107  0
         return name;
 108  
     }
 109  
 
 110  
     public void setName(String name) {
 111  0
         this.name = name;
 112  0
     }
 113  
 
 114  
     public Date getStartDate() {
 115  0
         return startDate;
 116  
     }
 117  
 
 118  
     public void setStartDate(Date startDate) {
 119  0
         this.startDate = startDate;
 120  0
     }
 121  
 
 122  
     public Date getEndDate() {
 123  0
         return endDate;
 124  
     }
 125  
 
 126  
     public void setEndDate(Date endDate) {
 127  0
         this.endDate = endDate;
 128  0
     }
 129  
 
 130  
     public String getAtpType() {
 131  0
         return atpType;
 132  
     }
 133  
 
 134  
     public void setAtpType(String atpType) {
 135  0
         this.atpType = atpType;
 136  0
     }
 137  
 
 138  
     public String getAtpState() {
 139  0
         return atpState;
 140  
     }
 141  
 
 142  
     public void setAtpState(String atpState) {
 143  0
         this.atpState = atpState;
 144  0
     }
 145  
 
 146  
     public boolean isAllDay() {
 147  0
         return isAllDay;
 148  
     }
 149  
 
 150  
     public void setAllDay(boolean isAllDay) {
 151  0
         this.isAllDay = isAllDay;
 152  0
     }
 153  
 
 154  
     public boolean isDateRange() {
 155  0
         return isDateRange;
 156  
     }
 157  
 
 158  
     public void setDateRange(boolean isDateRange) {
 159  0
         this.isDateRange = isDateRange;
 160  0
     }
 161  
 
 162  
     public boolean isRelative() {
 163  0
         return isRelative;
 164  
     }
 165  
 
 166  
     public void setRelative(boolean relative) {
 167  0
         isRelative = relative;
 168  0
     }
 169  
 
 170  
     public String getRelativeAnchorMilestoneId() {
 171  0
         return relativeAnchorMilestoneId;
 172  
     }
 173  
 
 174  
     public void setRelativeAnchorMilestoneId(String relativeAnchorMilestoneId) {
 175  0
         this.relativeAnchorMilestoneId = relativeAnchorMilestoneId;
 176  0
     }
 177  
 
 178  
     public void setAttributes(List<MilestoneAttributeEntity> attributes) {
 179  0
         this.attributes = attributes;
 180  0
     }
 181  
 
 182  
     public List<MilestoneAttributeEntity> getAttributes() {
 183  0
         return attributes;
 184  
     }
 185  
 
 186  
     public String getDescrFormatted() {
 187  0
         return descrFormatted;
 188  
     }
 189  
 
 190  
     public void setDescrFormatted(String formatted) {
 191  0
         this.descrFormatted = formatted;
 192  0
     }
 193  
 
 194  
     public String getDescrPlain() {
 195  0
         return descrPlain;
 196  
     }
 197  
 
 198  
     public void setDescrPlain(String plain) {
 199  0
         this.descrPlain = plain;
 200  0
     }
 201  
 
 202  
     public boolean getIsInstructionalDay() {
 203  0
         return isInstructionalDay;
 204  
     }
 205  
 
 206  
     public void setIsInstructionalDay(boolean isInstructionalDay) {
 207  0
         this.isInstructionalDay = isInstructionalDay;
 208  0
     }
 209  
     
 210  
 
 211  
     public void fromDto(Milestone milestone) {
 212  0
         boolean allDay = defaultFalse(milestone.getIsAllDay());
 213  0
         this.setAllDay(allDay);
 214  0
         this.setIsInstructionalDay(defaultFalse(milestone.getIsInstructionalDay()));
 215  0
         boolean dateRange = defaultFalse(milestone.getIsDateRange());
 216  0
         this.setDateRange(dateRange);
 217  0
         this.setRelative(defaultFalse(milestone.getIsRelative()));
 218  0
         this.relativeAnchorMilestoneId = milestone.getRelativeAnchorMilestoneId();
 219  0
         this.atpState = milestone.getStateKey();
 220  0
         this.name = milestone.getName();
 221  0
         if (milestone.getDescr() != null) {
 222  0
             this.descrFormatted = milestone.getDescr().getFormatted();
 223  0
             this.descrPlain = milestone.getDescr().getPlain();
 224  
         } else {
 225  0
             this.descrFormatted = null;
 226  0
             this.descrPlain = null;
 227  
         }
 228  
 //      For explanation See https://wiki.kuali.org/display/STUDENT/Storing+and+Querying+Milestone+Dates
 229  0
         this.startDate = DateUtil.startOfDayfIsAllDay (allDay, milestone.getStartDate());
 230  0
         this.endDate = DateUtil.endOfDayIfIsAllDay (allDay, DateUtil.nullIfNotDateRange(dateRange, milestone.getEndDate()));
 231  0
         this.attributes = new ArrayList<MilestoneAttributeEntity>();
 232  0
         if (null != milestone.getAttributes()) {
 233  0
             for (Attribute att : milestone.getAttributes()) {
 234  0
                 this.attributes.add(new MilestoneAttributeEntity(att, this));
 235  
             }
 236  
         }
 237  0
     }
 238  
 
 239  
     public MilestoneInfo toDto() {
 240  0
         MilestoneInfo info = new MilestoneInfo();
 241  0
         info.setId(getId());
 242  0
         info.setName(getName());
 243  0
         info.setTypeKey(atpType);
 244  0
         info.setStateKey(atpState);
 245  0
         info.setStartDate(getStartDate());
 246  0
         info.setEndDate(getEndDate());
 247  0
         info.setIsAllDay(isAllDay());
 248  0
         info.setIsDateRange(isDateRange());
 249  0
         info.setIsInstructionalDay(getIsInstructionalDay());
 250  0
         info.setIsRelative(isRelative());
 251  0
         info.setRelativeAnchorMilestoneId(relativeAnchorMilestoneId);
 252  0
         info.setMeta(super.toDTO());
 253  0
         info.setDescr(new RichTextHelper().toRichTextInfo(descrPlain, descrFormatted));
 254  0
         if (attributes != null) {
 255  0
             for (MilestoneAttributeEntity att : getAttributes()) {
 256  0
                 AttributeInfo attInfo = att.toDto();
 257  0
                 info.getAttributes().add(attInfo);
 258  0
             }
 259  
         }
 260  
 
 261  0
         return info;
 262  
     }
 263  
 }