Skip to content

Commit

Permalink
Merge pull request #5344 from Sage-Bionetworks/release-495
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros committed Apr 2, 2024
2 parents c9f5fc6 + 96d5d4f commit b39ccd9
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import org.sagebionetworks.web.client.DateTimeUtils;
import org.sagebionetworks.web.client.GWTWrapper;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.SynapseProperties;
import org.sagebionetworks.web.client.jsinterop.Promise;
import org.sagebionetworks.web.client.jsinterop.SRC.SynapseClient.FileUploadComplete;
import org.sagebionetworks.web.client.security.AuthenticationController;
import org.sagebionetworks.web.shared.WebConstants;

/**
* Perform a multi-part parallel upload utilizing code from the Synapse React Client
Expand All @@ -36,21 +38,24 @@ public class MultipartUploaderImplV2 implements MultipartUploader {
DateTimeUtils dateTimeUtils;
AuthenticationController auth;
SRCUploadFileWrapper srcUploadFileWrapper;
private SynapseProperties synapseProperties;

@Inject
public MultipartUploaderImplV2(
AuthenticationController auth,
GWTWrapper gwt,
SynapseJSNIUtils synapseJsniUtils,
DateTimeUtils dateTimeUtils,
SRCUploadFileWrapper srcUploadFileWrapper
SRCUploadFileWrapper srcUploadFileWrapper,
SynapseProperties synapseProperties
) {
super();
this.auth = auth;
this.synapseJsniUtils = synapseJsniUtils;
this.percentFormat = gwt.getNumberFormat("##");
this.dateTimeUtils = dateTimeUtils;
this.srcUploadFileWrapper = srcUploadFileWrapper;
this.synapseProperties = synapseProperties;
}

@Override
Expand All @@ -62,6 +67,15 @@ public void uploadFile(
final Long storageLocationId,
HasAttachHandlers view
) {
Long defaultStorageId = Long.parseLong(
synapseProperties.getSynapseProperty(
WebConstants.DEFAULT_STORAGE_ID_PROPERTY_KEY
)
);

int storageLocationIntValue = storageLocationId == null
? defaultStorageId.intValue()
: storageLocationId.intValue();
this.blob = blob;
this.view = view;
isCanceled = false;
Expand All @@ -76,7 +90,7 @@ public void uploadFile(
auth.getCurrentUserAccessToken(),
fileName,
blob,
storageLocationId.intValue(),
storageLocationIntValue,
contentType,
progress -> {
double currentProgress = progress.value / progress.total;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
Expand All @@ -22,6 +23,7 @@
import org.sagebionetworks.web.client.GWTWrapper;
import org.sagebionetworks.web.client.ProgressCallback;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.SynapseProperties;
import org.sagebionetworks.web.client.jsinterop.Promise;
import org.sagebionetworks.web.client.jsinterop.Promise.FunctionParam;
import org.sagebionetworks.web.client.jsinterop.SRC.SynapseClient.FileUploadComplete;
Expand Down Expand Up @@ -66,6 +68,9 @@ public class MultipartUploaderImplV2Test {
@Mock
SRCUploadFileWrapper mockSRCUploadFileWrapper;

@Mock
SynapseProperties mockSynapseProperties;

@Mock
Promise<FileUploadComplete> mockPromise;

Expand All @@ -83,6 +88,7 @@ public class MultipartUploaderImplV2Test {
public static final double FILE_SIZE = 9281;
public static final String FILE_NAME = "file.txt";
public static final String CONTENT_TYPE = "text/plain";
public static final long defaultStorageLocationId = 1L;

@Before
public void before() throws Exception {
Expand All @@ -104,12 +110,19 @@ public void before() throws Exception {
FILE_SIZE
);

when(
mockSynapseProperties.getSynapseProperty(
WebConstants.DEFAULT_STORAGE_ID_PROPERTY_KEY
)
).thenReturn(String.valueOf(defaultStorageLocationId));

uploader = new MultipartUploaderImplV2(
mockAuth,
gwt,
synapseJsniUtils,
mockDateTimeUtils,
mockSRCUploadFileWrapper
mockSRCUploadFileWrapper,
mockSynapseProperties
);

when(mockView.isAttached()).thenReturn(true);
Expand Down Expand Up @@ -152,6 +165,35 @@ public void testDirectUploadSinglePart() throws Exception {
verify(mockHandler).uploadSuccess(RESULT_FILE_HANDLE_ID);
}

@Test
public void testDirectUploadEmptyStorageLocationId() throws Exception {
uploader.uploadFile(
FILE_NAME,
CONTENT_TYPE,
mockFileBlob,
mockHandler,
null,
mockView
);

verify(mockPromise).then(promiseHandlerCaptor.capture());
FunctionParam thenHandler = promiseHandlerCaptor.getValue();

thenHandler.exec(mockFileUploadComplete);

verify(mockSRCUploadFileWrapper).uploadFile(
anyString(),
anyString(),
any(),
eq((int) defaultStorageLocationId),
anyString(),
any(),
any()
);
// the handler should get the id.
verify(mockHandler).uploadSuccess(RESULT_FILE_HANDLE_ID);
}

@Test
public void testUploadCanceled() throws Exception {
uploader.uploadFile(
Expand Down

0 comments on commit b39ccd9

Please sign in to comment.