incubator-esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vdic...@apache.org
Subject svn commit: r768001 - in /incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme: api/RestAPI.scala model/AccessPool.scala
Date Thu, 23 Apr 2009 18:20:35 GMT
Author: vdichev
Date: Thu Apr 23 18:20:34 2009
New Revision: 768001

URL: http://svn.apache.org/viewvc?rev=768001&view=rev
Log:
ESME-57 Add AccessPool realm and validation for duplicate name.

Modified:
    incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/api/RestAPI.scala
    incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/AccessPool.scala

Modified: incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/api/RestAPI.scala
URL: http://svn.apache.org/viewvc/incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/api/RestAPI.scala?rev=768001&r1=768000&r2=768001&view=diff
==============================================================================
--- incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/api/RestAPI.scala
(original)
+++ incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/api/RestAPI.scala
Thu Apr 23 18:20:34 2009
@@ -346,8 +346,9 @@
   def addPool(poolName: String): LiftResponse = {
     val r: Box[Boolean] =
     for (user <- User.currentUser;
-         pool = AccessPool.create.name(poolName).saveMe;
-         privilegeSaved = Privilege.create.pool(pool).user(user).permission(Permission.Admin).save
+         pool <- AccessPool.create.realm("Native").setName(poolName);
+         privilegeSaved = Privilege.create.pool(pool.saveMe).user(user).
+           permission(Permission.Admin).save
     ) yield privilegeSaved
     
     r

Modified: incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/AccessPool.scala
URL: http://svn.apache.org/viewvc/incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/AccessPool.scala?rev=768001&r1=768000&r2=768001&view=diff
==============================================================================
--- incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/AccessPool.scala
(original)
+++ incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/AccessPool.scala
Thu Apr 23 18:20:34 2009
@@ -23,16 +23,41 @@
 
 import net.liftweb._
 import mapper._
+import http._
 import util._
 
+import scala.xml.Text
+
 object AccessPool extends AccessPool with LongKeyedMetaMapper[AccessPool] {
 
 }
 
 class AccessPool extends LongKeyedMapper[AccessPool] {
-  def getSingleton = AccessPool // what's the "meta" server
+  def getSingleton = AccessPool
   def primaryKeyField = id
 
+  private def sameName(name: String) = 
+    AccessPool.findAll(By(AccessPool.name, name)).
+      filter(_.realm.is.equalsIgnoreCase(this.realm.is))
+  
   object id extends MappedLongIndex(this)
-  object name extends MappedText(this)
+
+  private[model] object name extends MappedString(this, 256) {
+    
+    override def validations = checkDuplicate _ :: super.validations
+    
+    def checkDuplicate(in: String): List[FieldError] = 
+      sameName(in).map(p =>
+        FieldError(this, Text("Duplicate pool: " + in + " in realm " + p.realm.is ))
+      )
+    
+  }
+  
+  def setName(in: String) = sameName(in) match {
+    case Nil => Full(this.name(in))
+    case List(_,_*) => Failure("Duplicate access pool name!")
+  }
+
+  object realm extends MappedString(this, 256)
+
 }



Mime
View raw message