Nicer structure for transactions

This commit is contained in:
Simon Redfern 2012-01-23 15:45:47 +01:00
parent dd0a7c35af
commit 902f04866f
5 changed files with 261 additions and 96 deletions

View File

@ -6,11 +6,11 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tesobe</groupId>
<artifactId>test_scala_281_lift_23</artifactId>
<artifactId>opan_bank</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>test_scala_281_lift_23 Project</name>
<inceptionYear>2010</inceptionYear>
<name>Opan Bank</name>
<inceptionYear>2011</inceptionYear>
<properties>
<scala.version>2.9.1</scala.version>
<!-- Common plugin settings -->
@ -80,8 +80,8 @@
</dependency>
<dependency>
<groupId>org.scala-tools.testing</groupId>
<artifactId>specs_2.8.1</artifactId>
<version>1.6.6</version>
<artifactId>specs_2.9.1</artifactId>
<version>1.6.9</version>
<scope>test</scope>
</dependency>
<dependency>
@ -98,78 +98,42 @@
<scope>test</scope>
</dependency>
<!-- For MongoDB -->
<!--
<dependency>
<groupId>net.liftweb</groupId><artifactId>lift-mongodb</artifactId><version>2.0-M5</version>
</dependency>
-->
<!--
<dependency>
<groupId>net.liftweb</groupId>
<artifactId>lift-mongodb-record_2.9.1</artifactId>
<version>2.4-M4</version>
</dependency>
<!--
<dependency>
<groupId>com.mongodb.casbah</groupId>
<artifactId>casbah-commons_2.8.1</artifactId>
<version>2.1.2</version>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.4-701.jdbc4</version>
</dependency>
-->
<!--
<dependency>
<groupId>com.foursquare</groupId>
<artifactId>rogue_2.9.1</artifactId>
<version>1.0.24</version>
</dependency>
-->
<dependency>
<groupId>com.foursquare</groupId>
<artifactId>rogue_2.9.1</artifactId>
<version>1.0.24</version>
</dependency>
<dependency>
<groupId>com.mongodb.casbah</groupId>
<artifactId>casbah_2.9.0-1</artifactId>
<version>2.1.5-1</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>net.liftweb</groupId>
<artifactId>lift-mongodb_2.9.1</artifactId>
<version>2.4</version>
</dependency>
<!--
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<packaging>jar</packaging>
<version>2.3</version>
<name>opencsv</name>
</dependency>
-->
<dependency>
<groupId>net.liftweb</groupId>
<artifactId>lift-mongodb-record_2.9.1</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.mongodb.casbah</groupId>
<artifactId>casbah_${scala.version}</artifactId>
<version>2.1.5-1</version>
<scope>compile</scope>
<type>pom</type>
</dependency>
<!-- TODO add to support these
import com.rabbitmq.client._
import net.liftweb.amqp._
-->
</dependencies>
@ -225,17 +189,7 @@ import net.liftweb.amqp._
</execution>
</executions>
</plugin>
<!-- try later.
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.25</version>
<configuration>
<contextPath>/</contextPath>
<scanIntervalSeconds>5</scanIntervalSeconds>
</configuration>
</plugin>
-->
<plugin>
<groupId>net.sf.alchim</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>

View File

@ -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")
}
}

View File

@ -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]

View File

@ -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)

View File

@ -1,6 +1,6 @@
import au.com.bytecode.opencsv.CSVReader
//import au.com.bytecode.opencsv.CSVReader
import java.io.FileReader
import scala.collection.JavaConversions._