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

.

.

.

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

Sequence ⤞ meta.nucleotide.nucleotide if 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 if 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.Sequence ⤞ meta.inputMessage >>= fasta >>= {                 } >>= { } >>= xml case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.

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.nucleotide.giNumber === _ } yield query      ! .inputMessage >>= fasta >>= {                 } >>= { } >>= xml case n: Nucleotide ⇒ ! ("media" → "nucleotide") ~> n.

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

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

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

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

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

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

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

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

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

_! // profit!! ._! import Scalaz.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]   }   .

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

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

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

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   .

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

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

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

.

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

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

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

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

.

Thank  You   .

Sign up to vote on this title
UsefulNot useful