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! .

.

.

.

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

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

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

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

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

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

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

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

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

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

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

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

.

.

.

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]   }   .

  ownerType = Chromosome.0"   val prefix = "chr"     // Features   val chromatine =   new Chromatine(   name = "chromatine". String])   }     .   mapping = Map.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.

implicit def enrich[A <: DomainModel](model: A) = new {   def metamodel: Option[Type] = Ontology.typeOf(model)   }   def xmlFilter[A <: DomainModel] =   (model: A) ⇒ model.empty[GraphEdge]   }       .target == vertex)   case _ ⇒ List.edges.filter(_.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.metamodel match {   case Some(vertex: GraphVertex) ⇒ ! Ontology.

typeOf(model)   }   def xmlFilter[A <: DomainModel] =   (model: A) ⇒ model.metamodel match {   case Some(vertex: GraphVertex) ⇒ ! Ontology.target == vertex)   case _ ⇒ List.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.empty[GraphEdge]   }       .implicit def enrich[A <: DomainModel](model: A) = new {   def metamodel: Option[Type] = Ontology.edges.filter(_.

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   .

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

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

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

.

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

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

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

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

.

Thank  You   .

Sign up to vote on this title
UsefulNot useful