Add comprehensive validation system with runtime configuration

Implements a flexible validation framework for student rankings, team assignments, and team composition with administrator-configurable rules and thresholds.

Validation System:
- Reflection-based rule discovery eliminates manual registration
- Base classes (RequiredEventTypeRuleBase, EventCountThresholdRuleBase) reduce code duplication by ~250 lines
- 12 validation rules covering event requirements, counts, and team constraints
- Configurable severity levels (Warning/Error) per rule type
- ValidationService with caching for optimal performance
- Rules apply contextually (StudentRanking, StudentAssignment, TeamComposition)

Configuration & Admin UI:
- ValidationSettings admin page for editing thresholds and severity levels
- ChapterSettings admin page for editing chapter information
- Settings stored in Data/appsettings.json for runtime configuration
- JSON config works in both development and production environments
- Auto-creates Data directory and config template on first run

User Experience:
- ValidationWarnings component displays inline warnings/errors
- Integrated in Event Ranking, Registration, and Team Assignment pages
- Color-coded severity indicators (warning yellow, error red)
- Includes "Too Many Regional Events" rule (max 3 recommended)

Technical Improvements:
- Template Method pattern for rule base classes
- Singleton rule instances with lazy initialization
- Configuration loaded via IConfiguration with fallback to defaults
- Safe JSON updates preserve other appsettings sections
This commit is contained in:
2025-12-13 22:15:16 -05:00
parent 215b9dccca
commit 1c7e704ad3
36 changed files with 1839 additions and 83 deletions
@@ -0,0 +1,22 @@
using Core.Entities;
using Core.Validation.Rules.BaseRules;
namespace Core.Validation.Rules.StudentRankingRules;
/// <summary>
/// Validation rule that checks if a student has ranked at least one individual event
/// </summary>
public class NoIndividualEventRule : RequiredEventTypeRuleBase
{
protected override bool IsRequired(ValidationConfiguration config) => config.RequireIndividualEvent;
protected override bool HasEventType(Student student) => student.RankedEvents.Any(e => e.EventFormat == EventFormat.Individual);
protected override ValidationSeverity GetSeverity(ValidationConfiguration config) => config.NoIndividualEventSeverity;
protected override string Code => "NO_INDIVIDUAL_EVENT";
protected override string Message => "No Individual Event";
protected override string IconIdentifier => "IndividualEvent";
}
@@ -0,0 +1,22 @@
using Core.Entities;
using Core.Validation.Rules.BaseRules;
namespace Core.Validation.Rules.StudentRankingRules;
/// <summary>
/// Validation rule that checks if a student has ranked at least one on-site activity
/// </summary>
public class NoOnSiteActivityRule : RequiredEventTypeRuleBase
{
protected override bool IsRequired(ValidationConfiguration config) => config.RequireOnSiteActivity;
protected override bool HasEventType(Student student) => student.RankedEvents.Any(e => e.OnSiteActivity);
protected override ValidationSeverity GetSeverity(ValidationConfiguration config) => config.NoOnSiteActivitySeverity;
protected override string Code => "NO_ONSITE_ACTIVITY";
protected override string Message => "No On-Site Activity";
protected override string IconIdentifier => "OnSiteActivity";
}
@@ -0,0 +1,22 @@
using Core.Entities;
using Core.Validation.Rules.BaseRules;
namespace Core.Validation.Rules.StudentRankingRules;
/// <summary>
/// Validation rule that checks if a student has ranked at least one regional event
/// </summary>
public class NoRegionalEventRule : RequiredEventTypeRuleBase
{
protected override bool IsRequired(ValidationConfiguration config) => config.RequireRegionalEvent;
protected override bool HasEventType(Student student) => student.RankedEvents.Any(e => e.RegionalEvent);
protected override ValidationSeverity GetSeverity(ValidationConfiguration config) => config.NoRegionalEventSeverity;
protected override string Code => "NO_REGIONAL_EVENT";
protected override string Message => "No Regional Event";
protected override string IconIdentifier => "RegionalEvent";
}
@@ -0,0 +1,36 @@
using Core.Entities;
using Core.Validation.Rules.BaseRules;
namespace Core.Validation.Rules.StudentRankingRules;
/// <summary>
/// Validation rule that checks if a student has too many regional events in their rankings
/// </summary>
public class TooManyRegionalEventsRule : EventCountThresholdRankingRuleBase
{
protected override int GetCount(Student student) =>
student.RankedEvents.Count(e => e.RegionalEvent);
protected override int GetThreshold(ValidationConfiguration config) => config.MaxRegionalEvents;
protected override bool ViolatesThreshold(int count, int threshold) => count > threshold;
protected override ValidationSeverity GetSeverity(ValidationConfiguration config) =>
config.TooManyRegionalEventsSeverity;
protected override string Code => "TOO_MANY_REGIONAL_EVENTS";
protected override string GetMessage(int count, int threshold) =>
$"Student has {count} regional events (max recommended: {threshold})";
protected override string? IconIdentifier => "RegionalEvent";
protected override Dictionary<string, object> BuildAdditionalMetadata(Student student, ValidationConfiguration config)
{
return new Dictionary<string, object>
{
{ "RegionalEventCount", GetCount(student) },
{ "MaxRegionalEvents", config.MaxRegionalEvents }
};
}
}