Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date search - archive attributes #231

Merged
merged 3 commits into from
Oct 29, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
- name: Print openssl version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
- name: Print openssl version
Expand Down
2 changes: 1 addition & 1 deletion Digipost.Api.Client.Archive.Tests/ArchiveTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void BuildCorrectNextDocumentsUri()
{
["key"] = "val"
};
Assert.Equal("https://www.testing.no/1010/archive/1000/document?limit=100&offset=0&attributes=a2V5LHZhbA==", archive.GetNextDocumentsUri(searchBy).ToString());
Assert.Equal("https://www.testing.no/1010/archive/1000/document?limit=100&offset=0&attributes=a2V5LHZhbA%3d%3d", archive.GetNextDocumentsUri(searchBy).ToString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.assert" Version="2.4.1" />
Expand Down
16 changes: 14 additions & 2 deletions Digipost.Api.Client.Archive.Tests/Smoke/ArchiveSmokeTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Digipost.Api.Client.Tests.Utilities;
using System;
using System.Collections.Generic;
using Digipost.Api.Client.Tests.Utilities;
using Xunit;

namespace Digipost.Api.Client.Archive.Tests.Smoke
Expand Down Expand Up @@ -26,10 +28,20 @@ public void ArchiveDocuments_read_and_delete()
[Fact(Skip = "SmokeTest")]
public void ArchiveADocumentWithAttributes()
{
var from = DateTime.Now;

var searchBy = new Dictionary<string, string>
{
["smoke"] = "test"
};

_t.ArchiveAFile()
.Get_Default_Archive()
.Get_All_DocumentsWithAttributes()
.Update_attritbutesOnFirst();
.Update_attritbutesOnFirst()
.Get_For_Timeinterval(from, DateTime.Now, 1)
.Get_For_TimeintervalWithAttributes(searchBy, from, DateTime.Now, 1);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ArchiveSmokeTestsHelper Get_Archive(string archiveName)

public ArchiveSmokeTestsHelper Get_Default_Archive()
{
_archive = _archiveApi.FetchArchives().Result.Where(a => a.Name == null).First();
_archive = _archiveApi.FetchArchives().Result.First(a => a.Name == string.Empty);
return this;
}

Expand Down Expand Up @@ -86,6 +86,24 @@ public ArchiveSmokeTestsHelper Get_All_DocumentsWithAttributes()
return this;
}

public ArchiveSmokeTestsHelper Get_For_Timeinterval(DateTime start, DateTime end, int expectCount = 0)
{
_byAttribute = _archiveApi.FetchArchiveDocuments(_archive.GetNextDocumentsUri(start, end)).Result;

Assert.Equal(expectCount, _byAttribute.ArchiveDocuments.Count);

return this;
}

public ArchiveSmokeTestsHelper Get_For_TimeintervalWithAttributes(Dictionary<string, string> searchBy, DateTime start, DateTime end, int expectCount = 0)
{
_byAttribute = _archiveApi.FetchArchiveDocuments(_archive.GetNextDocumentsUri(searchBy, start, end)).Result;

Assert.Equal(expectCount, _byAttribute.ArchiveDocuments.Count);

return this;
}

public ArchiveSmokeTestsHelper Update_attritbutesOnFirst()
{
Assert_state(_byAttribute);
Expand Down
11 changes: 11 additions & 0 deletions Digipost.Api.Client.Archive/Archive.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Digipost.Api.Client.Common;
using Digipost.Api.Client.Common.Relations;
Expand Down Expand Up @@ -66,5 +67,15 @@ public ArchiveNextDocumentsUri GetNextDocumentsUri(Dictionary<string, string> se
{
return new ArchiveNextDocumentsUri(Links["NEXT_DOCUMENTS"], searchBy);
}

public ArchiveNextDocumentsUri GetNextDocumentsUri(DateTime from, DateTime to)
{
return new ArchiveNextDocumentsUri(Links["NEXT_DOCUMENTS"], from, to);
}

public ArchiveNextDocumentsUri GetNextDocumentsUri(Dictionary<string,string> searchBy, DateTime from, DateTime to)
{
return new ArchiveNextDocumentsUri(Links["NEXT_DOCUMENTS"], searchBy, from, to);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.5" />
<ProjectReference Include="..\Digipost.Api.Client.Common\Digipost.Api.Client.Common.csproj">
<Project>{CD338E5A-1ED0-4331-B34E-8292FA8E387B}</Project>
<Name>Digipost.Api.Client.Common</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.assert" Version="2.4.1" />
Expand Down
36 changes: 36 additions & 0 deletions Digipost.Api.Client.Common.Tests/Relations/ApiRelationsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using Digipost.Api.Client.Common.Enums;
using Digipost.Api.Client.Common.Relations;
using Digipost.Api.Client.Common.Utilities;
using Xunit;

namespace Digipost.Api.Client.Common.Tests.Utilities
{
public class ApiRelationsTests
{
private static readonly Uri BaseUri = new Uri("https://api.io/api/archive/search?id=123");

[Fact]
public void should_produce_archive_search_url_query()
{
Assert.Equal("https://api.io:443/api/archive/search?id=123",
ArchiveNextDocumentsUri.ToUri(BaseUri, new Dictionary<string, string>(), null, null));

Assert.Equal("https://api.io:443/api/archive/search?id=123&attributes=aWQsMTIz",
ArchiveNextDocumentsUri.ToUri(BaseUri, new Dictionary<string, string>()
{
["id"] = "123",
},
null, null
));

var url = ArchiveNextDocumentsUri.ToUri(BaseUri, new Dictionary<string, string>(),
DateTime.Parse("2024-10-26 14:50:14Z"),
DateTime.Parse("2024-10-28 14:50:14Z")
);
Assert.Contains("fromDate=2024-10-26T", url);
Assert.Contains("toDate=2024-10-28T", url);
}
}
}
5 changes: 2 additions & 3 deletions Digipost.Api.Client.Common/Digipost.Api.Client.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.3" />
Expand Down
35 changes: 27 additions & 8 deletions Digipost.Api.Client.Common/Relations/ApiRelations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public class AddAdditionalDataUri : Uri
public AddAdditionalDataUri(Link link)
: base(link.Uri, UriKind.Absolute)
{

}
}

Expand Down Expand Up @@ -144,20 +143,41 @@ public ArchiveNextDocumentsUri(Link link)
}

public ArchiveNextDocumentsUri(Link link, Dictionary<string, string> searchBy)
: base(ToUri(new Uri(link.Uri, UriKind.Absolute), searchBy), UriKind.Absolute)
: base(ToUri(new Uri(link.Uri, UriKind.Absolute), searchBy, null, null), UriKind.Absolute)
{
}

public ArchiveNextDocumentsUri(Link link, DateTime from, DateTime to)
: base(ToUri(new Uri(link.Uri, UriKind.Absolute), new Dictionary<string, string>(), from, to), UriKind.Absolute)
{
}

public ArchiveNextDocumentsUri(Link link, Dictionary<string, string> searchBy, DateTime from, DateTime to)
: base(ToUri(new Uri(link.Uri, UriKind.Absolute), searchBy, from, to), UriKind.Absolute)
{

}

private static string ToUri(Uri nextDocumentsUri, Dictionary<string, string> searchBy)
internal static string ToUri(Uri nextDocumentsUri, Dictionary<string, string> searchBy, DateTime? from, DateTime? to)
{
var query = HttpUtility.ParseQueryString(nextDocumentsUri.Query);
var commaSeparated = string.Join(",", searchBy.Select(x => x.Key + "," + x.Value).ToArray());
var base64 = ToBase64String(Encoding.UTF8.GetBytes(commaSeparated));
if (searchBy.Count > 0)
{
var commaSeparated = string.Join(",", searchBy.Select(x => x.Key + "," + x.Value).ToArray());
var base64 = ToBase64String(Encoding.UTF8.GetBytes(commaSeparated));

query["attributes"] = base64;
}

if (from != null && to != null)
{
query["fromDate"] = from.Value.ToString("o");
query["toDate"] = to.Value.ToString("o");
}

query["attributes"] = "";
var uriBuilder = new UriBuilder(nextDocumentsUri)
{
Query = query + base64
Query = query.ToString()
};
return uriBuilder.ToString();
}
Expand Down Expand Up @@ -200,7 +220,6 @@ public class DocumentEventsUri : Uri
public DocumentEventsUri(Link link, Sender sender, DateTime from, DateTime to, int offset, int maxResults)
: base($"{link.Uri}?sender={sender.Id}&from={DatetimeFormatter(from)}&to={DatetimeFormatter(to)}&offset={offset}&maxResults={maxResults}", UriKind.Absolute)
{

}

private static string DatetimeFormatter(DateTime? dt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<ProjectReference Include="..\Digipost.Api.Client.Common\Digipost.Api.Client.Common.csproj">
Expand Down
5 changes: 2 additions & 3 deletions Digipost.Api.Client.Docs/Digipost.Api.Client.Docs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.5" />
<ProjectReference Include="..\Digipost.Api.Client.Common\Digipost.Api.Client.Common.csproj">
<Project>{CD338E5A-1ED0-4331-B34E-8292FA8E387B}</Project>
<Name>Digipost.Api.Client.Common</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.assert" Version="2.4.1" />
Expand Down
5 changes: 2 additions & 3 deletions Digipost.Api.Client.Inbox/Digipost.Api.Client.Inbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.5" />
<ProjectReference Include="..\Digipost.Api.Client.Common\Digipost.Api.Client.Common.csproj">
<Project>{CD338E5A-1ED0-4331-B34E-8292FA8E387B}</Project>
<Name>Digipost.Api.Client.Common</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.5" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.assert" Version="2.4.1" />
Expand Down
7 changes: 3 additions & 4 deletions Digipost.Api.Client.Send/Digipost.Api.Client.Send.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.DataTypes.Core" Version="4.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Digipost.Api.Client.DataTypes.Core" Version="4.2.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.5" />
<ProjectReference Include="..\Digipost.Api.Client.Common\Digipost.Api.Client.Common.csproj">
<Project>{CD338E5A-1ED0-4331-B34E-8292FA8E387B}</Project>
<Name>Digipost.Api.Client.Common</Name>
Expand Down
5 changes: 2 additions & 3 deletions Digipost.Api.Client.Tests/Digipost.Api.Client.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="CompareNETObjects" Version="4.66.0" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.assert" Version="2.4.1" />
Expand Down
5 changes: 2 additions & 3 deletions Digipost.Api.Client/Digipost.Api.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
<PackageReference Include="Difi.Felles.Utility" Version="5.0.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Digipost.Api.Client.Shared" Version="7.1.5" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.3" />
Expand Down