Adapt welcome wallpaper to SGU gender
This commit is contained in:
1 parent
1fe2006404
commit
93871b62b0
12 files changed
+367
-25
No files matched your search
@@ -0,0 +1,7 @@
|
||||
namespace SGU.AuthBroker.Core.Profiles;
|
||||
|
||||
public enum InstitutionalGender
|
||||
{
|
||||
Male,
|
||||
Female
|
||||
}
|
||||
@@ -12,7 +12,8 @@ public sealed record InstitutionalProfile(
|
||||
string? StreetAddress = null,
|
||||
string? City = null,
|
||||
string? State = null,
|
||||
string? PostalCode = null)
|
||||
string? PostalCode = null,
|
||||
InstitutionalGender? Gender = null)
|
||||
{
|
||||
public bool HasValues =>
|
||||
EmployeeNumber is not null ||
|
||||
@@ -26,7 +27,8 @@ public sealed record InstitutionalProfile(
|
||||
StreetAddress is not null ||
|
||||
City is not null ||
|
||||
State is not null ||
|
||||
PostalCode is not null;
|
||||
PostalCode is not null ||
|
||||
Gender is not null;
|
||||
|
||||
public InstitutionalProfile Overlay(InstitutionalProfile? values) =>
|
||||
values is null
|
||||
@@ -44,6 +46,7 @@ public sealed record InstitutionalProfile(
|
||||
StreetAddress = values.StreetAddress ?? StreetAddress,
|
||||
City = values.City ?? City,
|
||||
State = values.State ?? State,
|
||||
PostalCode = values.PostalCode ?? PostalCode
|
||||
PostalCode = values.PostalCode ?? PostalCode,
|
||||
Gender = values.Gender ?? Gender
|
||||
};
|
||||
}
|
||||
@@ -14,6 +14,8 @@ public static class SguProfileParser
|
||||
private const string AdministrativeGivenNameId = "ctl00_contenedor_txtNombre";
|
||||
private const string AdministrativePaternalSurnameId = "ctl00_contenedor_txtApaterno";
|
||||
private const string AdministrativeMaternalSurnameId = "ctl00_contenedor_txtAmaterno";
|
||||
private const string AdministrativeGenderId = "ctl00_contenedor_ddlsexo";
|
||||
private const string AdministrativeGenderName = "ctl00$contenedor$ddlsexo";
|
||||
private const string AdministrativeStreetId = "ctl00_contenedor_txtCalle";
|
||||
private const string AdministrativeExteriorNumberId = "ctl00_contenedor_txtNoExt";
|
||||
private const string AdministrativeInteriorNumberId = "ctl00_contenedor_txtNoInt";
|
||||
@@ -34,6 +36,7 @@ public static class SguProfileParser
|
||||
private const string StudentCityId = "ctl00_contenedor_HistorialAlumno1_lblCiudadAlumnoHP";
|
||||
private const string StudentMunicipalityId = "ctl00_contenedor_HistorialAlumno1_lblDeloMunAlumnoHP";
|
||||
private const string StudentPostalCodeId = "ctl00_contenedor_HistorialAlumno1_lblCPAlumnoHP";
|
||||
private const string StudentGenderId = "ctl00_contenedor_HistorialAlumno1_lblSexoAlumnoHP";
|
||||
|
||||
public static InstitutionalProfile? ParseAdministrative(string html, string expectedEmployeeNumber)
|
||||
=> ParseStaffHeader(html, expectedEmployeeNumber);
|
||||
@@ -91,7 +94,11 @@ public static class SguProfileParser
|
||||
InstitutionalProfile profile = new(
|
||||
DisplayName: displayName,
|
||||
GivenName: givenName,
|
||||
Surname: surname);
|
||||
Surname: surname,
|
||||
Gender: ParseStaffGender(ExtractSelectedOptionValue(
|
||||
html,
|
||||
AdministrativeGenderId,
|
||||
AdministrativeGenderName)));
|
||||
return profile.HasValues ? profile : null;
|
||||
}
|
||||
|
||||
@@ -151,7 +158,8 @@ public static class SguProfileParser
|
||||
StreetAddress: streetAddress,
|
||||
City: city ?? municipality,
|
||||
State: NormalizeTitle(ExtractSpanText(html, StudentStateId), 128),
|
||||
PostalCode: NormalizePostalCode(ExtractSpanText(html, StudentPostalCodeId)));
|
||||
PostalCode: NormalizePostalCode(ExtractSpanText(html, StudentPostalCodeId)),
|
||||
Gender: ParseStudentGender(ExtractSpanText(html, StudentGenderId)));
|
||||
return profile.HasValues ? profile : null;
|
||||
}
|
||||
|
||||
@@ -292,11 +300,68 @@ public static class SguProfileParser
|
||||
return nonPlaceholderOptions.Count == 1 ? nonPlaceholderOptions[0] : null;
|
||||
}
|
||||
|
||||
private static string? ExtractSelectedOptionValue(string html, string id, string name)
|
||||
{
|
||||
string? openingTag = FindOpeningTag(html, "select", id) ??
|
||||
FindOpeningTagByAttribute(html, "select", "name", name);
|
||||
if (openingTag is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int openingTagIndex = html.IndexOf(openingTag, StringComparison.OrdinalIgnoreCase);
|
||||
int contentStart = openingTagIndex + openingTag.Length;
|
||||
int contentEnd = html.IndexOf("</select", contentStart, StringComparison.OrdinalIgnoreCase);
|
||||
if (openingTagIndex < 0 || contentEnd < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string? selectedValue = ExtractAttributeValue(openingTag, "value");
|
||||
string optionsHtml = html[contentStart..contentEnd];
|
||||
int searchFrom = 0;
|
||||
while (searchFrom < optionsHtml.Length)
|
||||
{
|
||||
int optionStart = optionsHtml.IndexOf("<option", searchFrom, StringComparison.OrdinalIgnoreCase);
|
||||
if (optionStart < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
int optionTagEnd = optionsHtml.IndexOf('>', optionStart);
|
||||
if (optionTagEnd < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
string optionTag = optionsHtml[optionStart..(optionTagEnd + 1)];
|
||||
string? optionValue = ExtractAttributeValue(optionTag, "value");
|
||||
if (optionValue is not null &&
|
||||
(HasAttribute(optionTag, "selected") ||
|
||||
(selectedValue is not null &&
|
||||
string.Equals(optionValue, selectedValue, StringComparison.Ordinal))))
|
||||
{
|
||||
return NormalizeText(optionValue);
|
||||
}
|
||||
|
||||
searchFrom = optionTagEnd + 1;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string? FindOpeningTag(string html, string tagName, string id)
|
||||
=> FindOpeningTagByAttribute(html, tagName, "id", id);
|
||||
|
||||
private static string? FindOpeningTagByAttribute(
|
||||
string html,
|
||||
string tagName,
|
||||
string attributeName,
|
||||
string attributeValue)
|
||||
{
|
||||
foreach (char quote in new[] { '"', '\'' })
|
||||
{
|
||||
string marker = $"id={quote}{id}{quote}";
|
||||
string marker = $"{attributeName}={quote}{attributeValue}{quote}";
|
||||
int searchFrom = 0;
|
||||
while (searchFrom < html.Length)
|
||||
{
|
||||
@@ -324,6 +389,20 @@ public static class SguProfileParser
|
||||
return null;
|
||||
}
|
||||
|
||||
private static InstitutionalGender? ParseStaffGender(string? value) => value?.Trim() switch
|
||||
{
|
||||
"1" => InstitutionalGender.Male,
|
||||
"2" => InstitutionalGender.Female,
|
||||
_ => null
|
||||
};
|
||||
|
||||
private static InstitutionalGender? ParseStudentGender(string? value) => value?.Trim().ToUpperInvariant() switch
|
||||
{
|
||||
"M" => InstitutionalGender.Male,
|
||||
"F" => InstitutionalGender.Female,
|
||||
_ => null
|
||||
};
|
||||
|
||||
private static string? ExtractAttributeValue(string openingTag, string attributeName)
|
||||
{
|
||||
foreach (char quote in new[] { '"', '\'' })
|
||||
|
||||
Reference in new issue
Block a user