Skip to content

Commit 4577389

Browse files
authored
feat(dispatch): max filesize per use case (#261)
* feat(dispatch): max filesize per use case * docs(dispatch): README add max filesize * conf(dispatch): max filesize default 90MB * docs(dispatch): README update max filesize
1 parent 90d77d4 commit 4577389

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

dispatch-service/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ swim:
5151
bucket: # bucket to look for new files in
5252
path: # path to look for new files under
5353
recursive: # if the file lookup should be recursive (optional, default: false)
54+
max-file-size: # max size files can have that they are dispatched (optional, default: 90MB (IEC) -> 90*1024*1024B, example: 1GB)
5455
required-tags: # map of tags required on files to be dispatched (optional, default: {})
5556
requires-metadata: # if a metadata file is required (optional, default: false)
5657
destination-binding: # the target destination binding, see section "Adding additional target"

dispatch-service/src/main/java/de/muenchen/oss/swim/dispatcher/application/usecase/DispatcherUseCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ Map<String, Throwable> processDirectory(final UseCase useCase, final String fold
118118
* @param useCase The use case the file was found for.
119119
* @param file The file to be processed.
120120
* @throws FileSizeException If file is above configured
121-
* {@link SwimDispatcherProperties#getMaxFileSize()}
121+
* {@link UseCase#getMaxFileSize()}
122122
* @throws MetadataException If metadata file required but could not be loaded
123123
* @throws UseCaseException If use case can't be resolved in reroute action.
124124
*/
125125
protected void processFile(final UseCase useCase, final File file, final Map<String, String> tags)
126126
throws FileSizeException, MetadataException, UseCaseException {
127127
// check file size
128-
if (file.size() > swimDispatcherProperties.getMaxFileSize()) {
129-
final String message = String.format("File %s too large. %d > %d", file.path(), file.size(), swimDispatcherProperties.getMaxFileSize());
128+
if (file.size() > useCase.getMaxFileSize().toBytes()) {
129+
final String message = String.format("File %s too large. %d > %d", file.path(), file.size(), useCase.getMaxFileSize().toBytes());
130130
throw new FileSizeException(message);
131131
}
132132
// resolve action

dispatch-service/src/main/java/de/muenchen/oss/swim/dispatcher/configuration/SwimDispatcherProperties.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ public class SwimDispatcherProperties {
8787
*/
8888
@NotEmpty
8989
private String fallbackMail;
90-
/**
91-
* Max size files can have that they are dispatched.
92-
* Default: 100MiB
93-
*/
94-
private Long maxFileSize = 100 * 1024 * 1024L;
9590
/**
9691
* Folder name where finished files are moved to.
9792
*/

dispatch-service/src/main/java/de/muenchen/oss/swim/dispatcher/domain/model/UseCase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.List;
77
import java.util.Map;
88
import lombok.Data;
9+
import org.springframework.util.unit.DataSize;
910

1011
@Data
1112
public class UseCase {
@@ -28,6 +29,11 @@ public class UseCase {
2829
* If to look recursive for files.
2930
*/
3031
private boolean recursive = false;
32+
/**
33+
* Max size files can have that they are dispatched.
34+
* Default: 90MB (IEC)
35+
*/
36+
private DataSize maxFileSize = DataSize.ofMegabytes(90);
3137
/**
3238
* If filename contains sensitive data and should not be logged.
3339
*/

dispatch-service/src/main/resources/application-local.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ swim:
8282
bucket: swim-bucket
8383
path: test-dipa
8484
recursive: true
85+
max-file-size: 1GB
8586
destination-binding: dipa-out
8687
mail-addresses:
8788
- test-dipa@example.com

dispatch-service/src/test/java/de/muenchen/oss/swim/dispatcher/application/usecase/DispatcherUseCaseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void testProcessFile_MetadataDestination() throws FileSizeException, MetadataExc
152152
void testProcessFile_FileSizeException() {
153153
final UseCase useCase = swimDispatcherProperties.getUseCases().getFirst();
154154
assertThrows(FileSizeException.class,
155-
() -> dispatcherUseCase.processFile(useCase, new File(BUCKET, "test.pdf", swimDispatcherProperties.getMaxFileSize() + 1), TAGS));
155+
() -> dispatcherUseCase.processFile(useCase, new File(BUCKET, "test.pdf", useCase.getMaxFileSize().toBytes() + 1), TAGS));
156156
}
157157

158158
@Test

0 commit comments

Comments
 (0)