diff --git a/MavLift/pom.xml b/MavLift/pom.xml index e4978186..4f8094d3 100644 --- a/MavLift/pom.xml +++ b/MavLift/pom.xml @@ -6,11 +6,11 @@ 4.0.0 com.tesobe - test_scala_281_lift_23 + opan_bank 1.0 war - test_scala_281_lift_23 Project - 2010 + Opan Bank + 2011 2.9.1 @@ -80,8 +80,8 @@ org.scala-tools.testing - specs_2.8.1 - 1.6.6 + specs_2.9.1 + 1.6.9 test @@ -98,78 +98,42 @@ test - - + - - - - com.foursquare - rogue_2.9.1 - 1.0.24 - - - - com.mongodb.casbah - casbah_2.9.0-1 - 2.1.5-1 - pom - - - - net.sf.opencsv - opencsv - 2.3 - + + net.liftweb + lift-mongodb_2.9.1 + 2.4 + - + + net.liftweb + lift-mongodb-record_2.9.1 + 2.4 + + + +com.mongodb.casbah +casbah_${scala.version} +2.1.5-1 +compile +pom + - - @@ -225,17 +189,7 @@ import net.liftweb.amqp._ - + net.sf.alchim yuicompressor-maven-plugin diff --git a/MavLift/src/main/scala/code/model/MongoConfig.scala b/MavLift/src/main/scala/code/model/MongoConfig.scala index 740b6d38..4930a430 100644 --- a/MavLift/src/main/scala/code/model/MongoConfig.scala +++ b/MavLift/src/main/scala/code/model/MongoConfig.scala @@ -15,7 +15,7 @@ object MongoConfig { Props.get("mongo.host", "obp_mongod"), Props.getInt("mongo.port", 27017) ) - MongoDB.defineDb(DefaultMongoIdentifier, new Mongo(srvr), "OBP005") + MongoDB.defineDb(DefaultMongoIdentifier, new Mongo(srvr), "OBP006") MongoDB.defineDb(AdminDb, new Mongo(srvr), "admin") } } diff --git a/MavLift/src/main/scala/code/model/OBPTransaction.scala b/MavLift/src/main/scala/code/model/OBPTransaction.scala index 3fe1ff5a..72141cc2 100644 --- a/MavLift/src/main/scala/code/model/OBPTransaction.scala +++ b/MavLift/src/main/scala/code/model/OBPTransaction.scala @@ -1,9 +1,13 @@ package code.model +import net.liftweb.mongodb._ + import net.liftweb.mongodb.record.field.{BsonRecordField, ObjectIdPk} import net.liftweb.mongodb.record.{MongoMetaRecord, MongoRecord, BsonMetaRecord, BsonRecord} +import net.liftweb.json.JsonAST._ + class Location private () extends BsonRecord[Location] { def meta = Location @@ -13,11 +17,102 @@ class Location private () extends BsonRecord[Location] { } object Location extends Location with BsonMetaRecord[Location] +/* + +"World View": +[ + { + "obp_transaction":{ + "from_account":{ + "holder":"Music Pictures Limited", + "number":"123567", + "type":"current", + "bank":{ + "IBAN":"DE1235123612", + "national_identifier":"de.10010010", + "name":"Postbank" + } + }, + "to_account":{ + "holder":"Simon Redfern", + "number":"3225446882", + "type":"current", + "bank":{ + "IBAN":"UK12789879", + "national_identifier":"uk.10010010", + "name":"HSBC" + } + }, + "details":{ + "type_en":"Transfer", + "type_de":"Überweisung", + "posted":"ISODate 2011-11-25T10:28:38.273Z", + "completed":"ISODate 2011-11-26T10:28:38.273Z", + "value":{ + "currency":"EUR", + "amount":"354.99" + }, + "other_data":"9Z65HCF/0723203600/68550030\nAU 100467978\nKD-Nr2767322" + } + } + }, + { + "obp_transaction":{ + "from_account":{ + "holder":"Client 1", + "number":"123567", + "type":"current", + "bank":{ + "IBAN":"UK12222879", + "national_identifier":"de.10010010", + "name":"Postbank" + } + }, + "to_account":{ + "holder":"Music Pictures Limited", + "number":"3225446882", + "type":"current", + "bank":{ + "IBAN":"UK12789879", + "national_identifier":"uk.10010010", + "name":"HSBC" + } + }, + "details":{ + "type_en":"Transfer", + "type_de":"Überweisung", + "posted":"ISODate 2011-11-25T10:28:38.273Z", + "completed":"ISODate 2011-11-26T10:28:38.273Z", + "value":{ + "currency":"EUR", + "amount":"123.45" + }, + "other_data":"9Z65HCF/0723203600/68550030\nAU 100467978\nKD-Nr2767322" + } + } + } +] + + + */ + +// Seems to map to a collection of the plural name +class OBPEnvelope private() extends MongoRecord[OBPEnvelope] with ObjectIdPk[OBPEnvelope] { + def meta = OBPEnvelope + + // This creates a json attribute called "obp_transaction" + object obp_transaction extends BsonRecordField(this, OBPTransaction) + +} + +object OBPEnvelope extends OBPEnvelope with MongoMetaRecord[OBPEnvelope] + class OBPTransaction private() extends MongoRecord[OBPTransaction] with ObjectIdPk[OBPTransaction] { def meta = OBPTransaction // what does meta do? + object obp_transaction_date_start extends net.liftweb.record.field.DateTimeField(this) object obp_transaction_date_complete extends net.liftweb.record.field.DateTimeField(this) @@ -32,6 +127,17 @@ class OBPTransaction private() extends MongoRecord[OBPTransaction] with ObjectId object obp_transaction_location extends BsonRecordField(this, Location) + + + object from_account extends BsonRecordField(this, OBPAccount) + object to_account extends BsonRecordField(this, OBPAccount) + object details extends BsonRecordField(this, OBPDetails) + + object new_balance extends net.liftweb.record.field.StringField(this, 20) + + + + } object OBPTransaction extends OBPTransaction with MongoMetaRecord[OBPTransaction] @@ -40,13 +146,81 @@ object OBPTransaction extends OBPTransaction with MongoMetaRecord[OBPTransaction /// -// Seems to map to a collection of the plural name -class OBPEnvelope private() extends MongoRecord[OBPEnvelope] with ObjectIdPk[OBPEnvelope] { - def meta = OBPEnvelope +class OBPAccount private() extends MongoRecord[OBPAccount] with ObjectIdPk[OBPAccount] { + def meta = OBPAccount - // This creates a json attribute called "obp_transaction" - object obp_transaction extends BsonRecordField(this, OBPTransaction) + object holder extends net.liftweb.record.field.StringField(this, 255) + object number extends net.liftweb.record.field.StringField(this, 255) + object kind extends net.liftweb.record.field.StringField(this, 255) + object bank extends BsonRecordField(this, OBPBank) + + override def asJValue = { + JObject(List.(holder, number, kind, JField("bank",bank.asJValue))) + + } } -object OBPEnvelope extends OBPEnvelope with MongoMetaRecord[OBPEnvelope] +object OBPAccount extends OBPAccount with MongoMetaRecord[OBPAccount] + + + + +/* +class OBPAccount private() extends MongoRecord[OBPAccount] with ObjectIdPk[OBPAccount] { + def meta = OBPAccount + + object holder extends net.liftweb.record.field.StringField(this, 255) + object number extends net.liftweb.record.field.StringField(this, 255) + object kind extends net.liftweb.record.field.StringField(this, 255) + object bank extends BsonRecordField(this, OBPBank) + + +} + +object OBPAccount extends OBPAccount with MongoMetaRecord[OBPAccount] + +*/ + + +/////////// + +class OBPBank private() extends MongoRecord[OBPBank] with ObjectIdPk[OBPBank] { + def meta = OBPBank + + object IBAN extends net.liftweb.record.field.StringField(this, 255) + object national_identifier extends net.liftweb.record.field.StringField(this, 255) + object name extends net.liftweb.record.field.StringField(this, 255) + +} + +object OBPBank extends OBPBank with MongoMetaRecord[OBPBank] + + + +class OBPDetails private() extends MongoRecord[OBPDetails] with ObjectIdPk[OBPDetails] { + def meta = OBPDetails + + object type_en extends net.liftweb.record.field.StringField(this, 255) + object type_de extends net.liftweb.record.field.StringField(this, 255) + object posted extends net.liftweb.record.field.DateTimeField(this) + object completed extends net.liftweb.record.field.DateTimeField(this) + object value extends BsonRecordField(this, OBPValue) + object other_data extends net.liftweb.record.field.StringField(this, 5000) + +} + +object OBPDetails extends OBPDetails with MongoMetaRecord[OBPDetails] + + +class OBPValue private() extends MongoRecord[OBPValue] with ObjectIdPk[OBPValue] { + def meta = OBPValue + + object currency extends net.liftweb.record.field.StringField(this, 5) + object amount extends net.liftweb.record.field.DecimalField(this, 255) // ok to use decimal? + +} + +object OBPValue extends OBPValue with MongoMetaRecord[OBPValue] + + diff --git a/MavLift/src/main/scala/code/snippet/OBPREST.scala b/MavLift/src/main/scala/code/snippet/OBPREST.scala index a262dff2..58bdd549 100644 --- a/MavLift/src/main/scala/code/snippet/OBPREST.scala +++ b/MavLift/src/main/scala/code/snippet/OBPREST.scala @@ -5,36 +5,35 @@ import net.liftweb.http.rest._ import net.liftweb.json.JsonDSL._ import net.liftweb.json.Printer._ import net.liftweb.json.Extraction._ -import net.liftweb.json.JsonAST._ // this has render in it. +import net.liftweb.json.JsonAST._ +import java.util.Calendar + +// this has render in it. import net.liftweb.json._ // Yep everything import net.liftweb.common.Full import net.liftweb.mongodb._ import net.liftweb.json.JsonAST.JString -// import com.mongodb.casbah.commons._ + import com.mongodb.casbah.Imports._ -//import com.rabbitmq.client._ -//import net.liftweb.amqp._ - -// used to construct type -//import com.tesobe.something._ - import net.liftweb.mongodb._ import _root_.java.math.MathContext -import net.liftweb.mongodb.record._ -import net.liftweb.mongodb.record.field._ -import net.liftweb.record.field._ -import net.liftweb.record._ +import net.liftweb.mongodb._ + +//import net.liftweb.mongodb.record._ +//import net.liftweb.mongodb.record.field._ +//import net.liftweb.record.field._ +//import net.liftweb.record._ import org.bson.types._ import org.joda.time.{DateTime, DateTimeZone} //import com.foursquare.rogue -import com.foursquare.rogue.Rogue._ +//import com.foursquare.rogue.Rogue._ import java.util.regex.Pattern @@ -43,7 +42,7 @@ import java.util.regex.Pattern //import org.junit._ //import org.specs.SpecsMatchers -import com.foursquare.rogue.MongoHelpers._ +//import com.foursquare.rogue.MongoHelpers._ //////////// @@ -96,8 +95,46 @@ object OBPRest extends RestHelper { JsonResponse(transactions.map(t => { t.asJValue })) + + case Req("create":: Nil, _, _) => () => + + + val cal = Calendar.getInstance + cal.set(2009, 10, 2) + + + + // but this creates an id_ which we don't need + val from_account = OBPAccount.createRecord + .holder("Simon Redfern") + .kind("CURRENT") + .number("344533456") + + val tran = OBPTransaction.createRecord + .obp_transaction_data_blob("created-test") + .obp_transaction_amount("223344") + .obp_transaction_date_complete(cal) + .from_account(from_account) + + + val env = OBPEnvelope.createRecord + .obp_transaction(tran) + .save + + + + val json_message = ("hello simon" -> 123) + + // The last result of the function is returned. + Full(JsonResponse(json_message)) + + + case Req("mongodb":: Nil, _, _) => () => + + + // Create a location object val location = Location.createRecord.longitude(2).latitude(51) diff --git a/MavLift/src/main/scala/code/snippet/OBP_Import.scala b/MavLift/src/main/scala/code/snippet/OBP_Import.scala index e4341fca..7502eb3c 100644 --- a/MavLift/src/main/scala/code/snippet/OBP_Import.scala +++ b/MavLift/src/main/scala/code/snippet/OBP_Import.scala @@ -1,6 +1,6 @@ -import au.com.bytecode.opencsv.CSVReader +//import au.com.bytecode.opencsv.CSVReader import java.io.FileReader import scala.collection.JavaConversions._