Skip to content

Commit

Permalink
Changed the way the section definitions are loaded
Browse files Browse the repository at this point in the history
Added extra checks for when for example a field would be removed from the definition
  • Loading branch information
ArneMaes0 committed Jun 14, 2024
1 parent 56bdb58 commit 0266ee1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
23 changes: 17 additions & 6 deletions SLC-GQIDS-DOM-History_1/Provider/DataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,24 @@ public IEnumerable<DomChange> GetHistoryForInstance(Guid domInstanceId)
var filter = HistoryChangeExposers.SubjectID.Equal(instance.ID.ToFileFriendlyString());
var historyAll = helper.DomInstanceHistory.Read(filter);

helper.StitchDomInstances(new List<DomInstance> { instance });
var fieldMap = instance.Sections.SelectMany(section =>
var definition = instance.GetDomDefinition();
var sectionDefinitionIdFilters = definition.SectionDefinitionLinks.Select(x => SectionDefinitionExposers.ID.Equal(x.SectionDefinitionID));
var sectionDefinitionFilters = new ORFilterElement<SectionDefinition>(sectionDefinitionIdFilters.ToArray());
var sectionDefinitions = helper.SectionDefinitions.Read(sectionDefinitionFilters) ?? new List<SectionDefinition>();

var fieldMap = new List<DomFieldContainer>();
foreach(var sectionDefinition in sectionDefinitions)
{
var sectionDef = section.GetSectionDefinition();
return sectionDef.GetAllFieldDescriptors().Select(field =>
new { Field = field, Section = sectionDef });
}).ToDictionary(key => key.Field.ID.Id, value => new KeyValuePair<SectionDefinition, FieldDescriptor>(value.Section, value.Field));
var fields = sectionDefinition.GetAllFieldDescriptors();
foreach (var field in fields)
{
fieldMap.Add(new DomFieldContainer
{
SectionDefinition = sectionDefinition,
Field = field,
});
}
}

var changes = new List<DomChange>();
changes.AddRange(
Expand Down
21 changes: 16 additions & 5 deletions SLC-GQIDS-DOM-History_1/Provider/DomChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Skyline.GQI.Sources.DOM.History.Provider

using Skyline.DataMiner.Net.Apps.History.DomInstances;
using Skyline.DataMiner.Net.History;
using Skyline.DataMiner.Net.Sections;

public enum DomChangeType
{
Expand All @@ -25,18 +24,30 @@ public DomChange()
{
}

public DomChange(Dictionary<Guid, KeyValuePair<SectionDefinition, FieldDescriptor>> fieldMap, HistoryChange history, DomSectionChange sectionChange, DomFieldValueChange fieldChange)
public DomChange(
List<DomFieldContainer> fieldMap,
HistoryChange history,
DomSectionChange sectionChange,
DomFieldValueChange fieldChange)
{
var helperContainer = fieldMap.Find(x => x.Field.ID.Id == fieldChange.FieldDescriptorId.Id);
if (helperContainer != null)
{
var sectionDefinition = helperContainer.SectionDefinition;
var fieldDescriptor = helperContainer.Field;

SectionDefinitionName = SectionDefinitionId = Convert.ToString(sectionDefinition.GetID().Id);
SectionDefinitionName = sectionDefinition.GetName();
FieldDescriptorName = fieldDescriptor.Name;
}

DomHistoryId = history.ID;
DomInstanceId = Convert.ToString(history.SubjectId.ToAttachmentString());
DateOfChange = history.Time;
Type = DomChangeType.SectionChange;
ChangedBy = history.FullUsername;
SectionId = Convert.ToString(sectionChange.SectionId.Id);
SectionDefinitionId = Convert.ToString(fieldMap[fieldChange.FieldDescriptorId.Id].Key.GetID().Id);
SectionDefinitionName = fieldMap[fieldChange.FieldDescriptorId.Id].Key.GetName();
FieldDescriptorId = Convert.ToString(fieldChange.FieldDescriptorId.Id);
FieldDescriptorName = fieldMap[fieldChange.FieldDescriptorId.Id].Value.Name;
OldValue = Convert.ToString(fieldChange.ValueBefore?.Value);
NewValue = Convert.ToString(fieldChange.ValueAfter?.Value);
}
Expand Down
15 changes: 15 additions & 0 deletions SLC-GQIDS-DOM-History_1/Provider/DomFieldContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Ignore Spelling: GQI

namespace Skyline.GQI.Sources.DOM.History.Provider
{
using Skyline.DataMiner.Net.Sections;

public class DomFieldContainer
{
public FieldDescriptor Field { get; set; }

public Section Section { get; set; }

public SectionDefinition SectionDefinition { get; set; }
}
}
1 change: 0 additions & 1 deletion SLC-GQIDS-DOM-History_1/SLC-GQIDS-DOM-History_1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ namespace Skyline.GQI.Sources.DOM.History
using System.Linq;

using Skyline.DataMiner.Analytics.GenericInterface;
using Skyline.DataMiner.Net.Apps.DataMinerObjectModel;
using Skyline.GQI.Sources.DOM.History.Provider;

[GQIMetaData(Name = "Get DOM History")]
Expand Down

0 comments on commit 0266ee1

Please sign in to comment.