Initial import of MaxInventory
This commit is contained in:
@@ -0,0 +1,217 @@
|
||||
namespace MaxInventory.Core.Registry;
|
||||
|
||||
using MaxInventory.Core.Configuration;
|
||||
using MaxInventory.Core.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Registry of cross-entity relationship rules.
|
||||
/// Defines how records from different content types are linked.
|
||||
/// </summary>
|
||||
public sealed class RelationshipRegistry : IRelationshipRegistry
|
||||
{
|
||||
private readonly List<RelationshipRule> _allRules = new();
|
||||
private readonly Dictionary<ContentTypeName, List<RelationshipRule>> _rulesBySource = new();
|
||||
|
||||
public RelationshipRegistry()
|
||||
{
|
||||
RegisterAll();
|
||||
}
|
||||
|
||||
private void RegisterAll()
|
||||
{
|
||||
// Relationships are based on polymorphic host references (host_id + host_type).
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Systems,
|
||||
SourcePropertyName = "HostId",
|
||||
TargetContentType = ContentTypeName.Systems,
|
||||
TargetPropertyName = "Id",
|
||||
DisplayLabel = "Host System",
|
||||
SourceFilterPropertyName = "HostType",
|
||||
SourceFilterValue = "System",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Systems,
|
||||
SourcePropertyName = "HostId",
|
||||
TargetContentType = ContentTypeName.Devices,
|
||||
TargetPropertyName = "Id",
|
||||
DisplayLabel = "Host Device",
|
||||
SourceFilterPropertyName = "HostType",
|
||||
SourceFilterValue = "Device",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Systems,
|
||||
SourcePropertyName = "Id",
|
||||
TargetContentType = ContentTypeName.Systems,
|
||||
TargetPropertyName = "HostId",
|
||||
DisplayLabel = "Hosted Systems",
|
||||
TargetFilterPropertyName = "HostType",
|
||||
TargetFilterValue = "System",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Systems,
|
||||
SourcePropertyName = "Id",
|
||||
TargetContentType = ContentTypeName.Vms,
|
||||
TargetPropertyName = "HostId",
|
||||
DisplayLabel = "Hosted VMs",
|
||||
TargetFilterPropertyName = "HostType",
|
||||
TargetFilterValue = "System",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Systems,
|
||||
SourcePropertyName = "Id",
|
||||
TargetContentType = ContentTypeName.Ips,
|
||||
TargetPropertyName = "HostId",
|
||||
DisplayLabel = "IP Addresses",
|
||||
TargetFilterPropertyName = "HostType",
|
||||
TargetFilterValue = "System",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Devices,
|
||||
SourcePropertyName = "Id",
|
||||
TargetContentType = ContentTypeName.Systems,
|
||||
TargetPropertyName = "HostId",
|
||||
DisplayLabel = "Hosted Systems",
|
||||
TargetFilterPropertyName = "HostType",
|
||||
TargetFilterValue = "Device",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Devices,
|
||||
SourcePropertyName = "Id",
|
||||
TargetContentType = ContentTypeName.Vms,
|
||||
TargetPropertyName = "HostId",
|
||||
DisplayLabel = "Hosted VMs",
|
||||
TargetFilterPropertyName = "HostType",
|
||||
TargetFilterValue = "Device",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Devices,
|
||||
SourcePropertyName = "Id",
|
||||
TargetContentType = ContentTypeName.Ips,
|
||||
TargetPropertyName = "HostId",
|
||||
DisplayLabel = "IP Addresses",
|
||||
TargetFilterPropertyName = "HostType",
|
||||
TargetFilterValue = "Device",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Vms,
|
||||
SourcePropertyName = "HostId",
|
||||
TargetContentType = ContentTypeName.Systems,
|
||||
TargetPropertyName = "Id",
|
||||
DisplayLabel = "Host System",
|
||||
SourceFilterPropertyName = "HostType",
|
||||
SourceFilterValue = "System",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Vms,
|
||||
SourcePropertyName = "HostId",
|
||||
TargetContentType = ContentTypeName.Devices,
|
||||
TargetPropertyName = "Id",
|
||||
DisplayLabel = "Host Device",
|
||||
SourceFilterPropertyName = "HostType",
|
||||
SourceFilterValue = "Device",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Ips,
|
||||
SourcePropertyName = "HostId",
|
||||
TargetContentType = ContentTypeName.Systems,
|
||||
TargetPropertyName = "Id",
|
||||
DisplayLabel = "System",
|
||||
SourceFilterPropertyName = "HostType",
|
||||
SourceFilterValue = "System",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Ips,
|
||||
SourcePropertyName = "HostId",
|
||||
TargetContentType = ContentTypeName.Devices,
|
||||
TargetPropertyName = "Id",
|
||||
DisplayLabel = "Device",
|
||||
SourceFilterPropertyName = "HostType",
|
||||
SourceFilterValue = "Device",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Ips,
|
||||
SourcePropertyName = "CustomerZone",
|
||||
TargetContentType = ContentTypeName.CustomerZones,
|
||||
TargetPropertyName = "HexCode",
|
||||
DisplayLabel = "Customer Zone",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Ips,
|
||||
SourcePropertyName = "ApplicationZone",
|
||||
TargetContentType = ContentTypeName.ApplicationZones,
|
||||
TargetPropertyName = "HexCode",
|
||||
DisplayLabel = "Application Zone",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Subnets,
|
||||
SourcePropertyName = "CustomerZone",
|
||||
TargetContentType = ContentTypeName.CustomerZones,
|
||||
TargetPropertyName = "HexCode",
|
||||
DisplayLabel = "Customer Zone",
|
||||
});
|
||||
|
||||
Register(new RelationshipRule
|
||||
{
|
||||
SourceContentType = ContentTypeName.Subnets,
|
||||
SourcePropertyName = "ApplicationZone",
|
||||
TargetContentType = ContentTypeName.ApplicationZones,
|
||||
TargetPropertyName = "HexCode",
|
||||
DisplayLabel = "Application Zone",
|
||||
});
|
||||
}
|
||||
|
||||
private void Register(RelationshipRule rule)
|
||||
{
|
||||
_allRules.Add(rule);
|
||||
|
||||
if (!_rulesBySource.ContainsKey(rule.SourceContentType))
|
||||
_rulesBySource[rule.SourceContentType] = new List<RelationshipRule>();
|
||||
|
||||
_rulesBySource[rule.SourceContentType].Add(rule);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<RelationshipRule> GetRulesForContentType(ContentTypeName contentType)
|
||||
{
|
||||
if (_rulesBySource.TryGetValue(contentType, out var rules))
|
||||
return rules.AsReadOnly();
|
||||
|
||||
return Array.Empty<RelationshipRule>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<RelationshipRule> GetAllRules()
|
||||
{
|
||||
return _allRules.AsReadOnly();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user