Author: rhirsch
Date: Tue Sep 29 13:04:35 2009
New Revision: 819915
URL: http://svn.apache.org/viewvc?rev=819915&view=rev
Log:
[ESME-72] Add other attributes to the AccessPool object
Patch from Xuefeng Wu applied
Modified:
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/AccessPool.scala
Modified:
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/AccessPool.scala
URL:
http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/AccessPool.scala?rev=819915&r1=819914&r2=819915&view=diff
==============================================================================
---
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/AccessPool.scala
(original)
+++
incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/AccessPool.scala
Tue Sep 29 13:04:35 2009
@@ -1,71 +1,91 @@
-package org.apache.esme.model
-
-/**
- * Copyright 2008-2009 WorldWide Conferencing, LLC
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import net.liftweb._
-import mapper._
-import http._
-import util._
-
-import scala.xml.Text
-
-object AccessPool extends AccessPool with LongKeyedMetaMapper[AccessPool] {
- val Native = "Native"
-
- def findPool(name: String, realm: String): Box[AccessPool] =
- AccessPool.find(By(AccessPool.name, name),
- By(AccessPool.realm, realm))
-
-}
-
-class AccessPool extends LongKeyedMapper[AccessPool] {
- def getSingleton = AccessPool
- def primaryKeyField = id
-
- object id extends MappedLongIndex(this)
-
- // is it worth having foreign key to another table?
- object realm extends MappedString(this, 256)
-
- 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!")
- }
-
- def getName() = name.is
-
- private def sameName(name: String) =
- AccessPool.findAll(By(AccessPool.name, name)).
- filter(_.realm.is.equalsIgnoreCase(this.realm.is))
-
-}
+package org.apache.esme.model
+
+/**
+ * Copyright 2008-2009 WorldWide Conferencing, LLC
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import net.liftweb._
+import mapper._
+import http._
+import util._
+
+import scala.xml.Text
+
+import java.util.Date
+
+object AccessPool extends AccessPool with LongKeyedMetaMapper[AccessPool] {
+ val Native = "Native"
+
+ def findPool(name: String, realm: String): Box[AccessPool] =
+ AccessPool.find(By(AccessPool.name, name),
+ By(AccessPool.realm, realm))
+
+ //set createdDate and creator when instance AccessPool
+ override def create: AccessPool = {
+ val ap = super.create
+ ap.createdDate(new Date())
+ ap.creator(User.currentUser)
+ ap
+ }
+}
+
+class AccessPool extends LongKeyedMapper[AccessPool] {
+ def getSingleton = AccessPool
+ def primaryKeyField = id
+
+ object id extends MappedLongIndex(this)
+
+ // is it worth having foreign key to another table?
+ object realm extends MappedString(this, 256)
+
+ 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 ))
+ )
+
+ }
+
+ // set modify information when setName
+ def setName(in: String) = sameName(in) match {
+ case Nil => {
+ Full(this.name(in))
+ Full(this.lastModifyDate(new Date()))
+ Full(this.modifier(User.currentUser))
+ }
+ case List(_,_*) => Failure("Duplicate access pool name!")
+ }
+
+ def getName() = name.is
+
+ private def sameName(name: String) =
+ AccessPool.findAll(By(AccessPool.name, name)).
+ filter(_.realm.is.equalsIgnoreCase(this.realm.is))
+
+ //define create and modify fields
+ object createdDate extends MappedDateTime(this)
+ object creator extends MappedLongForeignKey(this,User)
+ object lastModifyDate extends MappedDateTime(this)
+ object modifier extends MappedLongForeignKey(this,User)
+
+}