Skip to content

Commit

Permalink
Fix compiler warnings related to nullability in Synchronization module (
Browse files Browse the repository at this point in the history
#497)

* refactor: make property required as it makes no sense to be null

* refactor: make properties required as the values are always passed through via json object

* refactor: update input parameter to match the base method and supress nullability warning with '!'

* fix: remove required keywords as it seems to break the tests

* refactor: make properties nullable

* refactor: make property nullable

* Helm Chart: Update Consumer API, Admin UI and Admin CLI (#501)

* feat: update adminui

* feat: update consumerapi

* Helm Chart: Update Consumer API, Admin UI and Admin CLI (#501)

* feat: update adminui

* feat: update consumerapi

* refactor: modify CompareTo so that it complies with standard

* refactor: make properties required instead of nullable

* ci: trigger pipelines

* chore: add nullable enable property group

* chore: add nullable enable property group for tests

* refactor: make Id required

* refactor: make Id required

* refactor: suppress possible null reference warning

* refactor: make RootFolder required

* refactor: make nullable

* refactor: make SyncRunId nullable

* refactor: remove redundant null expression

* refactor: remove ? since setupOptions is never null

* chore: fix comment typo

* chore: fix typo in test name

* refactor: make SyncRun nullable

* refactor: mappingHints is never null

* refactor: remove null check since id is not null

* refactor: make ConverterMappingHints nullable

* refactor: make Modifications nad Id required

* refactor: make SyncRun required

* refactor: make properties required

* refactor: declare as nullable

* refactor: expression is always false

* refactor: make BlobStorageOptions nullable

* refactor: null suppression

* refactor: remove null check

* refactor: make properties required

* refactor: fix multiple nullability issues

* refactor: remove _payload null check

* refactor: assign null! to DbContext properties

* refactor: add throw new ArgumentNullException

* refactor: make properties required

* refactor: make ErrorCode nullable

* refactor: make nullable

* refactor: make nullable type

* refactor: remove null conditionall operator

* chore: suppress nullability warning as null is never returned

* refactor: update interface return type

* refactor: suppress null warnings as the object is instantiated as empty but the properties are then immediately set

* refactor: make properties required to match SyncRun class

* refactor: make fields nullable

* refactor: suppress nullability warnings as fields are never null (they are marked as nullable since they are filled outside of ctor)
refactor: remove null check in case of events as it is never null

* refactor: remove null check in case of events as it is never null

* refactor: make fields nullable

* refactor: suppress nullability warnings (field is effectively never null though it is null after leaving ctor)

* refactor: suppress warning with a comment as no other solution is offered

* refactor: make property required

* refactor: make properties required

* refactor: make properties nullable

* refactor: make fields nullable and suppress nullability warnings

* refactor: remove conditional access and unreachable code

* chore: initialize properties with null! instead of using null suppression on usage

* chore: initialize properties with null! in ef core constructors

* fix: make EncryptedPayload and PayloadCategory optional

* test: fix compiler error

* chore: add words to resharper dicitionary

* chore: cleanup code

* chore: make properties of ExternalEventResult required

* chore: fix nullability warnings

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Timo Notheisen <65653426+tnotheis@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Hunor Tot-Bagi <hunortotbagi@gmail.com>
Co-authored-by: Timo Notheisen <timo.notheisen@js-soft.com>
  • Loading branch information
6 people authored Feb 20, 2024
1 parent e616965 commit 60b66b3
Show file tree
Hide file tree
Showing 59 changed files with 306 additions and 238 deletions.
5 changes: 4 additions & 1 deletion Backbone.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=jwts/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mediat/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Onboarded/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=parallelly/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Postgre/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unexhausted/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unonboarded/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unonboarded/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unproxied/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unsynced/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,5 @@ public static void AddAzureServiceBus(this IServiceCollection services, Action<S

public class ServiceBusOptions : BasicBusOptions
{
#pragma warning disable CS8618
public string ConnectionString { get; set; }
#pragma warning restore CS8618
public string ConnectionString { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
namespace Backbone.BuildingBlocks.Infrastructure.EventBus;
public class BasicBusOptions
{
#pragma warning disable CS8618
public string SubscriptionClientName { get; set; }
public HandlerRetryBehavior HandlerRetryBehavior { get; set; }
#pragma warning restore CS8618
public string SubscriptionClientName { get; set; } = null!;
public HandlerRetryBehavior HandlerRetryBehavior { get; set; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public static void AddGoogleCloudPubSub(this IServiceCollection services, Action

public class GoogleCloudPubSubOptions : BasicBusOptions
{
#pragma warning disable CS8618
public string ProjectId { get; set; }
public string TopicName { get; set; }
public string ConnectionInfo { get; set; }
#pragma warning restore CS8618
public string ProjectId { get; set; } = null!;
public string TopicName { get; set; } = null!;
public string ConnectionInfo { get; set; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ public static void AddRabbitMq(this IServiceCollection services, Action<RabbitMq

public class RabbitMqOptions : BasicBusOptions
{
#pragma warning disable CS8618
public string HostName { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string HostName { get; set; } = null!;
public string Username { get; set; } = null!;
public string Password { get; set; } = null!;
public int ConnectionRetryCount { get; set; } = 5;
#pragma warning restore CS8618
}
2 changes: 1 addition & 1 deletion ConsumerApi/SynchronizationDbContextSeeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SynchronizationDbContextSeeder : IDbSeeder<SynchronizationDbContext
public SynchronizationDbContextSeeder(IServiceProvider serviceProvider, ILogger<SynchronizationDbContextSeeder> logger)
{
_blobStorage = serviceProvider.GetService<IBlobStorage>();
_blobRootFolder = serviceProvider.GetService<IOptions<BlobOptions>>()!.Value.RootFolder;
_blobRootFolder = serviceProvider.GetService<IOptions<BlobOptions>>()?.Value.RootFolder;
_logger = logger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public class IdentityDeletionProcess
{
private readonly List<IdentityDeletionProcessAuditLogEntry> _auditLog;

// EF Core needs the empty constructor
#pragma warning disable CS8618
// ReSharper disable once UnusedMember.Local
private IdentityDeletionProcess()
#pragma warning restore CS8618
{
// This constructor is for EF Core only; initializing the properties with null is therefore not a problem
_auditLog = null!;
Id = null!;
}

public static IdentityDeletionProcess StartAsSupport(IdentityAddress createdBy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ public static IdentityDeletionProcessAuditLogEntry GracePeriodReminder3Sent(Iden
return new IdentityDeletionProcessAuditLogEntry(processId, "The third grace period reminder notification has been sent.", Hasher.HashUtf8(identityAddress.StringValue), null, DeletionProcessStatus.Approved, DeletionProcessStatus.Approved);
}

// EF Core needs the empty constructor
#pragma warning disable CS8618
// ReSharper disable once UnusedMember.Local
private IdentityDeletionProcessAuditLogEntry()
#pragma warning restore CS8618
{
// This constructor is for EF Core only; initializing the properties with null is therefore not a problem
Id = null!;
ProcessId = null!;
Message = null!;
IdentityAddressHash = null!;
}

private IdentityDeletionProcessAuditLogEntry(IdentityDeletionProcessId processId, string message, byte[] identityAddressHash, byte[]? deviceIdHash, DeletionProcessStatus? oldStatus, DeletionProcessStatus newStatus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ namespace Backbone.Modules.Relationships.Domain.Entities;

public class RelationshipChange
{
#pragma warning disable CS8618
protected RelationshipChange() { }
#pragma warning restore CS8618
// ReSharper disable once UnusedMember.Local
protected RelationshipChange()
{
// This constructor is for EF Core only; initializing the properties with null is therefore not a problem
Id = null!;
RelationshipId = null!;
Relationship = null!;
Request = null!;
}

protected RelationshipChange(Relationship relationship, IdentityAddress createdBy, DeviceId createdByDevice, RelationshipChangeType type, byte[]? requestContent)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static ApplicationError CannotReadExternalEventsOfSyncRunStartedByAnother
return new ApplicationError("error.platform.validation.syncRun.cannotReadExternalEventsOfASyncRunStartedByAnotherDevice", "This sync was started by another device. Only that device can read the corresponding external events.");
}

public static ApplicationError CannotStartSyncRunWhenAnotherSyncRunIsRunning(SyncRunId idOfRunningSyncRun = null)
public static ApplicationError CannotStartSyncRunWhenAnotherSyncRunIsRunning(SyncRunId? idOfRunningSyncRun = null)
{
var idString = idOfRunningSyncRun == null ? "" : $" (ID: {idOfRunningSyncRun})";
return new ApplicationError("error.platform.validation.syncRun.cannotStartSyncRunWhenAnotherSyncRunIsRunning", $"Another sync run is currently active{idString}. There can only be one active sync run at a time. Try again in a few seconds.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public class Handler : IRequestHandler<PushDatawalletModificationsCommand, PushD
private readonly IEventBus _eventBus;
private readonly IMapper _mapper;

private PushDatawalletModificationsCommand _request;
private PushDatawalletModificationsCommand _request = null!;
private CancellationToken _cancellationToken;
private DatawalletVersion _supportedDatawalletVersion;
private Datawallet _datawallet;
private DatawalletModification[] _modifications;
private PushDatawalletModificationsResponse _response;
private DatawalletVersion _supportedDatawalletVersion = null!;
private Datawallet? _datawallet;
private DatawalletModification[] _modifications = null!;
private PushDatawalletModificationsResponse _response = null!;

public Handler(ISynchronizationDbContext dbContext, IUserContext userContext, IMapper mapper, IEventBus eventBus)
{
Expand Down Expand Up @@ -77,7 +77,7 @@ private async Task EnsureNoActiveSyncRunExists(CancellationToken cancellationTok

private void EnsureSufficientSupportedDatawalletVersion()
{
if (_supportedDatawalletVersion < _datawallet.Version)
if (_supportedDatawalletVersion < _datawallet!.Version)
throw new OperationFailedException(ApplicationErrors.Datawallet.InsufficientSupportedDatawalletVersion());
}

Expand All @@ -87,18 +87,18 @@ private async Task CreateModifications()

var newModifications = _request.Modifications.Select(m => CreateModification(m, blobName));

_dbContext.Set<Datawallet>().Update(_datawallet);
_dbContext.Set<Datawallet>().Update(_datawallet!);

var modificationsArray = newModifications.ToArray();

await Save(modificationsArray, blobName);
await Save(modificationsArray);

_modifications = modificationsArray;
}

private DatawalletModification CreateModification(PushDatawalletModificationItem modificationDto, string blobReference)
{
return _datawallet.AddModification(
return _datawallet!.AddModification(
_mapper.Map<DatawalletModificationType>(modificationDto.Type),
new DatawalletVersion(modificationDto.DatawalletVersion),
modificationDto.Collection,
Expand All @@ -112,7 +112,7 @@ private DatawalletModification CreateModification(PushDatawalletModificationItem

private void EnsureDeviceIsUpToDate()
{
if (_datawallet.LatestModification != null && _datawallet.LatestModification.Index != _request.LocalIndex)
if (_datawallet!.LatestModification != null && _datawallet.LatestModification.Index != _request.LocalIndex)
throw new OperationFailedException(ApplicationErrors.Datawallet.DatawalletNotUpToDate(_request.LocalIndex, _datawallet.LatestModification.Index));
}

Expand All @@ -122,9 +122,9 @@ private void BuildResponse()
_response = new PushDatawalletModificationsResponse { Modifications = responseItems, NewIndex = responseItems.Max(i => i.Index) };
}

private async Task Save(DatawalletModification[] modifications, string blobName)
private async Task Save(DatawalletModification[] modifications)
{
await _dbContext.Set<DatawalletModification>().AddRangeAsync(modifications, _cancellationToken);
await _dbContext.Set<DatawalletModification>().AddRangeAsync(modifications);

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace Backbone.Modules.Synchronization.Application.Datawallets.Commands.Push

public class PushDatawalletModificationsResponse
{
public long NewIndex { get; set; }
public required long NewIndex { get; set; }

public IEnumerable<PushDatawalletModificationsResponseItem> Modifications { get; set; }
public required IEnumerable<PushDatawalletModificationsResponseItem> Modifications { get; set; }
}

public class PushDatawalletModificationsResponseItem : IMapTo<DatawalletModification>
{
public DatawalletModificationId Id { get; set; }
public long Index { get; set; }
public DateTime CreatedAt { get; set; }
public required DatawalletModificationId Id { get; set; }
public required long Index { get; set; }
public required DateTime CreatedAt { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Backbone.Modules.Synchronization.Application.Datawallets.DTOs;

public class CreatedDatawalletModificationDTO : IMapTo<DatawalletModification>
{
public string Id { get; set; }
public long Index { get; set; }
public DateTime CreatedAt { get; set; }
public required string Id { get; set; }
public required long Index { get; set; }
public required DateTime CreatedAt { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public enum DatawalletModificationType
CacheChanged
}

public DatawalletModificationId Id { get; set; }
public ushort DatawalletVersion { get; set; }
public long Index { get; set; }
public string ObjectIdentifier { get; set; }
public string PayloadCategory { get; set; }
public DateTime CreatedAt { get; set; }
public DeviceId CreatedByDevice { get; set; }
public string Collection { get; set; }
public string Type { get; set; }
public byte[] EncryptedPayload { get; set; }
public required DatawalletModificationId Id { get; set; }
public required ushort DatawalletVersion { get; set; }
public required long Index { get; set; }
public required string ObjectIdentifier { get; set; }
public string? PayloadCategory { get; set; }
public required DateTime CreatedAt { get; set; }
public required DeviceId CreatedByDevice { get; set; }
public required string Collection { get; set; }
public required string Type { get; set; }
public byte[]? EncryptedPayload { get; set; }


public void CreateMappings(Profile configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace Backbone.Modules.Synchronization.Application.Datawallets.DTOs;

public class PushDatawalletModificationItem
{
public string ObjectIdentifier { get; set; }
public string PayloadCategory { get; set; }
public string Collection { get; set; }
public DatawalletModificationDTO.DatawalletModificationType Type { get; set; }
public byte[] EncryptedPayload { get; set; }
public ushort DatawalletVersion { get; set; }
public required DatawalletModificationDTO.DatawalletModificationType Type { get; set; }
public required string ObjectIdentifier { get; set; }
public required string Collection { get; set; }
public string? PayloadCategory { get; set; }
public byte[]? EncryptedPayload { get; set; }
public required ushort DatawalletVersion { get; set; }
}

public class PushDatawalletModificationItemValidator : AbstractValidator<PushDatawalletModificationItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

namespace Backbone.Modules.Synchronization.Application.Datawallets.Queries.GetDatawallet;

public class GetDatawalletQuery : IRequest<DatawalletDTO> { }
public class GetDatawalletQuery : IRequest<DatawalletDTO>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Backbone.Modules.Synchronization.Application.Extensions;

public static class DatawalletQueryableExtensions
{
public static async Task<Datawallet> OfOwner(this IQueryable<Datawallet> query, IdentityAddress owner, CancellationToken cancellationToken)
public static async Task<Datawallet?> OfOwner(this IQueryable<Datawallet> query, IdentityAddress owner, CancellationToken cancellationToken)
{
return await query.FirstOrDefaultAsync(e => e.Owner == owner, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public static IEventBus AddSynchronizationIntegrationEventSubscriptions(this IEv
{
SubscribeToMessagesEvents(eventBus);
SubscribeToRelationshipsEvents(eventBus);
SubscribeToIdentitiesEvents(eventBus);

return eventBus;
}
Expand All @@ -21,16 +20,12 @@ private static void SubscribeToMessagesEvents(IEventBus eventBus)
{
eventBus.Subscribe<MessageCreatedIntegrationEvent, MessageCreatedIntegrationEventHandler>();
eventBus.Subscribe<IdentityDeletionProcessStartedIntegrationEvent, IdentityDeletionProcessStartedIntegrationEventHandler>();
// eventBus.Subscribe<MessageDeliveredIntegrationEvent, MessageDeliveredIntegrationEventHandler>(); // this is temporaryly disabled to avoid an external event flood when the same message is sent to many recipients (s. JSSNMSHDD-2174)
// eventBus.Subscribe<MessageDeliveredIntegrationEvent, MessageDeliveredIntegrationEventHandler>(); // this is temporarily disabled to avoid an external event flood when the same message is sent to many recipients
}

private static void SubscribeToRelationshipsEvents(IEventBus eventBus)
{
eventBus.Subscribe<RelationshipChangeCompletedIntegrationEvent, RelationshipChangeCompletedIntegrationEventHandler>();
eventBus.Subscribe<RelationshipChangeCreatedIntegrationEvent, RelationshipChangeCreatedIntegrationEventHandler>();
}

private static void SubscribeToIdentitiesEvents(IEventBus eventBus)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public class BlobOptions
{
public string RootFolder { get; set; }
public string? RootFolder { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ public interface ISynchronizationDbContext : IDbContext
Task<DbPaginationResult<DatawalletModification>> GetDatawalletModifications(IdentityAddress activeIdentity,
long? localIndex, PaginationFilter paginationFilter, CancellationToken cancellationToken);

Task<Datawallet> GetDatawalletForInsertion(IdentityAddress owner, CancellationToken cancellationToken);
Task<Datawallet> GetDatawallet(IdentityAddress owner, CancellationToken cancellationToken);
Task<long> GetNextExternalEventIndexForIdentity(IdentityAddress identity);
Task<Datawallet?> GetDatawalletForInsertion(IdentityAddress owner, CancellationToken cancellationToken);
Task<Datawallet?> GetDatawallet(IdentityAddress owner, CancellationToken cancellationToken);
Task<ExternalEvent> CreateExternalEvent(IdentityAddress owner, ExternalEventType type, object payload);
Task<SyncRun> GetSyncRun(SyncRunId syncRunId, IdentityAddress createdBy, CancellationToken cancellationToken);
Task<bool> IsActiveSyncRunAvailable(IdentityAddress createdBy, CancellationToken cancellationToken);
Expand All @@ -24,7 +23,7 @@ Task<SyncRun> GetSyncRunAsNoTracking(SyncRunId syncRunId, IdentityAddress create
Task<SyncRun> GetSyncRunWithExternalEvents(SyncRunId syncRunId, IdentityAddress createdBy,
CancellationToken cancellationToken);

Task<SyncRun> GetPreviousSyncRunWithExternalEvents(IdentityAddress createdBy, CancellationToken cancellationToken);
Task<SyncRun?> GetPreviousSyncRunWithExternalEvents(IdentityAddress createdBy, CancellationToken cancellationToken);

Task<List<ExternalEvent>> GetUnsyncedExternalEvents(IdentityAddress owner, byte maxErrorCount,
CancellationToken cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Backbone.Modules.Synchronization.Application.IntegrationEvents.Incomin

public class MessageCreatedIntegrationEvent : IntegrationEvent
{
public string Id { get; private set; }
public IEnumerable<string> Recipients { get; private set; }
public required string Id { get; set; }
public required IEnumerable<string> Recipients { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace Backbone.Modules.Synchronization.Application.IntegrationEvents.Incomin

public class RelationshipChangeCompletedIntegrationEvent : IntegrationEvent
{
public string ChangeId { get; set; }
public string RelationshipId { get; set; }
public string ChangeCreatedBy { get; set; }
public string ChangeRecipient { get; set; }
public string ChangeResult { get; set; }
public required string ChangeId { get; set; }
public required string RelationshipId { get; set; }
public required string ChangeCreatedBy { get; set; }
public required string ChangeRecipient { get; set; }
public required string ChangeResult { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace Backbone.Modules.Synchronization.Application.IntegrationEvents.Incomin

public class RelationshipChangeCreatedIntegrationEvent : IntegrationEvent
{
public string ChangeId { get; set; }
public string RelationshipId { get; set; }
public string ChangeCreatedBy { get; set; }
public string ChangeRecipient { get; set; }
public required string ChangeId { get; set; }
public required string RelationshipId { get; set; }
public required string ChangeCreatedBy { get; set; }
public required string ChangeRecipient { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public class FinalizeDatawalletVersionUpgradeSyncRunResponse
{
public long? NewDatawalletModificationIndex { get; set; }

public IEnumerable<CreatedDatawalletModificationDTO> DatawalletModifications { get; set; }
public required IEnumerable<CreatedDatawalletModificationDTO> DatawalletModifications { get; set; }
}
Loading

0 comments on commit 60b66b3

Please sign in to comment.