diff --git a/PoliNetwork.Graduatorie.Common/Objects/EnrollType.cs b/PoliNetwork.Graduatorie.Common/Objects/EnrollType.cs index 97671355..dd6b6ac2 100644 --- a/PoliNetwork.Graduatorie.Common/Objects/EnrollType.cs +++ b/PoliNetwork.Graduatorie.Common/Objects/EnrollType.cs @@ -1,5 +1,6 @@ #region +using System.Security.Cryptography; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -11,7 +12,7 @@ namespace PoliNetwork.Graduatorie.Common.Objects; [JsonObject(MemberSerialization.Fields, NamingStrategyType = typeof(CamelCaseNamingStrategy))] public class EnrollType { - public bool? CanEnroll; + public bool CanEnroll; public string? Course; public string? Type; @@ -20,8 +21,29 @@ public int GetHashWithoutLastUpdate() var i = "EnrollTypeNotNull".GetHashCode(); i ^= Course?.GetHashCode() ?? "Course".GetHashCode(); i ^= Type?.GetHashCode() ?? "Type".GetHashCode(); - i ^= CanEnroll?.GetHashCode() ?? "CanEnroll".GetHashCode(); return i; } + + public static EnrollType From(string? rowCanEnrollInto, bool rowCanEnroll) + { + if (rowCanEnroll == false) + return new EnrollType { CanEnroll = false, Course = null, Type = null }; + + if (string.IsNullOrEmpty(rowCanEnrollInto)) + return new EnrollType { CanEnroll = true, Course = null, Type = null }; + + string[] tester = { "assegnato", "prenotato" }; + const string sep = " - "; + if (!rowCanEnrollInto.Contains(sep) || !tester.Any(t => rowCanEnrollInto.ToLower().Contains(t))) + return new EnrollType { CanEnroll = true, Course = rowCanEnrollInto, Type = null }; + + var s = rowCanEnrollInto.Split(sep).ToList(); + var type = s.FirstOrDefault(x => tester.Any(t => t == x.ToLower())); + + if (type != null) s.Remove(type); + + var course = string.Join(sep, s); + return new EnrollType { CanEnroll = true, Course = course, Type = type }; + } } \ No newline at end of file diff --git a/PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs b/PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs deleted file mode 100644 index a9bf26a7..00000000 --- a/PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs +++ /dev/null @@ -1,32 +0,0 @@ -#region - -using PoliNetwork.Graduatorie.Common.Objects; - -#endregion - -namespace PoliNetwork.Graduatorie.Common.Utils; - -public static class EnrollUtil -{ - public static EnrollType GetEnrollType(string? rowCanEnrollInto, bool rowCanEnroll) - { - if (rowCanEnroll == false) - return new EnrollType { CanEnroll = false, Course = null, Type = null }; - - if (string.IsNullOrEmpty(rowCanEnrollInto)) - return new EnrollType { CanEnroll = true, Course = null, Type = null }; - - string[] tester = { "assegnato", "prenotato" }; - const string sep = " - "; - if (!rowCanEnrollInto.Contains(sep) || !tester.Any(t => rowCanEnrollInto.ToLower().Contains(t))) - return new EnrollType { CanEnroll = true, Course = rowCanEnrollInto, Type = null }; - - var s = rowCanEnrollInto.Split(sep).ToList(); - var type = s.FirstOrDefault(x => tester.Any(t => t == x.ToLower())); - - if (type != null) s.Remove(type); - - var course = string.Join(sep, s); - return new EnrollType { CanEnroll = true, Course = course, Type = type }; - } -} \ No newline at end of file diff --git a/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Converter.cs b/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Converter.cs index 05c3404e..fc32e7a4 100644 --- a/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Converter.cs +++ b/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Converter.cs @@ -1,6 +1,6 @@ #region -using PoliNetwork.Graduatorie.Common.Utils; +using PoliNetwork.Graduatorie.Common.Objects; using PoliNetwork.Graduatorie.Parser.Objects; using PoliNetwork.Graduatorie.Parser.Objects.Tables.Course; using PoliNetwork.Graduatorie.Parser.Objects.Tables.Merit; @@ -25,7 +25,7 @@ public static StudentResult FromMeritTableToStudentResult(MeritTableRow row) PositionCourse = null, SectionsResults = null, EnglishCorrectAnswers = null, - EnrollType = EnrollUtil.GetEnrollType(rowCanEnrollInto, rowCanEnroll) + EnrollType = EnrollType.From(rowCanEnrollInto, rowCanEnroll) }; } @@ -39,7 +39,7 @@ public static StudentResult FromCourseTableRowToStudentResult(CourseTableRow row Ofa = row.Ofa, Result = row.Result, BirthDate = row.BirthDate, - EnrollType = EnrollUtil.GetEnrollType(course.CourseTitle, rowCanEnroll), + EnrollType = EnrollType.From(course.CourseTitle, rowCanEnroll), PositionAbsolute = null, PositionCourse = row.Position, SectionsResults = row.SectionsResults, diff --git a/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Parser.cs b/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Parser.cs index 781c9e69..0ff79297 100644 --- a/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Parser.cs +++ b/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Parser.cs @@ -8,7 +8,6 @@ using PoliNetwork.Graduatorie.Common.Extensions; using PoliNetwork.Graduatorie.Common.Objects; using PoliNetwork.Graduatorie.Common.Objects.RankingNS; -using PoliNetwork.Graduatorie.Common.Utils; using PoliNetwork.Graduatorie.Common.Utils.HashNS; using PoliNetwork.Graduatorie.Parser.Objects; using PoliNetwork.Graduatorie.Parser.Objects.Json.Indexes.Specific; @@ -606,7 +605,7 @@ Table course Ofa = row.Ofa, Result = row.Result, BirthDate = row.BirthDate, - EnrollType = EnrollUtil.GetEnrollType(course.CourseTitle, canEnroll), + EnrollType = EnrollType.From(course.CourseTitle, canEnroll), PositionCourse = row.Position, SectionsResults = row.SectionsResults, EnglishCorrectAnswers = row.EnglishCorrectAnswers @@ -620,7 +619,7 @@ Table course return student; student.PositionAbsolute = meritRow.Position; - student.EnrollType = EnrollUtil.GetEnrollType(meritRow.CanEnrollInto, canEnroll); + student.EnrollType = EnrollType.From(meritRow.CanEnrollInto, canEnroll); return student; } @@ -643,7 +642,7 @@ IEnumerable courses var canEnroll = row.CanEnroll ?? false; var student = new StudentResult { - EnrollType = EnrollUtil.GetEnrollType(row.CanEnrollInto, canEnroll), + EnrollType = EnrollType.From(row.CanEnrollInto, canEnroll), Id = row.Id, PositionAbsolute = row.Position, Result = row.Result,