Skip to content

Commit

Permalink
More doc
Browse files Browse the repository at this point in the history
  • Loading branch information
steinho committed Oct 2, 2024
1 parent 85f6b40 commit 80a1bf9
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 479 deletions.
5 changes: 0 additions & 5 deletions Prod.Api/Changes.md

This file was deleted.

416 changes: 0 additions & 416 deletions Prod.Api/Helpers/CsvHelpers.cs

Large diffs are not rendered by default.

69 changes: 32 additions & 37 deletions Prod.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using IdentityModel.Client;
using Microsoft.AspNetCore.Authentication.JwtBearer;
Expand All @@ -21,17 +19,13 @@
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Logging;
using Microsoft.OpenApi.Models;
using Prod.Api.Controllers;
using Prod.Data.EFCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Prod.Api.Helpers;
using Prod.Domain.Helpers;


namespace Prod.Api
{
using Microsoft.AspNetCore.Http.Connections;
using Microsoft.Extensions.Configuration;

using Prod.Api.Services;
Expand All @@ -52,6 +46,8 @@ public void ConfigureServices(IServiceCollection services)
// The following line enables Application Insights telemetry collection.
services.AddApplicationInsightsTelemetry();// "023396f1-285d-45cc-920c-eb957cdd6c01");
StartupAddDependencies(services);

// help with handling existing json formatted string - from newtonsoft , changed types and so on...
services.AddControllers().AddJsonOptions(x =>
{
x.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
Expand All @@ -63,7 +59,6 @@ public void ConfigureServices(IServiceCollection services)
}
); //.AddNewtonsoftJson(); For å unngå camelcase - frem til klienten er camelcase.....

//services.AddMvc();
services.AddSwaggerGen(c =>
{
c.CustomSchemaIds(type => type.ToString());
Expand Down Expand Up @@ -102,7 +97,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Prod.Api v1"));

//app.UseHttpsRedirection();
// temp serve sandbox app
// Serve frontend
var path = Path.Combine(env.ContentRootPath, "Frontend");
if (Directory.Exists(path))
{
Expand All @@ -128,7 +123,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
endpoints.MapHealthChecks("/hc", new HealthCheckOptions
{
ResponseWriter = WriteResponse
ResponseWriter = FormatWriteHCResponse
});
endpoints.MapControllers();
endpoints.MapGet("/", async context =>
Expand All @@ -150,17 +145,17 @@ private void StartupAddDependencies(IServiceCollection services)
//}

services.AddDbContext<ProdDbContext>(opt => opt.UseSqlServer(connectionString));
Index implementationInstance;
Index index;
try
{
implementationInstance = new Index();
index = new Index();
}
catch (Exception e)
{
implementationInstance = new Index(false, true);
index = new Index(false, true);
throw;
}
services.AddSingleton(implementationInstance);
services.AddSingleton(index);
var options = new ReferenceServiceOptions()
{
AuthAuthority = Configuration.GetValue("AuthAuthority", "https://demo.identityserver.io"),
Expand Down Expand Up @@ -200,32 +195,32 @@ private void StartupAddDependencies(IServiceCollection services)
//};

IdentityModelEventSource.ShowPII = true;
identityServerAuthenticationOptions.Events = new JwtBearerEvents
{
OnMessageReceived = e =>
{
// _logger.LogTrace("JWT: message received");
return Task.CompletedTask;
},
OnTokenValidated = e =>
{
// _logger.LogTrace("JWT: token validated");
return Task.CompletedTask;
},
OnAuthenticationFailed = e =>
{
// _logger.LogTrace("JWT: authentication failed");
return Task.CompletedTask;
},
OnChallenge = e =>
{
// _logger.LogTrace("JWT: challenge");
return Task.CompletedTask;
}
};
//identityServerAuthenticationOptions.Events = new JwtBearerEvents
//{
// OnMessageReceived = e =>
// {
// // _logger.LogTrace("JWT: message received");
// return Task.CompletedTask;
// },
// OnTokenValidated = e =>
// {
// // _logger.LogTrace("JWT: token validated");
// return Task.CompletedTask;
// },
// OnAuthenticationFailed = e =>
// {
// // _logger.LogTrace("JWT: authentication failed");
// return Task.CompletedTask;
// },
// OnChallenge = e =>
// {
// // _logger.LogTrace("JWT: challenge");
// return Task.CompletedTask;
// }
//};
});
}
private static Task WriteResponse(HttpContext context, HealthReport healthReport)
private static Task FormatWriteHCResponse(HttpContext context, HealthReport healthReport)
{
context.Response.ContentType = "application/json; charset=utf-8";

Expand Down
3 changes: 0 additions & 3 deletions SwissKnife/Database/ImportDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ public void PatchImport(IConsole console, string inputFolder)
seen.Add(theMatchingAssessment.Key);


// todo: overfør manglende morro
var exAssessment = JsonSerializer.Deserialize<FA4>(real.Doc, _jsonSerializerOptions);
var orgCopy = JsonSerializer.Deserialize<FA4>(real.Doc, _jsonSerializerOptions);
exAssessment.ExtensionData = null;
Expand Down Expand Up @@ -444,7 +443,6 @@ public void PatchImport(IConsole console, string inputFolder)
//continue;
var real = _database.Assessments.Single(x => x.Id == item);

// todo: overfør manglende morro
var exAssessment = JsonSerializer.Deserialize<FA4>(real.Doc, _jsonSerializerOptions);
var orgCopy = JsonSerializer.Deserialize<FA4>(real.Doc, _jsonSerializerOptions);

Expand Down Expand Up @@ -528,7 +526,6 @@ public void PatchHsScans(IConsole console)
//continue;
var real = _database.Assessments.Single(x => x.Id == item);

// todo: overfør manglende morro
var exAssessment = JsonSerializer.Deserialize<FA4>(real.Doc, _jsonSerializerOptions);
var orgCopy = JsonSerializer.Deserialize<FA4>(real.Doc, _jsonSerializerOptions);

Expand Down
19 changes: 2 additions & 17 deletions SwissKnife/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ private void OnExecute(IConsole console)
[Command("importhsdata", Description = "Import and create assessments from names with data from horisontscanning")]
internal class ImportHSData : MaintananceBase
{
//[Option("--speciesgroup", Description = "SpeciesGroup to put assessments in")]
//[Required]
//public string SpeciesGroup { get; }

[Option("--csvfile", Description = "CvsFile with path")]
[Required]
public string InputFolder { get; }
Expand All @@ -125,13 +121,9 @@ private void OnExecute(IConsole console)
}
}

[Command("importfiles", Description = "update generaiontime on assessments")]
[Command("importfiles", Description = "update ekspansjonsdata on assessments")]
internal class ImportAttachementData : MaintananceBase
{
//[Option("--speciesgroup", Description = "SpeciesGroup to put assessments in")]
//[Required]
//public string SpeciesGroup { get; }

[Option("--folder", Description = "CvsFile with path")]
[Required]
public string InputFolder { get; }
Expand All @@ -145,10 +137,6 @@ private void OnExecute(IConsole console)
[Command("importgenerationtime", Description = "update generaiontime on assessments")]
internal class ImportGTData : MaintananceBase
{
//[Option("--speciesgroup", Description = "SpeciesGroup to put assessments in")]
//[Required]
//public string SpeciesGroup { get; }

[Option("--csvfile", Description = "CvsFile with path")]
[Required]
public string InputFolder { get; }
Expand Down Expand Up @@ -297,11 +285,9 @@ private int OnExecute(IConsole console)
}

internal class Trueteogsjeldnenaturtyper
//internal class TrueteOgSjeldneNaturtyper
{
//[Option("--trueteogsjeldnenaturtyper", Description = "Generate JSON file for truete og sjeldne naturtyper 2018")]
[Option("--outputfilename", Description = "Generate JSON file for truete og sjeldne naturtyper 2018")]
//[Required]

public string outputfilename { get; }
private void OnExecute(IConsole console)
{
Expand All @@ -315,7 +301,6 @@ private void OnExecute(IConsole console)
internal class Nin2
{
[Option("--outputfilename", Description = "Generate JSON file for NiN2")]
//[Required]
public string outputfilename { get; }
private void OnExecute(IConsole console)
{
Expand Down
3 changes: 2 additions & 1 deletion SwissKnife/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"commandLineArgs": "olddb dump --url http://localhost:8080 --db fab3 --fs fab3fs --outputfolder ../../../dumpsfab"
},
"RunNoTask": {
"commandName": "Project"
"commandName": "Project",
"commandLineArgs": "maintenance --help"
}
}
}
29 changes: 29 additions & 0 deletions SwissKnife/Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Fremmedartsbase SwissKnife

Tool for batchtasks, import, export and similar stuff.
See all functions below

No secrets - all input via command line.

Expand All @@ -16,9 +17,37 @@ Options:
Commands:
createjson Run tasks for creating static json data files
Commands:
nin2 - bruker kode-api og lager lokal json fil med naturtyper
trueteogsjeldnenaturtyper - csv fil til json format
maintenance Run tasks for maintaining database
Commands:
importfiles update ekspansjonsdata on assessments
importgenerationtime update generaiontime on assessments
importhsdata Import and create assessments from names with data from horisontscanning
importnames Import and create assessments from names
nighttasks nightly maintenance, basic night tasks check changed references, dowload missing artskart data ....
patchhs Patch horizon scanned assessments based on - used for fixing assessments after production went live
patchmigration Patch migrated assessments from original json dump - used for fixing assessments after production went live - lots of issues fixed
taxonomywash Check and update taxonomy on assessments - create comments to reflect result
taxonomywashdirect Check and update taxonomy on assessments direct with history - do taxonomic wash - also splits - without creating comments
transferacrossassessments Transfer information from-to assessment - replicate most info from one assessment to spesific other and create link between
transferfromhs transfer current result from horizontscan - all HS assessment with specific result move to full assessment
newDb Interact with new sql database instance
Commands:
import - importerer til sql server og nytt format fra outputfiler generert av olddb
oldDb Interact with old 2018 RavenDb instance
Commands:
dump dump content from db to json files
info show some statistics from db
Run 'SwissKnife [command] -?|-h|--help' for more information about a command.
```
Expand Down

0 comments on commit 80a1bf9

Please sign in to comment.