From 13837515fa770ce5185398ccbe932e70a78e9fb6 Mon Sep 17 00:00:00 2001 From: Everett Sochowski Date: Mon, 12 Mar 2012 13:46:39 +0100 Subject: [PATCH] Working display of the opencorporates url --- .../src/main/scala/code/model/Account.scala | 7 +++++++ .../main/scala/code/snippet/Management.scala | 6 +----- .../code/snippet/OBPTransactionSnippet.scala | 20 +++++++++---------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/MavLift/src/main/scala/code/model/Account.scala b/MavLift/src/main/scala/code/model/Account.scala index 577970b68..2375a51dc 100644 --- a/MavLift/src/main/scala/code/model/Account.scala +++ b/MavLift/src/main/scala/code/model/Account.scala @@ -102,6 +102,13 @@ class Account extends MongoRecord[Account] with ObjectIdPk[Account]{ } } + def getUnmediatedOpenCorporatesUrl(user: String, otherAccountHolder: String) : Box[String] = { + for{ + o <- otherAccounts.get.find(acc=> { + acc.holder.get.equals(otherAccountHolder) + }) + } yield o.openCorporatesUrl.get + } } object Account extends Account with MongoMetaRecord[Account] diff --git a/MavLift/src/main/scala/code/snippet/Management.scala b/MavLift/src/main/scala/code/snippet/Management.scala index 21cff6f0b..049bac226 100644 --- a/MavLift/src/main/scala/code/snippet/Management.scala +++ b/MavLift/src/main/scala/code/snippet/Management.scala @@ -41,11 +41,7 @@ class Management { val otherAcc = getMostUpToDateOtherAccount(holder) if(otherAcc.isDefined){ val newOtherAcc = alterOtherAccount(otherAcc.get, currentValue) - val otherAccsSize = currentAccount.otherAccounts.get.size - val otherAccHolders = currentAccount.otherAccounts.get.map(_.holder.get) val newOtherAccs = currentAccount.otherAccounts.get -- List(otherAcc.get) ++ List(newOtherAcc) - val newOtherAccHolders = newOtherAccs.map(_.holder.get) - val newOtherAccsSize = newOtherAccs.size currentAccount.otherAccounts(newOtherAccs).save } @@ -94,7 +90,7 @@ class Management { ".private_alias_name *" #> editablePrivateAlias(other.privateAlias.get, other.holder.get) & ".more_info *" #> editableMoreInfo(other.moreInfo.get, other.holder.get) & ".website_url *" #> editableUrl(other.url.get, other.holder.get) & - ".open_corporates_url *" #> editableUrl(other.openCorporatesUrl.get, other.holder.get)).apply(xhtml) + ".open_corporates_url *" #> editableOpenCorporatesUrl(other.openCorporatesUrl.get, other.holder.get)).apply(xhtml) }) } diff --git a/MavLift/src/main/scala/code/snippet/OBPTransactionSnippet.scala b/MavLift/src/main/scala/code/snippet/OBPTransactionSnippet.scala index a6cd074e0..a0cb837cc 100644 --- a/MavLift/src/main/scala/code/snippet/OBPTransactionSnippet.scala +++ b/MavLift/src/main/scala/code/snippet/OBPTransactionSnippet.scala @@ -169,17 +169,17 @@ class OBPTransactionSnippet extends StatefulSnippet with PaginatorSnippet[OBPEnv url getOrElse "" } - val openCorporatesUrl = for{ - a <- theAccount - oacc <- a.otherAccounts.get.find(o => o.holder.equals(otherUnmediatedHolder)) - } yield oacc.openCorporatesUrl.get + val openCorporatesUrl = { + val urlBox = for{ + a <- theAccount + openCorpUrl <- a.getUnmediatedOpenCorporatesUrl(consumer, otherUnmediatedHolder) + } yield openCorpUrl + urlBox.getOrElse("") + } ( ".amount *" #> transactionValue.mediated_amount(consumer).getOrElse(FORBIDDEN) & - ".other_account_holder_name *" #> { - val omh = otherMediatedHolder._1.getOrElse(FORBIDDEN) - omh - }& + ".other_account_holder_name *" #> otherMediatedHolder._1.getOrElse(FORBIDDEN) & { if(aliasImageSrc.equals("")){ ".alias_image" #> NodeSeq.Empty & //remove the img tag @@ -204,8 +204,8 @@ class OBPTransactionSnippet extends StatefulSnippet with PaginatorSnippet[OBPEnv else".other_acc_link [href]" #> otherAccWebsiteUrl } & { - if(openCorporatesUrl.getOrElse("").equals("")) ".open_corporates_link" #> NodeSeq.Empty - else ".open_corporates_link [src]" #> openCorporatesUrl + if(openCorporatesUrl.equals("")) ".open_corporates_link" #> NodeSeq.Empty + else ".open_corporates_link [href]" #> openCorporatesUrl } } } &