This repository has been archived by the owner on May 26, 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.
- Loading branch information
Showing
70 changed files
with
3,585 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,131 @@ | ||
# Compiled class file | ||
# Java | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
# Package Files | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
# Thumbnails | ||
Thumbs.db | ||
|
||
# Object files (no binaries in git repos!) | ||
*.obj | ||
*.exe | ||
*.so | ||
*.zip | ||
*.tar | ||
*.gz | ||
|
||
# Mac | ||
.fseventsd/ | ||
.Spotlight-V100/ | ||
.Trashes/ | ||
._.Trashes | ||
|
||
# Eclipse | ||
bin/ | ||
.bpmn/ | ||
.classpath | ||
.compatibility | ||
.project | ||
.pydevproject | ||
.factorypath | ||
.checkstyle | ||
.metadata/ | ||
.settings/ | ||
.pmd | ||
.springBeans | ||
.tern-project | ||
|
||
# IntelliJ | ||
.idea/ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
|
||
# Maven | ||
target/ | ||
imported/ | ||
|
||
# Subversion | ||
.svn/ | ||
|
||
# Misc | ||
*~ | ||
*.log | ||
*.orig | ||
*.sonar | ||
deployWars.sh | ||
buildContexts.sh | ||
======= | ||
temp/ | ||
target/ | ||
dist/ | ||
node_modules/ | ||
_SpecRunner.html | ||
.DS_Store | ||
test-results.xml | ||
.idea/ | ||
*.iml | ||
bower_components/ | ||
.project | ||
.settings | ||
.classpath | ||
.springBeans | ||
.directory | ||
.springBeans | ||
pom.xml~ | ||
.gitignore~ | ||
activemq-data/ | ||
.sonar | ||
### SublimeText ### | ||
# cache files for sublime text | ||
*.tmlanguage.cache | ||
*.tmPreferences.cache | ||
*.stTheme.cache | ||
# workspace files are user-specific | ||
*.sublime-workspace | ||
# project files should be checked into the repository, unless a significant | ||
# proportion of contributors will probably not be using SublimeText | ||
# *.sublime-project | ||
# sftp configuration file | ||
sftp-config.json | ||
.ftppass | ||
# Compiled source # | ||
################### | ||
*.com | ||
*.class | ||
*.dll | ||
*.exe | ||
*.o | ||
*.so | ||
# Packages # | ||
############ | ||
# it's better to unpack these files and commit the raw source | ||
# git has its own built in compression methods | ||
*.7z | ||
*.dmg | ||
*.gz | ||
*.iso | ||
*.jar | ||
*.rar | ||
*.tar | ||
*.zip | ||
# Logs and databases # | ||
###################### | ||
*.log | ||
*.sqlite | ||
# OS generated files # | ||
###################### | ||
.DS_Store | ||
.DS_Store? | ||
._* | ||
.Spotlight-V100 | ||
.Trashes | ||
ehthumbs.db | ||
Thumbs.db | ||
*.h2.db | ||
*.trace.db | ||
lightning-jenkins.properties |
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 @@ | ||
A Simple Cake Making example of using the job-manager library |
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,91 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>job-manager</artifactId> | ||
<groupId>uk.gov.justice.services</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>example</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>uk.gov.justice.services</groupId> | ||
<artifactId>jobstore-api</artifactId> | ||
<version>${project.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>uk.gov.justice.services</groupId> | ||
<artifactId>jobstore-persistence</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!-- TEST --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-library</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.tomee</groupId> | ||
<artifactId>openejb-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>uk.gov.justice.services</groupId> | ||
<artifactId>core</artifactId> | ||
<version>4.1.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>uk.gov.justice.utils</groupId> | ||
<artifactId>test-utils-logging-simple</artifactId> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<version>1.17.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>uk.gov.justice.services</groupId> | ||
<artifactId>test-utils-core</artifactId> | ||
<version>4.1.2</version> | ||
<scope>test</scope> | ||
<type>pom</type> | ||
</dependency> | ||
<dependency> | ||
<groupId>uk.gov.justice.services</groupId> | ||
<artifactId>jobstore-liquibase</artifactId> | ||
<scope>test</scope> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>uk.gov.justice.services</groupId> | ||
<artifactId>job-executor</artifactId> | ||
<scope>test</scope> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
<version>1.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!--<dependency>--> | ||
<!--<groupId>commons-dbutils</groupId>--> | ||
<!--<artifactId>commons-dbutils</artifactId>--> | ||
<!--<scope>test</scope>--> | ||
<!--<version>1.7</version>--> | ||
<!--</dependency>--> | ||
|
||
|
||
</dependencies> | ||
|
||
|
||
</project> |
56 changes: 56 additions & 0 deletions
56
example/src/main/java/uk/gov/moj/cpp/jobmanager/example/BakeryService.java
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,56 @@ | ||
package uk.gov.moj.cpp.jobmanager.example; | ||
|
||
import static java.time.ZonedDateTime.now; | ||
import static java.util.UUID.randomUUID; | ||
|
||
import uk.gov.justice.services.common.converter.ObjectToJsonObjectConverter; | ||
import uk.gov.moj.cpp.jobstore.api.JobRequest; | ||
import uk.gov.moj.cpp.jobstore.api.JobService; | ||
|
||
import javax.inject.Inject; | ||
import javax.transaction.Status; | ||
import javax.transaction.SystemException; | ||
import javax.transaction.UserTransaction; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class BakeryService { | ||
|
||
protected final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
@Inject | ||
protected ObjectToJsonObjectConverter objectConverter; | ||
|
||
@Inject | ||
private JobService jobService; | ||
|
||
@Inject | ||
private UserTransaction userTransaction; | ||
|
||
public void makeCake() { | ||
|
||
final MakeCakeWorkflow firstTask = MakeCakeWorkflow.firstTask(); | ||
|
||
final JobRequest startCakeJobRequest = new JobRequest(randomUUID(), objectConverter.convert(firstTask.getTaskData()), firstTask.toString(), now()); | ||
|
||
try { | ||
userTransaction.begin(); | ||
jobService.createJob(startCakeJobRequest); | ||
userTransaction.commit(); | ||
|
||
} catch (Exception ex) { | ||
logger.error("Unexpected exception during transaction, attempting rollback...", ex); | ||
|
||
try { | ||
if (userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION) { | ||
userTransaction.rollback(); | ||
logger.info("Transaction rolled back successfully"); | ||
} | ||
|
||
} catch(SystemException e1){ | ||
logger.error("Unexpected exception during transaction rollback, rollback maybe incomplete", e1); | ||
} | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
example/src/main/java/uk/gov/moj/cpp/jobmanager/example/MakeCakeWorkflow.java
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,50 @@ | ||
package uk.gov.moj.cpp.jobmanager.example; | ||
|
||
import static java.util.Arrays.asList; | ||
import static java.util.Arrays.stream; | ||
|
||
import uk.gov.moj.cpp.jobmanager.example.task.data.CakeBakingTime; | ||
import uk.gov.moj.cpp.jobmanager.example.task.data.Ingredients; | ||
import uk.gov.moj.cpp.jobmanager.example.task.data.Instruction; | ||
import uk.gov.moj.cpp.jobmanager.example.task.data.OvenSettings; | ||
import uk.gov.moj.cpp.jobmanager.example.task.data.SliceCake; | ||
import uk.gov.moj.cpp.jobmanager.example.task.data.Utensils; | ||
|
||
/** | ||
* Simple enum to encapsulate workflow steps, ordering and associated step/task data | ||
*/ | ||
public enum MakeCakeWorkflow { | ||
|
||
SWITCH_OVEN_ON(new OvenSettings(210, 2, true)), | ||
GET_INGREDIENTS(new Ingredients(asList("250g plain flour", "125g butter", "1Tbsp baking powder", "100g sugar", "2 eggs"))), | ||
GET_UTENSILS(new Utensils(asList("Large mixing bowl", "Fine sieve", "Large wooden spoon", "Whisk", "Cake Tin", "Pallette knife", "Icing bag"))), | ||
MIX_INGREDIENTS(new Instruction(asList("Put all ingredients in bowl", "Mix ingredients until you have a smooth consistency"))), | ||
FILL_CAKE_TIN(new Instruction(asList("Line cake tin with greaseproof paper", "Pour cake mixture into cake tin"))), | ||
BAKE_CAKE(new CakeBakingTime(5, null)), | ||
CAKE_MADE(new SliceCake(6)); | ||
|
||
private Object taskData; | ||
|
||
MakeCakeWorkflow(Object taskData) { | ||
this.taskData = taskData; | ||
} | ||
|
||
public static MakeCakeWorkflow firstTask() { | ||
return SWITCH_OVEN_ON; | ||
} | ||
|
||
|
||
public static MakeCakeWorkflow nextTask(final MakeCakeWorkflow lastTaskPerformed){ | ||
|
||
return stream(values()).filter(e -> e.ordinal() > lastTaskPerformed.ordinal()) | ||
.findFirst() | ||
.orElse(CAKE_MADE); | ||
|
||
} | ||
|
||
|
||
public Object getTaskData() { | ||
return taskData; | ||
} | ||
|
||
} |
Oops, something went wrong.