import gr.grnet.aquarium.util.yaml.YAMLHelpers
import gr.grnet.aquarium.util.Loggable
-import gr.grnet.aquarium.logic.credits.model.{CreditStructureDef, CreditStructure}
+import gr.grnet.aquarium.logic.credits.model.{CreditStructureClass, CreditStructure}
import java.io.{StringReader, InputStreamReader, Reader, InputStream}
/**
*/
object CreditsDSL extends Loggable {
object Keys {
- val StructureDef = "structure"
+ val StructureClass = "structure_class"
val Id = "id"
val Name = "name"
val Units = "units"
val Grouping = "grouping"
}
- def parseString(s: CharSequence): CreditStructureDef = {
+ def parseString(s: CharSequence): CreditStructureClass = {
doParse(new StringReader(s.toString))
}
- def parseStream(in: InputStream, encoding: String = "UTF-8", closeIn: Boolean = true): CreditStructureDef = {
+ def parseStream(in: InputStream, encoding: String = "UTF-8", closeIn: Boolean = true): CreditStructureClass = {
doParse(new InputStreamReader(in, encoding), closeIn)
}
// FIXME: implement
- private def doParse(r: Reader, closeReader: Boolean = true): CreditStructureDef = {
+ private def doParse(r: Reader, closeReader: Boolean = true): CreditStructureClass = {
val creditsDocument = YAMLHelpers.loadYAML(r, closeReader)
- val ystructureDef = creditsDocument / Keys.StructureDef
+ val ystructureDef = creditsDocument / Keys.StructureClass
val yId = ystructureDef / Keys.Id
val yname = ystructureDef / Keys.Name
val yunits = ystructureDef / Keys.Units
logger.debug("units = %s".format(yunits))
logger.debug("grouping = %s".format(ygrouping))
- CreditStructureDef("", "", Nil, None)
+ CreditStructureClass("", "", Nil)
}
}
\ No newline at end of file
/**
* The actual credit amount with info about its origin.
*
- * Note that origin can informa us of the credit type too.
+ * Note that origin can inform us of the credit type too.
*
* @author Christos KK Loverdos <loverdos@gmail.com>.
*/
val FixedAny = 10
/**
- * Credits are distributed (pushed) in fixed values and parts can be divided equally.
+ * Credits are distributed (pushed) in fixed values and parts are divided equally.
*/
val FixedEqual = 20
/**
* A credit holder is the entity to which credits can be assigned.
*
- * Credit holders can be composite or not.
- *
* @author Christos KK Loverdos <loverdos@gmail.com>.
*/
-sealed trait CreditHolder {
- def prototypeId: String
- def name: String
- def isSingleDefinition: Boolean
- def isCompositeDefinition: Boolean
- def memberHolders: List[CreditHolder]
-}
-
-/**
- * These are fixed definitions, from which all other inherit.
- *
- * @author Christos KK Loverdos <loverdos@gmail.com>.
- */
-object CreditHolderProtos {
- object IDs {
- val SingleCreditHolderID = "gr.grnet.aquarium.credits.model.holder.Single"
- val CompositeCreditHolderID = "gr.grnet.aquarium.credits.model.holder.Composite"
- }
-}
-
-/**
- *
- * @author Christos KK Loverdos <loverdos@gmail.com>.
- */
-sealed abstract class CreditHolderSkeleton extends CreditHolder {
- def isSingleDefinition = false
-
- def isCompositeDefinition = false
-}
-
-/**
- *
- * @author Christos KK Loverdos <loverdos@gmail.com>.
- */
-case class SingleCreditHolder(
- name: String,
- prototypeId: String = CreditHolderProtos.IDs.SingleCreditHolderID)
- extends CreditHolderSkeleton {
-
- def memberHolders = Nil
-
- override def isSingleDefinition = true
-}
-
-/**
- *
- * @author Christos KK Loverdos <loverdos@gmail.com>.
- */
-case class CompositeCreditHolder(
- name: String,
- memberHolders: List[CreditHolder],
- prototypeId: String = CreditHolderProtos.IDs.CompositeCreditHolderID)
- extends CreditHolderSkeleton {
-
- override def isCompositeDefinition = true
+case class CreditHolder(name: String, creditHolderClass: CreditHolderClass) {
+ def isSingleHolderClass = creditHolderClass.isSingleHolderClass
+ def isCompositeHolderClass = creditHolderClass.isCompositeHolderClass
}
\ No newline at end of file
--- /dev/null
+package gr.grnet.aquarium.logic.credits.model
+
+/**
+ * A credit holder definition that is used to instantiate credit holders.
+ *
+ * Notice the OOP parlance resemblance.
+
+ * Credit holders can be composite or not.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+sealed trait CreditHolderClass {
+ def name: String
+ def isSingleHolderClass: Boolean
+ def isCompositeHolderClass: Boolean
+ def members: List[CreditHolderClass]
+ def creditDistributions: MembersCreditDistributionMap
+}
+
+/**
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+case class SingleCreditHolderClass(name: String) extends CreditHolderClass {
+ def members = Nil
+ def creditDistributions = Map()
+ def isSingleHolderClass = true
+ def isCompositeHolderClass = false
+}
+
+/**
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+case class CompositeCreditHolderClass(
+ name: String,
+ members: List[CreditHolderClass],
+ creditDistributions: MembersCreditDistributionMap)
+ extends CreditHolderClass {
+
+ def isSingleHolderClass = true
+ def isCompositeHolderClass = true
+}
\ No newline at end of file
}
}
-
case object OwnCreditOrigin extends CreditOrigin {
override def isOwn = true
def name = CreditOrigin.Names.Own
}
-case class InheritedCreditOrigin(creditHolder: CreditHolder, creditDistributionType: CreditDistributionType) extends CreditOrigin {
+case class InheritedCreditOrigin(creditHolder: CreditHolderClass, creditDistributionType: CreditDistributionType) extends CreditOrigin {
override def isInherited = true
def name = CreditOrigin.Names.Own
*
* @author Christos KK Loverdos <loverdos@gmail.com>.
*/
-case class CreditStructure(id: String, name: String, creditStructureDef: CreditStructureDef)
\ No newline at end of file
+case class CreditStructure(
+ id: String,
+ name: String,
+ creditStructureDef: CreditStructureClass,
+ members: List[CreditHolder])
\ No newline at end of file
* The definition of a credit structure.
* This could mimic the organizational structure of the client though something like that is not necessary.
*
- * CreditStructures are top-level and system-wide definitions that can be reused.
- *
- * We also support single inheritance.
+ * These are top-level and system-wide definitions that can be reused.
*
* @author Christos KK Loverdos <loverdos@gmail.com>.
*/
-case class CreditStructureDef(id: String, name: String, units: List[CreditHolder], inherits: Option[String])
+case class CreditStructureClass(
+ id: String,
+ name: String,
+ memberClasses: List[CreditHolderClass])
--- /dev/null
+package gr.grnet.aquarium.logic.credits
+
+package object model {
+ /**
+ * For a member of a structure, provide the credit distribution type
+ * the parent follows for this member.
+ */
+ type MembersCreditDistributionMap = Map[CreditHolderClass, List[CreditDistributionType]]
+}
\ No newline at end of file
# Also, these structures are kind of static and are considered integral part of the business case each client
# represents/is characterized by.
-structure:
+structure_class:
id: "gr.grnet.aquarium.credit.struct.GreekUniversityCreditStructure"
name: Greek University Structure
- inherits: # TODO: Should we inherit an empty structure ?
- credit-holders:
+ credit_holders:
- University:
- name: University # if omitted, taken as the credit-holders key (University in this case)
+ name: University # if omitted, taken as the credit_holders key (University in this case)
id: University # if omitted, taken as the name (University in this case)
type: Composite # if omitted, inferred by the presence of members
members:
- Department: # Use the id here and not the name
- credit-distribution: # List of credit distribution types
+ credit_distribution: # List of credit distribution types
- AliasFixed # only specific amounts are given from Universities to Departments
- Lab:
- credit-distribution:
+ credit_distribution:
- AliasFixed # only specific amounts are given from Universities to Labs
- Department:
members:
- Professor:
- credit-distribution:
+ credit_distribution:
- AliasAny # A Department has the ability to distribute credits to its Professors in the most flexible way
- Lab:
- credit-distribution:
+ credit_distribution:
- AliasAny # A Department has the ability to distribute credits to its Labs in the most flexible way
- Course:
- credit-distribution:
+ credit_distribution:
- AliasAny # A Department has the ability to distribute credits to its Courses in the most flexible way
- Student: # Is this a undergrad, a postgrad, a PhD?
- credit-distribution:
+ credit_distribution:
- AliasFixed # only fixed amounts of credits are distributed to Students
- Lab:
members:
- Course:
- credit-distribution:
+ credit_distribution:
- AliasFixed # Lab members get only fixed amounts
- Course:
members:
import org.junit.Test
import org.junit.Assert._
import gr.grnet.aquarium.logic.credits.dsl.CreditsDSL
+import gr.grnet.aquarium.logic.credits.model.CreditStructureClass
+import java.io.{Reader, InputStreamReader, InputStream, StringReader}
+import gr.grnet.aquarium.util.yaml.YAMLHelpers
+import gr.grnet.aquarium.logic.credits.model.CreditStructureClass._
+import gr.grnet.aquarium.util.Loggable
-class CreditDSLTest {
+class CreditDSLTest extends Loggable {
+ object Keys {
+ val StructureClass = "structure_class"
+ val Id = "id"
+ val Name = "name"
+ val Units = "units"
+ val Grouping = "grouping"
+ }
+
+ def parseString(s: CharSequence): CreditStructureClass = {
+ doParse(new StringReader(s.toString))
+ }
+
+ def parseStream(in: InputStream, encoding: String = "UTF-8", closeIn: Boolean = true): CreditStructureClass = {
+ doParse(new InputStreamReader(in, encoding), closeIn)
+ }
+
+ // FIXME: implement
+ private def doParse(r: Reader, closeReader: Boolean = true): CreditStructureClass = {
+ val creditsDocument = YAMLHelpers.loadYAML(r, closeReader)
+
+ val ystructureDef = creditsDocument / Keys.StructureClass
+ val yId = ystructureDef / Keys.Id
+ val yname = ystructureDef / Keys.Name
+ val yunits = ystructureDef / Keys.Units
+ val ygrouping = ystructureDef / Keys.Grouping
+
+ logger.debug("name = %s".format(yname))
+ logger.debug("units = %s".format(yunits))
+ logger.debug("grouping = %s".format(ygrouping))
+
+ CreditStructureClass("", "", Nil)
+ }
@Test
def testDSLLoad = {
val structure = CreditsDSL.parseStream(getClass.getClassLoader.getResourceAsStream("credit-structure-greek-uni.yaml"))