Skip to content

Commit

Permalink
- Fixed bugs in SetAndActivateCurrentStorageProvider method in Provid…
Browse files Browse the repository at this point in the history
…erManager making it even more robust with improved error handling etc.

- Started adding new GetAllAvatarNames methods to AvatarController in ONode.WebAPI.

- Fixed a bug in ResetPassword method in AvatarService where the message was being set in the Result property instead of the Message one.

- Removed Connect and Disconnect methods in the Neo4jOASIS Provider.

- Re-wrote ActivateProvider and DeActivateProvider methods in Neo4jOASIS Provider fixing a number of bugs and improved error handling/reporting etc.
  • Loading branch information
dellams committed Jun 9, 2023
1 parent 02f03a3 commit 5f58cf1
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 16 deletions.
10 changes: 5 additions & 5 deletions NextGenSoftware.OASIS.API.Core/Managers/ProviderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,10 @@ public static OASISResult<IOASISStorageProvider> SetAndActivateCurrentStoragePro
{
OASISResult<bool> deactivateProviderResult = DeActivateProvider(CurrentStorageProvider);

if (deactivateProviderResult.IsError)
if (deactivateProviderResult != null && deactivateProviderResult.IsError || deactivateProviderResult == null)
{
// result.IsError = true; // TODO: Think its not an error as long as it can activate a provider below?
result.Message = deactivateProviderResult.Message;
result.IsWarning = true; // TODO: Think its not an error as long as it can activate a provider below?
result.Message = deactivateProviderResult != null ? deactivateProviderResult.Message : "Unknown error (deactivateProviderResult was null!)";
}
}

Expand All @@ -341,10 +341,10 @@ public static OASISResult<IOASISStorageProvider> SetAndActivateCurrentStoragePro

OASISResult<bool> activateProviderResult = ActivateProvider(CurrentStorageProvider);

if (activateProviderResult.IsError)
if (activateProviderResult != null && activateProviderResult.IsError || activateProviderResult == null)
{
result.IsError = true;
result.Message = activateProviderResult.Message;
result.Message = activateProviderResult != null ? activateProviderResult.Message : "Unknown error (activateProviderResult was null!)";
}

if (setGlobally)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ public async Task<OASISHttpResponseMessage<IEnumerable<IAvatarDetail>>> GetAllAv
/// </summary>
/// <returns></returns>
[Authorize(AvatarType.Wizard)]
//[Authorize]
[HttpGet("get-all-avatars")]
public async Task<OASISHttpResponseMessage<IEnumerable<IAvatar>>> GetAll()
{
Expand All @@ -688,6 +689,34 @@ public async Task<OASISHttpResponseMessage<IEnumerable<IAvatar>>> GetAll(Provide
return await GetAll();
}

/// <summary>
/// Get's all avatars within The OASIS.
/// Only works for logged in &amp; authenticated Wizards (Admins). Use Authenticate endpoint first to obtain a JWT Token.
/// </summary>
/// <returns></returns>
[Authorize]
[HttpGet("get-all-avatar-names")]
public async Task<OASISHttpResponseMessage<IEnumerable<IAvatar>>> GetAllAvatarNames()
{
return HttpResponseHelper.FormatResponse(await Program.AvatarManager.LoadAllAvatarsAsync());
}

/// <summary>
/// Get's all avatars within The OASIS.
/// Only works for logged in &amp; authenticated Wizards (Admins). Use Authenticate endpoint first to obtain a JWT Token.
/// Pass in the provider you wish to use. Set the setglobally flag to false for this provider to be used only for this request or true for it to be used for all future requests too.
/// </summary>
/// <param name="providerType"></param>
/// <param name="setGlobally"></param>
/// <returns></returns>
[Authorize]
[HttpGet("get-all-avatar-names/{providerType}/{setGlobally}")]
public async Task<OASISHttpResponseMessage<IEnumerable<IAvatar>>> GetAllAvatarNames(ProviderType providerType, bool setGlobally = false)
{
GetAndActivateProvider(providerType, setGlobally);
return await GetAll();
}

/// <summary>
/// Get's the avatar for the given id.
/// Only works for logged in users. Use Authenticate endpoint first to obtain a JWT Token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ public async Task<OASISResult<string>> ResetPassword(ResetPasswordRequest model)
return response;
}

response.Result = "Password reset successful, you can now login";
response.Message = "Password reset successful, you can now login";
response.Result = response.Message;
}
else
ErrorHandling.HandleError(ref response, $"Error occured in ResetPassword loading all avatars. Reason: {avatarsResult.Message}", avatarsResult.DetailedMessage);
Expand Down
65 changes: 55 additions & 10 deletions NextGenSoftware.OASIS.API.Providers.Neo4jOASIS.Aura/Neo4jOASIS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public Neo4jOASIS(string host, string username, string password)
Password = password;
}

private async Task<bool> Connect()
/*
private async Task<OASISResult<bool>> ConnectAsync()
{
OASISResult<bool>
try
{
_driver = GraphDatabase.Driver(Host, AuthTokens.Basic(Username, Password));
Expand All @@ -48,21 +50,22 @@ private async Task<bool> Connect()
return false;
}
}
private async Task Disconnect()
private async Task DisconnectAsync()
{
//TODO: Find if there is a disconnect/shutdown function?
await _driver.CloseAsync();
_driver = null;
}
}*/

public override OASISResult<bool> ActivateProvider()
{
OASISResult<bool> result = new OASISResult<bool>();

try
{
Connect().Wait();
base.ActivateProvider();
result.Result = true;
_driver = GraphDatabase.Driver(Host, AuthTokens.Basic(Username, Password));
_driver.VerifyConnectivityAsync().Wait();
result = base.ActivateProvider();
}
catch (Exception ex)
{
Expand All @@ -71,15 +74,16 @@ public override OASISResult<bool> ActivateProvider()

return result;
}
public override OASISResult<bool> DeActivateProvider()

public override async Task<OASISResult<bool>> ActivateProviderAsync()
{
OASISResult<bool> result = new OASISResult<bool>();

try
{
Disconnect().Wait();
base.DeActivateProvider();
result.Result = true;
_driver = GraphDatabase.Driver(Host, AuthTokens.Basic(Username, Password));
await _driver.VerifyConnectivityAsync();
result = await base.ActivateProviderAsync();
}
catch (Exception ex)
{
Expand All @@ -88,6 +92,47 @@ public override OASISResult<bool> DeActivateProvider()

return result;
}

public override OASISResult<bool> DeActivateProvider()
{
OASISResult<bool> result = new OASISResult<bool>();

try
{
if (_driver != null)
_driver.CloseAsync().Wait();

_driver = null;
result = base.DeActivateProvider();
}
catch (Exception ex)
{
ErrorHandling.HandleError(ref result, $"Unknwon error occured whilst dactivating neo4j provider: {ex}");
}

return result;
}

public override async Task<OASISResult<bool>> DeActivateProviderAsync()
{
OASISResult<bool> result = new OASISResult<bool>();

try
{
if (_driver != null)
await _driver.CloseAsync();

_driver = null;
result = await base.DeActivateProviderAsync();
}
catch (Exception ex)
{
ErrorHandling.HandleError(ref result, $"Unknwon error occured whilst dactivating neo4j provider: {ex}");
}

return result;
}

private static void WithDatabase(SessionConfigBuilder sessionConfigBuilder)
{
//var neo4jVersion = System.Environment.GetEnvironmentVariable("NEO4J_VERSION") ?? "";
Expand Down

0 comments on commit 5f58cf1

Please sign in to comment.