Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions pwiz_tools/Shared/CommonMsData/RemoteApi/Ardia/ArdiaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ public ArdiaResult<StorageInfoResponse> GetServerStorageInfo()
// API documentation: https://api.ardia-core-int.cmdtest.thermofisher.com/navigation/api/swagger/index.html
public ArdiaResult<GetParentFolderResponse> GetFolderByGetParentFolderByPath(string path)
{
var uri = UriFromParts(ServerUri, $"{PATH_GET_PARENT_BY_PATH}?itemPath={Uri.EscapeDataString(path)}");
var uri = UriWithParams(UriFromParts(ServerUri, PATH_GET_PARENT_BY_PATH), new Dictionary<string, string> { ["itemPath"] = path });

HttpStatusCode? statusCode = null;
try
Expand Down Expand Up @@ -720,12 +720,40 @@ private static Uri GetFolderContentsUrl(ArdiaAccount account, ArdiaUrl ardiaUrl)
return new Uri(account.GetFolderContentsUrl(ardiaUrl));
}

private static Uri UriFromParts(Uri host, string path)
public static Uri UriFromParts(Uri host, params string[] paths)
{
return new Uri(host.ToString().TrimEnd('/') + path);
var baseUri = host.AbsoluteUri.TrimEnd('/');

var combinedPath = string.Join("/", paths.Select(p => p.Trim('/')));

var full = $"{baseUri}/{combinedPath}";

if (!Uri.TryCreate(full, UriKind.Absolute, out var result))
throw new UriFormatException($"Resulting URI was not valid: {full}");

return new Uri(result.AbsoluteUri);
}

public static Uri UriWithParams(Uri url, IDictionary<string, string> queryParams)
{
var baseUri = url.AbsoluteUri.TrimEnd('/');

string full;

if (queryParams != null && queryParams.Count > 0)
{
var query = string.Join("&", queryParams.Select(kvp =>
$"{Uri.EscapeDataString(kvp.Key)}={Uri.EscapeDataString(kvp.Value)}"
));
full = $"{baseUri}?{query}";
}
else full = baseUri;

if (!Uri.TryCreate(full, UriKind.Absolute, out var result))
throw new UriFormatException($"Resulting URI was not valid: {full}");

return new Uri(result.AbsoluteUri);
}

private static bool ShouldHandleException(Exception exception)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
<data name="FileUpload_Success" xml:space="preserve">
<value>Successfully uploaded the document to Ardia.</value>
</data>
<data name="FileUpload_Success_OpenDataExplorer" xml:space="preserve">
<value>Successfully uploaded the document to Ardia. Would you like to view it in the Ardia Data Explorer?</value>
</data>
<data name="FileUpload_Error" xml:space="preserve">
<value>Unable to publish the document. A problem occurred communicating with the server.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace pwiz.CommonMsData.RemoteApi.Ardia
{
public class GetParentFolderResponse
{
private const string PATH_DATA_EXPLORER = @"/app/data-explorer/";
private const string PATH_DATA_EXPLORER = @"/app/data-explorer";

public string RLink2 { get; set; }

Expand All @@ -30,7 +30,7 @@ public class GetParentFolderResponse
public static GetParentFolderResponse FromJson(string json, Uri serverUrl)
{
var response = JsonConvert.DeserializeObject<GetParentFolderResponse>(json);
response.Url = new Uri(serverUrl.ToString().TrimEnd('/') + PATH_DATA_EXPLORER + response.RLink2);
response.Url = ArdiaClient.UriFromParts(serverUrl, PATH_DATA_EXPLORER, response.RLink2);
return response;
}
}
Expand Down
28 changes: 20 additions & 8 deletions pwiz_tools/Skyline/FileUI/PublishDocumentDlgArdia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -285,22 +286,33 @@ public void Upload(Control parent, SrmDocumentArchive archive)

if (isCanceled)
return;

if (result.IsSuccess)
{
PublishedDocument = result.Value;

MessageDlg.Show(parent, ArdiaResources.FileUpload_Success);
}
else

if (result.IsFailure)
{
string message;
if (result.ErrorStatusCode == HttpStatusCode.Unauthorized)
message = ArdiaResources.Error_InvalidToken;
else message = ArdiaResources.FileUpload_Error;

MessageDlg.ShowWithExceptionAndNetworkDetail(parent, message, result.ErrorMessage, result.ErrorException);
return;
}

PublishedDocument = result.Value;

var successMessage = ArdiaResources.FileUpload_Success_OpenDataExplorer;
if (MultiButtonMsgDlg.Show(parent, successMessage, MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, false) == DialogResult.No)
return;

var getUrlResult = Client.GetFolderByGetParentFolderByPath(DestinationPath);
if (getUrlResult.IsFailure)
{
var message = result.ErrorStatusCode == HttpStatusCode.Unauthorized ? ArdiaResources.Error_InvalidToken : ArdiaResources.Error_StatusCode_Unexpected;
MessageDlg.ShowWithExceptionAndNetworkDetail(parent, message, getUrlResult.ErrorMessage, getUrlResult.ErrorException);
return;
}

Process.Start(getUrlResult.Value.Url.ToString());
}

public TreeNode CreateFolder()
Expand Down
1 change: 1 addition & 0 deletions pwiz_tools/Skyline/Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<Compile Include="EncyclopeDiaHelpersTest.cs" />
<Compile Include="SrmSettingsNewTest.cs" />
<Compile Include="DllFinderUnitTest.cs" />
<Compile Include="UriBuilderTest.cs" />
<Compile Include="UtilTest.cs" />
<Compile Include="VariableModTest.cs" />
<Compile Include="WebEnabledFastaImporterTest.cs" />
Expand Down
38 changes: 38 additions & 0 deletions pwiz_tools/Skyline/Test/UriBuilderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using pwiz.CommonMsData.RemoteApi.Ardia;
using pwiz.SkylineTestUtil;

namespace pwiz.SkylineTest
{
[TestClass]
public class UriBuilderTest : AbstractUnitTest
{
private const string VALID_HOST = "https://ardia-core-int.cmdtest.thermofisher.com";
private const string PATH_1 = "/app/data-explorer";
private const string PATH_2 = "folders/8935b4af-015c-4ece-82a5-a812cd5a1626";

[TestMethod]
public void TestUriFromParts()
{
var host = new Uri(VALID_HOST);
Assert.AreEqual(VALID_HOST + PATH_1, ArdiaClient.UriFromParts(host, PATH_1).AbsoluteUri);
Assert.AreEqual(VALID_HOST + PATH_1 + "/" + PATH_2, ArdiaClient.UriFromParts(host, PATH_1, PATH_2).AbsoluteUri);
}

[TestMethod]
public void TestUriWithParams()
{
var host = new Uri(VALID_HOST);
var queryParams = new Dictionary<string, string> { ["param 1"] = "value 1" };
Assert.AreEqual(VALID_HOST + PATH_1 + $"?{Uri.EscapeDataString("param 1")}={Uri.EscapeDataString("value 1")}",
ArdiaClient.UriWithParams(ArdiaClient.UriFromParts(host, PATH_1), queryParams).AbsoluteUri);
queryParams.Add("param 2", "value 2");
Assert.AreEqual(
VALID_HOST + PATH_1 +
$"?{Uri.EscapeDataString("param 1")}={Uri.EscapeDataString("value 1")}&{Uri.EscapeDataString("param 2")}={Uri.EscapeDataString("value 2")}",
ArdiaClient.UriWithParams(ArdiaClient.UriFromParts(host, PATH_1), queryParams).AbsoluteUri);
}
}
}
6 changes: 3 additions & 3 deletions pwiz_tools/Skyline/TestConnected/ArdiaFileUploadTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,15 @@ private static void TestSuccessfulUpload(ArdiaAccount account, ArdiaClient clien
});

var shareTypeDlg = ShowDialog<ShareTypeDlg>(publishDlg.OkDialog);
var docUploadedDlg = ShowDialog<MessageDlg>(shareTypeDlg.OkDialog);
var docUploadedDlg = ShowDialog<MultiButtonMsgDlg>(shareTypeDlg.OkDialog);

// CONSIDER: in this case, MessageDlg displays when publishing is successful AND when there's an error.
// Calling OkDialog(...) works in both cases - which causes downstream, less obvious errors.
// Is there a better way to detect when a MessageDlg indicates an error without looking at
// the message string?
Assert.AreEqual(ArdiaResources.FileUpload_Success, docUploadedDlg.Message, @"Error publishing the document to Ardia");
Assert.AreEqual(ArdiaResources.FileUpload_Success_OpenDataExplorer, docUploadedDlg.Message, @"Error publishing the document to Ardia");

OkDialog(docUploadedDlg, docUploadedDlg.ClickOk);
OkDialog(docUploadedDlg, docUploadedDlg.ClickYes);
Assert.IsNotNull(publishDlg.DestinationPath);
Assert.AreEqual(@$"/{folderPath[0]}/{folderPath[1]}", publishDlg.DestinationPath);

Expand Down