Scala  Domain  Modeling   and  Architecture  

Experience  Report   Hossam  Karim  

.

.

for {! ! locus ← Chromosome ⤞ Gene ⤞ Locus! if Locus ∈ range! ! ! path ← locus ⤞ Sequence ⤞ nucleotide! if nucleotide alignment (_ > 89)! } yield path! .

.

.

.

giNumber === _ } yield query      ! .nucleotide if meta.giNumber case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence") case _ ⇒ ! fail[String](! "Expected a ‘single’ Sequence representation”)       for { query ← meta.inputMessage >>= fasta >>= {                 } >>= { } >>= xml case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.Sequence ⤞ meta.nucleotide.

giNumber === _ } yield query      ! .Sequence ⤞ meta.nucleotide.inputMessage >>= fasta >>= {                 } >>= { } >>= xml case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.nucleotide if meta.giNumber case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence") case _ ⇒ ! fail[String](! "Expected a ‘single’ Sequence representation”)       for { query ← meta.

nucleotide if meta.giNumber case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence") case _ ⇒ ! fail[String](! "Expected a ‘single’ Sequence representation”)       for { query ← meta.nucleotide.inputMessage >>= fasta >>= {                 } >>= { } >>= xml case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.Sequence ⤞ meta.giNumber === _ } yield query      ! .

giNumber case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence") case _ ⇒ ! fail[String](! "Expected a ‘single’ Sequence representation”)       for { query ← meta.nucleotide.inputMessage >>= fasta >>= {                 } >>= { } >>= xml case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.Sequence ⤞ meta.giNumber === _ } yield query      ! .nucleotide if meta.

inputMessage >>= fasta >>= {                 } >>= { } >>= xml case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.nucleotide.giNumber === _ } yield query      ! .Sequence ⤞ meta.giNumber case _: AminoAcid ⇒ ! fail[String](! "Expected a ‘nucleotide’ Sequence") case _ ⇒ ! fail[String](! "Expected a ‘single’ Sequence representation”)       for { query ← meta.nucleotide if meta.

trait Message[A. Option[A]]   val headers: H   }         trait MessageBuilder {   def build[A. H: Monoid](   body: Validation[H. Option[A]]. H]   }     . H] {   val body: Validation[H. headers: H): Message[A.

Option[A]]   val headers: H   }         trait MessageBuilder {   def build[A. H]   }     . headers: H): Message[A. H] {   val body: Validation[H.trait Message[A. H: Monoid](   body: Validation[H. Option[A]].

H]): Message[B. H] = . B]! (a: Message[A. . ! monoid: Monoid[H]) =!   new Monad[({type λ[α] = Message[α. .   }   . H] = .implicit def m2m[H]! (implicit builder: MessageBuilder. . H]})#λ] {     def pure[A](a: => A): Message[A. ! f: (A) => Message[B. . H].!   def bind[A.

H](Success(Option(a)).def pure[A](a: => A) = ! builder. ∅[H])     .build[A.

body.body match { case Success(Some(value)) case Success(None) builder. H](mb. H].build[B. B](! m: Message[A.build[B.build[B.headers |+| mb.def bind[A.headers) . H](! Success(Option.empty[B]). ∅[H]) case Failure(a) ⇒! builder. H] = m. ∅[H] |+| a)   ⇒ f(value) ⇒!     }   }!       builder. H]): Message[B. H](! Failure(a). m. ! f: (A) => Message[B. H] = {!   val mb: Message[B.

headers) }                 def body[A](value: A)(implicit builder: MessageBuilder) :! Message[A. headers) }         ! implicit object DiagnosisMessageBuilder extends! MessageBuilder { def build[A. HL] = builder. List. headers: H) = BasicMessage(body.build(Success(Some(value)). H: Monoid](! body: Validation[H. headers: H) = DiagnosisMessage(body.implicit object BasicMessageBuilder extends MessageBuilder { def build[A.empty[Header])     . Option[A]]. Option[A]]. H: Monoid](! body: Validation[H.

Gene ! if meta._! //import Transactional.uuid === _.uuid! ) yield e } >>= search       .Chromosome ⤞ meta.import Basic._! ! gene map { for (! e ← meta.Gene._! //import Diagnosis.

gene+json") >>=   json           for {   m ← body(<gene xmlns="urn:model:gene:1.uuid   if meta.Gene ⤞ meta.(genex <**> geney) (_ ++ _) >>=   header("media-type".Gene.uuid   } yield e   } >>= search     ..0">. "application/vnd.Gene.</gene>)   gene ← xml(m)   } yield gene           gene map {   for {   e ← meta.x.uuid === _..

import scalaz._! import Scalaz._! // profit!! .

.

.

.

trait Resource {! val name: String! } !     trait Ontology extends Resource {! val nestingOntology: Option[Ontology]! val nestedOntology: List[Ontology]! val ownedType: List[Type]! val ownedRelation: List[Relation]! }!   .

trait GraphResource {   this: Resource =>   }     trait GraphVertex extends GraphResource {   this: Entity =>   val graphFeatures: List[PrimitiveFeature]   val master: Boolean   val rootToMasterEdge: GraphEdge with Relation   val masterToSelf: Option[GraphEdge with Relation] = None   }     trait GraphEdge extends GraphResource {   this: Relation =>   }     .

trait RelationalResource {   this: Resource =>   }     trait NamedRelationalResource this: Resource =>   val relationalName: String   }   extends RelationalResource {         trait RelationalEntity extends NamedRelationalResource {   this: Entity =>   }   trait RelationalCompositeFeature extends RelationalResource {   this: CompositeFeature =>   val mapping: Map[String. String]   }   .

object Chromosome extends   Entity   with RelationalEntity!    with GraphVertex   with XmlElement {   self =>     sealed trait ChromosomePart {   val ownerType = self   }     // Ontology Trait   val featuringType = self   val ownedFeature = chromatine :: Nil     // XML Trait   val namespace = "urn:domain:chromosome:1.empty[String.   mapping = Map.0"   val prefix = "chr"     // Features   val chromatine =   new Chromatine(   name = "chromatine". String])   }     .   ownerType = Chromosome.

metamodel match {   case Some(vertex: GraphVertex) ⇒ ! Ontology.edges.filter(_.implicit def enrich[A <: DomainModel](model: A) = new {   def metamodel: Option[Type] = Ontology.typeOf(model)   }   def xmlFilter[A <: DomainModel] =   (model: A) ⇒ model.target == vertex)   case _ ⇒ List.empty[GraphEdge]   }       .metamodel match {   case Some(_: XmlElement) ⇒ body(XmlModel[A](model))   case _ ⇒ fail[XmlModel[A]]! ("No XmlElement meta-model definition could be found")   }   def ingoingEdges[A <: DomainModel] =   (model: A) ⇒ model.

implicit def enrich[A <: DomainModel](model: A) = new {   def metamodel: Option[Type] = Ontology.edges.metamodel match {   case Some(_: XmlElement) ⇒ body(XmlModel[A](model))   case _ ⇒ fail[XmlModel[A]]! ("No XmlElement meta-model definition could be found")   }   def ingoingEdges[A <: DomainModel] =   (model: A) ⇒ model.filter(_.target == vertex)   case _ ⇒ List.metamodel match {   case Some(vertex: GraphVertex) ⇒ ! Ontology.empty[GraphEdge]   }       .typeOf(model)   }   def xmlFilter[A <: DomainModel] =   (model: A) ⇒ model.

trait Type extends Resource   trait SimpleType extends Type   trait Entity extends Type! !   trait Relation extends Type   trait trait trait trait trait   trait trait trait     Feature[+T <: Type] extends Resource   SimpleFeature[+T <: SimpleType] extends Feature[T]   PrimitiveFeature extends SimpleFeature[Primitive]   EnumerationFeature extends SimpleFeature[Enumeration]   CompositeFeature extends SimpleFeature[Composite]   Primitive extends SimpleType   Enumeration extends SimpleType   Composite extends SimpleType   .

  }         def find(operator: Operator): Option[T]   def list(operator: Operator): List[T]!         import PrimitiveLogic.locusUUID === uuid)       . . . .locusUUID in list)       dao find (Locus.trait PrimitiveLogic {   val resource: Primitive         def ===[A](value: Primitive[A]): Operator = . ._   dao list (Locus.              def in[A](values: PrimitiveList[A]): Operator = .

accessionNumber !== x     import GraphOps.import Logic.accession.nucleotide._   val path =   Sequence.protein ⤞   Locus.typeOfGene where (_ !== y)     .nucleotide ⤞   Sequence._   val validation =   Sequence.

for {! ! locus ← Chromosome ⤞ Gene ⤞ Locus! if Locus ∈ range! ! ! path ← locus ⤞ Sequence ⤞ nucleotide! if nucleotide alignment (_ > 89)! } yield path! .

.

View. Query.trait Qvt[PIM. PSM] {         def query(pim: PIM): List[Query]   def view(query: Query): View   def transform(view: View): PSM   }     .

Package..   filter(graphProfile.class GraphSimpleQvt(   ontologyProfile: OntologyProfile.   .   }   ..graphPredicate)   }   def transform(view: Package) = graph(view)   def graph(element: Package): GraphOntology = {   . GraphOntology] {         def query(pim: Model) = {   walk[Package](pim)(_.getNestedPackages).   .   }   .   graphProfile: GraphProfile)   extends SimpleQvt[Model.

flatMap(walk(_.toList   children ++ ! (children.def walk[A]   (element: A)   (f: A => Iterable[A]): List[A] = {   val children = f(element). f)))   }   .

scala rocks !!   .getNestingPackage)   .") //.reverse   .isInstanceOf[Model])   .getName)   .map(_.iterate(element)(_.takeWhile(!_.mkString(".def packageName(element: Package): String =   Stream! .

.

Thank  You   .

Sign up to vote on this title
UsefulNot useful