Added REST functionality for the Bill. RabbitMQProducer was refined. UserActor sends...
[aquarium] / src / main / scala / gr / grnet / aquarium / charging / bill / BillEntry.scala
1 package gr.grnet.aquarium.charging.bill
2
3 import gr.grnet.aquarium.charging.state.WorkingUserState
4 import gr.grnet.aquarium.util.json.JsonSupport
5 import com.ckkloverdos.resource.FileStreamResource
6 import java.io.File
7 import com.ckkloverdos.props.Props
8 import gr.grnet.aquarium.converter.{PrettyJsonTextFormat, StdConverters}
9 import gr.grnet.aquarium.{Aquarium, ResourceLocator, AquariumBuilder}
10 import gr.grnet.aquarium.store.memory.MemStoreProvider
11 import gr.grnet.aquarium.converter.StdConverters._
12 import scala.Some
13 import gr.grnet.aquarium.logic.accounting.dsl.Timeslot
14
15 /*
16 * Copyright 2011-2012 GRNET S.A. All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or
19 * without modification, are permitted provided that the following
20 * conditions are met:
21 *
22 *   1. Redistributions of source code must retain the above
23 *      copyright notice, this list of conditions and the following
24 *      disclaimer.
25 *
26 *   2. Redistributions in binary form must reproduce the above
27 *      copyright notice, this list of conditions and the following
28 *      disclaimer in the documentation and/or other materials
29 *      provided with the distribution.
30 *
31 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
32 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
35 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
38 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
39 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
41 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGE.
43 *
44 * The views and conclusions contained in the software and
45 * documentation are those of the authors and should not be
46 * interpreted as representing official policies, either expressed
47 * or implied, of GRNET S.A.
48 */
49
50
51 /*
52 * @author Prodromos Gerakios <pgerakios@grnet.gr>
53 */
54
55 class EventEntry(id:String,
56                  eventType:String,
57                  unitPrice:String,
58                  startTime:String,
59                  endTime:String,
60                  ellapsedTime:String,
61                  credits:String) extends JsonSupport {
62
63 }
64
65 class ResourceEntry(val resourceName : String,
66                     val resourceType : String,
67                     val unitName : String,
68                     val totalCredits : String,
69                     val details : List[EventEntry]) extends JsonSupport {
70
71 }
72
73 class BillEntry(val id:String,
74                 val userID : String,
75                 val status : String,
76                 val remainingCredits:String,
77                 val deductedCredits:String,
78                 val startTime:String,
79                 val endTime:String,
80                 val bill:List[ResourceEntry]
81               )  extends JsonSupport {
82
83 }
84
85 object BillEntry {
86   def fromWorkingUserState(t:Timeslot,w:Option[WorkingUserState]) : BillEntry = {
87     //TODO: get entries at timeslot "t"
88     val eventEntry = new EventEntry("1234","onOff","0.1","323232323","3232223456","10000","5.00")
89     val resourceEntry = new ResourceEntry("VM_1","vmtime","0.01","5.0",List(eventEntry))
90     new BillEntry("323232","loverdos@grnet.gr","ok","100.00","5.00","23023020302","23232323",
91                   List(resourceEntry))
92   }
93
94   //
95   def main(args: Array[String]) = {
96     //Console.err.println("JSON: " +  (new BillEntry).toJsonString)
97     val propsfile = new FileStreamResource(new File("a1.properties"))
98     var _props: Props = Props(propsfile)(StdConverters.AllConverters).getOr(Props()(StdConverters.AllConverters))
99     val aquarium = new AquariumBuilder(_props, ResourceLocator.DefaultPolicyModel).
100       update(Aquarium.EnvKeys.storeProvider, new MemStoreProvider).
101       update(Aquarium.EnvKeys.eventsStoreFolder,Some(new File(".."))).
102       build()
103     aquarium.start()
104     ()
105   }
106 }