Skip to content

Commit

Permalink
Merge pull request #99 from CSCfi/qa
Browse files Browse the repository at this point in the history
FundingCall bug fixes
  • Loading branch information
sarkikos authored Nov 15, 2023
2 parents 8229f90 + 4474e5f commit 246c8f8
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 28 deletions.
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Indexer (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"launchSettingsProfile": "ElasticSearchIndexer",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/aspnetcore/src/Indexer/bin/Debug/net6.0/CSC.PublicApi.Indexer.dll",
"args": [],
"cwd": "${workspaceFolder}/aspnetcore/src/Indexer",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": "Interface (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"launchSettingsProfile": "Api",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/aspnetcore/src/Interface/bin/Debug/net6.0/CSC.PublicApi.Interface.dll",
"args": [],
"cwd": "${workspaceFolder}/aspnetcore/src/Interface",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
}
]
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/aspnetcore/PublicApi.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/aspnetcore/PublicApi.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/aspnetcore/PublicApi.sln"
],
"problemMatcher": "$msCompile"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,35 @@ private static IEnumerable<Func<QueryContainerDescriptor<FundingCall>, QueryCont
// When searching with Name, search from Fi,Sv,En names.
if (!string.IsNullOrWhiteSpace(parameters.Name))
{
subQueries.Add(t => t.MultiMatch(query => query
.Type(TextQueryType.PhrasePrefix)
.Fields(r => r
.Field(f => f.NameFi)
.Field(f => f.NameSv)
.Field(f => f.NameEn))
.Query(parameters.Name)));
subQueries.Add(
t => t.MultiMatch(
query => query
.Type(TextQueryType.PhrasePrefix)
.Fields(r => r
.Field(f => f.NameFi)
.Field(f => f.NameSv)
.Field(f => f.NameEn)
)
.Query(parameters.Name)));
}

// When searching with FoundationName, search from Fi,Sv,En names.
if (!string.IsNullOrWhiteSpace(parameters.FoundationName))
{
subQueries.Add(t => t.Nested(query => query
.Path(f => f.Foundations)
.Query(q => q.MultiMatch(multi => multi
.Type(TextQueryType.PhrasePrefix)
.Fields(r => r
.Field(f => f.Foundations.Suffix(nameof(Foundation.NameFi)))
.Field(f => f.Foundations.Suffix(nameof(Foundation.NameSv)))
.Field(f => f.Foundations.Suffix(nameof(Foundation.NameEn))))
.Query(parameters.FoundationName)
))));
subQueries.Add(
t => t.Nested(
query => query
.Path(f => f.Foundations)
.Query(
q => q.MultiMatch(
multi => multi
.Type(TextQueryType.PhrasePrefix)
.Fields(r => r
.Field(f => f.Foundations.Suffix(nameof(Foundation.NameFi)))
.Field(f => f.Foundations.Suffix(nameof(Foundation.NameSv)))
.Field(f => f.Foundations.Suffix(nameof(Foundation.NameEn)))
)
.Query(parameters.FoundationName)))));
}

return subQueries;
Expand All @@ -75,12 +82,16 @@ private static IEnumerable<Func<QueryContainerDescriptor<FundingCall>, QueryCont
// Searching with business id requires exact match.
if (!string.IsNullOrWhiteSpace(parameters.FoundationBusinessId))
{
filters.Add(x => x
.Bool(b => b
.Should(s =>
s.Term(r => r
.Field(f => f.Foundations.Suffix(nameof(Foundation.BusinessId)))
.Value(parameters.FoundationBusinessId)))));
filters.Add(
x => x.Nested(
query => query
.Path(f => f.Foundations)
.Query(q => q
.Bool(b => b
.Should(s =>
s.Term(r => r
.Field(f => f.Foundations.Suffix(nameof(Foundation.BusinessId)))
.Value(parameters.FoundationBusinessId)))))));
}

// Searching with category code requires exact match.
Expand Down
7 changes: 6 additions & 1 deletion aspnetcore/src/Interface/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
}
},
"WriteTo": {
"ConsoleSink": "Console",
"ConsoleSink": {
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}][{clientId}, {ClientIp}, {ClientAgent}]: {Message}{NewLine}{Exception}"
}
},
"HttpSink": {
"Name": "Http",
"Args": {
Expand Down
7 changes: 6 additions & 1 deletion aspnetcore/src/Interface/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
}
},
"WriteTo": {
"ConsoleSink": "Console",
"ConsoleSink": {
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}][{clientId}, {ClientIp}, {ClientAgent}]: {Message}{NewLine}{Exception}"
}
},
"HttpSink": {
"Name": "Http",
"Args": {
Expand Down
30 changes: 28 additions & 2 deletions aspnetcore/src/Repositories/FundingCallIndexRepository.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using AutoMapper;
using AutoMapper.QueryableExtensions;
using CSC.PublicApi.DatabaseContext;
using CSC.PublicApi.Service.Models;
using CSC.PublicApi.Service.Models.FundingCall;
using CSC.PublicApi.Service.Models.Organization;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;

Expand All @@ -23,7 +25,7 @@ protected override IQueryable<FundingCall> GetAll()
return _context.DimCallProgrammes
.AsNoTracking()
.AsSplitQuery()
.Where(callProgramme => callProgramme.Id != -1)
.Where(callProgramme => callProgramme.Id != -1 && callProgramme.DimOrganizations.Count > 0 && (callProgramme.DimDateIdOpen != -1 && callProgramme.DimDateIdDue != -1 || callProgramme.ContinuousApplicationPeriod == true))
.ProjectTo<FundingCall>(_mapper.ConfigurationProvider);
}

Expand All @@ -35,7 +37,7 @@ protected override IQueryable<FundingCall> GetChunk(int skipAmount, int takeAmou
.Take(takeAmount)
.AsNoTracking()
.AsSplitQuery()
.Where(callProgramme => callProgramme.Id != -1)
.Where(callProgramme => callProgramme.Id != -1 && callProgramme.DimOrganizations.Count > 0 && (callProgramme.DimDateIdOpen != -1 && callProgramme.DimDateIdDue != -1 || callProgramme.ContinuousApplicationPeriod == true))
.ProjectTo<FundingCall>(_mapper.ConfigurationProvider);
}

Expand All @@ -49,6 +51,7 @@ public override List<object> PerformInMemoryOperations(List<object> entities)
}

HandleEmptyCollections(fundingCall);
HandleFoundationBusinessID(fundingCall);
});
return entities;
}
Expand All @@ -65,4 +68,27 @@ private static void HandleEmptyCollections(FundingCall fundingCall)
fundingCall.Categories = null;
}
}

private void HandleFoundationBusinessID(FundingCall fundingCall)
{
// Use Finnish business id (Y-tunnus) from DimPid
if (fundingCall.Foundations != null) {
foreach (Foundation foundation in fundingCall.Foundations.ToList()){
if (MemoryCache.TryGetValue(MemoryCacheKeys.OrganizationById(foundation.Id),
out Organization organization))
{
if (organization.Pids != null)
{
foreach(PersistentIdentifier pid in organization.Pids.ToList())
{
if (pid.Type.ToLower() == "businessid") {
foundation.BusinessId = pid.Content;
break;
}
}
}
}
}
}
}
}
12 changes: 11 additions & 1 deletion aspnetcore/src/Service.Models/FundingCall/Foundation.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
namespace CSC.PublicApi.Service.Models.FundingCall;
using Nest;

namespace CSC.PublicApi.Service.Models.FundingCall;

public class Foundation
{
[Ignore]
public int Id { get; set; }

/// <summary>
/// Rahoittajan nimi
/// </summary>
[Text]
public string? NameFi { get; set; }

/// <summary>
/// Rahoittajan nimi
/// </summary>
[Text]
public string? NameSv { get; set; }

/// <summary>
/// Rahoittajan nimi
/// </summary>
[Text]
public string? NameEn { get; set; }

/// <summary>
/// Y-tunnus
/// </summary>
[Keyword]
public string? BusinessId { get; set; }

/// <summary>
/// Rahoittajan verkkosivu
/// </summary>
[Ignore]
public string? FoundationUrl { get; set; }
}
1 change: 1 addition & 0 deletions aspnetcore/src/Service.Models/FundingCall/FundingCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class FundingCall
/// <summary>
/// Rahoittajat
/// </summary>
[Nested]
public List<Foundation>? Foundations { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class FundingDecision

public Organization? Funder { get; set; }

[Keyword]
public string? FunderProjectNumber { get; set; }

public ReferenceData? TypeOfFunding { get; set; }
Expand Down

0 comments on commit 246c8f8

Please sign in to comment.