GH-9988: Add FileExistsMode expression support
Fixes: #9988 Issue link: https://github.com/spring-projects/spring-integration/issues/9988 This change allows dynamic determination of `FileExistsMode` using SpEL expressions, making the component more flexible when handling file existence conflicts. * Add `fileExistsModeExpression` field and setter methods * Use `resolveFileExistsMode()` in put and get operations * Add changes to the docs * Ignore `temporaryFileName` when `FileExistsMode.APPEND` Improve runtime behavior by ignoring temporary filename settings when file exists mode is `APPEND`. Now, in `FileExistsMode.APPEND` mode, content is always appended directly to the original file regardless of `useTemporaryFileName` setting. In `RemoteFileTemplate`: - Remove exception validation when `APPEND` mode is used with temporary filenames - Modify logic to skip applying `temporaryFileSuffix` in `APPEND` mode In `AbstractRemoteFileOutboundGateway`: - Remove logic that disabled temporary filenames when setting `APPEND` mode * Apply review feedback on `FileExistsMode` expression - Optimize `EvaluationContext` usage by creating it once in `doInit()` - Enhance expression evaluation to support String representation of `FileExistsMode` - Optimize temporary filename handling logic in `RemoteFileTemplate` - Add warning message for incompatible `APPEND` mode with temporary filenames - Rename method to `setFileExistsModeExpressionString` for consistency - Update Java DSL support in `RemoteFileOutboundGatewaySpec` - Update reference documentation and release notes * Apply additional review feedback on `FileExistsMode` expression - Add `Function` variant to `RemoteFileOutboundGatewaySpec` - Update documentations to use one-sentence-per-line style - Improve code flow in `resolveFileExistsMode()` method * Fix additional review feedback on `FileExistsMode` expression - Use `Object` instead of `String` in `fileExistsModeFunction` - Fix return method call in `fileExistsModeFunction` (`remoteDirectoryExpression` -> `fileExistsModeExpression`) - Fix `standardEvaluationContext` initialization in `doInit()` - Ensure proper `EvaluationContext` usage in other methods Signed-off-by: Jooyoung Pyoung <pyoungjy@gmail.com>
This commit is contained in:
@@ -37,3 +37,21 @@ This is useful when you need to perform several high-level operations of the `Re
|
||||
For example, `AbstractRemoteFileOutboundGateway` uses it with the `mput` command implementation, where we perform a `put` operation for each file in the provided directory and recursively for its sub-directories.
|
||||
See the https://docs.spring.io/spring-integration/api/org/springframework/integration/file/remote/RemoteFileOperations.html#invoke[Javadoc] for more information.
|
||||
|
||||
Starting with version 6.5, the `AbstractRemoteFileOutboundGateway` supports dynamic resolution of `FileExistsMode` at runtime via SpEL expressions.
|
||||
This allows you to determine the action to take when files already exist based on message content or other conditions.
|
||||
|
||||
To use this feature, configure the `fileExistsModeExpression` property on the gateway.
|
||||
The expression can evaluate to:
|
||||
|
||||
* A `FileExistsMode` enum value (e.g., `FileExistsMode.REPLACE`)
|
||||
* A string representation of a `FileExistsMode` (case-insensitive, e.g., "REPLACE", "append")
|
||||
|
||||
If the expression returns `null`, the default `fileExistsMode` configured on the gateway will be used.
|
||||
|
||||
See the https://docs.spring.io/spring-integration/api/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.html#setFileExistsModeExpression(org.springframework.expression.Expression)[Javadoc] for more information.
|
||||
|
||||
[IMPORTANT]
|
||||
====
|
||||
When using `FileExistsMode.APPEND`, temporary filename functionality is automatically disabled regardless of the `useTemporaryFileName` setting.
|
||||
This is because appending to a temporary file and then renaming it would not achieve the intended append behavior.
|
||||
====
|
||||
|
||||
@@ -79,6 +79,12 @@ The `AbstractRecentFileListFilter` strategy has been introduced to accept only t
|
||||
The respective implementations are provided: `RecentFileListFilter`, `FtpRecentFileListFilter`, `SftpRecentFileListFilter` and `SmbRecentFileListFilter`.
|
||||
See xref:file/reading.adoc[Reading Files] for more information.
|
||||
|
||||
[[x6.5-file-exists-mode-expression]]
|
||||
== FileExistsMode Expression Support
|
||||
|
||||
The remote file gateways (`AbstractRemoteFileOutboundGateway`) now support dynamic resolution of `FileExistsMode` at runtime via SpEL expressions.
|
||||
See xref:ftp/rft.adoc[Remote File Gateways] for more information.
|
||||
|
||||
[[x6.5-hazelcast-changes]]
|
||||
== Hazelcast Module Deprecations
|
||||
|
||||
|
||||
Reference in New Issue
Block a user