Skip to content

Commit

Permalink
Suppression de IFieldProperty (et donc alias de compositions)
Browse files Browse the repository at this point in the history
  • Loading branch information
JabX committed Aug 28, 2024
1 parent d2dab38 commit 9e45830
Show file tree
Hide file tree
Showing 65 changed files with 468 additions and 518 deletions.
2 changes: 1 addition & 1 deletion TopModel.Core/EndpointExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class EndpointExtensions
return null;
}

var bodyParams = endpoint.Params.Where(param => param is CompositionProperty || param is IFieldProperty { Domain.BodyParam: true });
var bodyParams = endpoint.Params.Where(param => param is CompositionProperty or { Domain.BodyParam: true });
return bodyParams.Count() > 1
? throw new ModelException(endpoint, $"L'endpoint '{endpoint.Name}' doit avoir une seule propriété dans le body. Propriétés trouvées : {string.Join(", ", bodyParams)}")
: bodyParams.SingleOrDefault();
Expand Down
13 changes: 7 additions & 6 deletions TopModel.Core/Model/AliasProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace TopModel.Core;

public class AliasProperty : IFieldProperty
public class AliasProperty : IProperty
{
private string? _comment;
private string? _defaultValue;
Expand All @@ -13,11 +13,11 @@ public class AliasProperty : IFieldProperty
private string? _name;

#nullable disable
private IFieldProperty _property;
private IProperty _property;
private bool? _readonly;
private bool? _required;

public IFieldProperty Property
public IProperty Property
{
get
{
Expand Down Expand Up @@ -133,9 +133,9 @@ public string? DefaultValue

public string? As { get; set; }

public IFieldProperty? OriginalProperty => _property;
public IProperty? OriginalProperty => _property;

public IFieldProperty? PersistentProperty => (Class?.IsPersistent ?? false)
public IProperty? PersistentProperty => (Class?.IsPersistent ?? false)
? this
: OriginalProperty is AliasProperty op
? op.PersistentProperty
Expand Down Expand Up @@ -165,6 +165,7 @@ public string? DefaultValue

internal AliasProperty? OriginalAliasProperty { get; private set; }

/// <inheritdoc cref="IProperty.CloneWithClassOrEndpoint" />
public IProperty CloneWithClassOrEndpoint(Class? classe = null, Endpoint? endpoint = null)
{
var alp = new AliasProperty
Expand Down Expand Up @@ -211,7 +212,7 @@ public override string ToString()
return Name;
}

internal AliasProperty Clone(IFieldProperty prop, Reference? includeReference)
internal AliasProperty Clone(IProperty prop, Reference? includeReference)
{
var alp = new AliasProperty
{
Expand Down
10 changes: 6 additions & 4 deletions TopModel.Core/Model/AssociationProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace TopModel.Core;

public class AssociationProperty : IFieldProperty
public class AssociationProperty : IProperty
{
private IFieldProperty? _property;
private IProperty? _property;

public LocatedString? Trigram { get; set; }

#nullable disable
public Class Association { get; set; }

public IFieldProperty Property
public IProperty Property
{
get
{
Expand Down Expand Up @@ -152,7 +152,7 @@ public string NameCamel

public Domain Domain => Type.IsToMany() && (Property?.Domain?.AsDomains.TryGetValue(As, out var ld) ?? false) ? ld : Property?.Domain!;

public string[] DomainParameters => Property?.DomainParameters ?? Array.Empty<string>();
public string[] DomainParameters => Property?.DomainParameters ?? [];

public bool PrimaryKey { get; set; }

Expand All @@ -165,7 +165,9 @@ public string NameCamel

internal Reference Location { get; set; }
#nullable enable
#pragma warning disable KTA1600

/// <inheritdoc cref="IProperty.CloneWithClassOrEndpoint" />
public IProperty CloneWithClassOrEndpoint(Class? classe = null, Endpoint? endpoint = null)
{
return new AssociationProperty
Expand Down
18 changes: 9 additions & 9 deletions TopModel.Core/Model/Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,34 @@ public class Class : IPropertyContainer

public bool Abstract { get; set; }

public IFieldProperty? OrderProperty { get; set; }
public IProperty? OrderProperty { get; set; }

public IFieldProperty? DefaultProperty { get; set; }
public IProperty? DefaultProperty { get; set; }

public IFieldProperty? FlagProperty { get; set; }
public IProperty? FlagProperty { get; set; }

public IList<IProperty> Properties { get; } = new List<IProperty>();
public IList<IProperty> Properties { get; } = [];

public IList<IProperty> ExtendedProperties => Extends != null ? Properties.Concat(Extends.ExtendedProperties).ToList() : Properties;

public bool PreservePropertyCasing { get; set; }

public Namespace Namespace { get; set; }

public IEnumerable<IFieldProperty> PrimaryKey => Properties.OfType<IFieldProperty>().Where(p => p.PrimaryKey);
public IEnumerable<IProperty> PrimaryKey => Properties.Where(p => p.PrimaryKey);

public IFieldProperty? ReferenceKey =>
public IProperty? ReferenceKey =>
PrimaryKey.Count() <= 1
? PrimaryKey.SingleOrDefault() ?? Extends?.PrimaryKey.SingleOrDefault() ?? Properties.OfType<IFieldProperty>().FirstOrDefault()
? PrimaryKey.SingleOrDefault() ?? Extends?.PrimaryKey.SingleOrDefault() ?? Properties.FirstOrDefault()
: null;

public IFieldProperty? EnumKey => Enum ? ReferenceKey : null;
public IProperty? EnumKey => Enum ? ReferenceKey : null;

public bool Enum { get; set; }

public List<ClassValue> Values { get; } = [];

public List<List<IFieldProperty>> UniqueKeys { get; } = [];
public List<List<IProperty>> UniqueKeys { get; } = [];

public List<FromMapper> FromMappers { get; } = [];

Expand Down
2 changes: 1 addition & 1 deletion TopModel.Core/Model/ClassMappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ClassMappings
public IEnumerable<IProperty> MissingRequiredProperties => Class.Properties
.Where(p =>
p.Required
&& (p is not IFieldProperty fp || fp.DefaultValue == null)
&& (p is CompositionProperty or AliasProperty { Property: CompositionProperty } || p.DefaultValue == null)
&& !(p.Class.IsPersistent && p.PrimaryKey && p.Class.PrimaryKey.Count() == 1 && p.Domain.AutoGeneratedValue))
.Except(Mappings.Select(m => m.Value));
}
2 changes: 1 addition & 1 deletion TopModel.Core/Model/ClassValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ClassValue

public Reference Reference { get; set; }

public Dictionary<IFieldProperty, string> Value { get; } = new();
public Dictionary<IProperty, string> Value { get; } = new();

public string ResourceKey => $"{Class.Namespace.ModuleCamel}.{Class.NameCamel}.values.{Name}";

Expand Down
10 changes: 6 additions & 4 deletions TopModel.Core/Model/CompositionProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CompositionProperty : IProperty

public Domain Domain { get; set; }

public string[] DomainParameters { get; set; } = Array.Empty<string>();
public string[] DomainParameters { get; set; } = [];

public string Comment { get; set; }

Expand All @@ -36,21 +36,23 @@ public class CompositionProperty : IProperty

public string Label => Name;

public bool IsMultipart => Composition.Properties.Any(cpp => cpp is IFieldProperty fp && fp.Domain.IsMultipart);
public bool IsMultipart => Composition.Properties.Any(cpp => cpp.Domain?.IsMultipart ?? false);

public bool PrimaryKey => false;

public bool Required { get; set; } = true;

#nullable enable

public string DefaultValue => throw new NotImplementedException();

public LocatedString? Trigram { get; set; }

public IFieldProperty? CompositionPrimaryKey
public IProperty? CompositionPrimaryKey
{
get
{
var cpPks = Composition.ExtendedProperties.OfType<IFieldProperty>().Where(p => p.PrimaryKey);
var cpPks = Composition.ExtendedProperties.Where(p => p.PrimaryKey);
if (!cpPks.Any())
{
cpPks = Composition.ExtendedProperties.OfType<AliasProperty>().Where(p => p.AliasedPrimaryKey);
Expand Down
10 changes: 5 additions & 5 deletions TopModel.Core/Model/DataFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public class DataFlow
public DataFlowType Type { get; set; }
#nullable enable

public List<DataFlow> DependsOn { get; set; } = new();
public List<DataFlow> DependsOn { get; set; } = [];

public List<DataFlowReference> DependsOnReference { get; set; } = new();
public List<DataFlowReference> DependsOnReference { get; set; } = [];

public List<FlowHook> Hooks { get; set; } = new();
public List<FlowHook> Hooks { get; set; } = [];

public IFieldProperty? ActiveProperty { get; set; }
public IProperty? ActiveProperty { get; set; }

public Reference? ActivePropertyReference { get; set; }

public List<DataFlowSource> Sources { get; set; } = new();
public List<DataFlowSource> Sources { get; set; } = [];

public override string ToString()
{
Expand Down
4 changes: 2 additions & 2 deletions TopModel.Core/Model/DataFlowSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class DataFlowSource

public DataFlowSourceMode Mode { get; set; }

public List<IFieldProperty> JoinProperties { get; set; } = new();
public List<IProperty> JoinProperties { get; set; } = [];

public List<Reference> JoinPropertyReferences { get; set; } = new();
public List<Reference> JoinPropertyReferences { get; set; } = [];

public bool InnerJoin { get; set; }

Expand Down
22 changes: 0 additions & 22 deletions TopModel.Core/Model/IFieldProperty.cs

This file was deleted.

22 changes: 20 additions & 2 deletions TopModel.Core/Model/IProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public interface IProperty

string Comment { get; }

string? DefaultValue { get; }

bool Readonly { get; set; }

LocatedString? Trigram { get; set; }
Expand All @@ -50,8 +52,8 @@ string SqlName

var apPk = ap switch
{
{ Property: IFieldProperty p } => p,
{ Association: Class classe } => classe.Properties.OfType<IFieldProperty>().FirstOrDefault(),
{ Property: IProperty p } => p,
{ Association: Class classe } => classe.Properties.FirstOrDefault(),
_ => null
};

Expand All @@ -78,6 +80,22 @@ string SqlName
}
}

IProperty ResourceProperty => Decorator != null && Parent != Decorator
? Decorator.Properties.First(p => p.Name == Name).ResourceProperty
: this is AliasProperty alp && alp.Label == alp.OriginalProperty?.Label
? alp.OriginalProperty!.ResourceProperty
: this;

string ResourceKey => $"{ResourceProperty.Parent.Namespace.ModuleCamel}.{ResourceProperty.Parent.NameCamel}.{ResourceProperty.NameCamel}";

IProperty CommentResourceProperty => Decorator != null && Parent != Decorator
? Decorator.Properties.First(p => p.Name == Name).CommentResourceProperty
: this is AliasProperty alp && alp.Comment == alp.OriginalProperty?.Comment
? alp.OriginalProperty!.CommentResourceProperty
: this;

string CommentResourceKey => $"comments.{CommentResourceProperty.Parent.Namespace.ModuleCamel}.{CommentResourceProperty.Parent.NameCamel}.{CommentResourceProperty.NameCamel}";

bool UseLegacyRoleName { get; init; }

IProperty CloneWithClassOrEndpoint(Class? classe = null, Endpoint? endpoint = null);
Expand Down
2 changes: 1 addition & 1 deletion TopModel.Core/Model/MappingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public static string GetNameCamel(this OneOf<ClassMappings, PropertyMapping> map

public static bool GetRequired(this OneOf<ClassMappings, PropertyMapping> mapping)
{
return mapping.Match(c => c.Required, p => p.Property.Required && p.Property is not IFieldProperty { DefaultValue: not null });
return mapping.Match(c => c.Required, p => p.Property.Required && p.Property is CompositionProperty or AliasProperty { Property: CompositionProperty } or { DefaultValue: null });
}
}
6 changes: 4 additions & 2 deletions TopModel.Core/Model/RegularProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace TopModel.Core;

public class RegularProperty : IFieldProperty
public class RegularProperty : IProperty
{
#nullable disable
public string Name { get; set; }
Expand Down Expand Up @@ -31,7 +31,7 @@ public class RegularProperty : IFieldProperty
#nullable disable
public Domain Domain { get; set; }

public string[] DomainParameters { get; set; } = Array.Empty<string>();
public string[] DomainParameters { get; set; } = [];

public string Comment { get; set; }

Expand All @@ -54,7 +54,9 @@ public class RegularProperty : IFieldProperty
#nullable disable
internal Reference Location { get; set; }
#nullable enable
#pragma warning disable KTA1600

/// <inheritdoc cref="IProperty.CloneWithClassOrEndpoint" />
public IProperty CloneWithClassOrEndpoint(Class? classe = null, Endpoint? endpoint = null)
{
return new RegularProperty
Expand Down
Loading

0 comments on commit 9e45830

Please sign in to comment.