Skip to content

Commit

Permalink
Merge branch 'release/0.0.4' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
fstueber committed Sep 23, 2021
2 parents 78b5938 + 8703c27 commit 2337330
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/CommandDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ public static Command Export()
{
var command = new Command("export", "Exports data from a Edoosys export CSV to ECF files")
{
new Option(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
new Option<FileInfo>(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
{
Argument = new Argument<FileInfo>(),
IsRequired = true
},
};
Expand Down
6 changes: 2 additions & 4 deletions src/Converters/CsvConverterResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ public class CsvConverterResolver : CsvDefaultConverterResolver
protected override void RegisterDefaultConverters()
{
base.RegisterDefaultConverters();
AddConverter<Date?>(new CsvDateConverter());
AddConverter<Date>(new CsvDateConverter());
AddConverter<EcfGender?>(new CsvGenderConverter());
AddConverter<EcfGender>(new CsvGenderConverter());
AddConverter(typeof(Date), new CsvDateConverter());
AddConverter(typeof(EcfGender), new CsvGenderConverter());
}
}
}
7 changes: 4 additions & 3 deletions src/Ecf.Edoosys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Enbrea.Csv" Version="0.1.1" />
<PackageReference Include="Enbrea.Ecf" Version="0.1.3" />
<PackageReference Include="Enbrea.Csv" Version="0.2.1" />
<PackageReference Include="Enbrea.Ecf" Version="0.1.10" />
<PackageReference Include="Enbrea.Edoosys.Db" Version="0.1.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
<PackageReference Include="Enbrea.GuidFactory" Version="0.2.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion src/Export/CsvExportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ private async Task<int> ExportStudentSubjects(CsvTableReader csvTableReader, Ecf
await ecfTableWriter.WriteHeadersAsync(
EcfHeaders.StudentId,
EcfHeaders.SchoolClassId,
EcfHeaders.SubjectId);
EcfHeaders.SubjectId,
EcfHeaders.TeacherId);
}

while (await csvTableReader.ReadAsync() > 0)
Expand All @@ -272,13 +273,15 @@ await ecfTableWriter.WriteHeadersAsync(
var subValueParts = csvLineParser.Read(subValue.Trim());
if (subValueParts.Length == 2)
{
var teacherCode = subValueParts[0];
var subjectCode = subValueParts[1];

if (!string.IsNullOrEmpty(subjectCode))
{
ecfTableWriter.TrySetValue(EcfHeaders.StudentId, student.Id);
ecfTableWriter.TrySetValue(EcfHeaders.SchoolClassId, schoolClass.Id);
ecfTableWriter.TrySetValue(EcfHeaders.SubjectId, subjectCode);
ecfTableWriter.TrySetValue(EcfHeaders.TeacherId, teacherCode);

await ecfTableWriter.WriteAsync();

Expand Down
26 changes: 21 additions & 5 deletions src/Export/DbExportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ await ecfTableWriter.WriteHeadersAsync(
ecfTableWriter.TrySetValue(EcfHeaders.Id, student.Id);
ecfTableWriter.TrySetValue(EcfHeaders.LastName, student.Lastname);
ecfTableWriter.TrySetValue(EcfHeaders.FirstName, student.Firstname);
ecfTableWriter.TrySetValue(EcfHeaders.Gender, student.Gender);
ecfTableWriter.TrySetValue(EcfHeaders.Birthdate, student.Birthdate);
ecfTableWriter.TrySetValue(EcfHeaders.Gender, Converter.GetGender(student.Gender));
ecfTableWriter.TrySetValue(EcfHeaders.Birthdate, Converter.GetDate(student.Birthdate));

await ecfTableWriter.WriteAsync();

Expand Down Expand Up @@ -226,6 +226,7 @@ private async Task<int> ExportStudentSchoolClassAttendances(EdoosysDbReader edoo
else
{
await ecfTableWriter.WriteHeadersAsync(
EcfHeaders.Id,
EcfHeaders.StudentId,
EcfHeaders.SchoolClassId);
}
Expand All @@ -234,6 +235,7 @@ await ecfTableWriter.WriteHeadersAsync(
{
var schoolClassId = _config.EcfExport.NoSchoolClassGroups ? attendance.SchoolClassRootId : attendance.SchoolClassId;

ecfTableWriter.TrySetValue(EcfHeaders.Id, GenerateKey(attendance.StudentId, schoolClassId));
ecfTableWriter.TrySetValue(EcfHeaders.StudentId, attendance.StudentId);
ecfTableWriter.TrySetValue(EcfHeaders.SchoolClassId, schoolClassId);
await ecfTableWriter.WriteAsync();
Expand Down Expand Up @@ -263,6 +265,7 @@ private async Task<int> ExportStudentSubjects(EdoosysDbReader edoosysDbReader, E
else
{
await ecfTableWriter.WriteHeadersAsync(
EcfHeaders.Id,
EcfHeaders.StudentId,
EcfHeaders.SchoolClassId,
EcfHeaders.SubjectId,
Expand All @@ -272,7 +275,8 @@ await ecfTableWriter.WriteHeadersAsync(
await foreach (var studentSubject in edoosysDbReader.StudentSubjectsAsync(_config.EcfExport.SchoolNo, _config.EcfExport.SchoolYearCode, activeStudentsOnly: true))
{
var schoolClassId = _config.EcfExport.NoSchoolClassGroups ? studentSubject.SchoolClassRootId : studentSubject.SchoolClassId;


ecfTableWriter.TrySetValue(EcfHeaders.Id, GenerateKey(studentSubject.StudentId, studentSubject.SubjectId, schoolClassId, studentSubject.TeacherId));
ecfTableWriter.TrySetValue(EcfHeaders.StudentId, studentSubject.StudentId);
ecfTableWriter.TrySetValue(EcfHeaders.SubjectId, studentSubject.SubjectId);
ecfTableWriter.TrySetValue(EcfHeaders.SchoolClassId, schoolClassId);
Expand Down Expand Up @@ -358,8 +362,8 @@ await ecfTableWriter.WriteHeadersAsync(
ecfTableWriter.TrySetValue(EcfHeaders.Code, teacher.Code);
ecfTableWriter.TrySetValue(EcfHeaders.LastName, teacher.Lastname);
ecfTableWriter.TrySetValue(EcfHeaders.FirstName, teacher.Firstname);
ecfTableWriter.TrySetValue(EcfHeaders.Gender, teacher.Gender);
ecfTableWriter.TrySetValue(EcfHeaders.Birthdate, teacher.Birthdate);
ecfTableWriter.TrySetValue(EcfHeaders.Gender, Converter.GetGender(teacher.Gender));
ecfTableWriter.TrySetValue(EcfHeaders.Birthdate, Converter.GetDate(teacher.Birthdate));

await ecfTableWriter.WriteAsync();

Expand All @@ -374,5 +378,17 @@ await ecfTableWriter.WriteHeadersAsync(
throw new Exception("No school no and/or no school year for edoo.sys database defined");
}
}

private Guid GenerateKey(params string[] array)
{
var csvLineBuilder = new CsvLineBuilder();

foreach (var arrayItem in array)
{
csvLineBuilder.Append(arrayItem);
}
return IdFactory.CreateIdFromValue(csvLineBuilder.ToString());
}

}
}
57 changes: 57 additions & 0 deletions src/Utils/Converter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#region ENBREA - Copyright (C) 2021 STÜBER SYSTEMS GmbH
/*
* ENBREA
*
* Copyright (C) 2021 STÜBER SYSTEMS GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#endregion

using Enbrea.Ecf;
using Enbrea.Edoosys.Db;
using System;

namespace Ecf.Edoosys
{
/// <summary>
/// Data type converter
/// </summary>
public static class Converter
{
public static Date? GetDate(DateTime? value)
{
if (value != null)
{
return new Date((DateTime)value);
}
return null;
}

public static EcfGender? GetGender(Gender? value)
{
if (value != null)
{
return (value) switch
{
Gender.Male => EcfGender.Male,
Gender.Female => EcfGender.Female,
Gender.Diverse => EcfGender.Diverse,
_ => null,
};
}
return null;
}
}
}
34 changes: 34 additions & 0 deletions src/Utils/IdFactory .cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#region ENBREA - Copyright (C) 2021 STÜBER SYSTEMS GmbH
/*
* ENBREA
*
* Copyright (C) 2021 STÜBER SYSTEMS GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#endregion

using Enbrea.GuidFactory;
using System;

namespace Ecf.Edoosys
{
public static class IdFactory
{
public static Guid CreateIdFromValue(string value)
{
return GuidGenerator.Create(GuidGenerator.IsoOidNamespace, value);
}
}
}
2 changes: 1 addition & 1 deletion test/xunit/Ecf.Edoosys.XUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit 2337330

Please sign in to comment.