Skip to content

Commit

Permalink
Add tenant ID
Browse files Browse the repository at this point in the history
Signed-off-by: Mehran Tahir Rashid <[email protected]>
  • Loading branch information
mehranrashid committed Sep 12, 2023
1 parent 6d2cf96 commit 456bb25
Show file tree
Hide file tree
Showing 21 changed files with 320 additions and 245 deletions.
5 changes: 5 additions & 0 deletions src/Api/BaseApplicationEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public class BaseApplicationEntity : MongoDBEntityBase
/// </summary>
public DateTime? DateTimeUpdated { get; set; }

/// <summary>
/// Gets or set the ID of the tenant used where multiple clients would share the same data
/// </summary>
public Guid? TenantId { get; set; }

public BaseApplicationEntity()
{
SetDefaultValues();
Expand Down
5 changes: 5 additions & 0 deletions src/Api/MonaiApplicationEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public class MonaiApplicationEntity : MongoDBEntityBase
/// </summary>
public DateTime? DateTimeUpdated { get; set; }

/// <summary>
/// Gets or set the ID of the tenant used where multiple clients would share the same data
/// </summary>
public Guid? TenantId { get; set; }

public MonaiApplicationEntity()
{
SetDefaultValues();
Expand Down
123 changes: 70 additions & 53 deletions src/Client/Test/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1817,109 +1817,126 @@
"monai.deploy.informaticsgateway": {
"type": "Project",
"dependencies": {
"DotNext.Threading": "[4.7.4, )",
"HL7-dotnetcore": "[2.36.0, )",
"Karambolo.Extensions.Logging.File": "[3.4.0, )",
"Monai.Deploy.InformaticsGateway.Api": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Common": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Configuration": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Database": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Database.Api": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Database.EntityFramework": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.DicomWeb.Client": "[1.0.0, )",
"Monai.Deploy.Messaging.RabbitMQ": "[1.0.0, )",
"Monai.Deploy.Security": "[0.1.3, )",
"Monai.Deploy.Storage.MinIO": "[0.2.18, )",
"NLog.Web.AspNetCore": "[5.3.3, )",
"Swashbuckle.AspNetCore": "[6.5.0, )"
"DotNext.Threading": "4.7.4",
"HL7-dotnetcore": "2.36.0",
"Karambolo.Extensions.Logging.File": "3.4.0",
"Monai.Deploy.InformaticsGateway.Api": "1.0.0",
"Monai.Deploy.InformaticsGateway.Common": "1.0.0",
"Monai.Deploy.InformaticsGateway.Configuration": "1.0.0",
"Monai.Deploy.InformaticsGateway.Database": "1.0.0",
"Monai.Deploy.InformaticsGateway.Database.Api": "1.0.0",
"Monai.Deploy.InformaticsGateway.Database.EntityFramework": "1.0.0",
"Monai.Deploy.InformaticsGateway.DicomWeb.Client": "1.0.0",
"Monai.Deploy.InformaticsGateway.PlugIns.RemoteAppExecution": "1.0.0",
"Monai.Deploy.Messaging.RabbitMQ": "1.0.0",
"Monai.Deploy.Security": "0.1.3",
"Monai.Deploy.Storage.MinIO": "0.2.18",
"NLog.Web.AspNetCore": "5.3.3",
"Swashbuckle.AspNetCore": "6.5.0"
}
},
"monai.deploy.informaticsgateway.api": {
"type": "Project",
"dependencies": {
"Macross.Json.Extensions": "[3.0.0, )",
"Microsoft.EntityFrameworkCore.Abstractions": "[6.0.21, )",
"Monai.Deploy.InformaticsGateway.Common": "[1.0.0, )",
"Monai.Deploy.Messaging": "[1.0.0, )",
"Monai.Deploy.Storage": "[0.2.18, )",
"fo-dicom": "[5.1.1, )"
"Macross.Json.Extensions": "3.0.0",
"Microsoft.EntityFrameworkCore.Abstractions": "6.0.21",
"Monai.Deploy.InformaticsGateway.Common": "1.0.0",
"Monai.Deploy.Messaging": "1.0.0",
"Monai.Deploy.Storage": "0.2.18",
"fo-dicom": "5.1.1"
}
},
"monai.deploy.informaticsgateway.client": {
"type": "Project",
"dependencies": {
"Monai.Deploy.InformaticsGateway.Api": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Client.Common": "[1.0.0, )"
"Monai.Deploy.InformaticsGateway.Api": "1.0.0",
"Monai.Deploy.InformaticsGateway.Client.Common": "1.0.0"
}
},
"monai.deploy.informaticsgateway.client.common": {
"type": "Project",
"dependencies": {
"Ardalis.GuardClauses": "[4.1.1, )"
"Ardalis.GuardClauses": "4.1.1"
}
},
"monai.deploy.informaticsgateway.common": {
"type": "Project",
"dependencies": {
"Ardalis.GuardClauses": "[4.1.1, )",
"System.IO.Abstractions": "[17.2.3, )"
"Ardalis.GuardClauses": "4.1.1",
"System.IO.Abstractions": "17.2.3"
}
},
"monai.deploy.informaticsgateway.configuration": {
"type": "Project",
"dependencies": {
"Monai.Deploy.InformaticsGateway.Api": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Common": "[1.0.0, )"
"Monai.Deploy.InformaticsGateway.Api": "1.0.0",
"Monai.Deploy.InformaticsGateway.Common": "1.0.0"
}
},
"monai.deploy.informaticsgateway.database": {
"type": "Project",
"dependencies": {
"AspNetCore.HealthChecks.MongoDb": "[6.0.2, )",
"Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore": "[6.0.21, )",
"Microsoft.Extensions.Options.ConfigurationExtensions": "[6.0.0, )",
"Monai.Deploy.InformaticsGateway.Api": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Configuration": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Database.Api": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Database.EntityFramework": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Database.MongoDB": "[1.0.0, )"
"AspNetCore.HealthChecks.MongoDb": "6.0.2",
"Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore": "6.0.21",
"Microsoft.Extensions.Options.ConfigurationExtensions": "6.0.0",
"Monai.Deploy.InformaticsGateway.Api": "1.0.0",
"Monai.Deploy.InformaticsGateway.Configuration": "1.0.0",
"Monai.Deploy.InformaticsGateway.Database.Api": "1.0.0",
"Monai.Deploy.InformaticsGateway.Database.EntityFramework": "1.0.0",
"Monai.Deploy.InformaticsGateway.Database.MongoDB": "1.0.0"
}
},
"monai.deploy.informaticsgateway.database.api": {
"type": "Project",
"dependencies": {
"Monai.Deploy.InformaticsGateway.Api": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Configuration": "[1.0.0, )"
"Monai.Deploy.InformaticsGateway.Api": "1.0.0",
"Monai.Deploy.InformaticsGateway.Configuration": "1.0.0"
}
},
"monai.deploy.informaticsgateway.database.entityframework": {
"type": "Project",
"dependencies": {
"Microsoft.EntityFrameworkCore": "[6.0.21, )",
"Microsoft.EntityFrameworkCore.Sqlite": "[6.0.21, )",
"Microsoft.Extensions.Configuration.FileExtensions": "[6.0.0, )",
"Microsoft.Extensions.Configuration.Json": "[6.0.0, )",
"Monai.Deploy.InformaticsGateway.Api": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Configuration": "[1.0.0, )",
"Monai.Deploy.InformaticsGateway.Database.Api": "[1.0.0, )",
"Polly": "[7.2.4, )"
"Microsoft.EntityFrameworkCore": "6.0.21",
"Microsoft.EntityFrameworkCore.Sqlite": "6.0.21",
"Microsoft.Extensions.Configuration.FileExtensions": "6.0.0",
"Microsoft.Extensions.Configuration.Json": "6.0.0",
"Monai.Deploy.InformaticsGateway.Api": "1.0.0",
"Monai.Deploy.InformaticsGateway.Configuration": "1.0.0",
"Monai.Deploy.InformaticsGateway.Database.Api": "1.0.0",
"Polly": "7.2.4"
}
},
"monai.deploy.informaticsgateway.database.mongodb": {
"type": "Project",
"dependencies": {
"Monai.Deploy.InformaticsGateway.Database.Api": "[1.0.0, )",
"MongoDB.Driver": "[2.21.0, )",
"Polly": "[7.2.4, )"
"Monai.Deploy.InformaticsGateway.Database.Api": "1.0.0",
"MongoDB.Driver": "2.21.0",
"Polly": "7.2.4"
}
},
"monai.deploy.informaticsgateway.dicomweb.client": {
"type": "Project",
"dependencies": {
"Microsoft.AspNet.WebApi.Client": "[5.2.9, )",
"Monai.Deploy.InformaticsGateway.Client.Common": "[1.0.0, )",
"System.Linq.Async": "[6.0.1, )",
"fo-dicom": "[5.1.1, )"
"Microsoft.AspNet.WebApi.Client": "5.2.9",
"Monai.Deploy.InformaticsGateway.Client.Common": "1.0.0",
"System.Linq.Async": "6.0.1",
"fo-dicom": "5.1.1"
}
},
"monai.deploy.informaticsgateway.plugins.remoteappexecution": {
"type": "Project",
"dependencies": {
"Microsoft.EntityFrameworkCore": "6.0.21",
"Microsoft.EntityFrameworkCore.Relational": "6.0.21",
"Microsoft.EntityFrameworkCore.Sqlite": "6.0.21",
"Microsoft.Extensions.Configuration": "6.0.1",
"Microsoft.Extensions.Configuration.FileExtensions": "6.0.0",
"Microsoft.Extensions.Configuration.Json": "6.0.0",
"Monai.Deploy.InformaticsGateway.Api": "1.0.0",
"Monai.Deploy.InformaticsGateway.Configuration": "1.0.0",
"Monai.Deploy.InformaticsGateway.Database.Api": "1.0.0",
"MongoDB.Driver": "2.21.0",
"Polly": "7.2.4"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Monai.Deploy.InformaticsGateway.Database.Api.Repositories
{
public interface IDestinationApplicationEntityRepository
{
Task<List<DestinationApplicationEntity>> ToListAsync(CancellationToken cancellationToken = default);
Task<List<DestinationApplicationEntity>> ToListAsync(Expression<Func<DestinationApplicationEntity, bool>> filter, CancellationToken cancellationToken = default);

Task<DestinationApplicationEntity?> FindByNameAsync(string name, CancellationToken cancellationToken = default);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Monai.Deploy.InformaticsGateway.Database.Api.Repositories
{
public interface IMonaiApplicationEntityRepository
{
Task<List<MonaiApplicationEntity>> ToListAsync(CancellationToken cancellationToken = default);
Task<List<MonaiApplicationEntity>> ToListAsync(Expression<Func<MonaiApplicationEntity, bool>> filter, CancellationToken cancellationToken = default);

Task<MonaiApplicationEntity?> FindByNameAsync(string name, CancellationToken cancellationToken = default);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Monai.Deploy.InformaticsGateway.Database.Api.Repositories
{
public interface ISourceApplicationEntityRepository
{
Task<List<SourceApplicationEntity>> ToListAsync(CancellationToken cancellationToken = default);
Task<List<SourceApplicationEntity>> ToListAsync(Expression<Func<SourceApplicationEntity, bool>> filter, CancellationToken cancellationToken = default);

Task<SourceApplicationEntity?> FindByNameAsync(string name, CancellationToken cancellationToken = default);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void Configure(EntityTypeBuilder<DestinationApplicationEntity> builder)
builder.Property(j => j.UpdatedBy).IsRequired(false);
builder.Property(j => j.DateTimeCreated).IsRequired();
builder.Property(j => j.DateTimeUpdated).IsRequired(false);
builder.Property(j => j.TenantId).IsRequired(false);

builder.HasIndex(p => p.Name, "idx_destination_name").IsUnique();
builder.HasIndex(p => new { p.Name, p.AeTitle, p.HostIp, p.Port }, "idx_source_all").IsUnique();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void Configure(EntityTypeBuilder<MonaiApplicationEntity> builder)
builder.Property(j => j.Grouping).IsRequired();
builder.Property(j => j.CreatedBy).IsRequired(false);
builder.Property(j => j.DateTimeCreated).IsRequired();
builder.Property(j => j.TenantId).IsRequired(false);
builder.Property(j => j.Workflows)
.HasConversion(
v => JsonSerializer.Serialize(v, jsonSerializerSettings),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityType
builder.Property(j => j.UpdatedBy).IsRequired(false);
builder.Property(j => j.DateTimeCreated).IsRequired();
builder.Property(j => j.DateTimeUpdated).IsRequired(false);
builder.Property(j => j.TenantId).IsRequired(false);

builder.HasIndex(p => p.Name, "idx_source_name").IsUnique();
builder.HasIndex(p => new { p.Name, p.AeTitle, p.HostIp }, "idx_source_all").IsUnique();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ public async Task<DestinationApplicationEntity> RemoveAsync(DestinationApplicati
}).ConfigureAwait(false);
}

public async Task<List<DestinationApplicationEntity>> ToListAsync(CancellationToken cancellationToken = default)
public async Task<List<DestinationApplicationEntity>> ToListAsync(
Expression<Func<DestinationApplicationEntity, bool>> filter,
CancellationToken cancellationToken = default)
{
return await _retryPolicy.ExecuteAsync(async () =>
{
return await _dataset.ToListAsync(cancellationToken).ConfigureAwait(false);
}).ConfigureAwait(false);
return await _retryPolicy.ExecuteAsync(async () => await _dataset.Where(filter).ToListAsync(cancellationToken).ConfigureAwait(false)).ConfigureAwait(false);
}

public async Task<DestinationApplicationEntity> UpdateAsync(DestinationApplicationEntity entity, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ public async Task<MonaiApplicationEntity> RemoveAsync(MonaiApplicationEntity ent
}).ConfigureAwait(false);
}

public async Task<List<MonaiApplicationEntity>> ToListAsync(CancellationToken cancellationToken = default)
public async Task<List<MonaiApplicationEntity>> ToListAsync(
Expression<Func<MonaiApplicationEntity, bool>> filter,
CancellationToken cancellationToken = default)
{
return await _retryPolicy.ExecuteAsync(async () =>
{
return await _dataset.ToListAsync(cancellationToken).ConfigureAwait(false);
}).ConfigureAwait(false);
return await _retryPolicy.ExecuteAsync(async () => await _dataset.Where(filter).ToListAsync(cancellationToken).ConfigureAwait(false)).ConfigureAwait(false);
}

public async Task<MonaiApplicationEntity> UpdateAsync(MonaiApplicationEntity entity, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,11 @@ public async Task<SourceApplicationEntity> RemoveAsync(SourceApplicationEntity e
}).ConfigureAwait(false);
}

public async Task<List<SourceApplicationEntity>> ToListAsync(CancellationToken cancellationToken = default)
public async Task<List<SourceApplicationEntity>> ToListAsync(
Expression<Func<SourceApplicationEntity, bool>> filter,
CancellationToken cancellationToken = default)
{
return await _retryPolicy.ExecuteAsync(async () =>
{
return await _dataset.ToListAsync(cancellationToken).ConfigureAwait(false);
}).ConfigureAwait(false);
return await _retryPolicy.ExecuteAsync(async () => await _dataset.Where(filter).ToListAsync(cancellationToken).ConfigureAwait(false)).ConfigureAwait(false);
}

public async Task<SourceApplicationEntity> UpdateAsync(SourceApplicationEntity entity, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ private void CreateIndexes()
_collection.Indexes.CreateOne(new CreateIndexModel<DestinationApplicationEntity>(indexDefinitionAll, options));
}

public async Task<List<DestinationApplicationEntity>> ToListAsync(CancellationToken cancellationToken = default)
public async Task<List<DestinationApplicationEntity>> ToListAsync(
Expression<Func<DestinationApplicationEntity, bool>> filter,
CancellationToken cancellationToken = default)
{
return await _retryPolicy.ExecuteAsync(async () =>
{
return await _collection.Find(Builders<DestinationApplicationEntity>.Filter.Empty).ToListAsync(cancellationToken).ConfigureAwait(false);
}).ConfigureAwait(false);
return await _retryPolicy.ExecuteAsync(async () => await _collection.Find(filter).ToListAsync(cancellationToken).ConfigureAwait(false)).ConfigureAwait(false);
}

public async Task<DestinationApplicationEntity?> FindByNameAsync(string name, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ private void CreateIndexes()
_collection.Indexes.CreateOne(new CreateIndexModel<MonaiApplicationEntity>(indexDefinition, options));
}

public async Task<List<MonaiApplicationEntity>> ToListAsync(CancellationToken cancellationToken = default)
public async Task<List<MonaiApplicationEntity>> ToListAsync(
Expression<Func<MonaiApplicationEntity, bool>> filter,
CancellationToken cancellationToken = default)
{
return await _retryPolicy.ExecuteAsync(async () =>
{
return await _collection.Find(Builders<MonaiApplicationEntity>.Filter.Empty).ToListAsync(cancellationToken).ConfigureAwait(false);
}).ConfigureAwait(false);
return await _retryPolicy.ExecuteAsync(async () => await _collection.Find(filter).ToListAsync(cancellationToken).ConfigureAwait(false)).ConfigureAwait(false);
}

public async Task<MonaiApplicationEntity?> FindByNameAsync(string name, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ private void CreateIndexes()
_collection.Indexes.CreateOne(new CreateIndexModel<SourceApplicationEntity>(indexDefinitionAll, options));
}

public async Task<List<SourceApplicationEntity>> ToListAsync(CancellationToken cancellationToken = default)
public async Task<List<SourceApplicationEntity>> ToListAsync(
Expression<Func<SourceApplicationEntity, bool>> filter,
CancellationToken cancellationToken = default)
{
return await _retryPolicy.ExecuteAsync(async () =>
{
return await _collection.Find(Builders<SourceApplicationEntity>.Filter.Empty).ToListAsync(cancellationToken).ConfigureAwait(false);
}).ConfigureAwait(false);
return await _retryPolicy.ExecuteAsync(async () => await _collection.Find(filter).ToListAsync(cancellationToken).ConfigureAwait(false)).ConfigureAwait(false);
}

public async Task<SourceApplicationEntity?> FindByNameAsync(string name, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ public DestinationAeTitleController(
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<IEnumerable<DestinationApplicationEntity>>> Get()
public async Task<ActionResult<IEnumerable<DestinationApplicationEntity>>> Get([FromQuery] Guid? tenantId = null)
{
try
{
return Ok(await _repository.ToListAsync(HttpContext.RequestAborted).ConfigureAwait(false));
if (tenantId is not null)
{
return Ok(await _repository.ToListAsync(d => d.TenantId == tenantId, HttpContext.RequestAborted).ConfigureAwait(false));
}

return Ok(await _repository.ToListAsync(d => true, HttpContext.RequestAborted).ConfigureAwait(false));
}
catch (Exception ex)
{
Expand Down
Loading

0 comments on commit 456bb25

Please sign in to comment.