void EnsureSpecializationAlignment(PanelItemMapping mapping) { var dto = mapping.Item1; var panelItem = mapping.Item2; if (!panelItem.HasSpecializations) { return; } var join = dto.Specializations .Select(d => { return(new { specialization = d, matches = panelItem.Concept.SpecializationGroups .SelectMany(s => s.Specializations) .Where(s => s.Id == d.Id || d.UniversalId != null && s.UniversalId.ToString() == d.UniversalId) }); }); foreach (var spec in join) { if (spec.matches.Count() != 1) { var message = $"SpecializationId: {spec.specialization.Id} or UniversalId: {spec.specialization.UniversalId} invalid"; log.LogWarning("Specialization Misalignment: {Message}. Payload:{@Payload}", message, mapping.Item1); throw new LeafCompilerException($"Specialization Misalignment: {message}."); } } }
void EnsureValidRecencyFilter(PanelItemMapping mapping) { var item = mapping.Item2; if (!item.UseRecencyFilter) { return; } if (item.RecencyFilter == RecencyFilterType.None) { log.LogWarning("Recency Filter Misalignment: No Recency Type Selected. Payload:{@Payload}", mapping.Item1); throw new LeafCompilerException($"Recency Filter Misalignment: No Recency Type Selected."); } }
void EnsureValidNumericFilter(PanelItemMapping mapping) { var item = mapping.Item2; if (!item.UseNumericFilter) { return; } var filter = item.NumericFilter; void throwIfNotLength(int expected) { var actual = filter.Filter.Length; if (actual < expected) { log.LogWarning("Numeric Filter Misalignment: Not enough arguments for NumericFilterType:{Type}. Payload:{@Payload}", filter.FilterType.ToString(), mapping.Item1); throw new LeafCompilerException($"Numeric Filter Misalignment: Missing Numeric Arguments."); } if (actual > expected) { log.LogWarning("Numeric Filter Misalignment: Too many arguments for NumericFilterType:{Type}. Payload:{@Payload}", filter.FilterType.ToString(), mapping.Item1); throw new LeafCompilerException($"Numeric Filter Misalignment: Excessive Numeric Arguments."); } } switch (filter.FilterType) { case NumericFilterType.EqualTo: case NumericFilterType.GreaterThan: case NumericFilterType.GreaterThanOrEqualTo: case NumericFilterType.LessThan: case NumericFilterType.LessThanOrEqualTo: throwIfNotLength(1); return; case NumericFilterType.Between: throwIfNotLength(2); return; } }