diff --git a/api/src/main/java/io/serverlessworkflow/api/mapper/WorkflowModule.java b/api/src/main/java/io/serverlessworkflow/api/mapper/WorkflowModule.java index b2e2606e..5b42598d 100644 --- a/api/src/main/java/io/serverlessworkflow/api/mapper/WorkflowModule.java +++ b/api/src/main/java/io/serverlessworkflow/api/mapper/WorkflowModule.java @@ -42,11 +42,11 @@ public class WorkflowModule extends SimpleModule { - private static final long serialVersionUID = 510l; + private static final long serialVersionUID = 510L; - private WorkflowPropertySource workflowPropertySource; - private ExtensionSerializer extensionSerializer; - private ExtensionDeserializer extensionDeserializer; + private final WorkflowPropertySource workflowPropertySource; + private final ExtensionSerializer extensionSerializer; + private final ExtensionDeserializer extensionDeserializer; public WorkflowModule() { this(null); diff --git a/api/src/main/java/io/serverlessworkflow/api/serializers/FunctionRefSerializer.java b/api/src/main/java/io/serverlessworkflow/api/serializers/FunctionRefSerializer.java index cf5ce81f..71f61606 100644 --- a/api/src/main/java/io/serverlessworkflow/api/serializers/FunctionRefSerializer.java +++ b/api/src/main/java/io/serverlessworkflow/api/serializers/FunctionRefSerializer.java @@ -41,12 +41,12 @@ public void serialize(FunctionRef functionRef, JsonGenerator gen, SerializerProv && (functionRef.getInvoke() == null || functionRef.getInvoke().equals(FunctionRef.Invoke.SYNC)) && functionRef.getRefName() != null - && functionRef.getRefName().length() > 0) { + && !functionRef.getRefName().isEmpty()) { gen.writeString(functionRef.getRefName()); } else { gen.writeStartObject(); - if (functionRef.getRefName() != null && functionRef.getRefName().length() > 0) { + if (functionRef.getRefName() != null && !functionRef.getRefName().isEmpty()) { gen.writeStringField("refName", functionRef.getRefName()); } @@ -54,7 +54,7 @@ public void serialize(FunctionRef functionRef, JsonGenerator gen, SerializerProv gen.writeObjectField("arguments", functionRef.getArguments()); } - if (functionRef.getSelectionSet() != null && functionRef.getSelectionSet().length() > 0) { + if (functionRef.getSelectionSet() != null && !functionRef.getSelectionSet().isEmpty()) { gen.writeStringField("selectionSet", functionRef.getSelectionSet()); } diff --git a/api/src/main/java/io/serverlessworkflow/api/serializers/WorkflowSerializer.java b/api/src/main/java/io/serverlessworkflow/api/serializers/WorkflowSerializer.java index 4bbaf9c1..b5ac7cbb 100644 --- a/api/src/main/java/io/serverlessworkflow/api/serializers/WorkflowSerializer.java +++ b/api/src/main/java/io/serverlessworkflow/api/serializers/WorkflowSerializer.java @@ -15,187 +15,171 @@ */ package io.serverlessworkflow.api.serializers; +import java.io.IOException; +import java.security.MessageDigest; +import java.util.List; +import java.util.UUID; + import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import io.serverlessworkflow.api.Workflow; -import io.serverlessworkflow.api.error.ErrorDefinition; -import io.serverlessworkflow.api.events.EventDefinition; -import io.serverlessworkflow.api.functions.FunctionDefinition; import io.serverlessworkflow.api.interfaces.Extension; import io.serverlessworkflow.api.interfaces.State; -import io.serverlessworkflow.api.retry.RetryDefinition; -import java.io.IOException; -import java.security.MessageDigest; -import java.util.UUID; public class WorkflowSerializer extends StdSerializer { - public WorkflowSerializer() { - this(Workflow.class); - } - - protected WorkflowSerializer(Class t) { - super(t); - } - - private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); - - @Override - public void serialize(Workflow workflow, JsonGenerator gen, SerializerProvider provider) - throws IOException { - - gen.writeStartObject(); - - if (workflow.getId() != null && !workflow.getId().isEmpty()) { - gen.writeStringField("id", workflow.getId()); - } else { - gen.writeStringField("id", generateUniqueId()); - } - - if (workflow.getKey() != null) { - gen.writeStringField("key", workflow.getKey()); - } - gen.writeStringField("name", workflow.getName()); - - if (workflow.getDescription() != null && !workflow.getDescription().isEmpty()) { - gen.writeStringField("description", workflow.getDescription()); - } - - if (workflow.getVersion() != null && !workflow.getVersion().isEmpty()) { - gen.writeStringField("version", workflow.getVersion()); - } - - if (workflow.getAnnotations() != null && !workflow.getAnnotations().isEmpty()) { - gen.writeObjectField("annotations", workflow.getAnnotations()); - } - - if (workflow.getDataInputSchema() != null) { - if (workflow.getDataInputSchema().getSchema() != null - && workflow.getDataInputSchema().getSchema().length() > 0 - && workflow.getDataInputSchema().isFailOnValidationErrors()) { - gen.writeStringField("dataInputSchema", workflow.getDataInputSchema().getSchema()); - - } else if (workflow.getDataInputSchema().getSchema() != null - && workflow.getDataInputSchema().getSchema().length() > 0 - && !workflow.getDataInputSchema().isFailOnValidationErrors()) { - gen.writeObjectField("dataInputSchema", workflow.getDataInputSchema()); - } - } - - if (workflow.getStart() != null) { - gen.writeObjectField("start", workflow.getStart()); - } - - if (workflow.getSpecVersion() != null && !workflow.getSpecVersion().isEmpty()) { - gen.writeStringField("specVersion", workflow.getSpecVersion()); - } - - if (workflow.getExtensions() != null && !workflow.getExpressionLang().isEmpty()) { - gen.writeStringField("expressionLang", workflow.getExpressionLang()); - } - - if (workflow.isKeepActive()) { - gen.writeBooleanField("keepActive", workflow.isKeepActive()); - } - - if (workflow.isAutoRetries()) { - gen.writeBooleanField("autoRetries", workflow.isAutoRetries()); - } - - if (workflow.getMetadata() != null && !workflow.getMetadata().isEmpty()) { - gen.writeObjectField("metadata", workflow.getMetadata()); - } - - if (workflow.getEvents() != null && !workflow.getEvents().getEventDefs().isEmpty()) { - gen.writeArrayFieldStart("events"); - for (EventDefinition eventDefinition : workflow.getEvents().getEventDefs()) { - gen.writeObject(eventDefinition); - } - gen.writeEndArray(); - } - - if (workflow.getFunctions() != null && !workflow.getFunctions().getFunctionDefs().isEmpty()) { - gen.writeArrayFieldStart("functions"); - for (FunctionDefinition function : workflow.getFunctions().getFunctionDefs()) { - gen.writeObject(function); - } - gen.writeEndArray(); - } - - if (workflow.getRetries() != null && !workflow.getRetries().getRetryDefs().isEmpty()) { - gen.writeArrayFieldStart("retries"); - for (RetryDefinition retry : workflow.getRetries().getRetryDefs()) { - gen.writeObject(retry); - } - gen.writeEndArray(); - } - - if (workflow.getErrors() != null && !workflow.getErrors().getErrorDefs().isEmpty()) { - gen.writeArrayFieldStart("errors"); - for (ErrorDefinition error : workflow.getErrors().getErrorDefs()) { - gen.writeObject(error); - } - gen.writeEndArray(); - } - - if (workflow.getSecrets() != null && !workflow.getSecrets().getSecretDefs().isEmpty()) { - gen.writeArrayFieldStart("secrets"); - for (String secretDef : workflow.getSecrets().getSecretDefs()) { - gen.writeString(secretDef); - } - gen.writeEndArray(); - } - - if (workflow.getConstants() != null && !workflow.getConstants().getConstantsDef().isEmpty()) { - gen.writeObjectField("constants", workflow.getConstants().getConstantsDef()); - } - - if (workflow.getTimeouts() != null) { - gen.writeObjectField("timeouts", workflow.getTimeouts()); - } - - if (workflow.getAuth() != null && !workflow.getAuth().getAuthDefs().isEmpty()) { - gen.writeObjectField("auth", workflow.getAuth().getAuthDefs()); - } - - if (workflow.getStates() != null && !workflow.getStates().isEmpty()) { - gen.writeArrayFieldStart("states"); - for (State state : workflow.getStates()) { - gen.writeObject(state); - } - gen.writeEndArray(); - } - - if (workflow.getExtensions() != null && !workflow.getExtensions().isEmpty()) { - gen.writeArrayFieldStart("extensions"); - for (Extension extension : workflow.getExtensions()) { - gen.writeObject(extension); - } - gen.writeEndArray(); - } - - gen.writeEndObject(); - } - - protected static String generateUniqueId() { - try { - MessageDigest salt = MessageDigest.getInstance("SHA-256"); - - salt.update(UUID.randomUUID().toString().getBytes("UTF-8")); - return bytesToHex(salt.digest()); - } catch (Exception e) { - return UUID.randomUUID().toString(); - } - } - - protected static String bytesToHex(byte[] bytes) { - char[] hexChars = new char[bytes.length * 2]; - for (int j = 0; j < bytes.length; j++) { - int v = bytes[j] & 0xFF; - hexChars[j * 2] = hexArray[v >>> 4]; - hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); + + public WorkflowSerializer() { + this(Workflow.class); + } + + protected WorkflowSerializer(Class t) { + super(t); + } + + protected static String generateUniqueId() { + try { + MessageDigest salt = MessageDigest.getInstance("SHA-256"); + salt.update(UUID.randomUUID().toString().getBytes("UTF-8")); + return bytesToHex(salt.digest()); + } catch (Exception e) { + return UUID.randomUUID().toString(); + } + } + + protected static String bytesToHex(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for (int j = 0; j < bytes.length; j++) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + + // Helper to write either an array of items or a single string reference + private void writeListOrRef( + JsonGenerator gen, + SerializerProvider prov, + String fieldName, + List items, + String refValue) throws IOException { + if (items != null && !items.isEmpty()) { + gen.writeArrayFieldStart(fieldName); + for (T item : items) { + prov.defaultSerializeValue(item, gen); + } + gen.writeEndArray(); + } else if (refValue != null) { + gen.writeStringField(fieldName, refValue); + } + } + + @Override + public void serialize(Workflow workflow, JsonGenerator gen, SerializerProvider provider) + throws IOException { + + gen.writeStartObject(); + + // --- ID / key / basic fields --- + if (workflow.getId() != null && !workflow.getId().isEmpty()) { + gen.writeStringField("id", workflow.getId()); + } else { + gen.writeStringField("id", generateUniqueId()); + } + if (workflow.getKey() != null) { + gen.writeStringField("key", workflow.getKey()); + } + gen.writeStringField("name", workflow.getName()); + if (workflow.getDescription() != null && !workflow.getDescription().isEmpty()) { + gen.writeStringField("description", workflow.getDescription()); + } + if (workflow.getVersion() != null && !workflow.getVersion().isEmpty()) { + gen.writeStringField("version", workflow.getVersion()); + } + if (workflow.getAnnotations() != null && !workflow.getAnnotations().isEmpty()) { + gen.writeObjectField("annotations", workflow.getAnnotations()); + } + if (workflow.getDataInputSchema() != null) { + if (workflow.getDataInputSchema().getSchema() != null + && !workflow.getDataInputSchema().getSchema().isEmpty() + && workflow.getDataInputSchema().isFailOnValidationErrors()) { + gen.writeStringField("dataInputSchema", workflow.getDataInputSchema().getSchema()); + } else if (workflow.getDataInputSchema().getSchema() != null + && !workflow.getDataInputSchema().getSchema().isEmpty() + && !workflow.getDataInputSchema().isFailOnValidationErrors()) { + gen.writeObjectField("dataInputSchema", workflow.getDataInputSchema()); + } + } + if (workflow.getStart() != null) { + gen.writeObjectField("start", workflow.getStart()); + } + if (workflow.getSpecVersion() != null && !workflow.getSpecVersion().isEmpty()) { + gen.writeStringField("specVersion", workflow.getSpecVersion()); + } + if (workflow.getExpressionLang() != null && !workflow.getExpressionLang().isEmpty()) { + gen.writeStringField("expressionLang", workflow.getExpressionLang()); + } + if (workflow.isKeepActive()) { + gen.writeBooleanField("keepActive", workflow.isKeepActive()); + } + if (workflow.isAutoRetries()) { + gen.writeBooleanField("autoRetries", workflow.isAutoRetries()); + } + if (workflow.getMetadata() != null && !workflow.getMetadata().isEmpty()) { + gen.writeObjectField("metadata", workflow.getMetadata()); + } + + // --- Collections or references --- + if (workflow.getEvents() != null) { + writeListOrRef(gen, provider, + "events", + workflow.getEvents().getEventDefs(), + workflow.getEvents().getRefValue()); + } + if (workflow.getFunctions() != null) { + writeListOrRef(gen, provider, + "functions", + workflow.getFunctions().getFunctionDefs(), + workflow.getFunctions().getRefValue()); + } + if (workflow.getRetries() != null) { + writeListOrRef(gen, provider, + "retries", + workflow.getRetries().getRetryDefs(), + workflow.getRetries().getRefValue()); + } + if (workflow.getErrors() != null) { + writeListOrRef(gen, provider, + "errors", + workflow.getErrors().getErrorDefs(), + workflow.getErrors().getRefValue()); + } + if (workflow.getSecrets() != null) { + writeListOrRef(gen, provider, + "secrets", + workflow.getSecrets().getSecretDefs(), + workflow.getSecrets().getRefValue()); + } + + // --- Always-array fields --- + if (workflow.getStates() != null && !workflow.getStates().isEmpty()) { + gen.writeArrayFieldStart("states"); + for (State state : workflow.getStates()) { + gen.writeObject(state); + } + gen.writeEndArray(); + } + if (workflow.getExtensions() != null && !workflow.getExtensions().isEmpty()) { + gen.writeArrayFieldStart("extensions"); + for (Extension ext : workflow.getExtensions()) { + gen.writeObject(ext); + } + gen.writeEndArray(); + } + + gen.writeEndObject(); } - return new String(hexChars); - } } diff --git a/api/src/main/java/io/serverlessworkflow/api/workflow/Auth.java b/api/src/main/java/io/serverlessworkflow/api/workflow/Auth.java index 280053fa..e7828370 100644 --- a/api/src/main/java/io/serverlessworkflow/api/workflow/Auth.java +++ b/api/src/main/java/io/serverlessworkflow/api/workflow/Auth.java @@ -16,42 +16,48 @@ package io.serverlessworkflow.api.workflow; -import io.serverlessworkflow.api.auth.AuthDefinition; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -public class Auth { - private String refValue; - private List authDefs; - - public Auth() {} - - public Auth(AuthDefinition authDef) { - this.authDefs = new ArrayList<>(); - this.authDefs.add(authDef); - } - - public Auth(List authDefs) { - this.authDefs = authDefs; - } - - public Auth(String refValue) { - this.refValue = refValue; - } - - public String getRefValue() { - return refValue; - } - - public void setRefValue(String refValue) { - this.refValue = refValue; - } - - public List getAuthDefs() { - return authDefs; - } +import io.serverlessworkflow.api.auth.AuthDefinition; - public void setAuthDefs(List authDefs) { - this.authDefs = authDefs; - } +public class Auth { + private String refValue; + private List authDefs; + + public Auth() { + } + + public Auth(AuthDefinition authDef) { + this.authDefs = new ArrayList<>(); + this.authDefs.add(authDef); + } + + public Auth(List authDefs) { + this.authDefs = authDefs; + } + + public Auth(String refValue) { + this.refValue = refValue; + } + + public String getRefValue() { + return refValue; + } + + public void setRefValue(String refValue) { + this.refValue = refValue; + } + + public List getAuthDefs() { + if (authDefs == null) { + return Collections.emptyList(); + } + return authDefs; + } + + public void setAuthDefs(List authDefs) { + this.authDefs = authDefs; + } } diff --git a/api/src/main/java/io/serverlessworkflow/api/workflow/BaseWorkflow.java b/api/src/main/java/io/serverlessworkflow/api/workflow/BaseWorkflow.java index 61692caf..e3fc3d55 100644 --- a/api/src/main/java/io/serverlessworkflow/api/workflow/BaseWorkflow.java +++ b/api/src/main/java/io/serverlessworkflow/api/workflow/BaseWorkflow.java @@ -15,6 +15,9 @@ */ package io.serverlessworkflow.api.workflow; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; @@ -23,53 +26,53 @@ import io.serverlessworkflow.api.Workflow; import io.serverlessworkflow.api.mapper.JsonObjectMapper; import io.serverlessworkflow.api.mapper.YamlObjectMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -/** Base Workflow provides some extra functionality for the Workflow types */ +/** + * Base Workflow provides some extra functionality for the Workflow types + */ public class BaseWorkflow { - private static JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(); - private static YamlObjectMapper yamlObjectMapper = new YamlObjectMapper(); + private static JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(); + private static YamlObjectMapper yamlObjectMapper = new YamlObjectMapper(); - private static Logger logger = LoggerFactory.getLogger(BaseWorkflow.class); + private static Logger logger = LoggerFactory.getLogger(BaseWorkflow.class); - public static Workflow fromSource(String source) { - // try it as json markup first, if fails try yaml - try { - return jsonObjectMapper.readValue(source, Workflow.class); - } catch (Exception e) { - logger.info("Unable to convert as json markup, trying as yaml"); - try { - return yamlObjectMapper.readValue(source, Workflow.class); - } catch (Exception ee) { - throw new IllegalArgumentException( - "Could not convert markup to Workflow: " + ee.getMessage()); - } + public static Workflow fromSource(String source) { + // try it as json markup first, if fails try yaml + try { + return jsonObjectMapper.readValue(source, Workflow.class); + } catch (Exception e) { + logger.info("Unable to convert as json markup, trying as yaml"); + try { + return yamlObjectMapper.readValue(source, Workflow.class); + } catch (Exception ee) { + throw new IllegalArgumentException( + "Could not convert markup to Workflow: " + ee.getMessage()); + } + } } - } - public static String toJson(Workflow workflow) { - try { - return jsonObjectMapper.writeValueAsString(workflow); - } catch (JsonProcessingException e) { - logger.error("Error mapping to json: " + e.getMessage()); - return null; + public static String toJson(Workflow workflow) { + try { + return jsonObjectMapper.writeValueAsString(workflow); + } catch (JsonProcessingException e) { + logger.error("Error mapping to json: {}", e.getMessage()); + throw new IllegalArgumentException("Could not convert workflow to json: " + e.getMessage()); + } } - } - public static String toYaml(Workflow workflow) { - try { - String jsonString = jsonObjectMapper.writeValueAsString(workflow); - JsonNode jsonNode = jsonObjectMapper.readTree(jsonString); - YAMLFactory yamlFactory = - new YAMLFactory() - .disable(YAMLGenerator.Feature.MINIMIZE_QUOTES) - .disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER); - return new YAMLMapper(yamlFactory).writeValueAsString(jsonNode); - } catch (Exception e) { - logger.error("Error mapping to yaml: " + e.getMessage()); - return null; + public static String toYaml(Workflow workflow) { + try { + String jsonString = jsonObjectMapper.writeValueAsString(workflow); + JsonNode jsonNode = jsonObjectMapper.readTree(jsonString); + YAMLFactory yamlFactory = + new YAMLFactory() + .disable(YAMLGenerator.Feature.MINIMIZE_QUOTES) + .disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER); + return new YAMLMapper(yamlFactory).writeValueAsString(jsonNode); + } catch (Exception e) { + logger.error("Error mapping to yaml: {}", e.getMessage()); + throw new IllegalArgumentException("Could not convert workflow to yaml: " + e.getMessage()); + } } - } } diff --git a/api/src/main/java/io/serverlessworkflow/api/workflow/Errors.java b/api/src/main/java/io/serverlessworkflow/api/workflow/Errors.java index 8431b94a..9e474139 100644 --- a/api/src/main/java/io/serverlessworkflow/api/workflow/Errors.java +++ b/api/src/main/java/io/serverlessworkflow/api/workflow/Errors.java @@ -15,36 +15,42 @@ */ package io.serverlessworkflow.api.workflow; -import io.serverlessworkflow.api.error.ErrorDefinition; +import java.util.Collections; import java.util.List; -public class Errors { - private String refValue; - private List errorDefs; - - public Errors() {} - - public Errors(List errorDefs) { - this.errorDefs = errorDefs; - } - - public Errors(String refValue) { - this.refValue = refValue; - } - - public String getRefValue() { - return refValue; - } - - public void setRefValue(String refValue) { - this.refValue = refValue; - } - - public List getErrorDefs() { - return errorDefs; - } +import io.serverlessworkflow.api.error.ErrorDefinition; - public void setErrorDefs(List errorDefs) { - this.errorDefs = errorDefs; - } +public class Errors { + private String refValue; + private List errorDefs; + + public Errors() { + } + + public Errors(List errorDefs) { + this.errorDefs = errorDefs; + } + + public Errors(String refValue) { + this.refValue = refValue; + } + + public String getRefValue() { + return refValue; + } + + public void setRefValue(String refValue) { + this.refValue = refValue; + } + + public List getErrorDefs() { + if (errorDefs == null) { + return Collections.emptyList(); + } + return errorDefs; + } + + public void setErrorDefs(List errorDefs) { + this.errorDefs = errorDefs; + } } diff --git a/api/src/main/java/io/serverlessworkflow/api/workflow/Events.java b/api/src/main/java/io/serverlessworkflow/api/workflow/Events.java index 24080e51..59af2c3f 100644 --- a/api/src/main/java/io/serverlessworkflow/api/workflow/Events.java +++ b/api/src/main/java/io/serverlessworkflow/api/workflow/Events.java @@ -15,36 +15,42 @@ */ package io.serverlessworkflow.api.workflow; -import io.serverlessworkflow.api.events.EventDefinition; +import java.util.Collections; import java.util.List; -public class Events { - private String refValue; - private List eventDefs; - - public Events() {} - - public Events(List eventDefs) { - this.eventDefs = eventDefs; - } - - public Events(String refValue) { - this.refValue = refValue; - } - - public String getRefValue() { - return refValue; - } - - public void setRefValue(String refValue) { - this.refValue = refValue; - } - - public List getEventDefs() { - return eventDefs; - } +import io.serverlessworkflow.api.events.EventDefinition; - public void setEventDefs(List eventDefs) { - this.eventDefs = eventDefs; - } +public class Events { + private String refValue; + private List eventDefs; + + public Events() { + } + + public Events(List eventDefs) { + this.eventDefs = eventDefs; + } + + public Events(String refValue) { + this.refValue = refValue; + } + + public String getRefValue() { + return refValue; + } + + public void setRefValue(String refValue) { + this.refValue = refValue; + } + + public List getEventDefs() { + if (eventDefs == null) { + return Collections.emptyList(); + } + return eventDefs; + } + + public void setEventDefs(List eventDefs) { + this.eventDefs = eventDefs; + } } diff --git a/api/src/main/java/io/serverlessworkflow/api/workflow/Functions.java b/api/src/main/java/io/serverlessworkflow/api/workflow/Functions.java index f269bc08..6e927f9b 100644 --- a/api/src/main/java/io/serverlessworkflow/api/workflow/Functions.java +++ b/api/src/main/java/io/serverlessworkflow/api/workflow/Functions.java @@ -15,36 +15,42 @@ */ package io.serverlessworkflow.api.workflow; -import io.serverlessworkflow.api.functions.FunctionDefinition; +import java.util.Collections; import java.util.List; -public class Functions { - private String refValue; - private List functionDefs; - - public Functions() {} - - public Functions(List functionDefs) { - this.functionDefs = functionDefs; - } - - public Functions(String refValue) { - this.refValue = refValue; - } - - public String getRefValue() { - return refValue; - } - - public void setRefValue(String refValue) { - this.refValue = refValue; - } - - public List getFunctionDefs() { - return functionDefs; - } +import io.serverlessworkflow.api.functions.FunctionDefinition; - public void setFunctionDefs(List functionDefs) { - this.functionDefs = functionDefs; - } +public class Functions { + private String refValue; + private List functionDefs; + + public Functions() { + } + + public Functions(List functionDefs) { + this.functionDefs = functionDefs; + } + + public Functions(String refValue) { + this.refValue = refValue; + } + + public String getRefValue() { + return refValue; + } + + public void setRefValue(String refValue) { + this.refValue = refValue; + } + + public List getFunctionDefs() { + if (functionDefs == null) { + return Collections.emptyList(); + } + return functionDefs; + } + + public void setFunctionDefs(List functionDefs) { + this.functionDefs = functionDefs; + } } diff --git a/api/src/main/java/io/serverlessworkflow/api/workflow/Retries.java b/api/src/main/java/io/serverlessworkflow/api/workflow/Retries.java index af1ae1e0..fa539ac0 100644 --- a/api/src/main/java/io/serverlessworkflow/api/workflow/Retries.java +++ b/api/src/main/java/io/serverlessworkflow/api/workflow/Retries.java @@ -15,36 +15,42 @@ */ package io.serverlessworkflow.api.workflow; -import io.serverlessworkflow.api.retry.RetryDefinition; +import java.util.Collections; import java.util.List; -public class Retries { - private String refValue; - private List retryDefs; - - public Retries() {} - - public Retries(List retryDefs) { - this.retryDefs = retryDefs; - } - - public Retries(String refValue) { - this.refValue = refValue; - } - - public String getRefValue() { - return refValue; - } - - public void setRefValue(String refValue) { - this.refValue = refValue; - } - - public List getRetryDefs() { - return retryDefs; - } +import io.serverlessworkflow.api.retry.RetryDefinition; - public void setRetryDefs(List retryDefs) { - this.retryDefs = retryDefs; - } +public class Retries { + private String refValue; + private List retryDefs; + + public Retries() { + } + + public Retries(List retryDefs) { + this.retryDefs = retryDefs; + } + + public Retries(String refValue) { + this.refValue = refValue; + } + + public String getRefValue() { + return refValue; + } + + public void setRefValue(String refValue) { + this.refValue = refValue; + } + + public List getRetryDefs() { + if (retryDefs == null) { + return Collections.emptyList(); + } + return retryDefs; + } + + public void setRetryDefs(List retryDefs) { + this.retryDefs = retryDefs; + } } diff --git a/api/src/main/java/io/serverlessworkflow/api/workflow/Secrets.java b/api/src/main/java/io/serverlessworkflow/api/workflow/Secrets.java index 2dbb6b31..03edc0fd 100644 --- a/api/src/main/java/io/serverlessworkflow/api/workflow/Secrets.java +++ b/api/src/main/java/io/serverlessworkflow/api/workflow/Secrets.java @@ -15,35 +15,40 @@ */ package io.serverlessworkflow.api.workflow; +import java.util.Collections; import java.util.List; public class Secrets { - private String refValue; - private List secretDefs; - - public Secrets() {} - - public Secrets(String refValue) { - this.refValue = refValue; - } - - public Secrets(List secretDefs) { - this.secretDefs = secretDefs; - } - - public String getRefValue() { - return refValue; - } - - public void setRefValue(String refValue) { - this.refValue = refValue; - } - - public List getSecretDefs() { - return secretDefs; - } - - public void setSecretDefs(List secretDefs) { - this.secretDefs = secretDefs; - } + private String refValue; + private List secretDefs; + + public Secrets() { + } + + public Secrets(String refValue) { + this.refValue = refValue; + } + + public Secrets(List secretDefs) { + this.secretDefs = secretDefs; + } + + public String getRefValue() { + return refValue; + } + + public void setRefValue(String refValue) { + this.refValue = refValue; + } + + public List getSecretDefs() { + if (secretDefs == null) { + return Collections.emptyList(); + } + return secretDefs; + } + + public void setSecretDefs(List secretDefs) { + this.secretDefs = secretDefs; + } } diff --git a/pom.xml b/pom.xml index d62d5b9d..61a17961 100644 --- a/pom.xml +++ b/pom.xml @@ -228,6 +228,15 @@ + + + org.slf4j + slf4j-nop + ${version.org.slf4j} + test + + +