Refactored TransactionImpl to take an envelope and account as parameters and do the work inside the class to figure out how to implement the trait.

This commit is contained in:
Everett Sochowski 2012-12-31 14:56:56 +01:00
parent 24a629ba8e
commit 27f3e8fdae
2 changed files with 40 additions and 60 deletions

View File

@ -82,49 +82,6 @@ trait LocalStorage extends Loggable {
}
class MongoDBLocalStorage extends LocalStorage {
private def createTransaction(env: OBPEnvelope, theAccount: Account): Transaction =
{
import net.liftweb.json.JsonDSL._
val transaction: OBPTransaction = env.obp_transaction.get
val thisAccount = transaction.this_account
val otherAccount_ = transaction.other_account.get
val otherUnmediatedHolder = otherAccount_.holder.get
val thisBankAccount = Account.toBankAccount(theAccount)
val oAccs = theAccount.otherAccounts.get
val oAccOpt = oAccs.find(o => {
otherUnmediatedHolder.equals(o.holder.get)
})
val oAcc = oAccOpt getOrElse {
OtherAccount.createRecord
}
val id = env.id.is.toString()
val oSwiftBic = None
val otherAccount = new OtherBankAccountImpl(
id_ = "",
label_ = otherAccount_.holder.get,
nationalIdentifier_ = otherAccount_.bank.get.national_identifier.get,
swift_bic_ = None, //TODO: need to add this to the json/model
iban_ = Some(otherAccount_.bank.get.IBAN.get),
number_ = otherAccount_.number.get,
bankName_ = "", //TODO: need to add this to the json/model
metadata_ = new OtherBankAccountMetadataImpl(oAcc.publicAlias.get, oAcc.privateAlias.get, oAcc.moreInfo.get,
oAcc.url.get, oAcc.imageUrl.get, oAcc.openCorporatesUrl.get))
val metadata = new TransactionMetadataImpl(env.narrative.get, env.obp_comments.objs,
(text => env.narrative(text).save), env.addComment _)
val transactionType = env.obp_transaction.get.details.get.type_en.get
val amount = env.obp_transaction.get.details.get.value.get.amount.get
val currency = env.obp_transaction.get.details.get.value.get.currency.get
val label = None
val startDate = env.obp_transaction.get.details.get.posted.get
val finishDate = env.obp_transaction.get.details.get.completed.get
val balance = env.obp_transaction.get.details.get.new_balance.get.amount.get
new TransactionImpl(id, thisBankAccount, otherAccount, metadata, transactionType, amount, currency,
label, startDate, finishDate, balance)
}
def getTransactions(permalink: String, bankPermalink: String, envelopesForAccount: Account => List[OBPEnvelope]): Box[List[Transaction]] =
{
@ -133,7 +90,7 @@ class MongoDBLocalStorage extends LocalStorage {
case Full (bank) => bank.getAccount(permalink) match {
case Full(account) => {
val envs = envelopesForAccount(account)
Full(envs.map(createTransaction(_, account)))
Full(envs.map(new TransactionImpl(_, account)))
}
case _ => Empty
}
@ -175,7 +132,7 @@ class MongoDBLocalStorage extends LocalStorage {
account <- bank.getAccount(accountPermalink)
ifTransactionsIsInAccount <- Full(account.transactionsForAccount.put("_id").is(new ObjectId(id)).get)
envelope <- OBPEnvelope.find(ifTransactionsIsInAccount)
} yield createTransaction(envelope,account)
} yield new TransactionImpl(envelope, account)
}
def getAllAccounts() : List[Account] = Account.findAll

View File

@ -39,21 +39,44 @@ import scala.collection.immutable.List
import net.liftweb.common.Loggable
import net.liftweb.common.Box
import code.model.traits.Comment
import code.model.dataAccess.Account
class TransactionImpl(id_ : String, var _thisAccount : BankAccount = null, otherAccount_ : OtherBankAccount,
metadata_ : TransactionMetadata, transactionType_ : String, amount_ : BigDecimal, currency_ : String,
label_ : Option[String], startDate_ : Date, finishDate_ : Date, balance_ : BigDecimal) extends Transaction with Loggable {
class TransactionImpl(env: OBPEnvelope, theAccount: Account) extends Transaction {
def id = id_
def thisAccount = _thisAccount
def thisAccount_= (newThisAccount : BankAccount) = _thisAccount = newThisAccount
def otherAccount = otherAccount_
def metadata = metadata_
def transactionType = transactionType_
def amount = amount_
def currency = currency_
def label = label_
def startDate = startDate_
def finishDate = finishDate_
def balance = balance_
val transaction: OBPTransaction = env.obp_transaction.get
val otherAccount_ = transaction.other_account.get
val otherUnmediatedHolder = otherAccount_.holder.get
var thisAccount = Account.toBankAccount(theAccount)
private val oAccs = theAccount.otherAccounts.get
val oAccOpt = oAccs.find(o => {
otherUnmediatedHolder.equals(o.holder.get)
})
val oAcc = oAccOpt getOrElse {
OtherAccount.createRecord
}
val id = env.id.is.toString()
val oSwiftBic = None
val otherAccount = new OtherBankAccountImpl(
id_ = "",
label_ = otherAccount_.holder.get,
nationalIdentifier_ = otherAccount_.bank.get.national_identifier.get,
swift_bic_ = None, //TODO: need to add this to the json/model
iban_ = Some(otherAccount_.bank.get.IBAN.get),
number_ = otherAccount_.number.get,
bankName_ = "", //TODO: need to add this to the json/model
metadata_ = new OtherBankAccountMetadataImpl(oAcc.publicAlias.get, oAcc.privateAlias.get, oAcc.moreInfo.get,
oAcc.url.get, oAcc.imageUrl.get, oAcc.openCorporatesUrl.get))
val metadata = new TransactionMetadataImpl(env.narrative.get, env.obp_comments.objs,
(text => env.narrative(text).save), env.addComment _)
val transactionType = env.obp_transaction.get.details.get.type_en.get
val amount = env.obp_transaction.get.details.get.value.get.amount.get
val currency = env.obp_transaction.get.details.get.value.get.currency.get
val label = None
val startDate = env.obp_transaction.get.details.get.posted.get
val finishDate = env.obp_transaction.get.details.get.completed.get
val balance = env.obp_transaction.get.details.get.new_balance.get.amount.get
}