Commit 054b5a78 authored by Jay Jay Billings's avatar Jay Jay Billings
Browse files

Added a simple Spring State Machine for file moving.


Signed-off-by: default avatarJay Jay Billings <billingsjj@ornl.gov>
parent 514e3202
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<catalog prefer="public" xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<group id="Folder Repository, directory=, recursive=true, Auto-Update=true, version=2" prefer="public" xml:base=""/>
</catalog>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
......
......@@ -15,6 +15,11 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
......
......@@ -20,12 +20,49 @@
</plugins>
</build>
<properties>
<org.springframework.version>5.0.6.RELEASE</org.springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.statemachine</groupId>
<artifactId>spring-statemachine-core</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.statemachine</groupId>
<artifactId>spring-statemachine-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.statemachine</groupId>
<artifactId>spring-statemachine-bom</artifactId>
<version>2.1.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${org.springframework.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>${org.springframework.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
package org.eclipse.ice.workflow;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.EnumSet;
import org.eclipse.ice.workflow.WorkflowEngine.Events;
import org.eclipse.ice.workflow.WorkflowEngine.States;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.action.Action;
import org.springframework.statemachine.config.StateMachineBuilder;
import org.springframework.statemachine.config.StateMachineBuilder.Builder;
public class TaskTest {
static String name = "ICEIII/ice/org.eclipse.ice.workflow/src/main/resources/test1.txt";
static String newName = "ICEIII/ice/org.eclipse.ice.workflow/src/main/resources/test2.txt";
static public StateMachine<WorkflowEngine.States, WorkflowEngine.Events> buildMachine()
throws Exception {
Builder<WorkflowEngine.States, WorkflowEngine.Events> builder = new StateMachineBuilder.Builder<>();
builder.configureStates().withStates().initial(WorkflowEngine.States.INITIALIZED)
.states(EnumSet.allOf(WorkflowEngine.States.class));
builder.configureTransitions().withExternal().source(WorkflowEngine.States.INITIALIZED)
.target(WorkflowEngine.States.EXECUTING)
.event(WorkflowEngine.Events.PARAMETERS_RECEIVED).and().withExternal()
.source(WorkflowEngine.States.EXECUTING).target(WorkflowEngine.States.FINISHED)
.action(new Action<WorkflowEngine.States, WorkflowEngine.Events>() {
@Override
public void execute(StateContext<States, Events> context) {
try {
moveFile(name, newName);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).event(WorkflowEngine.Events.EXECUTION_COMPLETE);
return builder.build();
}
public static void moveFile(final String filePath, final String newFilePath)
throws IOException {
String home = System.getProperty("user.home");
String separator = String.valueOf(File.separatorChar);
String homePath = home+separator;
Path source = (new File(homePath + filePath)).toPath();
Path target = (new File(homePath + newFilePath)).toPath();
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
return;
}
public static void main(String[] args) throws Exception {
StateMachine<WorkflowEngine.States, WorkflowEngine.Events> taskProcessor = buildMachine();
taskProcessor.start();
taskProcessor.sendEvent(WorkflowEngine.Events.PARAMETERS_RECEIVED);
taskProcessor.sendEvent(WorkflowEngine.Events.EXECUTION_COMPLETE);
System.out.println(taskProcessor.getState());
return;
}
}
package org.eclipse.ice.workflow;
public class WorkflowEngine {
public enum States {
EXECUTING, FAILED, FINISHED, INITIALIZED, READY, REVIEWING, WAITING, WAITING_FOR_INFO
}
public enum Events {
PARAMETERS_RECEIVED, EXCEPTION, EXCEPTIONHANDLED, EXECUTION_COMPLETE
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<catalog prefer="public" xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<uri id="User Entered Import Resolution" name="http://swan.mindinformatics.org/ontologies/1.2/collections.owl" uri="file:/home/bkj/ICEIII/collections-ontology/collections.owl"/>
<uri id="User Entered Import Resolution" name="http://www.essepuntato.it/2009/10/error" uri="file:/home/bkj/ICEIII/collections-ontology/alignment.owl"/>
<uri id="User Entered Import Resolution" name="http://purl.org/co" uri="file:/home/bkj/ICEIII/collections-ontology/collections.owl"/>
<group id="Folder Repository, directory=, recursive=true, Auto-Update=true, version=2" prefer="public" xml:base=""/>
</catalog>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment