Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

## 1.0.0 - 2024-02-26
Official release

### Added
- Added datetime field to the Runabout json object.
- Added a setter to the RunaboutServiceBuilder to provide custom datetime suppliers.

## 0.0.2 - 2024-02-25
### Changed
- Changed the dependencies portion of the Runabout to be a Set of Strings representing the fully qualified class names of the dependencies.

## 0.0.1 - 2024-02-25
Initial release of the runabout-java library.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = 'dev.runabout'
version = '0.0.2'
version = '1.0.0'

repositories {
mavenCentral()
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/runabout/RunaboutConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ private RunaboutConstants() {
public static final String EVAL_KEY = "eval";
public static final String DEPENDENCIES_KEY = "dependencies";
public static final String INPUTS_KEY = "inputs";
public static final String DATETIME_KEY = "datetime";
}
23 changes: 21 additions & 2 deletions src/main/java/dev/runabout/RunaboutServiceBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.runabout;

import java.lang.reflect.Method;
import java.time.Instant;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
Expand All @@ -14,11 +15,12 @@
*/
public class RunaboutServiceBuilder<T extends JsonObject> {

private boolean excludeSuper = false;
private Supplier<Method> callerSupplier;
private Set<Class<?>> callerClassBlacklist;
private RunaboutSerializer customSerializer;
private Consumer<Throwable> throwableConsumer;
private boolean excludeSuper = false;
private Supplier<String> datetimeSupplier;

private final Supplier<T> jsonFactory;

Expand Down Expand Up @@ -109,6 +111,20 @@ public RunaboutServiceBuilder<T> setExcludeSuper(boolean excludeSuper) {
this.excludeSuper = excludeSuper;
return this;
}

/**
* Sets the datetime supplier for the RunaboutService.
* The supplier should return the current datetime UTC as an ISO-8601 formatted string.
* By default, the supplier will return the current datetime using {@link Instant#now()}.
*
* @param datetimeSupplier The datetime supplier.
* @return The RunaboutServiceBuilder.
*/
public RunaboutServiceBuilder<T> setDatetimeSupplier(Supplier<String> datetimeSupplier) {
this.datetimeSupplier = datetimeSupplier;
return this;
}

/**
* Builds the RunaboutService.
*
Expand All @@ -130,8 +146,11 @@ public RunaboutService<T> build() {
final Consumer<Throwable> throwableConsumerFinal = Optional.ofNullable(throwableConsumer)
.orElse(RunaboutServiceBuilder::defaultThrowableConsumer);

final Supplier<String> datetimeSupplier = Optional.ofNullable(this.datetimeSupplier)
.orElseGet(() -> () -> Instant.now().toString());

return new RunaboutServiceImpl<>(excludeSuper, throwableConsumerFinal, callerSupplierFinal,
customSerializerFinal, jsonFactory);
customSerializerFinal, jsonFactory, datetimeSupplier);
}

private static void defaultThrowableConsumer(Throwable t) {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/dev/runabout/RunaboutServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ class RunaboutServiceImpl<T extends JsonObject> implements RunaboutService<T> {
private final Supplier<Method> callerSupplier;
private final RunaboutSerializer customSerializer;
private final Supplier<T> jsonFactory;
private final Supplier<String> datetimeSupplier;

private final DefaultSerializer defaultSerializer = DefaultSerializer.getInstance();

RunaboutServiceImpl(boolean excludeSuper, Consumer<Throwable> throwableConsumer, Supplier<Method> callerSupplier,
RunaboutSerializer customSerializer, Supplier<T> jsonFactory) {
RunaboutSerializer customSerializer, Supplier<T> jsonFactory,
Supplier<String> datetimeSupplier) {
this.throwableConsumer = throwableConsumer;
this.excludeSuper = excludeSuper;
this.callerSupplier = callerSupplier;
this.customSerializer = customSerializer;
this.jsonFactory = jsonFactory;
this.datetimeSupplier = datetimeSupplier;
}

@Override
Expand Down Expand Up @@ -72,6 +75,9 @@ public T toRunaboutJson(Method method, Object... objects) {
// Put method data in json.
json.put(RunaboutConstants.METHOD_KEY, method.toString());

// Put datetime data in json.
json.put(RunaboutConstants.DATETIME_KEY, datetimeSupplier.get());

final List<JsonObject> inputs = new ArrayList<>();
for (final Object object: objects) {
final RunaboutInput input = serialize(object);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/runabout.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
JSON_CONTRACT_VERSION=1.0.0
JSON_CONTRACT_VERSION=1.1.0