This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit ed394897428a341dbc8198fca2052de44a00d047 Author: Yannick Martel <martel@©odelutin.com> Date: Thu Jan 29 15:59:22 2015 +0100 can remove file from document during save --- .../coselmar/services/v1/DocumentsWebService.java | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java index df083b8..a2cd223 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java @@ -318,6 +318,12 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { String filePath = pathAndContentType.getLeft(); String contentType = pathAndContentType.getRight(); + // If document has already a file, remove it + if (StringUtils.isNotBlank(document.getFilePath())) { + File documentFile = new File(document.getFilePath()); + FileUtils.deleteQuietly(documentFile); + } + document.setWithFile(true); document.setMimeType(contentType); document.setFilePath(filePath); @@ -409,6 +415,12 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { // Resource part documentEntity.setExternalUrl(document.getExternalUrl()); + // If had file info and now no file info : remove file + boolean hadFile = documentEntity.isWithFile(); + if (hadFile && StringUtils.isBlank(document.getFileName())) { + deleteAttachedFile(documentEntity); + } + documentEntity.setComment(document.getComment()); @@ -455,10 +467,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { } // Delete physical file - if (StringUtils.isNotBlank(document.getFilePath())) { - File documentFile = new File(document.getFilePath()); - FileUtils.deleteQuietly(documentFile); - } + deleteAttachedFile(document); getDocumentDao().delete(document); @@ -594,4 +603,18 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { return fullIds; } + /** + * Delete physically Document File, and update Document entity setting + * filePath and fileName to null and withFile boolean to false + */ + protected void deleteAttachedFile(Document document) { + if (StringUtils.isNotBlank(document.getFilePath())) { + File documentFile = new File(document.getFilePath()); + FileUtils.deleteQuietly(documentFile); + + document.setFilePath(null); + document.setFileName(null); + document.setWithFile(false); + } + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.