Skip to content

Commit

Permalink
Merge pull request #5183 from jay-hodgson/SWC-6515
Browse files Browse the repository at this point in the history
  • Loading branch information
xschildw authored Sep 8, 2023
2 parents a222d6e + 81a873c commit be7306b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,8 @@ public void onSuccess(List<UploadDestination> 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();
Expand All @@ -294,23 +293,22 @@ public void onSuccess(List<UploadDestination> 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 (
uploadDestinations.get(
0
) instanceof ExternalObjectStoreUploadDestination
) {
ExternalObjectStoreUploadDestination externalUploadDestination = (ExternalObjectStoreUploadDestination) uploadDestinations.get(
0
);
ExternalObjectStoreUploadDestination externalUploadDestination =
(ExternalObjectStoreUploadDestination) uploadDestinations.get(
0
);
storageLocationId =
externalUploadDestination.getStorageLocationId();
currentUploadType = externalUploadDestination.getUploadType();
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -952,22 +956,26 @@ public void cancelClicked() {
* Private Methods
*/
private void refreshAfterSuccessfulUpload(String entityId) {
jsClient.getEntity(
entityId,
OBJECT_TYPE.FileEntity,
new AsyncCallback<Entity>() {
@Override
public void onSuccess(Entity result) {
entity = result;
uploadSuccess();
}
if (entityId != null) {
jsClient.getEntity(
entityId,
OBJECT_TYPE.FileEntity,
new AsyncCallback<Entity>() {
@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) {
Expand Down Expand Up @@ -1077,25 +1085,29 @@ 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())) {
banner += "/" + dest.getBaseKey();
}
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -341,9 +341,8 @@ public void testDirectUploadSinglePart() throws Exception {
anyBoolean(),
any(AsyncCallback.class)
);
ArgumentCaptor<BatchPresignedUploadUrlRequest> captor = ArgumentCaptor.forClass(
BatchPresignedUploadUrlRequest.class
);
ArgumentCaptor<BatchPresignedUploadUrlRequest> captor =
ArgumentCaptor.forClass(BatchPresignedUploadUrlRequest.class);
verify(mockJsClient)
.getMultipartPresignedUrlBatch(
captor.capture(),
Expand Down

0 comments on commit be7306b

Please sign in to comment.