From e5825340b92bda5bc2fc192d6bc7ee065893d94c Mon Sep 17 00:00:00 2001 From: alan Date: Fri, 10 Jul 2020 15:37:10 +0100 Subject: [PATCH] created a 1.5.2 release --- pom.xml | 11 +- readme.md | 166 +++++------------- thingifier/readme.md | 128 ++++++++++++++ .../application/PreRequestHook.java | 9 + .../application/ThingifierRestServer.java | 21 +++ thingifierapp/Procfile | 1 + thingifierapp/deploy.txt | 6 + thingifierapp/pom.xml | 17 +- .../application/ClearDataPreRequestHook.java | 43 +++++ .../thingifier/application/Main.java | 35 +++- .../src/main/resources/public/index.html | 44 ++++- 11 files changed, 352 insertions(+), 129 deletions(-) create mode 100644 thingifier/readme.md create mode 100644 thingifier/src/main/java/uk/co/compendiumdev/thingifier/application/PreRequestHook.java create mode 100644 thingifierapp/Procfile create mode 100644 thingifierapp/deploy.txt create mode 100644 thingifierapp/src/main/java/uk/co/compendiumdev/thingifier/application/ClearDataPreRequestHook.java diff --git a/pom.xml b/pom.xml index ea87f9dd..4fbd00d6 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ - 1.5.2-SNAPSHOT + 1.5.2 1.8 @@ -25,6 +25,15 @@ - thingifier-${project.version}-full + thingifierapp-${project.version}-full false @@ -112,6 +112,21 @@ + + com.heroku.sdk + heroku-maven-plugin + 1.1.3 + + ${java.version} + apithingifier + + + + + java $JAVA_OPTS -cp target/classes:target/dependency/* uk.co.compendiumdev.thingifier.application.Main -model=simpleTodoList -noshutdown -autocleardown=10 + + + diff --git a/thingifierapp/src/main/java/uk/co/compendiumdev/thingifier/application/ClearDataPreRequestHook.java b/thingifierapp/src/main/java/uk/co/compendiumdev/thingifier/application/ClearDataPreRequestHook.java new file mode 100644 index 00000000..954402bc --- /dev/null +++ b/thingifierapp/src/main/java/uk/co/compendiumdev/thingifier/application/ClearDataPreRequestHook.java @@ -0,0 +1,43 @@ +package uk.co.compendiumdev.thingifier.application; + +import spark.Request; +import spark.Response; +import uk.co.compendiumdev.thingifier.Thing; +import uk.co.compendiumdev.thingifier.Thingifier; +import uk.co.compendiumdev.thingifier.generic.instances.ThingInstance; + +public class ClearDataPreRequestHook implements PreRequestHook{ + private long lastReset; + private final int minutes; + private final Thingifier thingifier; + private final long maxgap; + + public ClearDataPreRequestHook(final int minutes, Thingifier thingifier) { + this.minutes = minutes; + this.lastReset = System.currentTimeMillis(); + this.thingifier = thingifier; + this.maxgap = minutes*60*1000; + } + + @Override + public boolean run(final Request request, final Response response) { + long currentTime = System.currentTimeMillis(); + long gap = currentTime-lastReset; + if(gap>maxgap){ + // reset the thingifier data + this.lastReset=currentTime; + System.out.println("Clearing all data"); + thingifier.clearAllData(); + System.out.println("Cleared all data"); + + System.out.println("Adding test data"); + final Thing todo = thingifier.getThingNamed("todo"); + ThingInstance paperwork = todo.createInstance().setValue("title", "Scan my paperwork"); + todo.addInstance(paperwork); + + ThingInstance filework = todo.createInstance().setValue("title", "File my paperwork"); + todo.addInstance(filework); + } + return false; + } +} diff --git a/thingifierapp/src/main/java/uk/co/compendiumdev/thingifier/application/Main.java b/thingifierapp/src/main/java/uk/co/compendiumdev/thingifier/application/Main.java index f59d3916..23732e55 100644 --- a/thingifierapp/src/main/java/uk/co/compendiumdev/thingifier/application/Main.java +++ b/thingifierapp/src/main/java/uk/co/compendiumdev/thingifier/application/Main.java @@ -11,7 +11,6 @@ import java.util.ArrayList; import java.util.List; -import static spark.Spark.*; /* @@ -116,6 +115,11 @@ public static void main(String[] args) { // prevent shutdown verb as configurable through arguments e.g. -noshutdown Boolean allowShutdown = true; + // clear data every 10 minutes configuragle through arguments e.g. -autocleardown + // -autocleardown=15 + Boolean clearDataPeriodically = false; + int clearDownMinutes=10; + System.out.println("Valid Model Names -model="); for(String aModelName : validModelNames){ System.out.println(aModelName); @@ -150,6 +154,20 @@ public static void main(String[] args) { if (arg.startsWith("-noshutdown")) { allowShutdown = false; } + + if (arg.startsWith("-autocleardown")) { + clearDataPeriodically = true; + String[] details = arg.split("="); + if (details != null && details.length > 1) { + String minutes = details[1].trim(); + try{ + clearDownMinutes = Integer.valueOf(minutes); + }catch(Exception e){ + System.out.println("Invalid minutes " + minutes + " " +e.getMessage()); + } + System.out.println(String.format("Will clear down every %d minutes", clearDownMinutes)); + } + } } @@ -176,15 +194,25 @@ public static void main(String[] args) { switch (modelName){ case "simpleTodoList": thingifier = new TodoListThingifier().get(); + break; case "todoListManager": default: thingifier = new TodoManagerThingifier().get(); } + thingifier.apiConfig().allowShowIdsInUrlsIfAvailable(true); + thingifier.apiConfig().allowShowIdsInResponsesIfAvailable(true); + thingifier.apiConfig().showSingleInstancesAsPlural(true); + thingifier.apiConfig().allowShowGuidsInResponses(false); + additionalRoutes.addAll(new DefaultGUI(thingifier). configureRoutes(). getRoutes()); + + + + ThingifierRestServer restServer; switch (modelName){ @@ -200,7 +228,10 @@ public static void main(String[] args) { additionalRoutes); } - + if(clearDataPeriodically) { + restServer.registerPreRequestHook( + new ClearDataPreRequestHook(clearDownMinutes, thingifier)); + } System.out.println("Running on " + Spark.port()); System.out.println(" e.g. http://localhost:" + Spark.port()); diff --git a/thingifierapp/src/main/resources/public/index.html b/thingifierapp/src/main/resources/public/index.html index 3665ac2e..ec01f37c 100644 --- a/thingifierapp/src/main/resources/public/index.html +++ b/thingifierapp/src/main/resources/public/index.html @@ -13,9 +13,49 @@ -

Thingifier App

+ + +

Thingifier App

+

This is the deployable version of Thingifier.

+

When deployed to heroku at:

+ +

The data will automatically clear down every 10 minutes.

+

NOTE: We are not responsible for any data that + you see on the apithingifier.herokuapp.com site. This is + publically available.

+

We recommend that you download a local version of the application from:

+

https://github.com/eviltester/thingifier

+

We reserve the right to remove the cloud deploy or change the reset time if we discover it is being misused.

+
+ + -

This is the deployable version of thingifier