Permalink
Browse files

Now using the new common traits in model.

  • Loading branch information...
1 parent 7d585c2 commit 0c48562cbba08ef0240a15f97e0eb968f293a626 charlieMonroe committed Mar 15, 2012
Showing with 95 additions and 290 deletions.
  1. +1 −1 payola/common/src/main/scala/cz/payola/common/model/Analysis.scala
  2. +2 −2 payola/common/src/main/scala/cz/payola/common/model/Group.scala
  3. +1 −1 payola/common/src/main/scala/cz/payola/common/model/Plugin.scala
  4. +1 −1 payola/common/src/main/scala/cz/payola/common/model/PluginInstance.scala
  5. +6 −4 payola/common/src/main/scala/cz/payola/common/model/User.scala
  6. +1 −1 payola/data/src/main/scala/cz/payola/data/model/graph/RDFEdge.scala
  7. +2 −2 payola/data/src/main/scala/cz/payola/data/model/graph/RDFGraph.scala
  8. +1 −1 payola/data/src/main/scala/cz/payola/data/model/graph/RDFIdentifiedNode.scala
  9. +1 −1 payola/data/src/main/scala/cz/payola/data/model/graph/RDFLiteralNode.scala
  10. +7 −10 payola/model/src/main/scala/cz/payola/model/Analysis.scala
  11. +1 −1 payola/model/src/main/scala/cz/payola/model/AnalysisShare.scala
  12. +8 −37 payola/model/src/main/scala/cz/payola/model/Group.scala
  13. +8 −16 payola/model/src/main/scala/cz/payola/model/Plugin.scala
  14. +20 −21 payola/model/src/main/scala/cz/payola/model/PluginInstance.scala
  15. +13 −9 payola/model/src/main/scala/cz/payola/model/User.scala
  16. +5 −4 payola/model/src/main/scala/cz/payola/model/generic/ConcreteEntity.scala
  17. +0 −27 payola/model/src/main/scala/cz/payola/model/generic/ConcreteNamedEntity.scala
  18. +1 −29 payola/model/src/main/scala/cz/payola/model/generic/ConcreteOwnedEntity.scala
  19. +9 −15 payola/model/src/main/scala/cz/payola/model/generic/SharedAnalysesOwner.scala
  20. +1 −3 payola/model/src/main/scala/cz/payola/model/parameter/Parameter.scala
  21. +1 −1 payola/model/src/main/scala/cz/payola/model/parameter/ParameterInstance.scala
  22. +2 −2 payola/model/src/main/scala/cz/payola/model/parameter/StringParameter.scala
  23. +0 −98 payola/scala2json/src/main/scala/cz/payola/scala2json/ApiProposal.scala
  24. +3 −3 payola/web/client/src/main/scala/cz/payola/web/client/model/rdf/SimpleGraph.scala
@@ -5,7 +5,7 @@ trait Analysis extends NamedEntity with OwnedEntity
/** Type of the plugin instances the analysis consists of. */
type PluginInstanceType <: PluginInstance
- protected var _pluginInstances: Seq[PluginInstanceType]
+ protected val _pluginInstances: Seq[PluginInstanceType]
def pluginInstances = _pluginInstances
}
@@ -5,9 +5,9 @@ trait Group extends NamedEntity with OwnedEntity
/** Type of the analysis shares that are associated with the group. */
type AnalysisShareType <: AnalysisShare
- protected var _members: Seq[UserType]
+ protected val _members: Seq[UserType]
- protected var _sharedAnalyses: Seq[AnalysisShareType]
+ protected val _sharedAnalyses: Seq[AnalysisShareType]
def members = _members
@@ -5,7 +5,7 @@ trait Plugin extends NamedEntity
/** Type of the parameters of the plugin */
type ParameterType <: Parameter[_]
- protected var _parameters: Seq[ParameterType]
+ protected val _parameters: Seq[ParameterType]
def parameters = _parameters
}
@@ -10,7 +10,7 @@ trait PluginInstance extends Entity
protected val _plugin: PluginType
- protected var _parameterInstances: Seq[ParameterInstanceType]
+ protected val _parameterInstances: Seq[ParameterInstanceType]
def plugin = _plugin
@@ -1,5 +1,7 @@
package cz.payola.common.model
+import scala.collection.mutable.Seq
+
trait User extends NamedEntity
{
/** Type of the groups that the user can own or be member of. */
@@ -15,13 +17,13 @@ trait User extends NamedEntity
protected var _password: String
- protected var _ownedGroups: Seq[GroupType]
+ protected val _ownedGroups: Seq[GroupType]
- protected var _memberGroups: Seq[GroupType]
+ protected val _memberGroups: Seq[GroupType]
- protected var _ownedAnalyses: Seq[AnalysisType]
+ protected val _ownedAnalyses: Seq[AnalysisType]
- protected var _sharedAnalyses: Seq[AnalysisShareType]
+ protected val _sharedAnalyses: Seq[AnalysisShareType]
def email = _email
@@ -3,7 +3,7 @@ package cz.payola.data.model.graph
import collection.mutable.HashMap
import cz.payola.common.rdf.Edge
-class RDFEdge(val origin: RDFIdentifiedNode, val destination: RDFNode, val uri: String) extends Edge
+class RDFEdge(protected val _origin: RDFIdentifiedNode, protected val _destination: RDFNode, protected val _uri: String) extends Edge
{
type VertexType = RDFNode
@@ -112,8 +112,8 @@ object RDFGraph {
import RDFGraph._
class RDFGraph(
- val vertices: List[RDFNode],
- val edges: List[RDFEdge])
+ protected val _vertices: List[RDFNode],
+ protected val _edges: List[RDFEdge])
extends Graph
{
@@ -2,6 +2,6 @@ package cz.payola.data.model.graph
import cz.payola.common.rdf.IdentifiedVertex
-class RDFIdentifiedNode(val uri: String) extends RDFNode with IdentifiedVertex
+class RDFIdentifiedNode(protected val _uri: String) extends RDFNode with IdentifiedVertex
{
}
@@ -2,6 +2,6 @@ package cz.payola.data.model.graph
import cz.payola.common.rdf.LiteralVertex
-class RDFLiteralNode(val value: Any, val language: Option[String] = None) extends RDFNode with LiteralVertex
+class RDFLiteralNode(protected val _value: Any, protected val _language: Option[String] = None) extends RDFNode with LiteralVertex
{
}
@@ -4,16 +4,13 @@ import cz.payola.common
import generic.{ConcreteOwnedEntity, ConcreteNamedEntity}
import scala.collection.mutable._
-class Analysis(n: String, u: User) extends common.model.Analysis with ConcreteNamedEntity with ConcreteOwnedEntity
-{
- setName(n)
- setOwner(u)
+class Analysis(protected var _name: String, protected val _owner: User) extends common.model.Analysis with ConcreteNamedEntity with ConcreteOwnedEntity{
type PluginInstanceType = PluginInstance
// Plugin instances that this analysis consists of.
private val _pluginInstanceIDs: ArrayBuffer[String] = new ArrayBuffer[String]()
- val _pluginInstances: HashMap[String, PluginInstance] = new HashMap[String, PluginInstance]()
+ protected val _pluginInstances: ArrayBuffer[PluginInstanceType] = new ArrayBuffer[PluginInstanceType]()
/** Adds a new plugin instance to the plugin instances array.
*
@@ -26,7 +23,7 @@ class Analysis(n: String, u: User) extends common.model.Analysis with ConcreteNa
if (!_pluginInstanceIDs.contains(instance.id)){
_pluginInstanceIDs += instance.id
- _pluginInstances.put(instance.id, instance)
+ _pluginInstances += instance
}
}
@@ -46,7 +43,7 @@ class Analysis(n: String, u: User) extends common.model.Analysis with ConcreteNa
*
* @return An immutable copy of the plugin instances array.
*/
- def pluginInstances = {
+ /*def pluginInstances = {
val instances = List[PluginInstanceType]()
_pluginInstanceIDs foreach { instanceID: String =>
val inst: Option[PluginInstanceType] = _pluginInstances.get(instanceID)
@@ -57,7 +54,7 @@ class Analysis(n: String, u: User) extends common.model.Analysis with ConcreteNa
}
}
instances.reverse
- }
+ }*/
/** Removes all items in the plugin instances array by the array passed as argument.
*
@@ -72,7 +69,7 @@ class Analysis(n: String, u: User) extends common.model.Analysis with ConcreteNa
_pluginInstances.clear()
instances foreach{ instance =>
_pluginInstanceIDs += instance.id
- _pluginInstances.put(instance.id, instance)
+ _pluginInstances += instance
}
}
@@ -86,7 +83,7 @@ class Analysis(n: String, u: User) extends common.model.Analysis with ConcreteNa
require(instance != null, "Cannot remove null plugin instance!")
_pluginInstanceIDs -= instance.id
- _pluginInstances.remove(instance.id)
+ _pluginInstances -= instance
}
/** Convenience method that just calls pluginInstances_=.
@@ -4,7 +4,7 @@ import generic.ConcreteEntity
import cz.payola.common
import cz.payola.common.model.SharePrivilege
-class AnalysisShare (val analysis: Analysis, var privilege: Int) extends common.model.AnalysisShare with ConcreteEntity {
+class AnalysisShare (protected val _analysis: Analysis, protected var _privilege: Int) extends common.model.AnalysisShare with ConcreteEntity {
require(analysis != null, "Analysis cannot be null!")
require(privilege == SharePrivilege.IncludingData || privilege == SharePrivilege.ResultOnly, "Privilige unknown!")
@@ -4,19 +4,17 @@ import collection.mutable._
import cz.payola._
import generic.{SharedAnalysesOwner, ConcreteOwnedEntity, ConcreteNamedEntity}
-class Group (nameStr: String, user: User) extends common.model.Group with ConcreteNamedEntity with ConcreteOwnedEntity with SharedAnalysesOwner
+class Group (protected var _name: String, protected val _owner: User) extends common.model.Group with ConcreteNamedEntity with ConcreteOwnedEntity with SharedAnalysesOwner
{
- setName(nameStr)
- setOwner(user)
type AnalysisShareType = AnalysisShare
// Members. Initially only IDs are loaded, actual members are loaded from the
// data layer as needed
private val _memberIDs: ArrayBuffer[String] = new ArrayBuffer[String]()
- private val _members: HashMap[String, User] = new HashMap[String, User]()
+ protected val _members: ArrayBuffer[UserType] = new ArrayBuffer[UserType]()
- user.addOwnedGroup(this)
+ _owner.addOwnedGroup(this)
/** Adds a member to the group. Does nothing if already a member.
*
@@ -31,7 +29,7 @@ class Group (nameStr: String, user: User) extends common.model.Group with Concre
if (!_memberIDs.contains(u.id)){
_memberIDs += u.id
- _members.put(u.id, u)
+ _members += u
u.addToGroup(this)
}
@@ -54,13 +52,7 @@ class Group (nameStr: String, user: User) extends common.model.Group with Concre
*/
def memberAtIndex(index: Int): User = {
require(index >= 0 && index < memberCount, "Member index out of bounds - " + index)
- val opt: Option[User] = _members.get(_memberIDs(index))
- if (opt.isEmpty){
- // TODO Load from DB
- null
- }else{
- opt.get
- }
+ _members(index)
}
/** Returns number of members. Doesn't include the owner.
@@ -73,7 +65,7 @@ class Group (nameStr: String, user: User) extends common.model.Group with Concre
*
* @return An immutable array of group members.
*/
- def members = {
+ /*def members = {
val users = List[User]()
_memberIDs foreach { userID =>
val u: Option[User] = _members.get(userID)
@@ -84,28 +76,7 @@ class Group (nameStr: String, user: User) extends common.model.Group with Concre
}
}
users.reverse
- }
-
- /** Sets the owner.
- *
- * @param u The owner.
- *
- * @throws IllegalArgumentException if the new user is null.
- */
- override def owner_=(u: User) = {
- // Owner mustn't be null
- require(u != null)
-
- val oldOwner = owner
- _owner = u
- _ownerID = u.id
-
- // Update relations
- u.addOwnedGroup(this)
- if (oldOwner != null) {
- oldOwner.removeOwnedGroup(this)
- }
- }
+ }*/
/** Removes user from members.
*
@@ -124,7 +95,7 @@ class Group (nameStr: String, user: User) extends common.model.Group with Concre
u.removeFromGroup(this)
_memberIDs -= u.id
- _members.remove(u.id)
+ _members -= u
}
}
@@ -2,18 +2,16 @@ package cz.payola.model
import cz.payola._
import cz.payola.model.parameter._
-import collection.mutable.{HashMap, ArrayBuffer}
+import collection.mutable.{Seq, ArrayBuffer}
import generic.ConcreteNamedEntity
-class Plugin(n: String) extends common.model.Plugin with ConcreteNamedEntity
+class Plugin(protected var _name: String) extends common.model.Plugin with ConcreteNamedEntity
{
type ParameterType = Parameter[_]
// Parameters. Doesn't need a setter as all we need to check is that it's not null
private val _parameterIDs: ArrayBuffer[String] = new ArrayBuffer[String]()
- private val _cachedParameters: HashMap[String, Parameter[_]] = new HashMap[String, Parameter[_]]()
-
- setName(n)
+ protected val _parameters: ArrayBuffer[ParameterType] = new ArrayBuffer[ParameterType]()
/** Adds a new parameter to the parameter list.
*
@@ -25,7 +23,7 @@ class Plugin(n: String) extends common.model.Plugin with ConcreteNamedEntity
require(p != null, "Cannot add null parameter!")
if (!containsParameter(p)){
_parameterIDs += p.id
- _cachedParameters.put(p.id, p)
+ _parameters += p
}
}
@@ -44,13 +42,7 @@ class Plugin(n: String) extends common.model.Plugin with ConcreteNamedEntity
*/
def parameterAtIndex(index: Int): ParameterType = {
require(index >= 0 && index < parameterCount, "Parameter index out of bounds - " + index)
- val opt: Option[Parameter[_]] = _cachedParameters.get(_parameterIDs(index))
- if (opt.isEmpty){
- // TODO Load from DB
- null
- }else{
- opt.get
- }
+ _parameters(index)
}
/** Returns number of parameters.
@@ -63,7 +55,7 @@ class Plugin(n: String) extends common.model.Plugin with ConcreteNamedEntity
*
* @return Immutable copy of the parameter array.
*/
- def parameters = {
+ /*def parameters = {
val params = List[ParameterType]()
_parameterIDs foreach { paramID: String =>
val p: Option[ParameterType] = _cachedParameters.get(paramID)
@@ -74,7 +66,7 @@ class Plugin(n: String) extends common.model.Plugin with ConcreteNamedEntity
}
}
params.reverse
- }
+ }*/
/** Removes a parameter from the parameter list.
*
@@ -86,7 +78,7 @@ class Plugin(n: String) extends common.model.Plugin with ConcreteNamedEntity
def removeParameter(p: ParameterType) = {
require(containsParameter(p), "Cannot remove a parameter that isn't a member of this plugin!")
_parameterIDs -= p.id
- _cachedParameters.remove(p.id)
+ _parameters -= p
}
}
Oops, something went wrong.

0 comments on commit 0c48562

Please sign in to comment.