Coverage Report - pt.digitalis.dif.dem.objects.parameters.constraints.impl.date.ParameterConstraintDateInFutureImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ParameterConstraintDateInFutureImpl
0%
0/18
0%
0/12
4,333
 
 1  0
 /**
 2  
  * 2010, Digitalis Informatica. All rights reserved. Distribuicao e Gestao de Informatica, Lda. Estrada de Paco de Arcos
 3  
  * num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999 http://www.digitalis.pt
 4  
  */
 5  
 
 6  
 package pt.digitalis.dif.dem.objects.parameters.constraints.impl.date;
 7  
 
 8  
 import java.text.ParseException;
 9  
 import java.util.Calendar;
 10  
 import java.util.Date;
 11  
 
 12  
 import pt.digitalis.dif.dem.interfaces.IStageInstance;
 13  
 import pt.digitalis.utils.common.DateUtils;
 14  
 
 15  
 /**
 16  
  * Date in Future parameter constraint implementation.<br>
 17  
  * Will validate if the given date is in the future as it is mandatory.
 18  
  * 
 19  
  * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a><br/>
 20  
  * @created 2010/09/14
 21  
  */
 22  0
 public class ParameterConstraintDateInFutureImpl extends ParameterConstraintDateImpl {
 23  
 
 24  
     /**
 25  
      * @param value
 26  
      *            the date to see if it's in the future
 27  
      * @return T if the given date is not before the current one
 28  
      */
 29  
     private boolean isDateInFuture(Date value)
 30  
     {
 31  0
         Calendar calendarValue = Calendar.getInstance();
 32  0
         calendarValue.setTime(value);
 33  
 
 34  0
         return !Calendar.getInstance().after(calendarValue);
 35  
     }
 36  
 
 37  
     /**
 38  
      * @see pt.digitalis.dif.dem.objects.parameters.constraints.impl.date.ParameterConstraintDateImpl#validateConstraint(java.lang.Object,
 39  
      *      pt.digitalis.dif.dem.interfaces.IStageInstance)
 40  
      */
 41  
     @Override
 42  
     public boolean validateConstraint(Object value, IStageInstance stageInstance)
 43  
     {
 44  0
         if (value == null)
 45  0
             return true;
 46  0
         else if (value instanceof Date)
 47  
         {
 48  0
             lastTestedValue = DateUtils.simpleDateToString((Date) value);
 49  0
             return isDateInFuture((Date) value);
 50  
         }
 51  0
         else if (value instanceof String)
 52  0
             return this.validateConstraint(value.toString(), stageInstance);
 53  
         else
 54  0
             return false;
 55  
     }
 56  
 
 57  
     /**
 58  
      * @see pt.digitalis.dif.dem.objects.parameters.constraints.impl.date.ParameterConstraintDateImpl#validateConstraint(java.lang.String,
 59  
      *      pt.digitalis.dif.dem.interfaces.IStageInstance)
 60  
      */
 61  
     @Override
 62  
     public boolean validateConstraint(String value, IStageInstance stageInstance)
 63  
     {
 64  0
         if (super.validateConstraint(value, stageInstance))
 65  
         {
 66  
             try
 67  
             {
 68  0
                 return isDateInFuture(DateUtils.stringToSimpleDate(value));
 69  
             }
 70  0
             catch (ParseException e)
 71  
             {
 72  0
                 return false;
 73  
             }
 74  
         }
 75  
         else
 76  0
             return false;
 77  
     }
 78  
 }