Skip to content

Commit ea1c851

Browse files
marko-kriskovicivicac
authored andcommitted
2282 - added image helper tools
1 parent c49a170 commit ea1c851

File tree

9 files changed

+1956
-19
lines changed

9 files changed

+1956
-19
lines changed

server/libs/modules/components/image-helper/src/main/java/com/bytechef/component/image/helper/ImageHelperComponentHandler.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.bytechef.component.image.helper;
1818

1919
import static com.bytechef.component.definition.ComponentDsl.component;
20+
import static com.bytechef.component.definition.ComponentDsl.tool;
2021

2122
import com.bytechef.component.ComponentHandler;
2223
import com.bytechef.component.definition.ComponentCategory;
@@ -46,7 +47,14 @@ public class ImageHelperComponentHandler implements ComponentHandler {
4647
ImageHelperGetImageMetadataAction.ACTION_DEFINITION,
4748
ImageHelperImageToBase64Action.ACTION_DEFINITION,
4849
ImageHelperResizeImageAction.ACTION_DEFINITION,
49-
ImageHelperRotateImageAction.ACTION_DEFINITION);
50+
ImageHelperRotateImageAction.ACTION_DEFINITION)
51+
.clusterElements(
52+
tool(ImageHelperCompressImageAction.ACTION_DEFINITION),
53+
tool(ImageHelperCropImageAction.ACTION_DEFINITION),
54+
tool(ImageHelperGetImageMetadataAction.ACTION_DEFINITION),
55+
tool(ImageHelperImageToBase64Action.ACTION_DEFINITION),
56+
tool(ImageHelperResizeImageAction.ACTION_DEFINITION),
57+
tool(ImageHelperRotateImageAction.ACTION_DEFINITION));
5058

5159
@Override
5260
public ComponentDefinition getDefinition() {

server/libs/modules/components/image-helper/src/main/java/com/bytechef/component/image/helper/action/ImageHelperCompressImageAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.RESULT_FILE_NAME;
2727
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.RESULT_FILE_NAME_PROPERTY;
2828

29-
import com.bytechef.component.definition.ActionContext;
3029
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
30+
import com.bytechef.component.definition.Context;
3131
import com.bytechef.component.definition.FileEntry;
3232
import com.bytechef.component.definition.Parameters;
3333
import java.awt.image.BufferedImage;
@@ -67,7 +67,7 @@ private ImageHelperCompressImageAction() {
6767
}
6868

6969
protected static FileEntry perform(
70-
Parameters inputParameters, Parameters connectionParameters, ActionContext actionContext) throws IOException {
70+
Parameters inputParameters, Parameters connectionParameters, Context actionContext) throws IOException {
7171

7272
FileEntry imageFileEntry = inputParameters.getRequiredFileEntry(IMAGE);
7373

server/libs/modules/components/image-helper/src/main/java/com/bytechef/component/image/helper/action/ImageHelperCropImageAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.Y_COORDINATE;
3131
import static com.bytechef.component.image.helper.util.ImageHelperUtils.storeBufferedImage;
3232

33-
import com.bytechef.component.definition.ActionContext;
3433
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
34+
import com.bytechef.component.definition.Context;
3535
import com.bytechef.component.definition.FileEntry;
3636
import com.bytechef.component.definition.Parameters;
3737
import java.awt.image.BufferedImage;
@@ -75,11 +75,11 @@ private ImageHelperCropImageAction() {
7575
}
7676

7777
protected static FileEntry perform(
78-
Parameters inputParameters, Parameters connectionParameters, ActionContext actionContext) throws IOException {
78+
Parameters inputParameters, Parameters connectionParameters, Context context) throws IOException {
7979

8080
FileEntry imageFileEntry = inputParameters.getRequiredFileEntry(IMAGE);
8181

82-
BufferedImage bufferedImage = ImageIO.read((File) actionContext.file(file -> file.toTempFile(imageFileEntry)));
82+
BufferedImage bufferedImage = ImageIO.read((File) context.file(file -> file.toTempFile(imageFileEntry)));
8383

8484
int x = inputParameters.getRequiredInteger(X_COORDINATE);
8585
int y = inputParameters.getRequiredInteger(Y_COORDINATE);
@@ -91,7 +91,7 @@ protected static FileEntry perform(
9191
BufferedImage croppedImage = bufferedImage.getSubimage(x, y, width, height);
9292

9393
return storeBufferedImage(
94-
actionContext, croppedImage, imageFileEntry.getExtension(),
94+
context, croppedImage, imageFileEntry.getExtension(),
9595
inputParameters.getRequiredString(RESULT_FILE_NAME));
9696
}
9797

server/libs/modules/components/image-helper/src/main/java/com/bytechef/component/image/helper/action/ImageHelperGetImageMetadataAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.IMAGE_PROPERTY;
2222
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.RESULT_FILE_NAME_PROPERTY;
2323

24-
import com.bytechef.component.definition.ActionContext;
2524
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
25+
import com.bytechef.component.definition.Context;
2626
import com.bytechef.component.definition.FileEntry;
2727
import com.bytechef.component.definition.Parameters;
2828
import java.io.File;
@@ -53,7 +53,7 @@ private ImageHelperGetImageMetadataAction() {
5353
}
5454

5555
protected static Map<String, Object> perform(
56-
Parameters inputParameters, Parameters connectionParameters, ActionContext actionContext) throws IOException {
56+
Parameters inputParameters, Parameters connectionParameters, Context actionContext) throws IOException {
5757

5858
FileEntry imageFileEntry = inputParameters.getRequiredFileEntry(IMAGE);
5959

server/libs/modules/components/image-helper/src/main/java/com/bytechef/component/image/helper/action/ImageHelperImageToBase64Action.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.IMAGE;
2323
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.IMAGE_PROPERTY;
2424

25-
import com.bytechef.component.definition.ActionContext;
2625
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
26+
import com.bytechef.component.definition.Context;
2727
import com.bytechef.component.definition.Parameters;
2828

2929
/**
@@ -42,7 +42,7 @@ private ImageHelperImageToBase64Action() {
4242
}
4343

4444
protected static String perform(
45-
Parameters inputParameters, Parameters connectionParameters, ActionContext actionContext) {
45+
Parameters inputParameters, Parameters connectionParameters, Context actionContext) {
4646

4747
byte[] fileContent = actionContext.file(file -> file.readAllBytes(inputParameters.getRequiredFileEntry(IMAGE)));
4848

server/libs/modules/components/image-helper/src/main/java/com/bytechef/component/image/helper/action/ImageHelperResizeImageAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.WIDTH;
2929
import static com.bytechef.component.image.helper.util.ImageHelperUtils.storeBufferedImage;
3030

31-
import com.bytechef.component.definition.ActionContext;
3231
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
32+
import com.bytechef.component.definition.Context;
3333
import com.bytechef.component.definition.FileEntry;
3434
import com.bytechef.component.definition.Parameters;
3535
import java.awt.Graphics2D;
@@ -64,7 +64,7 @@ private ImageHelperResizeImageAction() {
6464
}
6565

6666
protected static FileEntry perform(
67-
Parameters inputParameters, Parameters connectionParameters, ActionContext actionContext) throws IOException {
67+
Parameters inputParameters, Parameters connectionParameters, Context actionContext) throws IOException {
6868
FileEntry image = inputParameters.getRequiredFileEntry(IMAGE);
6969

7070
BufferedImage bufferedImage = ImageIO.read((File) actionContext.file(file -> file.toTempFile(image)));

server/libs/modules/components/image-helper/src/main/java/com/bytechef/component/image/helper/action/ImageHelperRotateImageAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.RESULT_FILE_NAME_PROPERTY;
2929
import static com.bytechef.component.image.helper.util.ImageHelperUtils.storeBufferedImage;
3030

31-
import com.bytechef.component.definition.ActionContext;
3231
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
32+
import com.bytechef.component.definition.Context;
3333
import com.bytechef.component.definition.FileEntry;
3434
import com.bytechef.component.definition.Parameters;
3535
import java.awt.Graphics2D;
@@ -64,7 +64,7 @@ private ImageHelperRotateImageAction() {
6464
}
6565

6666
protected static FileEntry perform(
67-
Parameters inputParameters, Parameters connectionParameters, ActionContext actionContext) throws IOException {
67+
Parameters inputParameters, Parameters connectionParameters, Context actionContext) throws IOException {
6868

6969
FileEntry imageFileEntry = inputParameters.getRequiredFileEntry(IMAGE);
7070

server/libs/modules/components/image-helper/src/main/java/com/bytechef/component/image/helper/util/ImageHelperUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.bytechef.component.image.helper.util;
1818

19-
import com.bytechef.component.definition.ActionContext;
19+
import com.bytechef.component.definition.Context;
2020
import com.bytechef.component.definition.FileEntry;
2121
import java.awt.image.BufferedImage;
2222
import java.io.ByteArrayInputStream;
@@ -34,14 +34,14 @@ private ImageHelperUtils() {
3434
}
3535

3636
public static FileEntry storeBufferedImage(
37-
ActionContext actionContext, BufferedImage image, String extension, String resultFileName) throws IOException {
37+
Context context, BufferedImage image, String extension, String resultFileName) throws IOException {
3838

3939
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
4040

4141
ImageIO.write(image, extension, byteArrayOutputStream);
4242

4343
InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
4444

45-
return actionContext.file(file -> file.storeContent(resultFileName + "." + extension, inputStream));
45+
return context.file(file -> file.storeContent(resultFileName + "." + extension, inputStream));
4646
}
4747
}

0 commit comments

Comments
 (0)