One fact in one place commit
[aquarium] / src / main / scala / gr / grnet / aquarium / logic / accounting / dsl / DSL.scala
index 32a80fa..dbb5cb0 100644 (file)
@@ -48,29 +48,6 @@ import java.util.Date
  */
 trait DSL {
 
-  /**An empty time frame*/
-  val emptyTimeFrame = DSLTimeFrame(new Date(0), None, List())
-
-  /**An empty resource*/
-  val emptyResource = DSLSimpleResource("", "", OnOffCostPolicy)
-
-  /**An empty algorithm */
-  val emptyAlgorithm = DSLAlgorithm("", None, Map(), emptyTimeFrame)
-
-  /**An empty pricelist */
-  val emptyPriceList = DSLPriceList("", None, Map(), emptyTimeFrame)
-
-  /**An empty creditplan */
-  val emptyCreditPlan = DSLCreditPlan("", None, 0,
-    List(DSLTimeSpec(0, 0, -1, -1, -1)), emptyTimeFrame)
-
-  /**An empty agreement*/
-  val emptyAgreement = DSLAgreement("", None, emptyAlgorithm, emptyPriceList, emptyCreditPlan)
-
-  /**An empty policy*/
-  val emptyPolicy = DSLPolicy(List(emptyAlgorithm), List(emptyPriceList),
-    List(emptyResource), List(emptyCreditPlan), List(emptyAgreement))
-
   /**
    * Parse an InputStream containing an Aquarium DSL algorithm.
    */
@@ -161,7 +138,7 @@ trait DSL {
           case Some(x) => x
           case None => throw new DSLParseException("Cannot find super algorithm %s".format(superName))
         }
-      case YAMLEmptyNode => emptyAlgorithm
+      case YAMLEmptyNode => DSLAlgorithm.emptyAlgorithm
       case _ => throw new DSLParseException("Super algorithm name %s not a string".format())
     }
 
@@ -191,7 +168,7 @@ trait DSL {
         val algo = algorithm / r.name match {
           case x: YAMLStringNode => x.string
           case y: YAMLIntNode => y.int.toString
-          case YAMLEmptyNode => algoTmpl.equals(emptyAlgorithm) match {
+          case YAMLEmptyNode => algoTmpl.equals(DSLAlgorithm.emptyAlgorithm) match {
             case false => algoTmpl.algorithms.getOrElse(r,
               throw new DSLParseException(("Superalgo does not specify an algorithm for resource:%s").format(r.name)))
             case true => throw new DSLParseException(("Cannot find calculation algorithm for resource %s in either " +
@@ -203,7 +180,7 @@ trait DSL {
 
     val timeframe = algorithm / Vocabulary.effective match {
       case x: YAMLMapNode => parseTimeFrame(x)
-      case YAMLEmptyNode => algoTmpl.equals(emptyAlgorithm) match {
+      case YAMLEmptyNode => algoTmpl.equals(DSLAlgorithm.emptyAlgorithm) match {
         case false => algoTmpl.effective
         case true => throw new DSLParseException(("Cannot find effectivity period for algorithm %s ").format(name))
       }
@@ -228,7 +205,7 @@ trait DSL {
           case Some(x) => x
           case None => throw new DSLParseException("Cannot find super pricelist %s".format(superName))
         }
-      case YAMLEmptyNode => emptyPriceList
+      case YAMLEmptyNode => DSLPriceList.emptyPriceList
       case _ => throw new DSLParseException("Super pricelist name %s not a string".format())
     }
 
@@ -261,7 +238,7 @@ trait DSL {
           case y: YAMLIntNode => y.int.toFloat
           case z: YAMLDoubleNode => z.double.toFloat
           case a: YAMLStringNode => a.string.toFloat
-          case YAMLEmptyNode => tmpl.equals(emptyAlgorithm) match {
+          case YAMLEmptyNode => tmpl.equals(DSLAlgorithm.emptyAlgorithm) match {
             case false => tmpl.prices.getOrElse(r,
               throw new DSLParseException(("Superpricelist does not specify a price for resource:%s").format(r.name)))
             case true => throw new DSLParseException(("Cannot find price for resource %s in either pricelist %s or " +
@@ -273,7 +250,7 @@ trait DSL {
 
     val timeframe = pl / Vocabulary.effective match {
       case x: YAMLMapNode => parseTimeFrame(x)
-      case YAMLEmptyNode => tmpl.equals(emptyAlgorithm) match {
+      case YAMLEmptyNode => tmpl.equals(DSLAlgorithm.emptyAlgorithm) match {
         case false => tmpl.effective
         case true => throw new DSLParseException(("Cannot find effectivity period for pricelist %s").format(name))
       }
@@ -295,7 +272,7 @@ trait DSL {
           case Some(x) => x
           case None => throw new DSLParseException("Cannot find super credit plan %s".format(superName))
         }
-      case YAMLEmptyNode => emptyCreditPlan
+      case YAMLEmptyNode => DSLCreditPlan.emptyCreditPlan
       case _ => throw new DSLParseException("Super credit plan name %s not a string".format())
     }
 
@@ -324,6 +301,8 @@ trait DSL {
         "Credit plan does not define repetition specifier")
     }
 
+    val atCron = (plan / Vocabulary.at).asInstanceOf[YAMLStringNode]
+
     val credits = plan / Vocabulary.credits match {
       case x: YAMLIntNode => x.int.toFloat
       case y: YAMLDoubleNode => y.double.toFloat
@@ -333,14 +312,14 @@ trait DSL {
 
     val timeframe = plan / Vocabulary.effective match {
       case x: YAMLMapNode => parseTimeFrame(x)
-      case YAMLEmptyNode => tmpl.equals(emptyCreditPlan) match {
+      case YAMLEmptyNode => tmpl.equals(DSLCreditPlan.emptyCreditPlan) match {
         case false => tmpl.effective
         case true => throw new DSLParseException(
           ("Cannot find effectivity period for creditplan %s").format(name))
       }
     }
 
-    DSLCreditPlan(name, overr, credits, at, timeframe)
+    DSLCreditPlan(name, overr, credits, at, atCron.string, timeframe)
   }
 
   /** Parse top level agreements */
@@ -362,7 +341,7 @@ trait DSL {
            case Some(x) => x
            case None => throw new DSLParseException("Cannot find super agreement %s".format(superName))
          }
-       case YAMLEmptyNode => emptyAgreement
+       case YAMLEmptyNode => DSLAgreement.emptyAgreement
        case _ => throw new DSLParseException("Super agreement name %s not a string".format(superName))
      }
 
@@ -390,13 +369,13 @@ trait DSL {
         case Some(y) => y
         case None => throw new DSLParseException(("Cannot find algorithm named %s").format(x))
       }
-      case y: YAMLMapNode => tmpl.equals(emptyAgreement) match {
+      case y: YAMLMapNode => tmpl.equals(DSLAgreement.emptyAgreement) match {
         case true => throw new DSLParseException(("Incomplete algorithm definition for agreement %s").format(name))
         case false =>
           y.map += ("name" -> YAMLStringNode("/","%s-algorithm".format(name)))
           constructAlgorithm(y, tmpl.algorithm, resources)
       }
-      case YAMLEmptyNode => tmpl.equals(emptyAgreement) match {
+      case YAMLEmptyNode => tmpl.equals(DSLAgreement.emptyAgreement) match {
         case true => throw new DSLParseException(("No algorithm for agreement %s").format(name))
         case false => tmpl.algorithm
       }
@@ -407,13 +386,13 @@ trait DSL {
         case Some(y) => y
         case None => throw new DSLParseException(("Cannot find pricelist named %s").format(x))
       }
-      case y: YAMLMapNode => tmpl.equals(emptyAgreement) match {
+      case y: YAMLMapNode => tmpl.equals(DSLAgreement.emptyAgreement) match {
         case true => throw new DSLParseException(("Incomplete pricelist definition for agreement %s").format(name))
         case false =>
           y.map += ("name" -> YAMLStringNode("/","%s-pricelist".format(name)))
           constructPriceList(y, tmpl.pricelist, resources)
       }
-      case YAMLEmptyNode => tmpl.equals(emptyAgreement) match {
+      case YAMLEmptyNode => tmpl.equals(DSLAgreement.emptyAgreement) match {
         case true => throw new DSLParseException(("No algorithm for agreement %s").format(name))
         case false => tmpl.pricelist
       }
@@ -424,19 +403,19 @@ trait DSL {
         case Some(y) => y
         case None => throw new DSLParseException(("Cannot find crediplan named %s").format(x))
       }
-      case y: YAMLMapNode => tmpl.equals(emptyAgreement) match {
+      case y: YAMLMapNode => tmpl.equals(DSLAgreement.emptyAgreement) match {
         case true => throw new DSLParseException(("Incomplete creditplan definition for agreement %s").format(name))
         case false =>
           y.map += ("name" -> YAMLStringNode("/","%s-pricelist".format(name)))
           constructCreditPlan(y, tmpl.creditplan)
       }
-      case YAMLEmptyNode => tmpl.equals(emptyAgreement) match {
+      case YAMLEmptyNode => tmpl.equals(DSLAgreement.emptyAgreement) match {
         case true => throw new DSLParseException(("No creditplan for agreement %s").format(name))
         case false => tmpl.creditplan
       }
     }
 
-    val overrides = tmpl.equals(emptyAgreement) match {
+    val overrides = tmpl.equals(DSLAgreement.emptyAgreement) match {
       case true => Some(tmpl)
       case false => None
     }