Skip to content

Commit

Permalink
[#18] Conversion - part
Browse files Browse the repository at this point in the history
  • Loading branch information
alberskib committed Jul 28, 2014
1 parent 31fb7e8 commit 3e79ed0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
24 changes: 11 additions & 13 deletions src/main/scala/com/bio4j/dynamograph/AnyDynamoVertex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@ import com.bio4j.dynamograph.dao.go.AnyDynamoDbDao
import com.bio4j.dynamograph.model.GeneralSchema.id
import com.amazonaws.services.dynamodbv2.model.AttributeValue
import scala.collection.JavaConverters._
import ohnosequences.tabula.AnyItem
import ohnosequences.tabula.AnyItem._


trait AnyDynamoVertex extends AnyVertex { dynamoVertex =>

final type Raw = Map[String, AttributeValue]
type Raw <: AnyItem

This comment has been minimized.

Copy link
@alberskib

alberskib Jul 28, 2014

Author Contributor

What type there should be? Raw <: Any Item or, <:AnyItem#Raw or just <:TypeSet?

This comment has been minimized.

Copy link
@eparejatobes

eparejatobes Jul 28, 2014

Member

hey @alberskib is not that I forgot about you; I've been changing some stuff in scarph, type-sets and tabula to make this simpler. It's almost finished, but I have torticollis and I can barely type :) so probably it will be ready tomorrow. All the properties stuff has been moved to Record in type-sets, and now items have a record field. I need to add sealed vertex/edge types to scarph using the same approach.

Maybe is better for you to wait for it and work on the docs or something like that in the meantime. Anyway, everything's publish in the latest snapshot versions, see


val dao: AnyDynamoDbDao = ServiceProvider.dao


implicit def unsafeGetProperty[P <: AnyProperty: Property.Of[this.Tpe]#is](p: P) =
new PropertyGetter[P](p) {
def apply(rep: Rep): p.Raw = getValue(rep, p.label)
def apply(rep: Rep): p.Raw = rep.get(p)
}


implicit def unsafeGetOneOutEdge[E <: Singleton with AnyDynamoEdge {
type Tpe <: From[dynamoVertex.Tpe] with OneOut }](e: E): GetOutEdge[E] = new GetOutEdge[E](e) {

def apply(rep: dynamoVertex.Rep): e.tpe.Out[e.Rep] = {
val it = dao.getOutRelationships(getId(rep), e).asInstanceOf[List[e.Rep]]
val it = dao.getOutRelationships(rep.get(id), e).asInstanceOf[List[e.Rep]]
it.headOption: Option[e.Rep]
}
}
Expand All @@ -32,7 +35,7 @@ trait AnyDynamoVertex extends AnyVertex { dynamoVertex =>
type Tpe <: From[dynamoVertex.Tpe] with ManyOut }](e: E): GetOutEdge[E] = new GetOutEdge[E](e) {

def apply(rep: dynamoVertex.Rep): e.tpe.Out[e.Rep] = {
val it = dao.getOutRelationships(getId(rep),e).asInstanceOf[List[e.Rep]]
val it = dao.getOutRelationships(rep.get(id),e).asInstanceOf[List[e.Rep]]
it: List[e.Rep]
}
}
Expand All @@ -41,7 +44,7 @@ trait AnyDynamoVertex extends AnyVertex { dynamoVertex =>
type Tpe <: To[dynamoVertex.Tpe] with OneIn }](e: E): GetInEdge[E] = new GetInEdge[E](e) {

def apply(rep: dynamoVertex.Rep): e.tpe.In[e.Rep] = {
val it = dao.getOutRelationships(getId(rep),e).asInstanceOf[List[e.Rep]]
val it = dao.getOutRelationships(rep.get(id),e).asInstanceOf[List[e.Rep]]
it.headOption: Option[e.Rep]
}
}
Expand All @@ -50,22 +53,17 @@ trait AnyDynamoVertex extends AnyVertex { dynamoVertex =>
type Tpe <: To[dynamoVertex.Tpe] with ManyIn }](e: E): GetInEdge[E] = new GetInEdge[E](e) {

def apply(rep: dynamoVertex.Rep): e.tpe.In[e.Rep] = {
val it = dao.getOutRelationships(getId(rep), e).asInstanceOf[List[e.Rep]]
val it = dao.getOutRelationships(rep.get(id), e).asInstanceOf[List[e.Rep]]
it.toList: List[e.Rep]
}
}

private def getValue[T](rep: Rep, attributeName : String) : T = rep.get(attributeName).getOrElse(new AttributeValue().withS("")).getS.asInstanceOf[T]

private def getId(rep: Rep) : String = getValue(rep, id.label)

}

class DynamoVertex[VT <: Singleton with AnyVertexType](val tpe: VT) extends AnyDynamoVertex {
class DynamoVertex[VT <: Singleton with DynamoVertexType](val tpe: VT) extends AnyDynamoVertex {
type Tpe = VT
}

object AnyDynamoVertex{
type ofType[VT <: AnyVertexType] = AnyDynamoVertex { type Tpe = VT }
type ofType[VT <: DynamoVertexType] = AnyDynamoVertex { type Tpe = VT }
}

10 changes: 10 additions & 0 deletions src/main/scala/com/bio4j/dynamograph/DynamoVertexType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.bio4j.dynamograph

import ohnosequences.scarph.VertexType
import ohnosequences.typesets.TypeSet
import ohnosequences.tabula.{AnyItem, Item}


class DynamoVertexType[As <:TypeSet ](override val label: String, val attributes : As) extends VertexType(label){
type Attributes = As
}
27 changes: 18 additions & 9 deletions src/main/scala/com/bio4j/dynamograph/model/go/GoSchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import com.bio4j.dynamograph.model.GeneralSchema.id
import ohnosequences.typesets._
import ohnosequences.tabula.{Item, Represented}
import com.bio4j.dynamograph.model.go.TableGoImplementation.IsATables
import com.amazonaws.services.dynamodbv2.model.AttributeValue
import shapeless.Poly1
import ohnosequences.tabula.impl.ImplicitConversions.fromSDKRep
import com.bio4j.dynamograph.DynamoVertexType

object GoSchema {

Expand All @@ -14,15 +18,20 @@ object GoSchema {
case object comment extends Property[String]

// Vertex Type
object GoTermType extends VertexType("GoTerm")
implicit val GoTermType_id = GoTermType has id
implicit val GoTermType_name = GoTermType has name
implicit val GoTermType_definition = GoTermType has definition
implicit val GoTermType_comment = GoTermType has comment

object GoNamespacesType extends VertexType("GoNamespace")

implicit val GoNamespacesType_id = GoNamespacesType has id
object GoTermType extends DynamoVertexType("GoTerm", id :~: GoSchema.name :~: comment :~: definition :~: ){
// val attributes = id :~: GoSchema.name :~: comment :~: definition :~: ∅
}
implicit val GoTermType_properties = GoTermType has GoTermType.attributes
// implicit val GoTermType_id = GoTermType has id
// implicit val GoTermType_name = GoTermType has name
// implicit val GoTermType_definition = GoTermType has definition
// implicit val GoTermType_comment = GoTermType has comment

object GoNamespacesType extends DynamoVertexType("GoNamespace", id :~: ){
// val attributes = id :~: ∅
}
implicit val GoNamespacesType_properties = GoNamespacesType has GoNamespacesType.attributes
//implicit val GoNamespacesType_id = GoNamespacesType has id

// Edge Types
case object HasPartType extends ManyToMany (GoTermType, "hasPart", GoTermType)
Expand Down

0 comments on commit 3e79ed0

Please sign in to comment.