Skip to content
Snippets Groups Projects
Commit 81b74f81 authored by Evgeny Bardin's avatar Evgeny Bardin
Browse files

OZG-7426 handle empty/missing file content

parent 67a22412
Branches
Tags
1 merge request!13Ozg 7426 Fix NPE und OutOfMemory Exception
...@@ -89,6 +89,9 @@ class OzgCloudFileRepository { ...@@ -89,6 +89,9 @@ class OzgCloudFileRepository {
} }
private long getContentSize(String contentId) { private long getContentSize(String contentId) {
if (Objects.isNull(contentId)) {
return 0;
}
var contentGridFsFile = gridFsTemplate.find(queryByObjectId(contentId)).first(); var contentGridFsFile = gridFsTemplate.find(queryByObjectId(contentId)).first();
if (Objects.isNull(contentGridFsFile)) { if (Objects.isNull(contentGridFsFile)) {
throw new NotFoundException(GridFSFile.class, contentId); throw new NotFoundException(GridFSFile.class, contentId);
......
...@@ -100,6 +100,15 @@ class OzgCloudFileRepositoryITCase { ...@@ -100,6 +100,15 @@ class OzgCloudFileRepositoryITCase {
assertThat(result.getSize()).isEqualTo(OzgCloudFileTestFactory.SIZE); assertThat(result.getSize()).isEqualTo(OzgCloudFileTestFactory.SIZE);
} }
@Test
void shouldSetContentSizeToZero() {
var ozgCloudFile = OzgCloudFileTestFactory.createBuilder().id(null).version(0).contentId(null).build();
var result = repository.save(ozgCloudFile);
assertThat(result.getSize()).isZero();
}
@Test @Test
void shouldFailIfContentMissing() { void shouldFailIfContentMissing() {
var ozgCloudFile = OzgCloudFileTestFactory.createBuilder().id(null).version(0).contentId("missing").build(); var ozgCloudFile = OzgCloudFileTestFactory.createBuilder().id(null).version(0).contentId("missing").build();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment