diff --git a/src/main/java/org/sagebionetworks/web/client/widget/entity/download/Uploader.java b/src/main/java/org/sagebionetworks/web/client/widget/entity/download/Uploader.java index d2bad63823..105fb5f6ab 100644 --- a/src/main/java/org/sagebionetworks/web/client/widget/entity/download/Uploader.java +++ b/src/main/java/org/sagebionetworks/web/client/widget/entity/download/Uploader.java @@ -272,9 +272,8 @@ public void onSuccess(List uploadDestinations) { } else if ( uploadDestinations.get(0) instanceof ExternalUploadDestination ) { - ExternalUploadDestination externalUploadDestination = (ExternalUploadDestination) uploadDestinations.get( - 0 - ); + ExternalUploadDestination externalUploadDestination = + (ExternalUploadDestination) uploadDestinations.get(0); storageLocationId = externalUploadDestination.getStorageLocationId(); currentUploadType = externalUploadDestination.getUploadType(); @@ -294,13 +293,11 @@ public void onSuccess(List uploadDestinations) { } else if ( uploadDestinations.get(0) instanceof ExternalS3UploadDestination ) { - ExternalS3UploadDestination externalUploadDestination = (ExternalS3UploadDestination) uploadDestinations.get( - 0 - ); + ExternalS3UploadDestination externalUploadDestination = + (ExternalS3UploadDestination) uploadDestinations.get(0); storageLocationId = externalUploadDestination.getStorageLocationId(); currentUploadType = externalUploadDestination.getUploadType(); - String banner = externalUploadDestination.getBanner(); updateUploadBannerView(externalUploadDestination); // direct to s3(-like) storage } else if ( @@ -308,9 +305,10 @@ public void onSuccess(List uploadDestinations) { 0 ) instanceof ExternalObjectStoreUploadDestination ) { - ExternalObjectStoreUploadDestination externalUploadDestination = (ExternalObjectStoreUploadDestination) uploadDestinations.get( - 0 - ); + ExternalObjectStoreUploadDestination externalUploadDestination = + (ExternalObjectStoreUploadDestination) uploadDestinations.get( + 0 + ); storageLocationId = externalUploadDestination.getStorageLocationId(); currentUploadType = externalUploadDestination.getUploadType(); @@ -700,8 +698,21 @@ private void processNextFile() { } } + private void postUpload() { + if (currIndex + 1 == fileNames.length) { + // to new file handle id, or create new file entity with this file handle id + view.hideLoading(); + refreshAfterSuccessfulUpload(entityId); + } else { + // more files to upload + uploadNextFile(); + } + } + public void setFileEntityFileHandle(String fileHandleId) { - if (entityId != null || currentFileParentEntityId != null) { + if (fileHandleId == null) { + postUpload(); + } else if (entityId != null || currentFileParentEntityId != null) { synapseClient.setFileEntityFileHandle( fileHandleId, entityId, @@ -710,14 +721,7 @@ public void setFileEntityFileHandle(String fileHandleId) { @Override public void onSuccess(String entityId) { fileHasBeenUploaded = true; - if (currIndex + 1 == fileNames.length) { - // to new file handle id, or create new file entity with this file handle id - view.hideLoading(); - refreshAfterSuccessfulUpload(entityId); - } else { - // more files to upload - uploadNextFile(); - } + postUpload(); } @Override @@ -952,22 +956,26 @@ public void cancelClicked() { * Private Methods */ private void refreshAfterSuccessfulUpload(String entityId) { - jsClient.getEntity( - entityId, - OBJECT_TYPE.FileEntity, - new AsyncCallback() { - @Override - public void onSuccess(Entity result) { - entity = result; - uploadSuccess(); - } + if (entityId != null) { + jsClient.getEntity( + entityId, + OBJECT_TYPE.FileEntity, + new AsyncCallback() { + @Override + public void onSuccess(Entity result) { + entity = result; + uploadSuccess(); + } - @Override - public void onFailure(Throwable caught) { - view.showErrorMessage(caught.getMessage()); + @Override + public void onFailure(Throwable caught) { + view.showErrorMessage(caught.getMessage()); + } } - } - ); + ); + } else { + uploadSuccess(); + } } public void uploadError(String message, Throwable t) { @@ -1077,17 +1085,20 @@ private String getBannerText(UploadDestination uploadDestination) { String bannerPrefix = "Uploading to "; if (uploadDestination instanceof ExternalUploadDestination) { - ExternalUploadDestination dest = (ExternalUploadDestination) uploadDestination; + ExternalUploadDestination dest = + (ExternalUploadDestination) uploadDestination; return bannerPrefix + dest.getUrl(); } else if ( uploadDestination instanceof ExternalObjectStoreUploadDestination ) { - ExternalObjectStoreUploadDestination dest = (ExternalObjectStoreUploadDestination) uploadDestination; + ExternalObjectStoreUploadDestination dest = + (ExternalObjectStoreUploadDestination) uploadDestination; return bannerPrefix + dest.getEndpointUrl() + "/" + dest.getBucket(); } else if ( uploadDestination instanceof ExternalGoogleCloudUploadDestination ) { - ExternalGoogleCloudUploadDestination dest = (ExternalGoogleCloudUploadDestination) uploadDestination; + ExternalGoogleCloudUploadDestination dest = + (ExternalGoogleCloudUploadDestination) uploadDestination; String banner = bannerPrefix + "Google Cloud Storage: " + dest.getBucket(); if (DisplayUtils.isDefined(dest.getBaseKey())) { @@ -1095,7 +1106,8 @@ private String getBannerText(UploadDestination uploadDestination) { } return banner; } else if (uploadDestination instanceof ExternalS3UploadDestination) { - ExternalS3UploadDestination dest = (ExternalS3UploadDestination) uploadDestination; + ExternalS3UploadDestination dest = + (ExternalS3UploadDestination) uploadDestination; String banner = bannerPrefix + "AWS S3: " + dest.getBucket(); if (DisplayUtils.isDefined(dest.getBaseKey())) { banner += "/" + dest.getBaseKey(); diff --git a/src/main/java/org/sagebionetworks/web/client/widget/upload/MultipartUploaderImpl.java b/src/main/java/org/sagebionetworks/web/client/widget/upload/MultipartUploaderImpl.java index 9e0a8a562f..546647c9c3 100755 --- a/src/main/java/org/sagebionetworks/web/client/widget/upload/MultipartUploaderImpl.java +++ b/src/main/java/org/sagebionetworks/web/client/widget/upload/MultipartUploaderImpl.java @@ -110,10 +110,9 @@ public void uploadFile( isCanceled = false; isDebugLevelLogging = DisplayUtils.isInTestWebsite(cookies); - // SWC-3779: check for empty file long fileSize = (long) synapseJsniUtils.getFileSize(blob); if (fileSize <= 0) { - handler.uploadFailed(EMPTY_FILE_ERROR_MESSAGE + fileName); + handler.uploadSuccess(null); return; } @@ -252,7 +251,8 @@ public void attemptUploadCurrentPart() { currentPartNumber + "\n" ); - BatchPresignedUploadUrlRequest batchPresignedUploadUrlRequest = new BatchPresignedUploadUrlRequest(); + BatchPresignedUploadUrlRequest batchPresignedUploadUrlRequest = + new BatchPresignedUploadUrlRequest(); batchPresignedUploadUrlRequest.setContentType(BINARY_CONTENT_TYPE); batchPresignedUploadUrlRequest.setPartNumbers( Collections.singletonList(new Long(currentPartNumber)) diff --git a/src/test/java/org/sagebionetworks/web/unitclient/widget/upload/MultipartUploaderTest.java b/src/test/java/org/sagebionetworks/web/unitclient/widget/upload/MultipartUploaderTest.java index a4169b9036..7d00279955 100755 --- a/src/test/java/org/sagebionetworks/web/unitclient/widget/upload/MultipartUploaderTest.java +++ b/src/test/java/org/sagebionetworks/web/unitclient/widget/upload/MultipartUploaderTest.java @@ -321,7 +321,7 @@ public void testDirectUploadEmptyFile() throws Exception { anyBoolean(), any(AsyncCallback.class) ); - verify(mockHandler).uploadFailed(EMPTY_FILE_ERROR_MESSAGE + FILE_NAME); + verify(mockHandler).uploadSuccess(null); } @Test @@ -341,9 +341,8 @@ public void testDirectUploadSinglePart() throws Exception { anyBoolean(), any(AsyncCallback.class) ); - ArgumentCaptor captor = ArgumentCaptor.forClass( - BatchPresignedUploadUrlRequest.class - ); + ArgumentCaptor captor = + ArgumentCaptor.forClass(BatchPresignedUploadUrlRequest.class); verify(mockJsClient) .getMultipartPresignedUrlBatch( captor.capture(),