Skip to content

Commit

Permalink
netstandard2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed Oct 18, 2023
1 parent ad0cbd0 commit d838163
Show file tree
Hide file tree
Showing 37 changed files with 1,300 additions and 340 deletions.
15 changes: 11 additions & 4 deletions src/Stac.Api.Clients/Converters/FilterSearchBodyConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,25 @@ public FilterSearchBody ReadJObject(JObject jo, Type objectType, object existing
// Read base object SearchBody
SearchBody searchBody = serializer.Deserialize<SearchBody>(jo.CreateReader());

FilterLang? filter_lang = null;
Api.Converters.CQL2FilterConverter.FilterLang? filter_lang = null;
CQL2FilterConverter cql2FilterConverter = new CQL2FilterConverter();
if (jo.ContainsKey("filter-lang"))
{
filter_lang = StacAccessorsHelpers.LazyEnumParse(typeof(FilterLang), jo["filter-lang"].ToString()) as FilterLang?;
cql2FilterConverter = new CQL2FilterConverter(filter_lang != null ? Enum.Parse<CQL2FilterConverter.FilterLang>(filter_lang.ToString()) : null);
filter_lang = StacAccessorsHelpers.LazyEnumParse(typeof(Api.Converters.CQL2FilterConverter.FilterLang), jo["filter-lang"].ToString()) as Api.Converters.CQL2FilterConverter.FilterLang?;
if (filter_lang != null)
{
cql2FilterConverter = new CQL2FilterConverter(filter_lang.Value);
}
else
{
cql2FilterConverter = new CQL2FilterConverter();
}
}
// Read additional properties
var additionalProperties = jo.Properties().Where(p => p.Name != "filter" && p.Name != "filter-lang" && p.Name != "filter_crs").ToDictionary(p => p.Name, p => p.Value);

return new FilterSearchBody(searchBody){
FilterLang = filter_lang ?? FilterLang.Cql2Text,
FilterLang = filter_lang ?? Api.Converters.CQL2FilterConverter.FilterLang.Cql2Text,
Filter = cql2FilterConverter.ReadJObject(jo["filter"] as JObject, typeof(CQL2Expression), existingValue, serializer),
FilterCrs = jo["filter_crs"]?.ToObject<Uri>(),
AdditionalProperties = additionalProperties.Select(p => new KeyValuePair<string, object>(p.Key, p.Value.ToObject<object>())).ToDictionary(p => p.Key, p => p.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using Stac;
using Stac.Common;
using Stac.Api.Converters;
using Stac.Api.Models;
using Stac.Api.Interfaces;

Expand All @@ -20,6 +21,7 @@

namespace Stac.Api.Clients.Extensions.Filter
{

using System = global::System;

[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")]
Expand Down Expand Up @@ -238,7 +240,7 @@ public virtual async System.Threading.Tasks.Task<StacQueryables> GetQueryablesFo
/// <br/>is 'http://www.opengis.net/def/crs/OGC/1.3/CRS84'.</param>
/// <returns>A feature collection.</returns>
/// <exception cref="StacApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task<StacFeatureCollection> GetItemSearchAsync(Models.Cql2.CQL2Expression filter, FilterLang? filter_lang, System.Uri filter_crs)
public virtual System.Threading.Tasks.Task<StacFeatureCollection> GetItemSearchAsync(Models.Cql2.CQL2Expression filter, CQL2FilterConverter.FilterLang? filter_lang, System.Uri filter_crs)
{
return GetItemSearchAsync(filter, filter_lang, filter_crs, System.Threading.CancellationToken.None);
}
Expand All @@ -259,7 +261,7 @@ public virtual System.Threading.Tasks.Task<StacFeatureCollection> GetItemSearchA
/// <br/>is 'http://www.opengis.net/def/crs/OGC/1.3/CRS84'.</param>
/// <returns>A feature collection.</returns>
/// <exception cref="StacApiException">A server side error occurred.</exception>
public virtual async System.Threading.Tasks.Task<StacFeatureCollection> GetItemSearchAsync(Models.Cql2.CQL2Expression filter, FilterLang? filter_lang, System.Uri filter_crs, System.Threading.CancellationToken cancellationToken)
public virtual async System.Threading.Tasks.Task<StacFeatureCollection> GetItemSearchAsync(Models.Cql2.CQL2Expression filter, CQL2FilterConverter.FilterLang? filter_lang, System.Uri filter_crs, System.Threading.CancellationToken cancellationToken)
{
if (filter == null)
throw new System.ArgumentNullException("filter");
Expand Down Expand Up @@ -575,29 +577,13 @@ public partial class FilterSearchBody : Stac.Api.Clients.ItemSearch.SearchBody

[Newtonsoft.Json.JsonProperty("filter-lang", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public FilterLang FilterLang { get; set; }
public CQL2FilterConverter.FilterLang FilterLang { get; set; }

[Newtonsoft.Json.JsonProperty("filter-crs", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Uri FilterCrs { get; set; }

}

/// <summary>
/// The CQL2 filter encoding that the 'filter' value uses.
/// <br/>
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")]
public enum FilterLang
{

[System.Runtime.Serialization.EnumMember(Value = @"cql2-text")]
Cql2Text = 0,

[System.Runtime.Serialization.EnumMember(Value = @"cql2-json")]
Cql2Json = 1,

}


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class SortModelExtensions
{
public static SearchBody SortBy(this SearchBody searchBody, Sortby sortby)
{
searchBody.AdditionalProperties.Add(ISortParameters.QuerySortKeyName, sortby);
searchBody.AdditionalProperties.Add(DefaultSortBy.QuerySortKeyName, sortby);
return searchBody;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Task BindModelAsync(ModelBindingContext bindingContext)
{
var searchBody = (bindingContext.Result.Model as SearchBody);
// Read the sort parameter from the additional properties
searchBody.AdditionalProperties.TryGetValue(ISortParameters.QuerySortKeyName, out var sortValue);
searchBody.AdditionalProperties.TryGetValue(DefaultSortBy.QuerySortKeyName, out var sortValue);
if (sortValue == null)
{
return Task.CompletedTask;
Expand All @@ -33,8 +33,8 @@ public Task BindModelAsync(ModelBindingContext bindingContext)
{
var sortValueString = JsonConvert.SerializeObject(sortValue);
Sortby sortby = JsonConvert.DeserializeObject<Sortby>(sortValueString);
searchBody.AdditionalProperties.Remove(ISortParameters.QuerySortKeyName);
searchBody.AdditionalProperties.Add(ISortParameters.QuerySortKeyName, sortby);
searchBody.AdditionalProperties.Remove(DefaultSortBy.QuerySortKeyName);
searchBody.AdditionalProperties.Add(DefaultSortBy.QuerySortKeyName, sortby);
}
catch (Exception ex)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Stac.Api.Clients/Stac.Api.Clients.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net7.0</TargetFrameworks>
<IncludeSymbols>true</IncludeSymbols>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.*" />
<PackageReference Include="NJsonSchema" Version="10.8.*" />
<PackageReference Include="DotNetStac" Version="1.7.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.*" />

</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/Stac.Api.CodeGen/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@
"Ids",
"StacFeatureCollectionType",
"BboxFilter",
"FilterLang",
"StacFeatureCollection",
"Stac.Api.Clients.Features.Error",
"Stac.Api.Clients.ItemSearch.SearchBody"
Expand All @@ -480,6 +481,7 @@
"Response": "StacQueryables",
"SearchBody": "FilterSearchBody",
"Filter": "Models.Cql2.CQL2Filter",
"FilterLang": "Api.Converters.CQL2FilterConverter.FilterLang",
"ItemCollection": "StacFeatureCollection",
"Error": "Stac.Api.Clients.Features.Error",
"Anonymous": "Stac.Api.Clients.ItemSearch.SearchBody",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public async Task DeleteItemAsync(string featureId, IStacApiContext stacApiConte
}
}

public async Task<ActionResult<StacItem>> UpdateItemAsync(StacItem newItem, string featureId, IStacApiContext stacApiContext, CancellationToken cancellationToken)
public async Task<StacItem> UpdateItemAsync(StacItem newItem, string featureId, IStacApiContext stacApiContext, CancellationToken cancellationToken)
{
await DeleteItemAsync(newItem.Id, stacApiContext, cancellationToken);
return await CreateItemAsync(newItem, stacApiContext, cancellationToken);
Expand Down
27 changes: 15 additions & 12 deletions src/Stac.Api.Package/ForceAssemblyReference.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
namespace Stac.Api.Package;
using System;

[AttributeUsage(AttributeTargets.Assembly)]
public class ForceAssemblyReference: Attribute
{
public ForceAssemblyReference(Type forcedType)
{
//not sure if these two lines are required since
//the type is passed to constructor as parameter,
//thus effectively being used
Action<Type> noop = _ => { };
noop(forcedType);
namespace Stac.Api.Package
{
[AttributeUsage(AttributeTargets.Assembly)]
public class ForceAssemblyReference: Attribute
{
public ForceAssemblyReference(Type forcedType)
{
//not sure if these two lines are required since
//the type is passed to constructor as parameter,
//thus effectively being used
Action<Type> noop = _ => { };
noop(forcedType);
}
}
}

}
12 changes: 7 additions & 5 deletions src/Stac.Api.Package/Stac.Api.Package.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
<Company>Terradue</Company>
<RepositoryUrl>https://github.com/Terradue/DotNetStac.Api</RepositoryUrl>
<Copyright>Copyright (c) by Terradue Srl. All Rights Reserved.\nLicense under the AGPL, Version 3.0.</Copyright>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFrameworks>netstandard2.0;net6.0;net7.0</TargetFrameworks>
<!-- <ImplicitUsings>enable</ImplicitUsings> -->
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>beta.2</VersionSuffix>
<PackageId>DotNetStac.Api</PackageId>
Expand All @@ -37,10 +36,13 @@
<None Include="..\..\docs\images\stac_logo_128.png" Pack="true" PackagePath=""/>
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<ProjectReference Include="..\Stac.Api.Clients\Stac.Api.Clients.csproj" PrivateAssets="All" />
<ProjectReference Include="..\Stac.Api.WebApi\Stac.Api.WebApi.csproj" PrivateAssets="All" />
<ProjectReference Include="..\Stac.Api.FileSystem\Stac.Api.FileSystem.csproj" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<ProjectReference Include="..\Stac.Api.Clients\Stac.Api.Clients.csproj" PrivateAssets="All" />
</ItemGroup>


Expand Down
1 change: 0 additions & 1 deletion src/Stac.Api.Tests/AppTests/CoreApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public async Task GetLandingPageAsync(string catalogName)
public static void ValidateLandingPage(LandingPage landingPage)
{
Assert.Contains("https://api.stacspec.org/v1.0.0/core", landingPage.ConformanceClasses);
Assert.Contains("https://api.stacspec.org/v1.0.0/browseable", landingPage.ConformanceClasses);
Assert.NotNull(landingPage.Links.FirstOrDefault(l => l.RelationshipType == "self"));
Assert.NotNull(landingPage.Links.FirstOrDefault(l => l.RelationshipType == "root"));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Stac.Api.Tests/AppTests/Extensions/FilterApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task GetItemSearchAsync(string catalogName)

StacFeatureCollection result = await filterClient.GetItemSearchAsync(
filter,
FilterLang.Cql2Json,
Converters.CQL2FilterConverter.FilterLang.Cql2Json,
null
);

Expand Down
2 changes: 1 addition & 1 deletion src/Stac.Api.Tests/AppTests/Extensions/SortApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task PostItemSearchAsync(string catalogName)

FilterSearchBody body = new FilterSearchBody();
body.Filter = filter;
body.FilterLang = FilterLang.Cql2Json;
body.FilterLang = Api.Converters.CQL2FilterConverter.FilterLang.Cql2Json;
body.AdditionalProperties.Add("sortby", new Sortby(){
new SortByItem(){
Field = "id",
Expand Down
Loading

0 comments on commit d838163

Please sign in to comment.