From e74127f64c98257ed37cfbeb24ba66e8df22869c Mon Sep 17 00:00:00 2001 From: Ayoub BENALI Date: Fri, 23 Nov 2012 11:50:20 +0100 Subject: [PATCH] changed the API calls to use the new HostedAccount class --- .../main/scala/bootstrap/liftweb/Boot.scala | 3 +- .../code/model/dataAccess/Connectors.scala | 34 ++++--------------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/MavLift/src/main/scala/bootstrap/liftweb/Boot.scala b/MavLift/src/main/scala/bootstrap/liftweb/Boot.scala index c557365a2..03fd9db98 100755 --- a/MavLift/src/main/scala/bootstrap/liftweb/Boot.scala +++ b/MavLift/src/main/scala/bootstrap/liftweb/Boot.scala @@ -35,7 +35,7 @@ import http._ import sitemap._ import Loc._ import mapper._ -import code.model.dataAccess.{MongoConfig,OBPUser,Privilege,Account, MongoDBLocalStorage, HostedAccount} +import code.model.dataAccess.{MongoConfig,OBPUser,Privilege,Account, HostedBank, MongoDBLocalStorage, HostedAccount} import code.model.{Nonce, Consumer, Token} import code.model.traits.{Bank, View, ModeratedTransaction} import code.model.implementedTraits.{BankImpl, Anonymous, View} @@ -189,6 +189,7 @@ class Boot extends Loggable{ /** * A temporary measure to make sure there is an owner for the account, so that someone can set permissions */ + Account.find(("holder", "Music Pictures Limited")) match{ case Full(a) => HostedAccount.find(By(HostedAccount.accountID,a.id.toString)) match { diff --git a/MavLift/src/main/scala/code/model/dataAccess/Connectors.scala b/MavLift/src/main/scala/code/model/dataAccess/Connectors.scala index 02e2b46e9..51e38c218 100644 --- a/MavLift/src/main/scala/code/model/dataAccess/Connectors.scala +++ b/MavLift/src/main/scala/code/model/dataAccess/Connectors.scala @@ -135,35 +135,13 @@ class MongoDBLocalStorage extends LocalStorage { } } - def getBank(permalink: String): Box[Bank] = { - /** - * As banks are not actually represented anywhere in the system as a single object (yet?), but are rather more - * abstract entities referenced by permalink in transactions and accounts, we can't just as the data store - * for a bank by permalink. - * - * Until a bank model is defined (and I suggest this doesn't happen until we have a nice interface for CRUD ops on banks - * as mucking around with the database manually isn't worth the time IMO -E.S.), this hacky way of doing things will apply: - * - */ - val accountForBank = Account.find("bankPermalink", permalink) - accountForBank.map(acc => new BankImpl("", acc.bankName, permalink)) - } + def getBank(permalink: String): Box[Bank] = + HostedBank.find("permalink", permalink). + map( bank => new BankImpl(bank.id.toString, bank.name.get, permalink)) - def allBanks : List[Bank] = { - //query collects a list of all the distinct values of Account.bankPermalink found in the db - val bankPermalinks = Account.useColl(_.distinct("bankPermalink")) - val banks : List[Box[Bank]] = bankPermalinks match { - case permalinks: ArrayList[String] => { - import scala.collection.JavaConversions._ - permalinks.toList.map(getBank) - } - case _ => { - logger.warn("Conversion from java List to scala List[String] didn't work as expected. No banks will be returned") - Nil - } - } - banks.flatten - } + def allBanks : List[Bank] = + HostedBank.findAll. + map(bank => new BankImpl(bank.id.toString, bank.name.get, bank.permalink.get)) def getBankAccounts(bank: Bank): Set[BankAccount] = { val rawAccounts = Account.findAll("bankName", bank.name).toSet