Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Load existing state machines from the disk #19
Browse files Browse the repository at this point in the history
  • Loading branch information
tdauth committed Apr 2, 2019
1 parent a4bb8ae commit a0d74cd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ There can be different backends which manage the state machine.

This backend uses the GraphDB [Neo4J](https://neo4j.com/) (community edition) with an embedded database.
It uses [Neo4J-OGM](https://neo4j.com/docs/ogm-manual/current/) to map our types to the graph database.
All state machines are stored in separate directories in `$HOME/.guistatemachines`.

Each state machine is represented by a separate graph database stored in a separate directory.
The nodes all have the property "sutState" which contains the corresponding SUT state serialized as XML.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package de.retest.guistatemachine.api
import java.nio.file.Paths

import de.retest.guistatemachine.api.impl.GuiStateMachineApiImpl
import de.retest.guistatemachine.api.neo4j.GuiStateMachineApiNeo4J

Expand Down Expand Up @@ -38,12 +40,17 @@ trait GuiStateMachineApi {
}

object GuiStateMachineApi {
val default = new GuiStateMachineApiImpl

/**
* @return The standard implementaiton of the API.
*/
def apply(): GuiStateMachineApi = default

/**
* The directory in which all GUI state machines will be persisted.
*/
val StateMachinesDir = Paths.get(System.getProperty("user.home"), ".guistatemachines").toAbsolutePath.toString

val default = new GuiStateMachineApiImpl
val neo4j = new GuiStateMachineApiNeo4J
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package de.retest.guistatemachine.api.neo4j

import java.io.File
import java.io.{File, FilenameFilter}
import java.nio.file.Paths

import com.typesafe.scalalogging.Logger
import de.retest.guistatemachine.api.impl.GuiStateMachineImpl
import de.retest.guistatemachine.api.{GuiStateMachine, GuiStateMachineApi}

import scala.collection.concurrent.TrieMap

class GuiStateMachineApiNeo4J extends GuiStateMachineApi {
private val logger = Logger[GuiStateMachineImpl]
private val logger = Logger[GuiStateMachineApiNeo4J]
private val stateMachines = TrieMap[String, GuiStateMachine]()
// TODO #19 Load existing state machines from the disk.

loadExistingStateMachinesFromDisk()

override def createStateMachine(name: String): GuiStateMachine = {
val uri = getUri(name)
Expand Down Expand Up @@ -41,5 +42,27 @@ class GuiStateMachineApiNeo4J extends GuiStateMachineApi {
removeStateMachine(name)
} // TODO #19 Removes from disk?

private def getUri(name: String): String = new File(name).toURI.toString
private def getUri(name: String): String = Paths.get(GuiStateMachineApi.StateMachinesDir, name).toUri.toString

private def getExistingFolders(): Seq[String] =
new File(GuiStateMachineApi.StateMachinesDir).list(new FilenameFilter() {
def accept(dir: File, name: String): Boolean = new File(dir, name).isDirectory
})

private def loadExistingStateMachinesFromDisk(): Unit = {
val dir = new File(GuiStateMachineApi.StateMachinesDir)

if (!dir.exists()) {
dir.mkdir()

logger.info("No existing graphs in {}.", dir.toString)
} else {
logger.info("Loading existing graphs from {}.", dir.toString)

getExistingFolders() foreach { f =>
logger.info("Loading graph {}.", f)
createStateMachine(f)
}
}
}
}

0 comments on commit a0d74cd

Please sign in to comment.