Skip to content
11 changes: 6 additions & 5 deletions roles/lib/files/FWO.Report/Data/ViewData/RuleViewData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ public class RuleViewData : IRuleViewData

public Rule? DataObject { get; set; }
public bool Show { get; set; } = true;
public ILogger Logger {get; set; } = new Logger();

public RuleViewData()
{

}

public RuleViewData(Rule rule, NatRuleDisplayHtml natRuleDisplayHtml, OutputLocation outputLocation, bool show, List<Device>? devices = null, List<Management>? managements = null, ComplianceViolationType? complianceViolationType = null)
Expand Down Expand Up @@ -94,13 +95,13 @@ public string GetFromCustomField(Rule rule, string[] field)
}
}
}

return displayString;
}
catch (JsonException)
catch (JsonException e)
{
// If custom fields are not valid JSON, just return empty string.

return "";
Logger.TryWriteError("RuleViewData", $"Error while resolving rule '{rule.Uid}': {e.Message}", true);
return $"Error while resolving custom fields. Raw Data: {rule.CustomFields}";
}
}

Expand Down
5 changes: 4 additions & 1 deletion roles/lib/files/FWO.Report/ReportCompliance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ReportCompliance : ReportBase
public List<RuleViewData> RuleViewData = [];
public List<ComplianceViolation> Violations { get; set; } = [];
public bool ShowNonImpactRules { get; set; }
public List<Management> Managements { get; set; } = [];
public List<Management> Managements { get; set; } = [];
protected virtual string InternalQuery => RuleQueries.getRulesWithCurrentViolationsByChunk;
protected DebugConfig DebugConfig;

Expand All @@ -51,6 +51,8 @@ public class ReportCompliance : ReportBase

public ReportCompliance(DynGraphqlQuery query, UserConfig userConfig, ReportType reportType) : base(query, userConfig, reportType)
{
// Getting config values.

if (userConfig.GlobalConfig != null)
{
_globalConfig = userConfig.GlobalConfig;
Expand Down Expand Up @@ -354,6 +356,7 @@ public void GetViewDataFromRules(List<Rule> rules)
RuleViewData ruleViewData = new RuleViewData(rule, _natRuleDisplayHtml, OutputLocation.report, ShowRule(rule), _devices ?? [], Managements, ruleCompliance);
RuleViewData.Add(ruleViewData);
}

}


Expand Down
19 changes: 19 additions & 0 deletions roles/tests-unit/files/FWO.Test/RuleViewDataTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,24 @@ public void GetFromCustomField_KeyTwo_ReturnsCorrectValue()

Assert.That("Change123".Equals(result));
}

[Test]
public void GetFromCustomField_Example_ReturnsCorrectValue()
{
RuleViewData rvd = new RuleViewData();
Rule rule = new Rule
{
CustomFields = "{'AdoIT': \"Infr-AdoIT:X\", 'Datum-Regelpruefung': 'dd.mm.yyyy'}"
};

string resultDatumRegelpruefung = rvd.GetFromCustomField(rule, ["field-2", "Datum-Regelpruefung"]);
string resultAdoItId = rvd.GetFromCustomField(rule, ["field-3", "AdoIT"]);

Assert.That("dd.mm.yyyy".Equals(resultDatumRegelpruefung));
Assert.That("Infr-AdoIT:X".Equals(resultAdoItId));
}



}
}
Loading