This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We use converters and OGM annotations instead of converting SutStates and Actions manually. Open sessions for all state machines and create transactions for the sessions.
- Loading branch information
Showing
11 changed files
with
133 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/scala/de/retest/guistatemachine/api/neo4j/ActionConverter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package de.retest.guistatemachine.api.neo4j | ||
|
||
import de.retest.surili.commons.actions.{Action, NavigateRefreshAction} | ||
import org.neo4j.ogm.typeconversion.AttributeConverter | ||
|
||
/* | ||
* https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/src/main/asciidoc/reference/conversion.adoc | ||
*/ | ||
class ActionConverter extends AttributeConverter[Action, String] { | ||
def toGraphProperty(value: Action): String = value.toString // TODO #19 convert to XML with element | ||
def toEntityAttribute(value: String): Action = new NavigateRefreshAction // TODO #19 convert from XML to an action | ||
} |
18 changes: 13 additions & 5 deletions
18
src/main/scala/de/retest/guistatemachine/api/neo4j/ActionTransitionEntity.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
package de.retest.guistatemachine.api.neo4j | ||
import de.retest.recheck.ui.descriptors.SutState | ||
import de.retest.surili.commons.actions.Action | ||
import org.neo4j.ogm.annotation.typeconversion.Convert | ||
import org.neo4j.ogm.annotation.{EndNode, RelationshipEntity, StartNode} | ||
|
||
@RelationshipEntity(`type` = "EXECUTED") | ||
class ActionTransitionEntity(start: SutState, end: SutState) extends Entity { | ||
@RelationshipEntity(`type` = "ACTIONS") | ||
class ActionTransitionEntity(s: SutState, e: SutState, a: Action) extends Entity { | ||
|
||
def this() = this(null, null) | ||
def this() = this(null, null, null) | ||
|
||
@StartNode val s = start | ||
@StartNode val start: SutState = s | ||
|
||
@EndNode val e = end | ||
@EndNode val end: SutState = e | ||
|
||
@Convert(classOf[ActionConverter]) | ||
val action: Action = a | ||
|
||
/// The number of times this action has been executed. | ||
var counter: Int = 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 26 additions & 3 deletions
29
src/main/scala/de/retest/guistatemachine/api/neo4j/Neo4jSessionFactory.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
package de.retest.guistatemachine.api.neo4j | ||
|
||
import org.neo4j.ogm.session.SessionFactory | ||
import org.neo4j.ogm.config.Configuration | ||
import org.neo4j.ogm.session.{Session, SessionFactory} | ||
import org.neo4j.ogm.transaction.Transaction | ||
|
||
import scala.collection.concurrent.TrieMap | ||
|
||
// TODO #19 Use sessions to modify the state graph. | ||
object Neo4jSessionFactory { | ||
private val sessionFactory = new SessionFactory("de.retest.guistatemachine.api.neo4j") | ||
private val sessionFactories = TrieMap[String, SessionFactory]() | ||
|
||
def getSessionFactory(uri: String): SessionFactory = sessionFactories.get(uri) match { | ||
case Some(sessionFactory) => sessionFactory | ||
case None => | ||
val conf = new Configuration.Builder().uri(uri).build | ||
val sessionFactory = new SessionFactory(conf, "de.retest.guistatemachine.api.neo4j") | ||
sessionFactories += (uri -> sessionFactory) | ||
sessionFactory | ||
} | ||
|
||
def getSession() = sessionFactory.openSession() | ||
def transaction[A](f: => A)(implicit session: Session): A = { | ||
var txn: Option[Transaction] = None | ||
try { | ||
txn = Some(session.beginTransaction()) | ||
val r = f | ||
txn.get.commit() | ||
r | ||
} finally { | ||
if (txn.isDefined) { txn.get.close() } | ||
} | ||
} | ||
} |
8 changes: 0 additions & 8 deletions
8
src/main/scala/de/retest/guistatemachine/api/neo4j/RelationshipTypeAction.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.