Skip to content
Snippets Groups Projects
Commit 5c3ea522 authored by srosse's avatar srosse
Browse files

OO-1809: log a warning if the item cannot be found

parent 001d56f1
No related branches found
No related tags found
No related merge requests found
...@@ -334,25 +334,18 @@ public class FileUploadController extends FormBasicController { ...@@ -334,25 +334,18 @@ public class FileUploadController extends FormBasicController {
// if so, there is alread a error-msg in log (vfsContainer.createChildLeaf) // if so, there is alread a error-msg in log (vfsContainer.createChildLeaf)
success = false; success = false;
} else { } else {
InputStream in = null; try(InputStream in = new FileInputStream(uploadedFile);
OutputStream out = null; OutputStream out = newFile.getOutputStream(false)) {
try {
in = new FileInputStream(uploadedFile);
out = newFile.getOutputStream(false);
FileUtils.bcopy(in, out, "uploadTmpFileToDestFile"); FileUtils.bcopy(in, out, "uploadTmpFileToDestFile");
uploadedFile.delete(); uploadedFile.delete();
} catch (IOException e) { } catch (IOException e) {
success = false; success = false;
} finally {
FileUtils.closeSafely(in);
FileUtils.closeSafely(out);
} }
} }
if (success) { if (success) {
String filePath = (uploadRelPath == null ? "" : uploadRelPath + "/") + newFile.getName(); String filePath = (uploadRelPath == null ? "" : uploadRelPath + "/") + newFile.getName();
finishSuccessfullUpload(filePath, ureq); finishSuccessfullUpload(filePath, newFile, ureq);
fileInfoMBean.logUpload(newFile.getSize()); fileInfoMBean.logUpload(newFile.getSize());
fireEvent(ureq, Event.DONE_EVENT); fireEvent(ureq, Event.DONE_EVENT);
} else { } else {
...@@ -671,16 +664,20 @@ public class FileUploadController extends FormBasicController { ...@@ -671,16 +664,20 @@ public class FileUploadController extends FormBasicController {
private void finishUpload(UserRequest ureq) { private void finishUpload(UserRequest ureq) {
// in both cases the upload must be finished and notified with a FolderEvent // in both cases the upload must be finished and notified with a FolderEvent
String filePath = (uploadRelPath == null ? "" : uploadRelPath + "/") + newFile.getName(); String filePath = (uploadRelPath == null ? "" : uploadRelPath + "/") + newFile.getName();
finishSuccessfullUpload(filePath, ureq); VFSItem item = currentContainer.resolve(filePath);
fileInfoMBean.logUpload(newFile.getSize()); if(item != null) {
finishSuccessfullUpload(filePath, item, ureq);
fileInfoMBean.logUpload(newFile.getSize());
} else {
logWarn("Upload with error:" + filePath, null);
}
fireEvent(ureq, Event.DONE_EVENT); fireEvent(ureq, Event.DONE_EVENT);
} }
/** /**
* Internal helper to finish the upload and add metadata * Internal helper to finish the upload and add metadata
*/ */
private void finishSuccessfullUpload(String filePath, UserRequest ureq) { private void finishSuccessfullUpload(String filePath, VFSItem item, UserRequest ureq) {
VFSItem item = currentContainer.resolve(filePath);
if (item instanceof OlatRootFileImpl) { if (item instanceof OlatRootFileImpl) {
OlatRootFileImpl relPathItem = (OlatRootFileImpl) item; OlatRootFileImpl relPathItem = (OlatRootFileImpl) item;
// create meta data // create meta data
...@@ -692,10 +689,14 @@ public class FileUploadController extends FormBasicController { ...@@ -692,10 +689,14 @@ public class FileUploadController extends FormBasicController {
meta.clearThumbnails();//if overwrite an older file meta.clearThumbnails();//if overwrite an older file
meta.write(); meta.write();
} }
ThreadLocalUserActivityLogger.log(FolderLoggingAction.FILE_UPLOADED, getClass(), CoreLoggingResourceable.wrapUploadFile(filePath));
if(item == null) {
// Notify listeners about upload logError("File cannot be uploaded: " + filePath, null);
fireEvent(ureq, new FolderEvent(FolderEvent.UPLOAD_EVENT, item)); } else {
ThreadLocalUserActivityLogger.log(FolderLoggingAction.FILE_UPLOADED, getClass(), CoreLoggingResourceable.wrapUploadFile(filePath));
// Notify listeners about upload
fireEvent(ureq, new FolderEvent(FolderEvent.UPLOAD_EVENT, item));
}
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment