001 package edu.nrao.sss.model.project.scheduling; 002 003 import java.util.ArrayList; 004 import java.util.List; 005 006 import edu.nrao.sss.validation.AbstractValidator; 007 import edu.nrao.sss.validation.FailureSeverity; 008 import edu.nrao.sss.validation.Validation; 009 import edu.nrao.sss.validation.ValidationPurpose; 010 011 /** 012 * A validator of SchedTimes. 013 * slovelan 014 */ 015 016 public class SchedTimeValidator extends AbstractValidator<SchedTime>{ 017 018 /** 019 * Creates a new instance. 020 */ 021 public SchedTimeValidator(){ 022 super(SchedTimeValidator.class.getName(), SchedTime.class); 023 } 024 025 /* (non-Javadoc) 026 * @see AbstractValidator#makeValidationList(ValidationPurpose) 027 */ 028 @Override 029 protected List<Validation<SchedTime>> makeValidationList(ValidationPurpose purpose){ 030 List<Validation<SchedTime>> validations = new ArrayList<Validation<SchedTime>>(); 031 validations.add(new DayValidator (this, purpose)); 032 validations.add(new HourValidator (this, purpose)); 033 return validations; 034 } 035 036 037 private class DayValidator extends Validation<SchedTime>{ 038 039 private long minimumDay = 0; 040 private long tDay = 0; 041 042 protected DayValidator(AbstractValidator<SchedTime> validationContainer, 043 ValidationPurpose reasonForValidation ){ 044 super(validationContainer, reasonForValidation); 045 046 severity = (reasonForValidation == ValidationPurpose.CERTIFY_READY_TO_USE) ? 047 FailureSeverity.ERROR : FailureSeverity.WARNING; 048 } 049 050 /** 051 * This test is passed if the day and the hour is reasonable 052 */ 053 054 @Override 055 protected boolean passesTest(){ 056 minimumDay = ( long ) SchedTime.currentLSTTime(); 057 boolean passes = true; 058 tDay = target.getDay(); 059 if ( tDay < minimumDay ){ 060 passes = false; 061 } 062 return passes; 063 } 064 065 /* (non-Javadoc) 066 * @see edu.nrao.sss.validation.Validation#displayMessage() 067 */ 068 @Override 069 protected String displayMessage(){ 070 StringBuilder buff = new StringBuilder("The schedule time does not have a reasonable value. "); 071 String dayMinimum = "The LST day number must be at least "+minimumDay+"."; 072 if (purpose == ValidationPurpose.CERTIFY_READY_TO_USE){ 073 buff.append( dayMinimum ); 074 buff.append( "Please change the LST day number."); 075 } 076 else { 077 buff.append( dayMinimum ); 078 buff.append("This is fine for now, but you will to eventually change the day."); 079 } 080 return buff.toString(); 081 } 082 083 /* (non-Javadoc) 084 * @see edu.nrao.sss.validation.Validation#debugMessage() 085 */ 086 @Override 087 protected String debugMessage(){ 088 StringBuilder buff = new StringBuilder("SchedTime '"); 089 buff.append(" has incorrect day format: " + tDay ); 090 return buff.toString(); 091 } 092 } 093 094 private class HourValidator extends Validation<SchedTime>{ 095 096 private float minimumHour = 0; 097 private float maximumHour = SchedTime.HOURS_PER_LST_DAY; 098 private double tHours = 0; 099 100 protected HourValidator(AbstractValidator<SchedTime> validationContainer, 101 ValidationPurpose reasonForValidation ){ 102 super(validationContainer, reasonForValidation); 103 104 severity = (reasonForValidation == ValidationPurpose.CERTIFY_READY_TO_USE) ? 105 FailureSeverity.ERROR : FailureSeverity.WARNING; 106 } 107 108 /** 109 * This test is passed if the day and the hour is reasonable 110 */ 111 112 @Override 113 protected boolean passesTest(){ 114 boolean passes = true; 115 tHours = target.getHour(); 116 if ( tHours < minimumHour || tHours > maximumHour ){ 117 passes = false; 118 } 119 return passes; 120 } 121 122 /* (non-Javadoc) 123 * @see edu.nrao.sss.validation.Validation#displayMessage() 124 */ 125 @Override 126 protected String displayMessage(){ 127 StringBuilder buff = new StringBuilder("The schedule time does not have a reasonable value. "); 128 String dayMinimum = "The hour must be at least "+minimumHour+" and less than "+maximumHour; 129 if (purpose == ValidationPurpose.CERTIFY_READY_TO_USE){ 130 buff.append( dayMinimum ); 131 buff.append( "Please change the hour field."); 132 } 133 else { 134 buff.append( dayMinimum ); 135 buff.append("This is fine for now, but you will to eventually change the hour."); 136 } 137 return buff.toString(); 138 } 139 140 /* (non-Javadoc) 141 * @see edu.nrao.sss.validation.Validation#debugMessage() 142 */ 143 @Override 144 protected String debugMessage(){ 145 StringBuilder buff = new StringBuilder("SchedTime '"); 146 buff.append(" has incorrect day format: " + tHours); 147 return buff.toString(); 148 } 149 } 150 151 152 }