Skip to content

Commit

Permalink
feat: add ops console + ticket console + first input-output result
Browse files Browse the repository at this point in the history
* feat: add skeleton

* chore: code skeleton

* refactor: program

* refactor: processing records in console

* feat: add ticket.console

* chore: don't write header record when file exists

* chore: add api key + log failed actions

* chore: add input-output context

---------

Co-authored-by: ArneD <[email protected]>
  • Loading branch information
jvandaal and ArneD authored May 2, 2024
1 parent 6293a9f commit 1d68699
Show file tree
Hide file tree
Showing 18 changed files with 693 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Ops.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ops.Web.Tests", "test\Ops.Web.Tests\Ops.Web.Tests.csproj", "{19EB08BE-7086-47B2-BD56-22E675B86D9F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ops.Console", "src\Ops.Console\Ops.Console.csproj", "{76FB4D24-D5EF-47D7-8F8C-B260EF4431F9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ops.Tickets.Console", "src\Ops.Tickets.Console\Ops.Tickets.Console.csproj", "{F77FC2CB-BD70-4640-A54E-3D433DF45598}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +31,8 @@ Global
GlobalSection(NestedProjects) = preSolution
{1B99CF5A-159F-4434-AAAA-996C7B50A507} = {8ED67A50-116A-4250-BBAB-EED6377244B9}
{19EB08BE-7086-47B2-BD56-22E675B86D9F} = {42A894F8-BF47-43D2-9A25-3E35CE133E6E}
{76FB4D24-D5EF-47D7-8F8C-B260EF4431F9} = {8ED67A50-116A-4250-BBAB-EED6377244B9}
{F77FC2CB-BD70-4640-A54E-3D433DF45598} = {8ED67A50-116A-4250-BBAB-EED6377244B9}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1B99CF5A-159F-4434-AAAA-996C7B50A507}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -37,5 +43,13 @@ Global
{19EB08BE-7086-47B2-BD56-22E675B86D9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19EB08BE-7086-47B2-BD56-22E675B86D9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19EB08BE-7086-47B2-BD56-22E675B86D9F}.Release|Any CPU.Build.0 = Release|Any CPU
{76FB4D24-D5EF-47D7-8F8C-B260EF4431F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76FB4D24-D5EF-47D7-8F8C-B260EF4431F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76FB4D24-D5EF-47D7-8F8C-B260EF4431F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76FB4D24-D5EF-47D7-8F8C-B260EF4431F9}.Release|Any CPU.Build.0 = Release|Any CPU
{F77FC2CB-BD70-4640-A54E-3D433DF45598}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F77FC2CB-BD70-4640-A54E-3D433DF45598}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F77FC2CB-BD70-4640-A54E-3D433DF45598}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F77FC2CB-BD70-4640-A54E-3D433DF45598}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
framework: net8.0
source https://api.nuget.org/v3/index.json

nuget Microsoft.Extensions.Configuration.FileExtensions 8.0.0
nuget Microsoft.Extensions.Configuration.Json 8.0.0
nuget Microsoft.Extensions.Configuration.EnvironmentVariables 8.0.0
nuget Microsoft.Extensions.Configuration.Binder 8.0.0

nuget Be.Vlaanderen.Basisregisters.Grb.Building.Api.Abstractions 2.0.0
nuget Be.Vlaanderen.Basisregisters.TicketingService.Abstractions 2.0.0
nuget Be.Vlaanderen.Basisregisters.TicketingService.Proxy.HttpProxy 2.0.0
nuget Flurl 4.0.0
nuget IdentityModel 6.2.0

nuget CsvHelper 32.0.1

// VBR STUFF
nuget Be.Vlaanderen.Basisregisters.Build.Pipeline 7.1.0
nuget Be.Vlaanderen.Basisregisters.Testing.Infrastructure.Events 4.0.0 content: true, copy_content_to_output_dir: always, copy_local: true
Expand Down
25 changes: 24 additions & 1 deletion paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ NUGET
Be.Vlaanderen.Basisregisters.Utilities.HashCodeCalculator (4.0) - copy_local: true, copy_content_to_output_dir: always, content: true
Be.Vlaanderen.Basisregisters.Utilities.HexByteConvertor (4.0) - copy_local: true, copy_content_to_output_dir: always, content: true
Be.Vlaanderen.Basisregisters.Utilities.ToStringBuilder (4.0) - copy_local: true, copy_content_to_output_dir: always, content: true
CsvHelper (32.0.1)
FluentAssertions (6.12) - copy_local: true, copy_content_to_output_dir: always, content: true
System.Configuration.ConfigurationManager (>= 4.4)
Flurl (4.0)
Expand All @@ -42,8 +43,23 @@ NUGET
Microsoft.Extensions.Primitives (>= 8.0)
Microsoft.Extensions.Configuration.Abstractions (8.0)
Microsoft.Extensions.Primitives (>= 8.0)
Microsoft.Extensions.Configuration.Binder (8.0.1)
Microsoft.Extensions.Configuration.Binder (8.0)
Microsoft.Extensions.Configuration.Abstractions (>= 8.0)
Microsoft.Extensions.Configuration.EnvironmentVariables (8.0)
Microsoft.Extensions.Configuration (>= 8.0)
Microsoft.Extensions.Configuration.Abstractions (>= 8.0)
Microsoft.Extensions.Configuration.FileExtensions (8.0)
Microsoft.Extensions.Configuration (>= 8.0)
Microsoft.Extensions.Configuration.Abstractions (>= 8.0)
Microsoft.Extensions.FileProviders.Abstractions (>= 8.0)
Microsoft.Extensions.FileProviders.Physical (>= 8.0)
Microsoft.Extensions.Primitives (>= 8.0)
Microsoft.Extensions.Configuration.Json (8.0)
Microsoft.Extensions.Configuration (>= 8.0)
Microsoft.Extensions.Configuration.Abstractions (>= 8.0)
Microsoft.Extensions.Configuration.FileExtensions (>= 8.0)
Microsoft.Extensions.FileProviders.Abstractions (>= 8.0)
System.Text.Json (>= 8.0)
Microsoft.Extensions.DependencyInjection (8.0)
Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0)
Microsoft.Extensions.DependencyInjection.Abstractions (8.0.1)
Expand All @@ -55,6 +71,13 @@ NUGET
Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0)
Microsoft.Extensions.Options (>= 8.0)
System.Diagnostics.DiagnosticSource (>= 8.0)
Microsoft.Extensions.FileProviders.Abstractions (8.0)
Microsoft.Extensions.Primitives (>= 8.0)
Microsoft.Extensions.FileProviders.Physical (8.0)
Microsoft.Extensions.FileProviders.Abstractions (>= 8.0)
Microsoft.Extensions.FileSystemGlobbing (>= 8.0)
Microsoft.Extensions.Primitives (>= 8.0)
Microsoft.Extensions.FileSystemGlobbing (8.0)
Microsoft.Extensions.Http (8.0)
Microsoft.Extensions.Configuration.Abstractions (>= 8.0)
Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0)
Expand Down
90 changes: 90 additions & 0 deletions src/Ops.Console/AcmIdmService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
namespace Ops.Console
{
using System;
using System.Collections.Generic;
using System.Net.Http;
using IdentityModel;
using IdentityModel.Client;
using Microsoft.Extensions.Configuration;

public sealed class AcmIdmService
{
private static readonly object LockObject = new object();
private static AcmIdmService? _instance = null;

private const string RequiredScopes =
"dv_ar_adres_beheer dv_ar_adres_uitzonderingen dv_gr_geschetstgebouw_beheer dv_gr_geschetstgebouw_uitzonderingen dv_gr_ingemetengebouw_uitzonderingen";

private readonly string? _tokenEndpoint;
private readonly string? _clientId;
private readonly string? _clientSecret;

private AccessToken? _accessToken;

private AcmIdmService(IConfiguration configuration)
{
_clientId = configuration.GetSection("AuthOptions").GetValue<string>("ClientId");
_clientSecret = configuration.GetSection("AuthOptions").GetValue<string>("ClientSecret");
_tokenEndpoint = configuration.GetSection("AuthOptions").GetValue<string>("TokenEndpoint");
}

public static AcmIdmService GetInstance(IConfiguration configuration)
{
if (_instance == null)
{
lock (LockObject)
{
if (_instance == null)
{
_instance = new AcmIdmService(configuration);
}
}
}

return _instance;
}

public string GetAccessToken()
{
lock (LockObject)
{
if (_accessToken is not null && !_accessToken.IsExpired)
{
return _accessToken.Token;
}

var tokenClient = new TokenClient(
() => new HttpClient(),
new TokenClientOptions
{
Address = _tokenEndpoint,
ClientId = _clientId!,
ClientSecret = _clientSecret,
Parameters = new Parameters(new[] { new KeyValuePair<string, string>("scope", RequiredScopes) })
});

var response = tokenClient.RequestTokenAsync(OidcConstants.GrantTypes.ClientCredentials).GetAwaiter().GetResult();

_accessToken = new AccessToken(response.AccessToken!, response.ExpiresIn);

return _accessToken.Token;
}
}

private sealed class AccessToken
{
private readonly DateTime _expiresAt;

public string Token { get; }

// Let's regard it as expired 10 seconds before it actually expires.
public bool IsExpired => _expiresAt < DateTime.Now.Add(TimeSpan.FromSeconds(10));

public AccessToken(string token, int expiresIn)
{
_expiresAt = DateTime.Now.AddSeconds(expiresIn);
Token = token;
}
}
}
}
Binary file not shown.
40 changes: 40 additions & 0 deletions src/Ops.Console/Archive/20240502/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

# Gebouweenheden status incorrect tegenover gebouw

https://vlaamseoverheid.atlassian.net/browse/GAWR-6413

## Context
We hebben twee problemen gedetecteerd die niet werden opgelost bij migratie vanuit CRAB.

1. Er waren gebouweenheden met status `gerealiseerd`, maar het gebouw had nog (maar) status `gepland` of `inAanbouw`.

```
select bu.BuildingUnitPersistentLocalId As Id from [building-registry].buildingregistrylegacy.BuildingDetailsV2 b
inner join [building-registry].BuildingRegistryLegacy.BuildingUnitDetailsV2 bu on b.PersistentLocalId = bu.BuildingPersistentLocalId
where b.Status in ('Planned', 'UnderConstruction') and bu.Status in ('Realized') and bu.IsRemoved = 0 and bu.[Function] = 'Unknown'
```

2. Er waren gebouweenheden met status `gepland` of `gerealiseerd` in een `nietGerealiseerd` gebouw.

```
select bu.BuildingUnitPersistentLocalId As Id from [building-registry].buildingregistrylegacy.BuildingDetailsV2 b
inner join [building-registry].BuildingRegistryLegacy.BuildingUnitDetailsV2 bu on b.PersistentLocalId = bu.BuildingPersistentLocalId
where b.Status in ('NotRealized') and bu.Status in ('Realized', 'Planned') and bu.IsRemoved = 0 and bu.[Function] = 'Unknown'
```

## Oplossing probleem 1

Gebouweenheden met status `gerealiseerd` corrigeren naar `gepland`.

* input_prd_gerealiseerd_naar_gepland.csv
* output_prd_gerealiseerd_naar_gepland.csv

## Oplossing probleem 2

Gebouweenheden met status `gerealiseerd` corrigeren naar `gepland`.

Daarna gebouweenheden met status `gepland` niet-realiseren.

* input_prd_gerealiseerd_naar_gepland_naar_nietGerealiseerd.csv
* output_prd_gerealiseerd_naar_gepland_naar_nietGerealiseerd_stap1.csv
* output_prd_gerealiseerd_naar_gepland_naar_nietGerealiseerd_stap2.csv
20 changes: 20 additions & 0 deletions src/Ops.Console/InputRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Ops.Console
{
using CsvHelper.Configuration;

public sealed class InputRecord
{
public string Id { get; init; }

protected InputRecord()
{ }
}

public sealed class InputRecordMap : ClassMap<InputRecord>
{
public InputRecordMap()
{
Map(m => m.Id).Name("Id");
}
}
}
17 changes: 17 additions & 0 deletions src/Ops.Console/Ops.Console.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\packages\Be.Vlaanderen.Basisregisters.Build.Pipeline\Content\Be.Vlaanderen.Basisregisters.Build.Pipeline.Settings.App.props" />

<PropertyGroup>
<!-- Error NETSDK1152: https://docs.microsoft.com/en-us/dotnet/core/compatibility/sdk/6.0/duplicate-files-in-output -->
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
<ServerGarbageCollection>true</ServerGarbageCollection>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
</PropertyGroup>

<ItemGroup>
<Content Include="appsettings.json" CopyToOutputDirectory="Always" />
<Content Include="appsettings.*.json" CopyToOutputDirectory="Always" />
</ItemGroup>

<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
29 changes: 29 additions & 0 deletions src/Ops.Console/ProcessedRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Ops.Console
{
using CsvHelper.Configuration;

public sealed class ProcessedRecord
{
public string Id { get; init; }
public string TicketUrl { get; init; }

protected ProcessedRecord()
{
}

public ProcessedRecord(string id, string ticketUrl)
{
Id = id;
TicketUrl = ticketUrl;
}
}

public sealed class ProcessedRecordMap : ClassMap<ProcessedRecord>
{
public ProcessedRecordMap()
{
Map(m => m.Id).Name("Id");
Map(m => m.TicketUrl).Name("Ticket");
}
}
}
Loading

0 comments on commit 1d68699

Please sign in to comment.