diff --git a/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/S3ConnectorFunction.java b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/S3ConnectorFunction.java index 0ec57a3538..83211e6426 100644 --- a/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/S3ConnectorFunction.java +++ b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/S3ConnectorFunction.java @@ -43,6 +43,6 @@ public class S3ConnectorFunction implements OutboundConnectorFunction { public Object execute(OutboundConnectorContext context) { Function createDocument = context::createDocument; S3Request s3Request = context.bindVariables(S3Request.class); - return S3Executor.create(s3Request, createDocument).execute(s3Request.getData()); + return S3Executor.create(s3Request, createDocument).execute(s3Request.getAction()); } } diff --git a/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/core/S3Executor.java b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/core/S3Executor.java index 6e554402c4..9b0e842212 100644 --- a/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/core/S3Executor.java +++ b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/core/S3Executor.java @@ -11,6 +11,7 @@ import io.camunda.connector.aws.s3.model.request.*; import io.camunda.connector.aws.s3.model.response.DeleteResponse; import io.camunda.connector.aws.s3.model.response.DownloadResponse; +import io.camunda.connector.aws.s3.model.response.Element; import io.camunda.connector.aws.s3.model.response.UploadResponse; import io.camunda.document.Document; import io.camunda.document.store.DocumentCreationRequest; @@ -55,33 +56,32 @@ public Object execute(S3Action s3Action) { return switch (s3Action) { case DeleteS3Action deleteS3Action -> delete(deleteS3Action); case DownloadS3Action downloadS3Action -> download(downloadS3Action); - case UploadS3Action uploadS3Action -> upload(uploadS3Action); + case UploadObject uploadObject -> upload(uploadObject); }; } - private Object upload(UploadS3Action uploadS3Action) { - Long contentLength = uploadS3Action.document().metadata().getSize(); - String contentType = uploadS3Action.document().metadata().getContentType(); + private Object upload(UploadObject uploadObject) { + Long contentLength = uploadObject.document().metadata().getSize(); + String contentType = uploadObject.document().metadata().getContentType(); PutObjectRequest putObjectRequest = PutObjectRequest.builder() - .bucket(uploadS3Action.bucket()) + .bucket(uploadObject.bucket()) .key( - Optional.ofNullable(uploadS3Action.key()) - .orElse(uploadS3Action.document().metadata().getFileName())) + Optional.ofNullable(uploadObject.key()) + .orElse(uploadObject.document().metadata().getFileName())) .contentLength(contentLength) .contentType(contentType) .build(); this.s3Client.putObject( putObjectRequest, - RequestBody.fromInputStream(uploadS3Action.document().asInputStream(), contentLength)); + RequestBody.fromInputStream(uploadObject.document().asInputStream(), contentLength)); return new UploadResponse( - uploadS3Action.bucket(), - uploadS3Action.key(), - String.format( - "https://%s.s3.amazonaws.com/%s", uploadS3Action.bucket(), uploadS3Action.key())); + uploadObject.bucket(), + uploadObject.key(), + String.format("https://%s.s3.amazonaws.com/%s", uploadObject.bucket(), uploadObject.key())); } private DownloadResponse download(DownloadS3Action downloadS3Action) { @@ -107,7 +107,9 @@ private DownloadResponse download(DownloadS3Action downloadS3Action) { .andThen( document -> new DownloadResponse( - downloadS3Action.bucket(), downloadS3Action.key(), document, null)) + downloadS3Action.bucket(), + downloadS3Action.key(), + new Element.DocumentContent(document))) .apply( DocumentCreationRequest.from(getObjectResponse) .contentType(getObjectResponse.response().contentType()) @@ -122,11 +124,14 @@ private DownloadResponse retrieveResponseWithContent( byte[] rawBytes = responseResponseInputStream.readAllBytes(); return switch (responseResponseInputStream.response().contentType()) { case "text/plain" -> - new DownloadResponse(bucket, key, null, new String(rawBytes, StandardCharsets.UTF_8)); + new DownloadResponse( + bucket, key, new Element.StringContent(new String(rawBytes, StandardCharsets.UTF_8))); case "application/json" -> - new DownloadResponse(bucket, key, null, new ObjectMapper().readTree(rawBytes)); + new DownloadResponse( + bucket, key, new Element.JsonContent(new ObjectMapper().readTree(rawBytes))); default -> - new DownloadResponse(bucket, key, null, Base64.getEncoder().encodeToString(rawBytes)); + new DownloadResponse( + bucket, key, new Element.StringContent(Base64.getEncoder().encodeToString(rawBytes))); }; } diff --git a/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/S3Action.java b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/S3Action.java index 7a9343d963..9a61a3fd79 100644 --- a/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/S3Action.java +++ b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/S3Action.java @@ -15,4 +15,4 @@ name = "actionDiscriminator", defaultValue = "uploadObject") @TemplateSubType(id = "action", label = "Action") -public sealed interface S3Action permits DeleteS3Action, DownloadS3Action, UploadS3Action {} +public sealed interface S3Action permits DeleteS3Action, DownloadS3Action, UploadObject {} diff --git a/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/S3Request.java b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/S3Request.java index 017d7fc80b..ad2054f825 100644 --- a/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/S3Request.java +++ b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/S3Request.java @@ -22,7 +22,7 @@ public class S3Request extends AwsBaseRequest { @JsonSubTypes( value = { @JsonSubTypes.Type(value = DeleteS3Action.class, name = "deleteObject"), - @JsonSubTypes.Type(value = UploadS3Action.class, name = "uploadObject"), + @JsonSubTypes.Type(value = UploadObject.class, name = "uploadObject"), @JsonSubTypes.Type(value = DownloadS3Action.class, name = "downloadObject"), }) @Valid @@ -32,11 +32,11 @@ public class S3Request extends AwsBaseRequest { public S3Request() {} - public S3Action getData() { + public S3Action getAction() { return action; } - public void setData(S3Action data) { - this.action = data; + public void setAction(S3Action action) { + this.action = action; } } diff --git a/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/UploadS3Action.java b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/UploadObject.java similarity index 95% rename from connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/UploadS3Action.java rename to connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/UploadObject.java index 0d9697cbba..bfd72ac497 100644 --- a/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/UploadS3Action.java +++ b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/request/UploadObject.java @@ -12,8 +12,8 @@ import io.camunda.document.Document; import jakarta.validation.constraints.NotBlank; -@TemplateSubType(id = "uploadObject", label = "Upload document") -public record UploadS3Action( +@TemplateSubType(id = "uploadObject", label = "Upload object") +public record UploadObject( @TemplateProperty( label = "AWS bucket", id = "uploadActionBucket", diff --git a/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/response/DownloadResponse.java b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/response/DownloadResponse.java index 33fb8b3ba3..476cf8b08f 100644 --- a/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/response/DownloadResponse.java +++ b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/response/DownloadResponse.java @@ -6,6 +6,5 @@ */ package io.camunda.connector.aws.s3.model.response; -import io.camunda.document.Document; -public record DownloadResponse(String bucket, String key, Document document, Object content) {} +public record DownloadResponse(String bucket, String key, Element element) {} diff --git a/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/response/Element.java b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/response/Element.java new file mode 100644 index 0000000000..f20241cebe --- /dev/null +++ b/connectors/aws/aws-s3/src/main/java/io/camunda/connector/aws/s3/model/response/Element.java @@ -0,0 +1,11 @@ +package io.camunda.connector.aws.s3.model.response; + +import io.camunda.document.Document; + +public interface Element { + record DocumentContent(Document document) implements Element {} + + record StringContent(String content) implements Element {} + + record JsonContent(Object content) implements Element {} +} diff --git a/connectors/aws/aws-s3/src/test/java/io/camunda/connector/aws/s3/S3ConnectorFunctionTest.java b/connectors/aws/aws-s3/src/test/java/io/camunda/connector/aws/s3/S3ConnectorFunctionTest.java index 475b9d2fe1..bc84fabfad 100644 --- a/connectors/aws/aws-s3/src/test/java/io/camunda/connector/aws/s3/S3ConnectorFunctionTest.java +++ b/connectors/aws/aws-s3/src/test/java/io/camunda/connector/aws/s3/S3ConnectorFunctionTest.java @@ -51,7 +51,7 @@ void executeDownloadActionReturnsCorrectResult(String variables) { try (MockedStatic s3ExecutorMockedStatic = Mockito.mockStatic(S3Executor.class)) { s3ExecutorMockedStatic.when(() -> S3Executor.create(any(), any())).thenReturn(s3Executor); - when(s3Executor.execute(any())).thenReturn(new DownloadResponse("test", "test", null, null)); + when(s3Executor.execute(any())).thenReturn(new DownloadResponse("test", "test", null)); var response = s3ConnectorFunction.execute(context); Assertions.assertNotNull(response); Assertions.assertInstanceOf(DownloadResponse.class, response); diff --git a/connectors/aws/aws-s3/src/test/java/io/camunda/connector/aws/s3/core/S3ExecutorTest.java b/connectors/aws/aws-s3/src/test/java/io/camunda/connector/aws/s3/core/S3ExecutorTest.java index 43f60625ba..e6efbca24c 100644 --- a/connectors/aws/aws-s3/src/test/java/io/camunda/connector/aws/s3/core/S3ExecutorTest.java +++ b/connectors/aws/aws-s3/src/test/java/io/camunda/connector/aws/s3/core/S3ExecutorTest.java @@ -14,9 +14,10 @@ import io.camunda.connector.aws.s3.model.request.DeleteS3Action; import io.camunda.connector.aws.s3.model.request.DownloadS3Action; import io.camunda.connector.aws.s3.model.request.S3Action; -import io.camunda.connector.aws.s3.model.request.UploadS3Action; +import io.camunda.connector.aws.s3.model.request.UploadObject; import io.camunda.connector.aws.s3.model.response.DeleteResponse; import io.camunda.connector.aws.s3.model.response.DownloadResponse; +import io.camunda.connector.aws.s3.model.response.Element; import io.camunda.connector.aws.s3.model.response.UploadResponse; import io.camunda.document.Document; import io.camunda.document.store.DocumentCreationRequest; @@ -53,7 +54,7 @@ void executeUploadAction() { Function function = doc -> mock(Document.class); S3Executor executor = new S3Executor(s3Client, function); Document document = mock(Document.class, RETURNS_DEEP_STUBS); - S3Action s3Action = new UploadS3Action("test", "key", document); + S3Action s3Action = new UploadObject("test", "key", document); when(document.metadata().getSize()).thenReturn(42L); when(document.metadata().getContentType()).thenReturn("application/octet-stream"); @@ -81,8 +82,7 @@ void executeDownloadAsDocumentAction() { verify(s3Client, times(1)).getObject(any(GetObjectRequest.class)); assertInstanceOf(DownloadResponse.class, object); - assertNull(((DownloadResponse) object).content()); - assertNotNull(((DownloadResponse) object).document()); + assertInstanceOf(Element.DocumentContent.class, ((DownloadResponse) object).element()); } @Test @@ -104,9 +104,9 @@ void executeDownloadAsTextContentAction() throws IOException { verify(s3Client, times(1)).getObject(any(GetObjectRequest.class)); assertInstanceOf(DownloadResponse.class, object); - assertNotNull(((DownloadResponse) object).content()); - assertNull(((DownloadResponse) object).document()); - assertEquals("Hello World", ((DownloadResponse) object).content()); + assertNotNull(((DownloadResponse) object).element()); + assertInstanceOf(Element.StringContent.class, ((DownloadResponse) object).element()); + assertEquals("Hello World", ((DownloadResponse) object).element()); } @Test @@ -129,9 +129,8 @@ void executeDownloadAsJsonContentAction() throws IOException { verify(s3Client, times(1)).getObject(any(GetObjectRequest.class)); assertInstanceOf(DownloadResponse.class, object); DownloadResponse downloadResponse = (DownloadResponse) object; - assertNotNull(downloadResponse.content()); - assertNull(downloadResponse.document()); - assertEquals("World", ((ObjectNode) downloadResponse.content()).get("Hello").asText()); + assertNotNull(downloadResponse.element()); + assertEquals("World", ((ObjectNode) downloadResponse.element()).get("Hello").asText()); } @Test @@ -154,9 +153,8 @@ void executeDownloadAsBase64BytesContentAction() throws IOException { verify(s3Client, times(1)).getObject(any(GetObjectRequest.class)); assertInstanceOf(DownloadResponse.class, object); DownloadResponse downloadResponse = (DownloadResponse) object; - assertNotNull(downloadResponse.content()); - assertNull(downloadResponse.document()); + assertNotNull(downloadResponse.element()); assertEquals( - Base64.getEncoder().encodeToString("Hello".getBytes()), downloadResponse.content()); + Base64.getEncoder().encodeToString("Hello".getBytes()), downloadResponse.element()); } }