From 0b7b30188d84cddee62b93e554927eb9221fb973 Mon Sep 17 00:00:00 2001 From: koutsoub Date: Wed, 16 Feb 2011 20:41:37 +0200 Subject: [PATCH] fix for create empty file --- src/gr/ebs/gss/server/ejb/ExternalAPIBean.java | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java b/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java index 1694f30..3563c2b 100644 --- a/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java +++ b/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java @@ -2778,10 +2778,60 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { permission.setModifyACL(p.getModifyACL()); file.addPermission(permission); } + // Create the file body. + try { + createEmptyFileBody(name, contentType, 0, file, auditInfo); + } catch (FileNotFoundException e) { + throw new GSSIOException(e); + } touchParentFolders(parent, owner, new Date()); dao.flush(); return file.getDTO(); } + + private void createEmptyFileBody(String name, String mimeType, long fileSize, + FileHeader header, AuditInfo auditInfo) + throws FileNotFoundException, QuotaExceededException, ObjectNotFoundException { + + long currentTotalSize = 0; + if (!header.isVersioned() && header.getCurrentBody() != null && header.getBodies() != null) + currentTotalSize = header.getTotalSize(); + Long quotaLeft = getQuotaLeft(header.getOwner().getId()); + + + FileBody body = new FileBody(); + + // if no mime type or the generic mime type is defined by the client, then try to identify it from the filename extension + if (StringUtils.isEmpty(mimeType) || "application/octet-stream".equals(mimeType) + || "application/download".equals(mimeType) || "application/force-download".equals(mimeType) + || "octet/stream".equals(mimeType) || "application/unknown".equals(mimeType)) + body.setMimeType(identifyMimeType(name)); + else + body.setMimeType(mimeType); + body.setAuditInfo(auditInfo); + body.setFileSize(fileSize); + body.setOriginalFilename(name); + body.setStoredFilePath(generateRepositoryFilePath()); + //CLEAR OLD VERSION IF FILE IS NOT VERSIONED AND GETS UPDATED + if(!header.isVersioned() && header.getCurrentBody() != null){ + header.setCurrentBody(null); + if (header.getBodies() != null) { + Iterator it = header.getBodies().iterator(); + while(it.hasNext()){ + FileBody bo = it.next(); + deleteActualFile(bo.getStoredFilePath()); + it.remove(); + dao.delete(bo); + } + } + } + + dao.flush(); + header.addBody(body); + header.setAuditInfo(auditInfo); + + dao.create(body); + } /*** WEBDAV LOCK **/ @Override public GssLock getLockById(String id) { -- 1.7.10.4