Skip to content

Commit

Permalink
feature(s3-connector): corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
mathias-vandaele committed Dec 18, 2024
1 parent 1a50033 commit ecc2b88
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"name" : "Download document",
"value" : "downloadObject"
}, {
"name" : "Upload document",
"name" : "Upload object",
"value" : "uploadObject"
} ]
}, {
Expand Down Expand Up @@ -216,9 +216,6 @@
"id" : "uploadActionKey",
"label" : "AWS key",
"optional" : true,
"constraints" : {
"notEmpty" : true
},
"feel" : "optional",
"group" : "uploadObject",
"binding" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"name" : "Download document",
"value" : "downloadObject"
}, {
"name" : "Upload document",
"name" : "Upload object",
"value" : "uploadObject"
} ]
}, {
Expand Down Expand Up @@ -221,9 +221,6 @@
"id" : "uploadActionKey",
"label" : "AWS key",
"optional" : true,
"constraints" : {
"notEmpty" : true
},
"feel" : "optional",
"group" : "uploadObject",
"binding" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public static S3Executor create(

public Object execute(S3Action s3Action) {
return switch (s3Action) {
case DeleteS3Action deleteS3Action -> delete(deleteS3Action);
case DownloadS3Action downloadS3Action -> download(downloadS3Action);
case DeleteObject deleteObject -> delete(deleteObject);
case DownloadObject downloadObject -> download(downloadObject);
case UploadObject uploadObject -> upload(uploadObject);
};
}
Expand Down Expand Up @@ -84,20 +84,20 @@ private Object upload(UploadObject uploadObject) {
String.format("https://%s.s3.amazonaws.com/%s", uploadObject.bucket(), uploadObject.key()));
}

private DownloadResponse download(DownloadS3Action downloadS3Action) {
private DownloadResponse download(DownloadObject downloadObject) {
GetObjectRequest getObjectRequest =
GetObjectRequest.builder()
.bucket(downloadS3Action.bucket())
.key(downloadS3Action.key())
.bucket(downloadObject.bucket())
.key(downloadObject.key())
.build();

ResponseInputStream<GetObjectResponse> getObjectResponse =
this.s3Client.getObject(getObjectRequest);

if (!downloadS3Action.asFile()) {
if (!downloadObject.asFile()) {
try {
return retrieveResponseWithContent(
downloadS3Action.bucket(), downloadS3Action.key(), getObjectResponse);
downloadObject.bucket(), downloadObject.key(), getObjectResponse);
} catch (IOException e) {
log.error("An error occurred while trying to read and parse the downloaded file", e);
throw new RuntimeException(e);
Expand All @@ -107,13 +107,13 @@ private DownloadResponse download(DownloadS3Action downloadS3Action) {
.andThen(
document ->
new DownloadResponse(
downloadS3Action.bucket(),
downloadS3Action.key(),
downloadObject.bucket(),
downloadObject.key(),
new Element.DocumentContent(document)))
.apply(
DocumentCreationRequest.from(getObjectResponse)
.contentType(getObjectResponse.response().contentType())
.fileName(downloadS3Action.key())
.fileName(downloadObject.key())
.build());
}
}
Expand All @@ -135,14 +135,14 @@ private DownloadResponse retrieveResponseWithContent(
};
}

private DeleteResponse delete(DeleteS3Action deleteS3Action) {
private DeleteResponse delete(DeleteObject deleteObject) {
DeleteObjectRequest deleteObjectRequest =
DeleteObjectRequest.builder()
.bucket(deleteS3Action.bucket())
.key(deleteS3Action.key())
.bucket(deleteObject.bucket())
.key(deleteObject.key())
.build();

this.s3Client.deleteObject(deleteObjectRequest);
return new DeleteResponse(deleteS3Action.bucket(), deleteS3Action.key());
return new DeleteResponse(deleteObject.bucket(), deleteObject.key());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import io.camunda.connector.generator.java.annotation.TemplateSubType;
import jakarta.validation.constraints.NotBlank;

@TemplateSubType(id = "deleteObject", label = "Delete document")
public record DeleteS3Action(
@TemplateSubType(id = "deleteObject", label = "Delete object")
public record DeleteObject(
@TemplateProperty(
label = "AWS bucket",
id = "deleteActionBucket",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import io.camunda.connector.generator.java.annotation.TemplateSubType;
import jakarta.validation.constraints.NotBlank;

@TemplateSubType(id = "downloadObject", label = "Download document")
public record DownloadS3Action(
@TemplateSubType(id = "downloadObject", label = "Download object")
public record DownloadObject(
@TemplateProperty(
label = "AWS bucket",
id = "downloadActionBucket",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
name = "actionDiscriminator",
defaultValue = "uploadObject")
@TemplateSubType(id = "action", label = "Action")
public sealed interface S3Action permits DeleteS3Action, DownloadS3Action, UploadObject {}
public sealed interface S3Action permits DeleteObject, DownloadObject, UploadObject {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class S3Request extends AwsBaseRequest {
property = "actionDiscriminator")
@JsonSubTypes(
value = {
@JsonSubTypes.Type(value = DeleteS3Action.class, name = "deleteObject"),
@JsonSubTypes.Type(value = DeleteObject.class, name = "deleteObject"),
@JsonSubTypes.Type(value = UploadObject.class, name = "uploadObject"),
@JsonSubTypes.Type(value = DownloadS3Action.class, name = "downloadObject"),
@JsonSubTypes.Type(value = DownloadObject.class, name = "downloadObject"),
})
@Valid
@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public record UploadObject(
optional = true,
feel = Property.FeelMode.optional,
binding = @TemplateProperty.PropertyBinding(name = "action.key"))
@NotBlank
String key,
@TemplateProperty(
label = "Document",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
*/
package io.camunda.connector.aws.s3.model.response;


public record DownloadResponse(String bucket, String key, Element element) {}
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. Licensed under a proprietary license.
* See the License.txt file for more information. You may not use this file
* except in compliance with the proprietary license.
*/
package io.camunda.connector.aws.s3.model.response;

import io.camunda.document.Document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import static org.mockito.Mockito.*;

import com.fasterxml.jackson.databind.node.ObjectNode;
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.DeleteObject;
import io.camunda.connector.aws.s3.model.request.DownloadObject;
import io.camunda.connector.aws.s3.model.request.S3Action;
import io.camunda.connector.aws.s3.model.request.UploadObject;
import io.camunda.connector.aws.s3.model.response.DeleteResponse;
Expand Down Expand Up @@ -40,7 +40,7 @@ void executeDeleteAction() {
S3Client s3Client = mock(S3Client.class);
Function<DocumentCreationRequest, Document> function = doc -> mock(Document.class);
S3Executor executor = new S3Executor(s3Client, function);
S3Action s3Action = new DeleteS3Action("test", "key");
S3Action s3Action = new DeleteObject("test", "key");

Object object = executor.execute(s3Action);

Expand Down Expand Up @@ -73,7 +73,7 @@ void executeDownloadAsDocumentAction() {
S3Executor executor = new S3Executor(s3Client, function);
ResponseInputStream<GetObjectResponse> responseInputStream = mock(ResponseInputStream.class);
GetObjectResponse getObjectResponse = mock(GetObjectResponse.class);
S3Action s3Action = new DownloadS3Action("test", "key", true);
S3Action s3Action = new DownloadObject("test", "key", true);

when(s3Client.getObject(any(GetObjectRequest.class))).thenReturn(responseInputStream);
when(responseInputStream.response()).thenReturn(getObjectResponse);
Expand All @@ -93,7 +93,7 @@ void executeDownloadAsTextContentAction() throws IOException {
S3Executor executor = new S3Executor(s3Client, function);
ResponseInputStream<GetObjectResponse> responseInputStream = mock(ResponseInputStream.class);
GetObjectResponse getObjectResponse = mock(GetObjectResponse.class);
S3Action s3Action = new DownloadS3Action("test", "key", false);
S3Action s3Action = new DownloadObject("test", "key", false);

when(s3Client.getObject(any(GetObjectRequest.class))).thenReturn(responseInputStream);
when(responseInputStream.response()).thenReturn(getObjectResponse);
Expand All @@ -117,7 +117,7 @@ void executeDownloadAsJsonContentAction() throws IOException {
S3Executor executor = new S3Executor(s3Client, function);
ResponseInputStream<GetObjectResponse> responseInputStream = mock(ResponseInputStream.class);
GetObjectResponse getObjectResponse = mock(GetObjectResponse.class);
S3Action s3Action = new DownloadS3Action("test", "key", false);
S3Action s3Action = new DownloadObject("test", "key", false);

when(s3Client.getObject(any(GetObjectRequest.class))).thenReturn(responseInputStream);
when(responseInputStream.response()).thenReturn(getObjectResponse);
Expand All @@ -141,7 +141,7 @@ void executeDownloadAsBase64BytesContentAction() throws IOException {
S3Executor executor = new S3Executor(s3Client, function);
ResponseInputStream<GetObjectResponse> responseInputStream = mock(ResponseInputStream.class);
GetObjectResponse getObjectResponse = mock(GetObjectResponse.class);
S3Action s3Action = new DownloadS3Action("test", "key", false);
S3Action s3Action = new DownloadObject("test", "key", false);

when(s3Client.getObject(any(GetObjectRequest.class))).thenReturn(responseInputStream);
when(responseInputStream.response()).thenReturn(getObjectResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"contentType":"text/plain", "size":41730,
"fileName":"test.txt"
},
"documentType":"camunda"
"camunda.document.type":"camunda"
}
}, "configuration":{"region":"eu-central-1"},
"authentication":{
Expand Down

0 comments on commit ecc2b88

Please sign in to comment.