diff --git a/src/main/java/org/folio/rest/delegate/FileDelegate.java b/src/main/java/org/folio/rest/delegate/FileDelegate.java index 1cf5c4a7..e6afd824 100644 --- a/src/main/java/org/folio/rest/delegate/FileDelegate.java +++ b/src/main/java/org/folio/rest/delegate/FileDelegate.java @@ -35,6 +35,8 @@ public class FileDelegate extends AbstractWorkflowIODelegate { private Expression op; + private Expression target; + @Override public void execute(DelegateExecution execution) throws Exception { long startTime = System.nanoTime(); @@ -107,14 +109,26 @@ public void execute(DelegateExecution execution) throws Exception { } break; case WRITE: + // iterate over `target` input varaible + // writing entry per line + String targetInputVariable = this.target.getValue(execution).toString(); StringBuilder content = new StringBuilder(); - for (Object value : inputs.values()) { - if (value instanceof String) { - content.append(value); - } else { - content.append(objectMapper.writeValueAsString(value)); - } - content.append("\n"); + Object obj = inputs.get(targetInputVariable); + if (obj instanceof List) { + List objects = (List) obj; + logger.info("{} {} has {} entries to write", + obj.getClass().getSimpleName(), targetInputVariable, objects.size()); + for (Object value : (List) objects) { + if (value instanceof String) { + content.append(value); + } else { + content.append(objectMapper.writeValueAsString(value)); + } + content.append("\n"); + } + } else { + logger.warn("{} {} unsupported input type for target parameter of WRITE operation", + obj.getClass().getSimpleName(), targetInputVariable); } FileUtils.writeStringToFile(file, content.toString(), StandardCharsets.UTF_8); logger.info("{} written", filePath); @@ -148,6 +162,10 @@ public void setOp(Expression op) { this.op = op; } + public void setTarget(Expression target) { + this.target = target; + } + @Override public Class fromTask() { return FileTask.class;