Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a0f4752
[#18] Rafactoring
alberskib Jul 19, 2014
162e4cd
[NT] Merge
alberskib Jul 19, 2014
bd7b707
update to Properties instead of Attributes
eparejatobes Jul 27, 2014
56a63af
[#18] Change of return type for vertex writer
alberskib Jul 27, 2014
61f05a6
[#18] Conversion from taw type to item rep
alberskib Jul 27, 2014
31fb7e8
[#18] Conversion
alberskib Jul 27, 2014
3e79ed0
[#18] Conversion - part
alberskib Jul 28, 2014
4220363
[#18] Conversion - remove commented code
alberskib Jul 28, 2014
66a845b
[#18] Conversion - next part
alberskib Jul 28, 2014
bf555ae
[#18] Conversion - next part
alberskib Jul 28, 2014
bd01d7f
[#18] Migration to new versions of tabula, scarph and typesets - firs…
alberskib Jul 29, 2014
8ffc2ea
[#18] Migration to new versions of tabula, scarph and typesets
alberskib Jul 29, 2014
643399e
[#18] Migration to new versions of tabula, scarph and typesets
alberskib Jul 29, 2014
adcf8ac
fix TableGoSchema, add more precise typing
eparejatobes Jul 30, 2014
3da4aaa
[#18] Proof of concept for mapper
alberskib Aug 2, 2014
d63e8d3
[#18] Proof of concept for mapper
alberskib Aug 2, 2014
b3b2e11
[#18] Mapper proof of concept
alberskib Aug 2, 2014
4153009
[#18] Solution for some compilation issues
alberskib Aug 3, 2014
7820a6b
pretty big refactoring, more types
eparejatobes Aug 4, 2014
32c9527
[#18] Readers refactoring
alberskib Aug 4, 2014
4579bc3
[#18] Edge writers refactoring
alberskib Aug 6, 2014
2b11e49
[#18] Vertex readers refactoring
alberskib Aug 6, 2014
edb3469
review code, fix some typing stuff
eparejatobes Aug 7, 2014
70bb536
[#18] EdgeWriter refactoring
alberskib Aug 8, 2014
4a5d3e9
[#18] Mapper refactoring
alberskib Aug 9, 2014
5fb18ad
[#18] Mapper refactoring
alberskib Aug 9, 2014
cc4c8ca
Merge branch 'refactoring/recomendations' of github.com:bio4j/dynamog…
alberskib Aug 9, 2014
b038084
[#18] Further refactoring of GoMapper
alberskib Aug 9, 2014
6553ea3
[#18] Tests refactoring
alberskib Aug 9, 2014
14af2e4
[#18] AnyVertexTypeWithId
alberskib Aug 9, 2014
7c02484
[#18] Fix typo
alberskib Aug 9, 2014
7cb25b0
[NT] Update gitignore
alberskib Aug 9, 2014
c7d7837
[#18] AnyEdgeTypeWithId
alberskib Aug 10, 2014
48d2904
[#18] EdgeWriter refactoring
alberskib Aug 10, 2014
a472bae
simplify types around, write some instructions on how to follow
eparejatobes Aug 10, 2014
cc950c3
[#18] Move vertex reader to dynamo edge
alberskib Aug 11, 2014
9da9e7f
[#18] Edge related things refactoring
alberskib Aug 11, 2014
8af27a1
back to .types, WIP
eparejatobes Aug 11, 2014
4772917
uh oh
eparejatobes Aug 11, 2014
878bc3b
asdfadf
eparejatobes Aug 11, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ project/plugins/project/
*.sublime-project
*.sublime-workspace

# scala-ide
.project
.classpath
.settings
.settings/*


# data folders
data/in/
data/out/

credentials.sbt
/bin/
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ scalaVersion := "2.11.1"
skip in update := true

libraryDependencies ++= Seq(
"ohnosequences" %% "scarph" % "0.1.0",
"ohnosequences" %% "scarph" % "0.2.0-SNAPSHOT",
"ohnosequences" %% "tabula" % "0.1.0-SNAPSHOT",
"ohnosequences" %% "type-sets" % "0.5.0-SNAPSHOT",
//"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "3.0.0", currentlu unavailable for 2.11
"com.amazonaws" % "aws-java-sdk" % "1.8.0",
"org.scala-lang.modules" %% "scala-xml" % "1.0.2",
Expand All @@ -23,7 +24,6 @@ libraryDependencies ++= Seq(
)

dependencyOverrides ++= Set(
"ohnosequences" %% "type-sets" % "0.5.0-SNAPSHOT",
"org.apache.httpcomponents" % "httpclient" % "4.2",
"commons-codec" % "commons-codec" % "1.7",
"com.amazonaws" % "aws-java-sdk" % "1.8.0",
Expand Down
117 changes: 96 additions & 21 deletions src/main/scala/com/bio4j/dynamograph/AnyDynamoEdge.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,123 @@ import com.amazonaws.services.dynamodbv2.model.AttributeValue
import ohnosequences.scarph._
import com.bio4j.dynamograph.dao.go.{AnyDynamoDbDao}
import com.bio4j.dynamograph.model.GeneralSchema._
import com.bio4j.dynamograph.model._
import ohnosequences.typesets._
import com.bio4j.dynamograph.writer.AnyVertexWriter
import com.bio4j.dynamograph.reader.AnyVertexReader
import ohnosequences.tabula._, impl.ImplicitConversions._, toSDKRep._, fromSDKRep._, impl._, impl.actions._


trait AnyDynamoEdge extends AnyEdge { dynamoEdge =>
trait AnyDynamoEdge extends AnySealedEdge { dynamoEdge =>

type Tpe <: Singleton with AnyEdgeTypeWithId

val dao: AnyDynamoDbDao = ServiceProvider.dao

final type Raw = Map[String, AttributeValue]
type EdgeTables <: Singleton with AnyEdgeTables
val edgeTables : EdgeTables

type SourceTable <: Singleton with AnyVertexTable.withVertexType[Tpe#SourceType]
val sourceTable : SourceTable
type SourceReader <: Singleton with AnyVertexReader.withVertexTableType[SourceTable]
val sourceReader : SourceReader

type TargetTable <: Singleton with AnyVertexTable.withVertexType[Tpe#TargetType]
val targetTable : TargetTable
type TargetReader <: Singleton with AnyVertexReader.withVertexTableType[TargetTable]
val targetReader : TargetReader

/*
you need the tables here!! same for DynamoVertex, but there is less obvious. If you would have them, what you need to do is:

val dao: AnyDynamoDbDao = ServiceProvider.dao
1. use sourceId, targetId from there to get the id from the in/out table
2. get the vertex from the corresponding vertex table

*/

type Other = String

type Source <: AnyDynamoVertex { type Tpe <: Singleton with AnyVertexTypeWithId with dynamoEdge.tpe.SourceType }

type Source <: AnyVertex.ofType[Tpe#SourceType] with AnyDynamoVertex
val source: Source

type Target <: AnyVertex.ofType[Tpe#TargetType] with AnyDynamoVertex
type Target <: AnyDynamoVertex { type Tpe <: Singleton with AnyVertexTypeWithId with dynamoEdge.tpe.TargetType }

val target: Target

implicit object sourceGetter extends GetSource {

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

implicit object sourceGetter extends GetSource {
def apply(rep: dynamoEdge.Rep): Out =
source ->> dao.get(getValue(rep,sourceId.label), source)
def apply(rep: dynamoEdge.Rep): Out = source ->> {

val srcId: sourceId.Rep = rep get sourceId

// try to get it
import ServiceProvider.executors._

val getResult = ServiceProvider.service please (

FromHashKeyTable (

source.vertexTable.table,
Active (
source.vertexTable.table,
ServiceProvider.service.account,
ThroughputStatus(1, 1)
)
) getItem source.vertexTable.vertexItem withKey (srcId)
)

val recordEntry = getResult.right.get

source.raw ( recordEntry, "" )
}
}

implicit object targetGetter extends GetTarget {
def apply(rep: dynamoEdge.Rep): target.Rep =
target ->> dao.get(getValue(rep,targetId.label), target)
}

// NOTE: why was it private?
def getValue(rep: Rep, attributeName : String) : String = rep.get(attributeName).getOrElse(new AttributeValue().withS("")).getS
import tpe._

def apply(rep: dynamoEdge.Rep): target.Rep = target ->> {

val tgtId = rep get targetId
val couldBeRecordEntry = targetReader.read(tgtId)
val recordEntry = couldBeRecordEntry.right.get
target.raw ( recordEntry, "" )
}
}
}

class DynamoEdge[
ET <: AnyEdgeType,
S <: Singleton with AnyVertex.ofType[ET#SourceType] with AnyDynamoVertex,
T <: Singleton with AnyVertex.ofType[ET#TargetType] with AnyDynamoVertex
](val source: S, val tpe: ET, val target: T) extends AnyDynamoEdge {
ET <: Singleton with AnyEdgeTypeWithId,
ETab <: Singleton with AnyEdgeTables.withEdgeType[ET],
S <: Singleton with AnyDynamoVertex.ofType[ET#SourceType] with AnyDynamoVertex,
STab <: Singleton with AnyVertexTable.withVertexType[ET#SourceType],
SR <: Singleton with AnyVertexReader.withVertexTableType[STab],
T <: Singleton with AnyDynamoVertex.ofType[ET#TargetType] with AnyDynamoVertex,
TTab <: Singleton with AnyVertexTable.withVertexType[ET#TargetType],
TR <: Singleton with AnyVertexReader.withVertexTableType[TTab]
](
val source: S,
val sourceTable: STab,
val sourceReader: SR,
val tpe: ET,
val edgeTables: ETab,
val target: T,
val targetTable : TTab,
val targetReader : TR
) extends AnyDynamoEdge {
type Source = S
type Tpe = ET
type Target = T
type EdgeTables = ETab
type SourceTable = STab
type TargetTable = TTab
type SourceReader = SR
type TargetReader = TR
}

object AnyDynamoEdge{
type ofType[ET <: Singleton with AnyEdgeTypeWithId] = AnyDynamoEdge { type Tpe = ET }
}
76 changes: 48 additions & 28 deletions src/main/scala/com/bio4j/dynamograph/AnyDynamoVertex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,89 @@ package com.bio4j.dynamograph
import ohnosequences.scarph._
import com.bio4j.dynamograph.dao.go.AnyDynamoDbDao
import com.bio4j.dynamograph.model.GeneralSchema.id
import com.amazonaws.services.dynamodbv2.model.AttributeValue
import com.bio4j.dynamograph.model._
import scala.collection.JavaConverters._
import ohnosequences.tabula.AnyItem
import ohnosequences.tabula.AnyItem._
import ohnosequences.typesets._
import com.bio4j.dynamograph.reader.EdgeReader


trait AnyDynamoVertex extends AnyVertex { dynamoVertex =>
trait AnyDynamoVertex extends AnySealedVertex { dynamoVertex =>

final type Raw = Map[String, AttributeValue]
type Tpe <: AnySealedVertexType with AnyVertexTypeWithId
type VertexTable <: Singleton with AnyVertexTable
val vertexTable: VertexTable

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)
}
type Other = String

implicit def unsafeGetOneOutEdge [
E <: AnyDynamoEdge { type Tpe <: From[dynamoVertex.Tpe] with OneOut }
]
(e: E)(implicit
isThere: tpe.Id ∈ tpe.record.Properties,
lookup: Lookup[tpe.record.Values, tpe.id.Rep]
)
: GetOutEdge[E] = new GetOutEdge[E](e) {

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] = {

def apply(rep: dynamoVertex.Rep): e.tpe.Out[e.Rep] = {
val it = dao.getOutRelationships(getId(rep), e).asInstanceOf[List[e.Rep]]
it.headOption: Option[e.Rep]

val idV = rep get tpe.id
val it = dao.getOutRelationships( idV, e ).asInstanceOf[List[E#Rep]]
it.headOption: Option[E#Rep]
}
}

implicit def unsafeGetManyOutEdge[E <: Singleton with AnyDynamoEdge {
type Tpe <: From[dynamoVertex.Tpe] with ManyOut }](e: E): GetOutEdge[E] = new GetOutEdge[E](e) {
implicit def unsafeGetManyOutEdge [
E <: AnyDynamoEdge {type Tpe <: From[dynamoVertex.Tpe] with ManyOut }
]
(e: E)(implicit
isThere: tpe.Id ∈ tpe.record.Properties,
lookup: Lookup[tpe.record.Values, tpe.id.Rep]
)
: GetOutEdge[E] = new GetOutEdge[E](e) {

def apply(rep: dynamoVertex.Rep): e.tpe.Out[E#Rep] = {

val it = dao.getOutRelationships( rep get tpe.id, e).asInstanceOf[List[E#Rep]]

def apply(rep: dynamoVertex.Rep): e.tpe.Out[e.Rep] = {
val it = dao.getOutRelationships(getId(rep),e).asInstanceOf[List[e.Rep]]
it: List[e.Rep]
it: List[E#Rep]
}
}

implicit def unsafeGetOneInEdge[E <: Singleton with AnyDynamoEdge {
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]]
def apply(rep: dynamoVertex.Rep)(implicit isThere: id.type ∈ dynamoVertex.tpe.record.Properties, lookup: Lookup[dynamoVertex.tpe.record.Values, id.Entry]): e.tpe.In[e.Rep] = {
val it = dao.getOutRelationships(rep.get(id),e).asInstanceOf[List[e.Rep]]
it.headOption: Option[e.Rep]
}
}

implicit def unsafeGetManyInEdge[E <: Singleton with AnyDynamoEdge {
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]]
def apply(rep: dynamoVertex.Rep)(implicit isThere: id.type ∈ dynamoVertex.tpe.record.Properties, lookup: Lookup[dynamoVertex.tpe.record.Values, id.Entry]): e.tpe.In[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 AnySealedVertexType, VTab <: Singleton with AnyVertexTable]
(
val tpe: VT,
val vertexTable: VTab
) extends AnyDynamoVertex {
type Tpe = VT
type VertexTable = VTab
}

object AnyDynamoVertex{
type ofType[VT <: AnyVertexType] = AnyDynamoVertex { type Tpe = VT }
type ofType[VT <: Singleton with AnySealedVertexType] = AnyDynamoVertex { type Tpe = VT }
}


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

import ohnosequences.scarph.AnySealedEdgeType
import ohnosequences.typesets._
import com.bio4j.dynamograph.model.GeneralSchema._
import ohnosequences.scarph.From
import ohnosequences.scarph.To


trait AnyEdgeTypeWithId extends AnySealedEdgeType {

type Id <: Singleton with AnyProperty with AnyProperty.ofValue[String]
val id : Id

implicit val containsId: (Id ∈ record.Properties)
implicit val idLookup: Lookup[Record#Raw, id.Rep]

type SourceType <: AnyVertexTypeWithId

// the id of the source
type SourceId <: Singleton with AnyProperty with AnyProperty.ofValue[sourceType.id.Value]
val sourceId: SourceId

type TargetType <: AnyVertexTypeWithId

type TargetId <: Singleton with AnyProperty with AnyProperty.ofValue[targetType.id.Value]
val targetId: TargetId

implicit val containsSourceId: (SourceId ∈ record.Properties)
implicit val sourceLookup: Lookup[record.Values, sourceId.Rep]
implicit val containsTargetId: (TargetId ∈ record.Properties)
implicit val targetLookup: Lookup[record.Values, targetId.Rep]
}

abstract class EdgeTypeWithId[
S <: Singleton with AnyVertexTypeWithId,
PS <: Singleton with AnyProperty with AnyProperty.ofValue[S#Id#Value],
P <: Singleton with AnyProperty with AnyProperty.ofValue[String],
R <: Singleton with AnyRecord,
T <: Singleton with AnyVertexTypeWithId,
PT <: Singleton with AnyProperty with AnyProperty.ofValue[T#Id#Value]
](
val sourceType: S,
val sourceId: PS,
val id: P,
val label: String,
val record: R,
val targetType: T,
val targetId: PT
)
extends AnyEdgeTypeWithId with From[S] with To[T] {

type Id = P
type Record = R
type SourceType = S
type SourceId = PS
type TargetType = T
type TargetId = PT
}
29 changes: 29 additions & 0 deletions src/main/scala/com/bio4j/dynamograph/AnyVertexTypeWithId.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.bio4j.dynamograph

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


trait AnyVertexTypeWithId extends AnySealedVertexType {

type Id <: Singleton with AnyProperty with AnyProperty.ofValue[String]
val id: Id

implicit val containsId: Id ∈ record.Properties
}

abstract class VertexTypeWithId [
P <: Singleton with AnyProperty with AnyProperty.ofValue[String],
R <: Singleton with AnyRecord
](
val id: P,
val label: String,
val record: R
)
extends AnyVertexTypeWithId {

type Record = R
type Id = P

implicit val containsId: Id ∈ record.Properties
}
Loading