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

Add job AD419.Jobs.PullNifaData #2

Merged
merged 1 commit into from
Dec 8, 2023
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
22 changes: 19 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"name": "Launch (AD419.Jobs.PullAggieEnterpriseData)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"preLaunchTask": "build-AD419.Jobs.PullAggieEnterpriseData",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/AD419.Jobs.PullAggieEnterpriseData/bin/Debug/net6.0/AD419.Jobs.PullAggieEnterpriseData.dll",
"args": [],
Expand All @@ -17,10 +17,26 @@
"console": "internalConsole",
"stopAtEntry": false
},
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": "Launch (AD419.Jobs.PullNifaData)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build-AD419.Jobs.PullNifaData",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/AD419.Jobs.PullNifaData/bin/Debug/net6.0/AD419.Jobs.PullNifaData.dll",
"args": [],
"cwd": "${workspaceFolder}/AD419.Jobs.PullNifaData",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
}
16 changes: 14 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "2.0.0",
"tasks": [
{
"label": "build",
"label": "build-AD419.Jobs.PullAggieEnterpriseData",
"command": "dotnet",
"type": "process",
"args": [
Expand All @@ -13,6 +13,18 @@
],
"problemMatcher": "$msCompile"
},
{
"label": "build-AD419.Jobs.PullNifaData",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/AD419.Jobs.PullNifaData/AD419.Jobs.PullNifaData.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
Expand All @@ -38,4 +50,4 @@
"problemMatcher": "$msCompile"
}
]
}
}
2 changes: 2 additions & 0 deletions AD419.Jobs.Core/AD419.Jobs.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
<ItemGroup>
<PackageReference Include="Elastic.Apm.NetCoreAll" Version="1.12.1"/>
<PackageReference Include="Elastic.Apm.SerilogEnricher" Version="1.5.3"/>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.0"/>
<PackageReference Include="Microsoft.SqlServer.TransactSQL.ScriptDom" Version="150.4897.1" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
Expand Down
20 changes: 20 additions & 0 deletions AD419.Jobs.Core/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace AD419.Jobs.Core.Extensions;

public static class StringExtensions
{
public static string ToPascalCase(this string titleCase)
{
if (string.IsNullOrWhiteSpace(titleCase))
{
return string.Empty;
}

var words = titleCase.Split(new[] { "_", " " }, StringSplitOptions.RemoveEmptyEntries);
var pascalCase = string.Join(string.Empty, words.Select(x => char.ToUpper(x[0]) + x.Substring(1).ToLower()));
return pascalCase;
}
}


Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Data;
using Microsoft.Data.SqlClient;
using Microsoft.SqlServer.TransactSql.ScriptDom;
using Serilog;

namespace AD419.Jobs.Utilities;
namespace AD419.Jobs.Core.Utilities;

public static class SqlHelper
{
Expand Down Expand Up @@ -51,4 +53,20 @@ public static IEnumerable<string> GetBatchesFromString(string script)
yield return batch;
}
}

public static async Task ExecuteScript(string fileName, SqlConnection connection, SqlTransaction? transaction = null)
{
Log.Information("Executing script {FileName}", fileName);
// TODO: use connection.CreateBatch() once it is implemented for SqlConnection
foreach (var script in GetBatchesFromFile(fileName))
{
using var command = connection.CreateCommand();
command.CommandText = script;
if (transaction != null)
{
command.Transaction = transaction;
}
await command.ExecuteNonQueryAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="AggieEnterpriseApi" Version="0.2.171" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
<PackageReference Include="Microsoft.SqlServer.TransactSQL.ScriptDom" Version="150.4897.1" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
Expand Down
31 changes: 9 additions & 22 deletions AD419.Jobs.PullAggieEnterpriseData/Services/SyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.Extensions.Options;
using AD419.Jobs.Configuration;
using Serilog;
using AD419.Jobs.Utilities;
using AD419.Jobs.Core.Utilities;

namespace AD419.Jobs.Services;

Expand Down Expand Up @@ -60,7 +60,7 @@ public async Task Run()

private async Task SyncFinancialDepartmentValues(SqlConnection connection, SqlTransaction transaction)
{
await ExecuteScript("Scripts/ErpFinancialDepartmentValues_Start.sql", connection, transaction);
await SqlHelper.ExecuteScript("Scripts/ErpFinancialDepartmentValues_Start.sql", connection, transaction);

var i = 0;
await foreach (var item in _aggieEnterpriseService.GetFinancialDepartmentValues())
Expand All @@ -82,12 +82,12 @@ private async Task SyncFinancialDepartmentValues(SqlConnection connection, SqlTr
_dataTable.Rows.Clear();
}

await ExecuteScript("Scripts/ErpFinancialDepartmentValues_Finish.sql", connection, transaction);
await SqlHelper.ExecuteScript("Scripts/ErpFinancialDepartmentValues_Finish.sql", connection, transaction);
}

private async Task SyncFundValues(SqlConnection connection, SqlTransaction transaction)
{
await ExecuteScript("Scripts/ErpFundValues_Start.sql", connection, transaction);
await SqlHelper.ExecuteScript("Scripts/ErpFundValues_Start.sql", connection, transaction);

var i = 0;
await foreach (var item in _aggieEnterpriseService.GetFundValues())
Expand All @@ -109,12 +109,12 @@ private async Task SyncFundValues(SqlConnection connection, SqlTransaction trans
_dataTable.Rows.Clear();
}

await ExecuteScript("Scripts/ErpFundValues_Finish.sql", connection, transaction);
await SqlHelper.ExecuteScript("Scripts/ErpFundValues_Finish.sql", connection, transaction);
}

private async Task SyncAccountValues(SqlConnection connection, SqlTransaction transaction)
{
await ExecuteScript("Scripts/ErpAccountValues_Start.sql", connection, transaction);
await SqlHelper.ExecuteScript("Scripts/ErpAccountValues_Start.sql", connection, transaction);

var i = 0;
await foreach (var item in _aggieEnterpriseService.GetAccountValues())
Expand All @@ -136,12 +136,12 @@ private async Task SyncAccountValues(SqlConnection connection, SqlTransaction tr
_dataTable.Rows.Clear();
}

await ExecuteScript("Scripts/ErpAccountValues_Finish.sql", connection, transaction);
await SqlHelper.ExecuteScript("Scripts/ErpAccountValues_Finish.sql", connection, transaction);
}

private async Task SyncProjectValues(SqlConnection connection, SqlTransaction transaction)
{
await ExecuteScript("Scripts/ErpProjectValues_Start.sql", connection, transaction);
await SqlHelper.ExecuteScript("Scripts/ErpProjectValues_Start.sql", connection, transaction);

var i = 0;
await foreach (var item in _aggieEnterpriseService.GetProjectValues())
Expand All @@ -163,20 +163,7 @@ private async Task SyncProjectValues(SqlConnection connection, SqlTransaction tr
_dataTable.Rows.Clear();
}

await ExecuteScript("Scripts/ErpProjectValues_Finish.sql", connection, transaction);
}

private static async Task ExecuteScript(string fileName, SqlConnection connection, SqlTransaction transaction)
{
Log.Information("Executing script {FileName}", fileName);
// TODO: use connection.CreateBatch() once it is implemented for SqlConnection
foreach (var script in SqlHelper.GetBatchesFromFile(fileName))
{
using var command = connection.CreateCommand();
command.CommandText = script;
command.Transaction = transaction;
await command.ExecuteNonQueryAsync();
}
await SqlHelper.ExecuteScript("Scripts/ErpProjectValues_Finish.sql", connection, transaction);
}

private static async Task SyncDataTable(SqlConnection connection, DataTable dataTable, SqlTransaction transaction, string tableName)
Expand Down
35 changes: 35 additions & 0 deletions AD419.Jobs.PullNifaData/AD419.Jobs.PullNifaData.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>1af5cb6b-980b-448a-ad94-1677a1314f4b</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AD419.Jobs.Core\AD419.Jobs.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AggieEnterpriseApi" Version="0.2.171" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
<PackageReference Include="Microsoft.SqlServer.TransactSQL.ScriptDom" Version="150.4897.1" />
<PackageReference Include="SSH.NET" Version="2023.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="run.cmd">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="settings.job">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Content Include="Scripts/**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions AD419.Jobs.PullNifaData/Configuration/ConnectionStrings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AD419.Jobs.Configuration;

public class ConnectionStrings
{
public string DefaultConnection { get; set; } = "";
}
7 changes: 7 additions & 0 deletions AD419.Jobs.PullNifaData/Configuration/SyncOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace AD419.Jobs.Configuration;

public class SyncOptions
{
public int BulkCopyBatchSize { get; set; } = 1000;
public string ProcessedFileLocation { get; set; } = "/Already Uploaded";
}
75 changes: 75 additions & 0 deletions AD419.Jobs.PullNifaData/Models/NifaGlModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using CsvHelper.Configuration.Attributes;

namespace AD419.Jobs.Models;

public class NifaGlModel
{
[Name("ACCOUNTING YEAR")]
public int AccountingYear { get; set; }
[Name("POSTED YEAR")]
public int? PostedYear { get; set; }
[Name("PERIOD")]
public string Period { get; set; } = "";
[Name("ACCOUNTING DATE")]
public DateTime? AccountingDate { get; set; }
[Name("POSTED DATE")]
public DateTime? PostedDate { get; set; }
[Name("JOURNAL CATEGORY")]
public string JournalCategory { get; set; } = "";
[Name("JOURNAL SOURCE")]
public string JournalSource { get; set; } = "";
[Name("ACCOUNT COMBINATION")]
public string AccountCombination { get; set; } = "";
[Name("ENTITY")]
public string Entity { get; set; } = "";
[Name("ENTITY DESCRIPTION")]
public string EntityDesctiption { get; set; } = "";
[Name("FUND")]
public string Fund { get; set; } = "";
[Name("FUND DESCRIPTION")]
public string FundDescription { get; set; } = "";
[Name("PARENT FUND")]
public string ParentFund { get; set; } = "";
[Name("PARENT FUND DESCRIPTION")]
public string ParentFundDescription { get; set; } = "";
[Name("FINANCIAL DEPARTMENT PARENT C")]
public string FinancialDepartmentParentC { get; set; } = "";
[Name("FINANCIAL DEPARTMENT PARENT C DESCRIPTION")]
public string FinancialDepartmentParentC_Description { get; set; } = "";
[Name("FINANCIAL DEPARTMENT")]
public string FinancialDepartment { get; set; } = "";
[Name("FINANCIAL DEPARTMENT DESCRIPTION")]
public string FinancialDepartmentDescription { get; set; } = "";
[Name("NATURAL ACCOUNT")]
public string NaturalAccount { get; set; } = "";
[Name("NATURAL ACCOUNT DESCRIPTION")]
public string NaturalAccountDescription { get; set; } = "";
[Name("NATURAL ACCOUNT TYPE")]
public string NatruralAccountType { get; set; } = "";
[Name("PURPOSE")]
public string Purpose { get; set; } = "";
[Name("PURPOSE DESCRIPTION")]
public string PurposeDescription { get; set; } = "";
[Name("PROGRAM")]
public string Program { get; set; } = "";
[Name("PROGRAM DESCRIPTION")]
public string ProgramDescription { get; set; } = "";
[Name("PROJECT")]
public string Project { get; set; } = "";
[Name("PROJECT DESCRIPTION")]
public string ProjectDescription { get; set; } = "";
[Name("ACTIVITY")]
public string Activity { get; set; } = "";
[Name("ACTIVITY DESCRIPTION")]
public string ActivityDescription { get; set; } = "";
[Name("INTER ENTITY")]
public string InterEntity { get; set; } = "";
[Name("GL FUTURE 1")]
public string GL_Future1 { get; set; } = "";
[Name("GL FUTURE 2")]
public string GL_Future2 { get; set; } = "";
[Name("DEBIT AMOUNT")]
public decimal? DebitAmount { get; set; }
[Name("CREDIT AMOUNT")]
public decimal? CreditAmount { get; set; }
}
Loading