Reputation: 79
I'm trying to compare two Seq strings, which I got using Apache LDAP API with Play! Framework on Scala. After few days I'm out of ideas. Here is the beginning:
@(compares:Seq[Compare] , compares1:Seq[Compare], compareForm: Form[(String, String)])(implicit request:Request[Any])
@import helper._
@main("Admin Tools", request.uri){
I have two interations - how to compare them ?
@for(compare <- compares) {
<td>@for(group <- compare.memberOf) {
<li style="list-style-type: none;">@group.replaceAll(",(.*)","").replaceAll("(.*)=","")</li>
}</td>
}
@for(compare1 <- compares1) {
<td>@for(group1 <- compare1.memberOf) {
<li style="list-style-type: none;">@group1.replaceAll(",(.*)","").replaceAll("(.*)=","")</li>
}</td>
}
Upvotes: 0
Views: 570
Reputation: 79
I know it might be one late answer, but I managed to solve this at that time. Code might be a bit dirty, but I hope it will come in handy to someone.
Model part:
def intersection(c1:Seq[String], c2:Seq[String]): Seq[String] = {
(Set(c1: _*) & Set(c2: _*)).toSeq
}
Controller part:
compareForm.bindFromRequest.fold(
hasErrors = {errors => BadRequest(views.html.compares.index(compareForm, username, User.find(username)))},
success = { ldapName =>
val leftUser = Compare.findAll(ldapName._1)
val rightUser = Compare.findAll(ldapName._2)
val intersection = Compare.intersection(leftUser.memberOf,rightUser.memberOf)
val rightLacking: Seq[String] = (leftUser.memberOf.toSet -- intersection.toSet).toList.map(_.toString).sorted
val leftLacking: Seq[String] = (rightUser.memberOf.toSet -- intersection.toSet).toList.map(_.toString).sorted
val bothOk: Seq[String] = (intersection.toSet).toList.sorted
Ok(views.html.compares.list(leftUser, rightUser, rightLacking, leftLacking, bothOk, compareForm, username, User.find(username)))
} )
Regards!
Upvotes: 0