Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

persistence v3 mongo #228

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

JoTec2002
Copy link

Hello,
I know it’s a relatively large Pull Request, but I still hope that it can be used. I'm open for feedback/ improvements.
This pull request is in an some what beta state of the feature but I wanted to be able to hopefully get some feedback.

Description

The gool if this pull request is adding alternatively to the Entity Framework a complete MongoDB Database integration.
Current state:

  • Fully linked Asset CRUD operation with Database – API can be configured to either use the current implementation or the MongoDB Database interface
  • Limited file functionality
  • Files still need to be loaded currently on startup, to show up in Web UI.

Newly added dependencies:
MongoDB.Driver
MongoDB.Driver.GridFS

Motivation and Context

The implementation is created as part of a German University Project at DHBW Stuttgart.
If added an early Version of the University Document below.
Studienarbeit_Jonas_Graubner_V0.1.pdf

The motivation for adding an alternative to the Entity Framework is, that it seems impossible to fully map the interfaces to EF. The MongoDB Driver was able to achieve this.
An Interface was created, so that new Native DB Driver still cloud be added in the Future.
For ease of use a docker compose file was added to startup an MongoDB – File will be extended to also include the server itself.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

I used Apidog to run most of the queries against the original Server and afterwards my implementation and looked if the response was identical.
Test Environment:

  • For Original: Lasted Docker Container
  • For new: MongoDB in Docker Server in Visual Studio Debuger

Checklist:

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Copy link
Contributor

@Freezor Freezor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some major issues found. Please resolve them first and finish the open TODO's in your code, before we can continue the review. On any questions, please feel free to contact me.

@@ -0,0 +1 @@
/mongo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need a new gitignore here. That should also be configurable in the existing gitignore

@@ -10,7 +10,7 @@
},
"AasxServerBlazor": {
"commandName": "Project",
"commandLineArgs": "--no-security --secret-string-api 1234 --aasx-in-memory 1000 --data-path \"C:\\Development\\Ronny\" --edit --external-blazor http://localhost:5001",
"commandLineArgs": "--no-security --aasx-in-memory 1000 --data-path \"C:\\GitClones\\aasx-server\\content-for-demo\\aasxs\" --edit --external-blazor http://localhost:5001 --with-mongodb \"mongodb://mongo:mongo@localhost:27017/\"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert the changes for --data-path

using System.IO;


//Author: Jonas Graubner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use personalised author tags. I know that we do not have a template for that yet, but creating your own one will be harder to resolve in the end. All your commits can be viewed in the git history and if you want to add yourself as a contributor, you can add a new entry in the CONTRIBUTORS.md

@@ -32,6 +32,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.13.1" />
<PackageReference Include="MongoDB.Driver" Version="2.25.0" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the license for these package checked, to be compatible with the open source guidelines?


public void Initialize(String connectionString)
{
//_client = new MongoClient("mongodb://AAS:[email protected]:27017/?authSource=AAS");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't commit commented code. If you think this might be useful information as an example, please create a valid c# method summary




public List<IAssetAdministrationShell> GetAllAssetAdministrationShells(List<SpecificAssetId> assetIds = null, string idShort = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using LINQ for filtering to enhance readability and maintainability within this method.


public void DeleteAssetInformationThumbnail(int packageIndex, IResource defaultThumbnail)
{
//TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding your TODO comments, you have two options:

  1. Please resolve the TODO before finalizing this PR.
  2. If you cannot resolve it immediately, please add detailed information on why and create a GitHub issue to keep track of it.

stream.Close();
}else
{
//throw new ArgumentNullException(nameof(stream));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's important to handle exceptions appropriately rather than commenting them out. In your WriteFile method, you've commented out the ArgumentNullException handling for the stream parameter. This approach can lead to unexpected behavior or silent failures if stream is null, as it will not be properly handled or logged.

Best practice dictates that exceptions should be handled or propagated correctly to maintain application reliability and provide meaningful error messages for debugging. Commenting out exceptions can obscure issues and make troubleshooting more difficult, which is considered a code smell.

To improve, consider either uncommenting the exception handling and adding appropriate logging or refactor the method to handle null stream scenarios more gracefully.

using (var cursor = _bucket.Find(filter, options))
{
var fileInfo = cursor.ToList().FirstOrDefault();
// fileInfo either has the matching file information or is null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could rather be used as a method summary.

/// <summary>
/// Retrieves the ObjectId of the latest file matching the specified filename in the GridFS bucket.
/// </summary>
/// <param name="filename">The filename of the file to retrieve.</param>
/// <returns>The ObjectId of the matching file, or ObjectId.Empty if no matching file is found.</returns>

});
}

public void importAdminShellPackageEnv(AdminShellPackageEnv adminShellPackageEnv)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the standard C# naming for methods, which is PascalCase please

@Freezor Freezor added enhancement New feature or request database Relates to changes involving the database schema, migrations, queries, or overall database managemen labels Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Relates to changes involving the database schema, migrations, queries, or overall database managemen enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants