changed the API calls to use the new HostedAccount class

This commit is contained in:
Ayoub BENALI 2012-11-23 11:50:20 +01:00
parent 5c459f4410
commit e74127f64c
2 changed files with 8 additions and 29 deletions

View File

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

View File

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