Skip to content

Commit

Permalink
[#18] AnyVertexTypeWithId
Browse files Browse the repository at this point in the history
  • Loading branch information
alberskib committed Aug 9, 2014
1 parent 6553ea3 commit 14af2e4
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/com/bio4j/dynamograph/AnyDynamoVertex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait AnyDynamoVertex extends AnySealedVertex { dynamoVertex =>

// TODO move this to have a VertexTable and use that

type Tpe <: Singleton with AnySealedVertexType
type Tpe <: Singleton with AnyVertexTypeWithId

val dao: AnyDynamoDbDao = ServiceProvider.dao

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

import ohnosequences.typesets._
import ohnosequences.scarph.AnySealedVertexType


trait AnyVertexTypeWithId extends AnySealedVertexType{

This comment has been minimized.

Copy link
@alberskib

alberskib Aug 9, 2014

Author Contributor

@eparejatobes You mean sth like this?

This comment has been minimized.

Copy link
@eparejatobes

eparejatobes Aug 9, 2014

Member

yup, that's it

type Id <: Singleton with AnyProperty.ofValue[String]
val id : Id
val containId : Id Record#Properties
}

abstract class VertexTypeWithId[P <: Singleton with AnyProperty.ofValue[String],R <: AnyRecord](
val id: P,
val label: String,
val record: R)
(
implicit containId : P R#Properties
) extends AnyVertexTypeWithId{
type Record = R
type Id = P
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bio4j.dynamograph.model

import ohnosequences.typesets._
import ohnosequences.scarph._

object GeneralSchema {

Expand All @@ -14,3 +15,7 @@ object GeneralSchema {
case object comment extends Property[String]

}




Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bio4j.dynamograph.model.go

import com.bio4j.dynamograph.{DynamoEdge, DynamoVertex}
import com.bio4j.dynamograph._
import com.bio4j.dynamograph.model.go.GoSchema._


Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/com/bio4j/dynamograph/model/go/GoSchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ package com.bio4j.dynamograph.model.go

import ohnosequences.scarph._
import com.bio4j.dynamograph.model.GeneralSchema._
import com.bio4j.dynamograph.VertexTypeWithId
import ohnosequences.typesets._
import ohnosequences.typesets.Represented._

object GoSchema {

val goTermAttributes = id :~: name :~: comment :~: definition :~:
val goTermAttributes = id :~: name :~: comment :~: definition :~:
case object GoTermRecord extends Record(goTermAttributes)
object GoTermType extends SealedVertexType("GoTerm", GoTermRecord)
object GoTermType extends VertexTypeWithId(id, "GoTerm", GoTermRecord)
implicit val GoTermType_properties = GoTermType has goTermAttributes

val goNamespacesAttributes = id :~:
case object GoNamespacesRecord extends Record(goNamespacesAttributes)
object GoNamespacesType extends SealedVertexType("GoNamespace", GoNamespacesRecord)
object GoNamespacesType extends VertexTypeWithId(id, "GoNamespace", GoNamespacesRecord)
implicit val GoNamespacesType_properties = GoNamespacesType has goNamespacesAttributes


Expand Down
23 changes: 13 additions & 10 deletions src/main/scala/com/bio4j/dynamograph/model/vertexTables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import ohnosequences.scarph._
import ohnosequences.typesets._
import ohnosequences.tabula._, impl.ImplicitConversions._, toSDKRep._, fromSDKRep._
import shapeless._
import com.bio4j.dynamograph.{AnyDynamoVertex, AnyDynamoEdge}
import com.bio4j.dynamograph.model.GeneralSchema._
import com.bio4j.dynamograph._

/*
This type creates a link between a sealed vertex type and a DynamoDB table
*/
trait AnyVertexTable { vertexTable =>

type VertexType <: Singleton with AnySealedVertexType
type VertexType <: Singleton with AnyVertexTypeWithId
val vertexType: VertexType

type Region <: AnyRegion
val region: Region

Expand All @@ -26,11 +25,13 @@ trait AnyVertexTable { vertexTable =>
type Record = vertexType.Record
val record: Record = vertexType.record

type VertexId <: Singleton with AnyProperty.ofValue[String]
val vertexId: VertexId
type VertexId = vertexType.Id
val vertexId: VertexId = vertexType.id

// provided implicitly at construction
val recordValuesAreOK: everyElementOf[VertexType#Record#Values]#isOneOf[ValidValues]
type ContainId = VertexId Record#Properties
val containId: ContainId

type VertexItem <: Singleton with AnyItem with
AnyItem.ofTable[vertexTable.Table] with
Expand All @@ -41,10 +42,10 @@ trait AnyVertexTable { vertexTable =>

object AnyVertexTable {

type withVertexType[V <: Singleton with AnySealedVertexType] = AnyVertexTable { type VertexType = V }
type withVertexType[V <: Singleton with AnyVertexTypeWithId] = AnyVertexTable { type VertexType = V }
}

class VertexTable[VT <: Singleton with AnySealedVertexType, R <: AnyRegion](
class VertexTable[VT <: Singleton with AnyVertexTypeWithId, R <: AnyRegion](
val vertexType : VT,
val tableName : String,
val region: R
Expand All @@ -57,8 +58,10 @@ extends AnyVertexTable {
type VertexType = VT
type Region = R

type VertexId = id.type
val vertexId = id
type VertexId = VertexType#Id
val vertexId = vertexType.id

val containId = vertexType.containId

type Record = VertexType#Record
val record = vertexType.record
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object GoReaders {
case object namespaceEdgeReader extends EdgeReader(NamespaceTables, ServiceProvider.dynamoDbExecutor)

def reader[VT <: Singleton with AnySealedVertexType](vertex : VT) : AnyVertexReader.withVertexType[VT] = vertexReaders(vertex).asInstanceOf[AnyVertexReader.withVertexType[VT]]

val vertexReaders = Map[AnySealedVertexType, AnyVertexReader] (
GoTermType -> goTermVertexReader,
GoNamespacesType -> goNamespaceVertexReader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait AnyVertexReader { vertexReader =>
val record : Record = vertexTable.record

import ServiceProvider.executors._
def read(identifier : vertexTable.VertexId#Value) : Either[String,record.Rep] = {
def read(identifier : vertexTable.VertexId#Value)(implicit from : ToItem[SDKRep, Item]) : Either[String,record.Rep] = {
val getResult = ServiceProvider.service please (FromHashKeyTable(table, Active (
table,
ServiceProvider.service.account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ trait AnyVertexWriter { vertexWriter =>

type Record = vertexTable.Record
val record = vertexTable.record

type VertexId = vertexTable.VertexId
val vertexId = vertexTable.vertexId

implicit val containId : VertexId Record#Properties

// write an item
def write(vertexItemValue: TaggedWith[Item])(implicit transf: From.Item[Item, SDKRep]): List[AnyPutItemAction] = {
def write(vertexItemValue: TaggedWith[Item])(implicit transf: From.Item[Item, SDKRep], containId : VertexId Record#Properties): List[AnyPutItemAction] = {
// fails to compile, and it is ok because we need to extract the id from the sealed vertex type
val action = InHashKeyTable (
table,
Expand Down
16 changes: 0 additions & 16 deletions src/test/scala/com/bio4j/dynamograph/writer/EdgeWriterTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@ class EdgeWriterTest extends Specification {

result.map(x => x.table.name) must containTheSameElementsAs(tableNames)
}

// "throw exception if relationId is not provided" in new context {
// val incorrectRep = testEdge ->> Map(sourceId.label -> new AttributeValue().withS("sourceId"), targetId.label -> new AttributeValue().withS("targetId"))
// writer.write(incorrectRep) must throwA[NoSuchElementException]
// }
//
// "throw exception if source is not provided" in new context {
// val incorrectRep = testEdge ->> Map(relationId.label -> new AttributeValue().withS("relationId"), targetId.label -> new AttributeValue().withS("targetId"))
// writer.write(incorrectRep) must throwA[ NoSuchElementException]
// }
//
// "throw exception if target is not provided" in new context {
// val incorrectRep = testEdge ->> Map(relationId.label -> new AttributeValue().withS("relationId"), sourceId.label -> new AttributeValue().withS("sourceId"))
// writer.write(incorrectRep) must throwA[NoSuchElementException]
// }

}

trait context extends Scope {
Expand Down

0 comments on commit 14af2e4

Please sign in to comment.