Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukeybooi committed Jul 25, 2023
2 parents 2980fdc + 885f051 commit 027b3ac
Show file tree
Hide file tree
Showing 17 changed files with 307 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Shesha.EntityReferences
{
public class GenericEntityReference : IGenericEntityReference
public class GenericEntityReference : IEquatable<GenericEntityReference>, IGenericEntityReference
{
private object _entity;

Expand Down Expand Up @@ -55,5 +55,32 @@ private static GenericEntityReference SetEntity<T>(Entity<T> entity)
{
return new GenericEntityReference(entity);
}

public override bool Equals(object obj) => this.Equals(obj as GenericEntityReference);

public bool Equals(GenericEntityReference obj)
{
return Id == obj.Id && _className == obj._className;
}

public static bool operator ==(GenericEntityReference l, GenericEntityReference r)
{
if (l is null)
{
if (r is null)
return true;
// Only the left side is null.
return false;
}
// Equals handles case of null on right side.
return l.Equals(r);
}

public static bool operator !=(GenericEntityReference l, GenericEntityReference r) => !(l == r);

public override int GetHashCode()
{
return Id.IsNullOrEmpty() ? 0 : Id.GetHashCode();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using FluentMigrator;
using Shesha.FluentMigrator;

namespace Shesha.Migrations.PostgreSql
{
[Migration(20230725153499), PostgreSqlOnly]
public class M20230725153499 : OneWayMigration
{
public override void Up()
{
Execute.Sql(
@"CREATE OR REPLACE FUNCTION public.""log_Frwk_UserLoginAttempts_UpdateLastLoginDate_AI""()
RETURNS trigger
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$
BEGIN
IF NEW.""UserId"" IS NOT NULL AND NEW.""ResultLkp"" = 1 THEN
UPDATE ""AbpUsers""
SET ""LastLoginDate"" = NEW.""CreationTime""
WHERE ""Id"" = NEW.""UserId"";
END IF;
RETURN NEW;
END;
$BODY$;");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Shesha.EntityReferences;
using System;
using System.Data.Common;
using System.Data.SqlTypes;

namespace Shesha.NHibernate.UserTypes
{
Expand Down Expand Up @@ -37,8 +38,10 @@ public object Disassemble(object value, ISessionImplementor session)

public new bool Equals(object x, object y)
{
if (x == null && y == null) return true;

if (x is GenericEntityReference erx && y is GenericEntityReference ery)
return erx.Id == ery.Id && erx._className == ery._className;
return erx == ery;
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ public object Disassemble(object value, ISessionImplementor session)

public new bool Equals(object x, object y)
{
if (x == null && y == null) return true;

if (x is GenericEntityReference erx && y is GenericEntityReference ery)
return erx.Id == ery.Id && erx._className == ery._className;
return erx == ery;
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public new bool Equals(object x, object y)
if (x == null && y == null)
return true;

if (x == null || y == null)
if (x == null && y != null || x != null && y == null)
return false;

if (x is IJsonEntityProxy xp && y is IJsonEntityProxy yp)
Expand Down
6 changes: 0 additions & 6 deletions shesha-core/src/Shesha.Web.Core/SheshaWebCoreModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
using Abp.Zero.Configuration;
using Boxfusion.Authorization;
using Castle.MicroKernel.Registration;
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using Shesha.Application;
using Shesha.Authentication.JwtBearer;
using Shesha.Authorization;
using Shesha.Bootstrappers;
Expand All @@ -21,10 +18,7 @@
using Shesha.Languages;
using Shesha.NHibernate;
using Shesha.Scheduler;
using Shesha.Startup;
using Shesha.Validations;
using System;
using System.Reflection;
using System.Text;

namespace Shesha
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Abp.Timing;
using DocumentFormat.OpenXml.Vml.Office;
using Shesha.Domain;
using Shesha.Domain.ConfigurationItems;
using Shesha.DynamicEntities;
using Shesha.EntityReferences;
using Shesha.Extensions;
using Shesha.NHibernate;
using Shesha.NHibernate.Session;
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
Expand All @@ -17,7 +20,7 @@
namespace Shesha.Tests.EntityReferenceTest
{
public class EntityReference_Tests : SheshaNhTestBase
{
{
private readonly IUnitOfWorkManager _unitOfWorkManager;
private readonly IRepository<Person, Guid> _personRepository;
private readonly IRepository<Organisation, Guid> _organisationRepository;
Expand All @@ -40,12 +43,40 @@ public EntityReference_Tests()
_moduleRepo = Resolve<IRepository<Module, Guid>>();
}

[Fact]
public async Task TestGnericEntityReference()
{
LoginAsHostAdmin();

using (var uow = _unitOfWorkManager.Begin())
{
var repo = LocalIocManager.Resolve<IRepository<ShaRoleAppointedPerson, Guid>>();
var items = await repo.GetAllListAsync();

var sessionProvider = LocalIocManager.Resolve<ISessionProvider>();
var session = sessionProvider.Session;

//GenericEntityReference i = null;

foreach (var item in items)
{
//var b = i == item.PermissionedEntity1;
//i = item.PermissionedEntity1;
var entry = session?.GetEntry(item, false);
var dirty = session.GetDirtyProperties(item);
}

await uow.CompleteAsync();
}
}

[Fact]
public async Task CheckUow()
{
LoginAsHostAdmin();

using (var uow = _unitOfWorkManager.Begin(new UnitOfWorkOptions {
using (var uow = _unitOfWorkManager.Begin(new UnitOfWorkOptions
{
IsTransactional = true,
IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
}))
Expand Down Expand Up @@ -75,70 +106,70 @@ public async Task CheckUow()
}
}

/* [Table("Test_EntityRef")]
public class EntityRef : Entity<Guid>
{
public GenericEntityReference AnyEntity { get; set; }
/* [Table("Test_EntityRef")]
public class EntityRef : Entity<Guid>
{
public GenericEntityReference AnyEntity { get; set; }
public GenericEntityReference MyEntity { get; set; }
public GenericEntityReference MyEntity { get; set; }
}
}
[Fact]
public async Task CheckUserType()
{
LoginAsHostAdmin();
[Fact]
public async Task CheckUserType()
{
LoginAsHostAdmin();
using (var uow = _unitOfWorkManager.Begin())
{
EntityRef er = _entityRefRepository.GetAll().FirstOrDefault();
using (var uow = _unitOfWorkManager.Begin())
{
EntityRef er = _entityRefRepository.GetAll().FirstOrDefault();
Entity<Guid> anyEntity = er.AnyEntity;
Entity<Guid> anyEntity = er.AnyEntity;
if (anyEntity is Person person)
{
if (anyEntity is Person person)
{
}
if (anyEntity is Organisation organisation)
{
}
if (anyEntity is Organisation organisation)
{
}
}
var entity = (Person)er.AnyEntity;
var entity = (Person)er.AnyEntity;
if (anyEntity is Person person2)
{
var name = person2.FullName;
}
if (anyEntity is Person person2)
{
var name = person2.FullName;
}
var org = _organisationRepository.GetAll().FirstOrDefault();
var org = _organisationRepository.GetAll().FirstOrDefault();
GenericEntityReference eref = org;
er.AnyEntity = org;
_entityRefRepository.InsertOrUpdate(er);
GenericEntityReference eref = org;
er.AnyEntity = org;
_entityRefRepository.InsertOrUpdate(er);
uow.Complete();
}
}
uow.Complete();
}
}
[Fact]
public async Task CheckMuliProp()
{
LoginAsHostAdmin();
[Fact]
public async Task CheckMuliProp()
{
LoginAsHostAdmin();
using (var uow = _unitOfWorkManager.Begin())
{
EntityRef er = _entityRefRepository.GetAll().FirstOrDefault();
using (var uow = _unitOfWorkManager.Begin())
{
EntityRef er = _entityRefRepository.GetAll().FirstOrDefault();
Entity<Guid> anyEntity = er.AnyEntity;
Entity<Guid> anyEntity = er.AnyEntity;
er.MyEntity = anyEntity;
er.MyEntity = anyEntity;
_entityRefRepository.InsertOrUpdate(er);
_entityRefRepository.InsertOrUpdate(er);
uow.Complete();
}
}
*/
uow.Complete();
}
}
*/
}
}

0 comments on commit 027b3ac

Please sign in to comment.