Skip to content

Commit

Permalink
fluent mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
VTsyk committed Dec 17, 2024
1 parent 72d9414 commit 170ce32
Show file tree
Hide file tree
Showing 48 changed files with 514 additions and 404 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Framework.Core;
using Framework.DomainDriven.Serialization;
using Framework.Persistent;
using Framework.Persistent.Mapping;
using Framework.Restriction;

namespace Framework.Authorization.Domain;
Expand All @@ -9,6 +10,7 @@ namespace Framework.Authorization.Domain;
/// Набор секьюрных операций, который выдается принципалу вместе с контекcтом их применения
/// </summary>
[UniqueGroup]
[IgnoreHbmMapping]
public class BusinessRole : BaseDirectory
{
private readonly ICollection<Permission> permissions = new List<Permission>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Framework.Authorization.Domain;
/// Пермиссии могут выдаваться в рамках контекстов
/// </remarks>
/// <seealso cref="SecurityContextType"/>
[IgnoreHbmMapping]
[System.Diagnostics.DebuggerDisplay("Principal={Principal.Name}, Role={Role.Name}")]
public class Permission : AuditPersistentDomainObjectBase,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using Framework.DomainDriven.Serialization;
using Framework.DomainDriven.Tracking.LegacyValidators;
using Framework.Persistent;
using Framework.Persistent.Mapping;
using Framework.Restriction;

namespace Framework.Authorization.Domain;

/// <summary>
/// Связь между пермиссией и контекстом
/// </summary>
[IgnoreHbmMapping]
public class PermissionRestriction : AuditPersistentDomainObjectBase, IDetail<Permission>
{
private readonly Permission permission;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics;

using Framework.Persistent;
using Framework.Persistent.Mapping;
using Framework.Restriction;

namespace Framework.Authorization.Domain;
Expand All @@ -10,6 +11,7 @@ namespace Framework.Authorization.Domain;
/// </summary>
[DebuggerDisplay("{Name}, RunAs={RunAs}")]
[UniqueGroup]
[IgnoreHbmMapping]
public class Principal : BaseDirectory, IMaster<Permission>
{
private readonly ICollection<Permission> permissions = new List<Permission>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Framework.DomainDriven.Serialization;
using Framework.Persistent.Mapping;

namespace Framework.Authorization.Domain;

Expand All @@ -11,6 +12,7 @@ namespace Framework.Authorization.Domain;
/// <seealso cref="PermissionRestriction"/>
/// Типы, в контексте которых выдаются права пользователю, записываются вручную на уровне SQL в базу конкретной системы
/// </remarks>
[IgnoreHbmMapping]
public class SecurityContextType : BaseDirectory
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
<Compile Include="..\..\__SolutionItems\CommonAssemblyInfo.cs" Link="Properties\CommonAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Mapping\Generated.Framework.Authorization.Domain.hbm.xml" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Framework.Authorization.Domain\Framework.Authorization.Domain.csproj" />
<ProjectReference Include="..\..\_DomainDriven\Framework.DomainDriven.NHibernate\Framework.DomainDriven.NHibernate.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using FluentNHibernate.Mapping;

using Framework.Authorization.Domain;

namespace Framework.Authorization.Generated.DAL.NHibernate.Mapping.Base;

public abstract class AuthBaseMap<TEntity> : ClassMap<TEntity>
where TEntity : AuditPersistentDomainObjectBase
{
protected AuthBaseMap()
{
this.Schema("auth");

this.DynamicUpdate();

this.Id(x => x.Id).GeneratedBy.GuidComb();

this.Map(x => x.CreatedBy);
this.Map(x => x.CreateDate);
this.Map(x => x.ModifiedBy);
this.Map(x => x.ModifyDate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Framework.Authorization.Domain;
using Framework.Authorization.Generated.DAL.NHibernate.Mapping.Base;

namespace Framework.Authorization.Generated.DAL.NHibernate.Mapping;

public class BusinessRoleMap : AuthBaseMap<BusinessRole>
{
public BusinessRoleMap()
{
this.Map(x => x.Name).Unique().Not.Nullable();
this.Map(x => x.Description);
this.HasMany(x => x.Permissions).AsSet().Inverse().Cascade.None();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Framework.Authorization.Domain;
using Framework.Authorization.Generated.DAL.NHibernate.Mapping.Base;

namespace Framework.Authorization.Generated.DAL.NHibernate.Mapping;

public class PermissionMap : AuthBaseMap<Permission>
{
public PermissionMap()
{
this.Map(x => x.Comment).Length(int.MaxValue);
this.References(x => x.DelegatedFrom).Column($"{nameof(Permission.DelegatedFrom)}Id");
this.References(x => x.Principal).Column($"{nameof(Permission.Principal)}Id").Not.Nullable();
this.References(x => x.Role).Column($"{nameof(Permission.Role)}Id").Not.Nullable();
this.Component(
x => x.Period,
part =>
{
part.Map(x => x.EndDate).Column("periodendDate");
part.Map(x => x.StartDate).Column("periodstartDate");
});

this.HasMany(x => x.DelegatedTo).AsSet().Inverse().Cascade.AllDeleteOrphan();
this.HasMany(x => x.Restrictions).AsSet().Inverse().Cascade.AllDeleteOrphan();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Framework.Authorization.Domain;
using Framework.Authorization.Generated.DAL.NHibernate.Mapping.Base;

namespace Framework.Authorization.Generated.DAL.NHibernate.Mapping;

public class PermissionRestrictionMap : AuthBaseMap<PermissionRestriction>
{
public PermissionRestrictionMap()
{
this.Map(x => x.SecurityContextId).Not.Nullable()
.UniqueKey("UIX_permission_securityContextId_securityContextTypePermissionRestriction");
this.References(x => x.Permission).Column($"{nameof(PermissionRestriction.Permission)}Id").Not.Nullable()
.UniqueKey("UIX_permission_securityContextId_securityContextTypePermissionRestriction");
this.References(x => x.SecurityContextType).Column($"{nameof(PermissionRestriction.SecurityContextType)}Id").Not.Nullable()
.UniqueKey("UIX_permission_securityContextId_securityContextTypePermissionRestriction");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Framework.Authorization.Domain;
using Framework.Authorization.Generated.DAL.NHibernate.Mapping.Base;

namespace Framework.Authorization.Generated.DAL.NHibernate.Mapping;

public class PrincipalMap : AuthBaseMap<Principal>
{
public PrincipalMap()
{
this.Map(x => x.Name).Not.Nullable().UniqueKey("UIX_namePrincipal");
this.References(x => x.RunAs).Column($"{nameof(Principal.RunAs)}Id");
this.HasMany(x => x.Permissions).AsSet().Inverse().Cascade.AllDeleteOrphan();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Framework.Authorization.Domain;
using Framework.Authorization.Generated.DAL.NHibernate.Mapping.Base;

namespace Framework.Authorization.Generated.DAL.NHibernate.Mapping;

public class SecurityContextTypeMap : AuthBaseMap<SecurityContextType>
{
public SecurityContextTypeMap() => this.Map(x => x.Name).Not.Nullable();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Framework.DomainDriven;
using Framework.DomainDriven.DBGenerator;
using Framework.DomainDriven.NHibernate;

namespace Framework.Authorization.TestGenerate;

Expand Down Expand Up @@ -50,4 +51,28 @@ public string GenerateDB(
var lines = result.ToNewLinesCombined();
return lines;
}

public string GenerateDB(
MappingSettings mappingSettings,
string serverName,
DatabaseScriptGeneratorMode generatorMode = DatabaseScriptGeneratorMode.AutoGenerateUpdateChangeTypeScript,
DBGenerateScriptMode mode = DBGenerateScriptMode.AppliedOnTargetDatabase,
IEnumerable<string> migrationScriptFolderPaths = null,
IEnumerable<string> auditMigrationScriptFolderPaths = null,
bool preserveSchemaDatabase = false,
DbUserCredential credentials = null)
{
var generator = new DBGenerator(mappingSettings);
var result = generator.Generate(
serverName,
mode: mode,
generatorMode: generatorMode,
migrationScriptFolderPaths: migrationScriptFolderPaths,
auditMigrationScriptFolderPaths: auditMigrationScriptFolderPaths,
preserveSchemaDatabase: preserveSchemaDatabase,
credentials: credentials);

var lines = result.ToNewLinesCombined();
return lines;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Framework.Configuration.Domain;
/// <seealso cref="DomainObjectBase" />
[UniqueGroup]
[NotAuditedClass]
[IgnoreHbmMapping]
public class CodeFirstSubscription : AuditPersistentDomainObjectBase, ICodeObject<string>
{
private readonly string code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Framework.Configuration.Domain;

[NotAuditedClass]
[IgnoreHbmMapping]
public class ControlSettings : BaseDirectory,
IMaster<ControlSettings>,
IMaster<ControlSettingsParam>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Framework.Configuration.Domain;

[NotAuditedClass]
[IgnoreHbmMapping]
public class ControlSettingsParam : AuditPersistentDomainObjectBase, IMaster<ControlSettingsParamValue>, IDetail<ControlSettings>, ITypeObject<ControlSettingParamType>
{
private readonly ICollection<ControlSettingsParamValue> controlSettingsParamValues = new List<ControlSettingsParamValue>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Framework.Configuration.Domain;

[NotAuditedClass]
[IgnoreHbmMapping]
public class ControlSettingsParamValue : AuditPersistentDomainObjectBase, IDetail<ControlSettingsParam>
{
private readonly ControlSettingsParam controlSettingsParam;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Framework.Configuration.Domain;
/// Событие над объектом (Save, Remove etc), сохраняемое в базу.
/// </summary>
[NotAuditedClass]
[IgnoreHbmMapping]
public class DomainObjectEvent : AuditPersistentDomainObjectBase
{
private readonly QueueProgressStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Framework.Configuration.Domain;
/// </summary>
[UniqueGroup]
[NotAuditedClass]
[IgnoreHbmMapping]
public class DomainObjectModification : AuditPersistentDomainObjectBase, ITypeObject<ModificationType>, IVersionObject<long>
{
private Guid domainObjectId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Framework.Configuration.Domain;
/// Нотификация хранимая в бд
/// </summary>
[NotAuditedClass]
[IgnoreHbmMapping]
public class DomainObjectNotification : AuditPersistentDomainObjectBase
{
private readonly QueueProgressStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Framework.Configuration.Domain;
/// Механизм Framework-а сохраняет все ошибки по всем системам, записывает их в базу и высылает на почту
/// </remarks>
[NotAuditedClass]
[IgnoreHbmMapping]
public class ExceptionMessage : AuditPersistentDomainObjectBase
{
private ExceptionMessage innerException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ namespace Framework.Configuration.Domain;
/// </summary>
[UniqueGroup]
[NotAuditedClass]
[IgnoreHbmMapping]
public class GenericNamedLock : BaseDirectory;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Framework.Configuration.Domain;
/// Сообщение, отправленное пользователю
/// </summary>
[NotAuditedClass]
[IgnoreHbmMapping]
public class SentMessage : AuditPersistentDomainObjectBase
{
private readonly string from;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Framework.Configuration.Domain;
/// </summary>
[UniqueGroup]
[NotAuditedClass]
[IgnoreHbmMapping]
public class Sequence : BaseDirectory, INumberObject<long>
{
private long number;
Expand Down
Loading

0 comments on commit 170ce32

Please sign in to comment.