From 585f59170931a561c5ff97bc37777a23e72eeaa8 Mon Sep 17 00:00:00 2001 From: Vishwas Babu AJ Date: Mon, 22 Oct 2012 21:19:18 +0530 Subject: [PATCH] Minor fixes to detect empty file updates --- .../mifosng/platform/api/DocumentManagementApiResource.java | 2 +- .../documentmanagement/service/DocumentCommandValidator.java | 4 ---- .../DocumentWritePlatformServiceJpaRepositoryImpl.java | 5 ++--- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/DocumentManagementApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/DocumentManagementApiResource.java index bec528e43..fcad27e63 100755 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/DocumentManagementApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/DocumentManagementApiResource.java @@ -167,7 +167,7 @@ public class DocumentManagementApiResource { * passed in as a part of the update ***/ DocumentCommand documentCommand = null; - if (inputStream != null) { + if (inputStream != null && fileDetails.getFileName() != null) { modifiedParams.add("fileName"); modifiedParams.add("size"); modifiedParams.add("type"); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/documentmanagement/service/DocumentCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/documentmanagement/service/DocumentCommandValidator.java index 40a3f386f..0d7fd6485 100755 --- a/mifosng-provider/src/main/java/org/mifosng/platform/documentmanagement/service/DocumentCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/documentmanagement/service/DocumentCommandValidator.java @@ -31,8 +31,6 @@ public class DocumentCommandValidator { .notExceedingLengthOf(250); baseDataValidator.reset().parameter("location") .value(command.getLocation()).ignoreIfNull().notBlank(); - baseDataValidator.reset().parameter("type").value(command.getName()) - .ignoreIfNull().notBlank().notExceedingLengthOf(250); baseDataValidator.reset().parameter("description") .value(command.getName()).ignoreIfNull() .notExceedingLengthOf(250); @@ -65,8 +63,6 @@ public class DocumentCommandValidator { baseDataValidator.reset().parameter("fileName") .value(command.getFileName()).notBlank() .notExceedingLengthOf(250); - baseDataValidator.reset().parameter("type").value(command.getName()) - .notBlank().notExceedingLengthOf(250); baseDataValidator.reset().parameter("description") .value(command.getName()).notExceedingLengthOf(250); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java index 87bd08ae3..d08197aec 100755 --- a/mifosng-provider/src/main/java/org/mifosng/platform/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java @@ -124,7 +124,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements } oldLocation = documentForUpdate.getLocation(); // if a new file is also passed in - if (inputStream != null) { + if (inputStream != null && documentCommand.isFileNameChanged()) { String fileUploadLocation = FileUtils .generateFileParentDirectory( documentCommand.getParentEntityType(), @@ -136,7 +136,6 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements } // TODO replace file system appender with an Amazon S3 appender - // TODO delete the file at the previous location String fileLocation = FileUtils.saveToFileSystem(inputStream, fileUploadLocation, documentCommand.getFileName()); documentCommand.setLocation(fileLocation); @@ -144,7 +143,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements documentForUpdate.update(documentCommand); - if (inputStream != null) { + if (inputStream != null && documentCommand.isFileNameChanged()) { // delete previous file deleteFile(documentCommand.getName(), oldLocation); }