From 10d337eb3602289d110be14a71f974c331238df7 Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Thu, 17 Feb 2022 16:33:52 +0100 Subject: [PATCH 01/35] first commit - version 0.0.3 --- OpenAPI.yaml | 220 +++++++++++++++++++++++++++++++++++++++++++ additions.zip | Bin 0 -> 10881 bytes openapitools.json | 7 ++ readme.md | 231 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 458 insertions(+) create mode 100644 OpenAPI.yaml create mode 100644 additions.zip create mode 100644 openapitools.json create mode 100644 readme.md diff --git a/OpenAPI.yaml b/OpenAPI.yaml new file mode 100644 index 0000000..c71f46a --- /dev/null +++ b/OpenAPI.yaml @@ -0,0 +1,220 @@ +openapi: "3.0.0" +info: + version: 0.0.3 + title: World Storage API + description: API ensuring interoperability between an authoring tool and a World Storage service + license: + name: BSD-3-clause + url: https://opensource.org/licenses/BSD-3-Clause +servers: + - url: http://localhost:8080 +paths: + /ping: + get: + summary: Test the server availability + responses: + '200': + description: OK + /admin: + get: + summary: Get the version of the API + operationId: getVersion + responses: + '200': + description: OK world storage. + content: + text/plain: + schema: + type: string + /trackables: + post: + summary: Create a trackable + operationId: addTrackable + tags: + - trackables + requestBody: + description: the trackable to be added to the world storage + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/trackable' + application/xml: + schema: + $ref: '#/components/schemas/trackable' + responses: + '200': + description: OK returns the UUID of the Trackable defined by the world storage. + content: + text/plain: + schema: + type: string + '201': + description: Null response + default: + description: unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + get: + summary: returns the list of all trackables defined by the world storage. + operationId: getTrackables + tags: + - trackables + responses: + 200: + description: OK returns all the Trackables defined by the world storage. + content: + application/json: + schema: + type : array + items : + $ref: "#/components/schemas/trackable" + 201: + description: Null response + default: + description: unexpected error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /trackables/{trackableId}: + get: + summary: Find a trackable by his ID + operationId: getTrackableById + tags: + - trackables + parameters: + - name: trackableId + in: path + description: ID of the trackable to retrieve + required: true + schema: + type: string + responses: + '200': + description: "successful operation" + content: + application/json: + schema: + $ref: '#/components/schemas/trackable' + '400': + description: "Invalid ID supplied" + '404': + description: "Trackable not found" + delete: + summary: Deletes a trackable + operationId: deleteTrackable + tags: + - trackables + parameters: + - name: trackableId + in: path + description: trackable id to delete + required: true + schema: + type: string + responses: + '200': + description: OK + '400': + description: Invalid ID supplied + '404': + description: trackable not found +components: + schemas: + trackable: + type: object + required: + - UID + - creatorUID + - trackableType + - trackableEncodingInformation + - trackablePayload + - unitSystem + - trackableDimension + - keyvalueTagList + properties: + UID: + description: A Universally Unique IDentifier identifying the trackable + type: string + format: uuid + example: c75f6324-77a0-11ec-90d6-0242ac120001 + creatorUID: + description: A Universally Unique IDentifier identifying the creator of the trackable + type: string + format: uuid + example: c75f6324-77a0-11ec-90d6-0242ac120003 + trackableType: + description: Extensible list of trackable types possibly handled by complient World Storage implementation + type: string + enum: [FIDUCIAL_MARKER, IMAGE_MARKER, MAP, OTHER] + example: FIDUCIAL_MARKER + trackableEncodingInformation: + description: Identifies targeted framework and version of the format. + $ref: '#/components/schemas/encodingInformationStructure' + trackablePayload: + description: The data provided to create the trackable in a specific format handled by the World Storage service. + type: string + format: byte + example: "10110101" + localCRS: + description: Coordinate reference system of the trackable, a 4*4 matrix (rowmajor) represented by a float vector + type: array + minItems: 16 + maxItems: 16 + items: + type: number + format: float + example: [-2, 1, -3, 4, + 4, 4, 4, 2, + 1, 0, -2, 1, + -1, -2, 0, 0] + unitSystem: + description: Unit of length + type: string + enum: [MM, CM, DM, M, DAM, HM, KM, INCH, FOOT, YARD, MILE] + example: M + trackableDimension: + description: Bounding box of the Trackable, {width, length, 0} for 2D trackables, {width, length, depth} for 3D trackables + type: array + items: + type: number + format: double + minItems: 3 + maxItems: 3 + example: [1,5,0] + keyvalueTagList: + description: List of additional parameters to be stored with the trackable. + type: object + additionalProperties: + type: array + items: + type: string + minItems: 1 + example: { "author" : ["james","donovan"], "image" : ["skater"]} + encodingInformationStructure: + required: + - dataFormat + - version + properties: + dataFormat: + description: Identifier of the target framework + type: string + enum: [HOLOLENS, ARKIT, ARCORE] + example : "HOLOLENS" + version: + description: The version of the format + type: string + example : "1.01" + Error: + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string \ No newline at end of file diff --git a/additions.zip b/additions.zip new file mode 100644 index 0000000000000000000000000000000000000000..7427682278ab7586553d3d3654406f7806b54489 GIT binary patch literal 10881 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 HUyc3)c<;gp literal 0 HcmV?d00001 diff --git a/openapitools.json b/openapitools.json new file mode 100644 index 0000000..2774f45 --- /dev/null +++ b/openapitools.json @@ -0,0 +1,7 @@ +{ + "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json", + "spaces": 2, + "generator-cli": { + "version": "5.3.1" + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..79b8c84 --- /dev/null +++ b/readme.md @@ -0,0 +1,231 @@ +# Description of version 0.0.3 + +auto-generated ASP.NET server code + +includes description and code for a fully functional server with MongoDB integration + +# Generate or update the server + +In the following, we distinguish between a server code generation from scratch and an update of an existing solution + +--- + +# First generation + +We provide a zip-file `additions.zip` with a folder structure and some files to simplify your work. + +If you want to use it unpack `additions.zip` in this folder and continue with the instruction for an [update](#update). + +Otherwise skip the unzip operation and continue with the next step (if you like to, you can compare your version with the one in the zip-file afterwards) + +The zip-file additions.zip contains: +* server/src/Org.OpenAPITools/Dockerfile - a corrected Dockerfile +* server/src/Org.OpenAPITools/docker-compose.yml - for a stack of server and MongoDB +* server/src/Org.OpenAPITools/Startup.cs - the adapted original auto-generated file +* server/src/Org.OpenAPITools/appsettings.json - added database settings to the appsettings.json +* server/src/Org.OpenAPITools/Services/ - contains C# code for accessing MongoDB +* server/src/Org.OpenAPITools/ControllersImpl/ - for c# classes inherting classes from /src/Org.OpenAPITools/Controllers/ +* server/src/Org.OpenAPITools/docker/ - contains appsettings.json for the use in docker and folder data-dump for later dumping the database for transfer if desired +* server/programs/ - contains a readme.txt about how to install and run MongoDB for Windows +* server/data/ - empty folder for the databases of MongoDB +* server/.openapi-generator-ignore - to prevent openapi-generator to override these files + + +## auto-generate server code +open a command shell and execute +``` + openapi-generator-cli generate -i OpenAPI.yaml -g aspnetcore -o server +``` + +## set files to ignore +open the file `.openapi-generator-ignore` in server + +add the following file and folder entries: +``` +**/Startup.cs +**/appsettings.json +**/Dockerfile +**/docker-compoese.yml +**/.openapi-generator-ignore + +**/ControllersImpl +**/Services +**/programs +**/data +**/docker +``` + +## In Visual Studio: +open `NuGet Package Manager` and add `MongoDB.Driver` + +### - folder `Controllers`: +copy all files from `Controllers` to `ControllersImpl` +In all files in the folder `Controllers` change `public class` to `public abstract class` + +### - folder `ControllersImpl`: +change classnames by appending `Impl` to the original classnames (and change filenames accordingly) and inherit from original class in `Controllers` + +and replace `virtual` by `override` with all methods. + +Add +``` + using Org.OpenAPITools.Services; + using MongoDB.Driver; +``` + +Add a private readonly service class variable, e.g. +``` + private readonly TrackableService _trackableService; +``` + +Add a constructor with this service class variable, e.g. +``` + public TrackablesApiControllerImpl(TrackableService trackableService) + { + _trackableService = trackableService; + } +``` + +remove sample code and replace it by using the appropriate methods of the corresponding classes in the folder `Services` + +### - folder `Models`: +in the files add: +``` + using MongoDB.Bson; + using MongoDB.Bson.Serialization.Attributes; +``` + +at the value that is to become the Database ID, add: +``` + [BsonId] + [BsonRepresentation(BsonType.String)] +``` + +### - folder `Services` +contains one class with the DatabaseSettings and one with the database-access-methods (create, get, update, remove) for each API + +the naming in the DatabaseSettings is the same as defined in `appsettings.json ` + +### - file `startup.cs` +add +``` + using Org.OpenAPITools.Services; + using MongoDB.Bson.Serialization; + using MongoDB.Bson; + using MongoDB.Bson.Serialization.Serializers; + using Microsoft.Extensions.Options; +``` + +add the following code in `public void ConfigureServices(IServiceCollection services)`: +``` + BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard)); + BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3; + // requires using Microsoft.Extensions.Options + services.Configure<**insert classname of DatabaseSettings in Services**>( + Configuration.GetSection(nameof(**insert classname of DatabaseSettings in Services**))); + services.AddSingleton<**insert interface of DatabaseSettings in Services**>(sp => + sp.GetRequiredService>().Value); + services.AddSingleton<**insert classname of service class in Services**>(); +``` + +replace +``` + opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + opts.SerializerSettings.Converters.Add(new StringEnumConverter + { + NamingStrategy = new CamelCaseNamingStrategy() + }); +``` +by +``` + opts.SerializerSettings.ContractResolver = new DefaultContractResolver(); +``` + +### - file `appsettings.json` +add Database settings in `appsettings.json`, like +``` + "TrackableDatabaseSettings": { + "CollectionName": "Trackables", + "ConnectionString": "mongodb://localhost:27017", + "DatabaseName": "TrackablesDatabase" + }, +``` + +## MongoDB +if you don't have a MongoDB add the folders +* server/programs/MongoDB (for MongoDB) +* server/data/ (to store database of MongoDB) + +and put MongoDB in folder `server/programs/MongoDB` (download MongoDB as zip-file from https://www.mongodb.com/try/download/community and unzip the file into this directory, so that the bin-directory is in this folder) + + +--- + +# Update +## File adaptations: +change version number in all files if a new version is provided + +### - folder `Controllers`: +change `public class` to `public abstract class` + +compare files in `ControllersImpl` with the corresponding files in `Controllers` + +methods should be the same with `override` instead of `virtual` + +### - folder `Models`: +add: +``` + using MongoDB.Bson; + using MongoDB.Bson.Serialization.Attributes; +``` + +at the value that is to become the MongoDB ID, add: +``` + [BsonId] + [BsonRepresentation(BsonType.String)] +``` + +### Solution +open `NuGet Package Manager` and add `MongoDB.Driver` + + +--- + +# Use in Visual Studio +make sure, that in instance of MongoDB is running (have a look in the above mentioned zip-file `additions.zip`: in the sub-folder `programs/MongoDB` you find a description, of how to install and run MongoDB for Windows) + +start application with IIS Express + +--- + +# Use in Docker +remove the substring `src/Org.OpenAPITools/` in Dockerfile (if not already done) + +open a command shell and generate docker by executing in `server/src/Org.OpenAPITools`: +``` + docker build -t org.openapitools . +``` + +## to start: +open a command shell and use docker-compose (if necessary adapt docker-compose.yml) by executing in `server/src/Org.OpenAPITools`: +``` + docker-compose up +``` + +## to stop: +open a command shell by executing in `server/src/Org.OpenAPITools`: +``` + docker-compose down +``` + +## to dump database +execute the following command in docker: +``` + mongodump --db **insert database_name** --out /data-dump/`date +"%Y-%m-%d"` +``` + +## to import database: +execute the following command in docker: +``` + mongorestore --db **insert database_name** **insert path_to_bson_file** +``` \ No newline at end of file -- GitLab From a1783bd52a89a89dfc5439b11abe51f51549e795 Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Fri, 18 Feb 2022 08:14:13 +0100 Subject: [PATCH 02/35] updated readme.md --- readme.md | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/readme.md b/readme.md index 79b8c84..3b470ba 100644 --- a/readme.md +++ b/readme.md @@ -4,6 +4,13 @@ auto-generated ASP.NET server code includes description and code for a fully functional server with MongoDB integration + +# Prerequisites +1. installed npm: https://phoenixnap.com/kb/install-node-js-npm-on-windows +2. Installed openapi generator with npm: https://openapi-generator.tech/docs/installation/ +3. Installed docker (if you want to use it): https://www.docker.com/get-started + + # Generate or update the server In the following, we distinguish between a server code generation from scratch and an update of an existing solution @@ -11,7 +18,6 @@ In the following, we distinguish between a server code generation from scratch a --- # First generation - We provide a zip-file `additions.zip` with a folder structure and some files to simplify your work. If you want to use it unpack `additions.zip` in this folder and continue with the instruction for an [update](#update). @@ -30,7 +36,6 @@ The zip-file additions.zip contains: * server/data/ - empty folder for the databases of MongoDB * server/.openapi-generator-ignore - to prevent openapi-generator to override these files - ## auto-generate server code open a command shell and execute ``` @@ -45,7 +50,7 @@ add the following file and folder entries: **/Startup.cs **/appsettings.json **/Dockerfile -**/docker-compoese.yml +**/docker-compose.yml **/.openapi-generator-ignore **/ControllersImpl @@ -58,12 +63,10 @@ add the following file and folder entries: ## In Visual Studio: open `NuGet Package Manager` and add `MongoDB.Driver` -### - folder `Controllers`: -copy all files from `Controllers` to `ControllersImpl` -In all files in the folder `Controllers` change `public class` to `public abstract class` - ### - folder `ControllersImpl`: -change classnames by appending `Impl` to the original classnames (and change filenames accordingly) and inherit from original class in `Controllers` +create a folder `ControllersImpl` and copy all files from `Controllers` to `ControllersImpl` + +change classnames by appending `Impl` to the original classnames (and change filenames accordingly) and inherit from original class in `Controllers` (instead of `ControllerBase`) and replace `virtual` by `override` with all methods. @@ -86,7 +89,11 @@ Add a constructor with this service class variable, e.g. } ``` -remove sample code and replace it by using the appropriate methods of the corresponding classes in the folder `Services` +remove sample code and replace it by using the appropriate methods of the corresponding classes in the folder `Services` +(have a look into the above mentioned `additions.zip` for an example) + +### - folder `Controllers`: +In all files in the folder `Controllers` change `public class` to `public abstract class` ### - folder `Models`: in the files add: @@ -102,7 +109,9 @@ at the value that is to become the Database ID, add: ``` ### - folder `Services` -contains one class with the DatabaseSettings and one with the database-access-methods (create, get, update, remove) for each API +create the folder `Services` and have a look into the above mentioned `additions.zip` for an example + +the folder `Services` should contain one class with the DatabaseSettings and one with the database-access-methods (create, get, update, remove) for each API the naming in the DatabaseSettings is the same as defined in `appsettings.json ` @@ -158,7 +167,6 @@ if you don't have a MongoDB add the folders and put MongoDB in folder `server/programs/MongoDB` (download MongoDB as zip-file from https://www.mongodb.com/try/download/community and unzip the file into this directory, so that the bin-directory is in this folder) - --- # Update @@ -207,6 +215,15 @@ open a command shell and generate docker by executing in `server/src/Org.OpenAPI ``` ## to start: +the easiest way is to use docker-compose: + +if not already done (i.e. by using the above mentioned zip-file `additions.zip`): +* copy file `docker-compose.yml` and folder `docker` from the above mentioned zip-file `additions.zip` or + * create a folder `docker` + * create a sub-folder `data-dump` + * copy appsettings.json into the folder `docker` and adapt the connectionString for MongoDB for the usage in docker + * create a file docker-compose.yml for the above created image and MongoDB-image or copy it from the above mentioned zip-file `additions.zip` + open a command shell and use docker-compose (if necessary adapt docker-compose.yml) by executing in `server/src/Org.OpenAPITools`: ``` docker-compose up -- GitLab From 9701b5a3d7cf66a21f80c4ed7a949035ef8d99a3 Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Mon, 21 Feb 2022 08:14:56 +0100 Subject: [PATCH 03/35] added additional files directly --- additions.zip | Bin 10881 -> 0 bytes readme.md | 175 ++---------------- server/.openapi-generator-ignore | 37 ++++ server/programs/MongoDB/kill_MongoDB.bat | 1 + server/programs/MongoDB/readme.txt | 3 + server/programs/MongoDB/startMongoDB.bat | 3 + .../ControllersImpl/DefaultApiImpl.cs | 63 +++++++ .../ControllersImpl/TrackablesApiImpl.cs | 128 +++++++++++++ server/src/Org.OpenAPITools/Dockerfile | 32 ++++ .../Services/TrackableDatabaseSettings.cs | 21 +++ .../Services/TrackableService.cs | 50 +++++ server/src/Org.OpenAPITools/Startup.cs | 157 ++++++++++++++++ server/src/Org.OpenAPITools/appsettings.json | 13 ++ .../src/Org.OpenAPITools/docker-compose.yml | 41 ++++ .../Org.OpenAPITools/docker/appsettings.json | 13 ++ 15 files changed, 575 insertions(+), 162 deletions(-) delete mode 100644 additions.zip create mode 100644 server/.openapi-generator-ignore create mode 100644 server/programs/MongoDB/kill_MongoDB.bat create mode 100644 server/programs/MongoDB/readme.txt create mode 100644 server/programs/MongoDB/startMongoDB.bat create mode 100644 server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs create mode 100644 server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs create mode 100644 server/src/Org.OpenAPITools/Dockerfile create mode 100644 server/src/Org.OpenAPITools/Services/TrackableDatabaseSettings.cs create mode 100644 server/src/Org.OpenAPITools/Services/TrackableService.cs create mode 100644 server/src/Org.OpenAPITools/Startup.cs create mode 100644 server/src/Org.OpenAPITools/appsettings.json create mode 100644 server/src/Org.OpenAPITools/docker-compose.yml create mode 100644 server/src/Org.OpenAPITools/docker/appsettings.json diff --git a/additions.zip b/additions.zip deleted file mode 100644 index 7427682278ab7586553d3d3654406f7806b54489..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10881 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 HUyc3)c<;gp diff --git a/readme.md b/readme.md index 3b470ba..8ceacee 100644 --- a/readme.md +++ b/readme.md @@ -13,28 +13,7 @@ includes description and code for a fully functional server with MongoDB integra # Generate or update the server -In the following, we distinguish between a server code generation from scratch and an update of an existing solution - ---- - -# First generation -We provide a zip-file `additions.zip` with a folder structure and some files to simplify your work. - -If you want to use it unpack `additions.zip` in this folder and continue with the instruction for an [update](#update). - -Otherwise skip the unzip operation and continue with the next step (if you like to, you can compare your version with the one in the zip-file afterwards) - -The zip-file additions.zip contains: -* server/src/Org.OpenAPITools/Dockerfile - a corrected Dockerfile -* server/src/Org.OpenAPITools/docker-compose.yml - for a stack of server and MongoDB -* server/src/Org.OpenAPITools/Startup.cs - the adapted original auto-generated file -* server/src/Org.OpenAPITools/appsettings.json - added database settings to the appsettings.json -* server/src/Org.OpenAPITools/Services/ - contains C# code for accessing MongoDB -* server/src/Org.OpenAPITools/ControllersImpl/ - for c# classes inherting classes from /src/Org.OpenAPITools/Controllers/ -* server/src/Org.OpenAPITools/docker/ - contains appsettings.json for the use in docker and folder data-dump for later dumping the database for transfer if desired -* server/programs/ - contains a readme.txt about how to install and run MongoDB for Windows -* server/data/ - empty folder for the databases of MongoDB -* server/.openapi-generator-ignore - to prevent openapi-generator to override these files +we provided the file `.openapi-generator-ignore` in `server`, which prevents openapi-generator to override some adapted files ## auto-generate server code open a command shell and execute @@ -42,143 +21,20 @@ open a command shell and execute openapi-generator-cli generate -i OpenAPI.yaml -g aspnetcore -o server ``` -## set files to ignore -open the file `.openapi-generator-ignore` in server - -add the following file and folder entries: -``` -**/Startup.cs -**/appsettings.json -**/Dockerfile -**/docker-compose.yml -**/.openapi-generator-ignore - -**/ControllersImpl -**/Services -**/programs -**/data -**/docker -``` +open the solution `Org.OpenAPITools.sln` (folder `server`) in Visual Studio ## In Visual Studio: open `NuGet Package Manager` and add `MongoDB.Driver` -### - folder `ControllersImpl`: -create a folder `ControllersImpl` and copy all files from `Controllers` to `ControllersImpl` - -change classnames by appending `Impl` to the original classnames (and change filenames accordingly) and inherit from original class in `Controllers` (instead of `ControllerBase`) - -and replace `virtual` by `override` with all methods. - -Add -``` - using Org.OpenAPITools.Services; - using MongoDB.Driver; -``` - -Add a private readonly service class variable, e.g. -``` - private readonly TrackableService _trackableService; -``` - -Add a constructor with this service class variable, e.g. -``` - public TrackablesApiControllerImpl(TrackableService trackableService) - { - _trackableService = trackableService; - } -``` - -remove sample code and replace it by using the appropriate methods of the corresponding classes in the folder `Services` -(have a look into the above mentioned `additions.zip` for an example) - -### - folder `Controllers`: -In all files in the folder `Controllers` change `public class` to `public abstract class` - -### - folder `Models`: -in the files add: -``` - using MongoDB.Bson; - using MongoDB.Bson.Serialization.Attributes; -``` - -at the value that is to become the Database ID, add: -``` - [BsonId] - [BsonRepresentation(BsonType.String)] -``` - -### - folder `Services` -create the folder `Services` and have a look into the above mentioned `additions.zip` for an example - -the folder `Services` should contain one class with the DatabaseSettings and one with the database-access-methods (create, get, update, remove) for each API - -the naming in the DatabaseSettings is the same as defined in `appsettings.json ` - -### - file `startup.cs` -add -``` - using Org.OpenAPITools.Services; - using MongoDB.Bson.Serialization; - using MongoDB.Bson; - using MongoDB.Bson.Serialization.Serializers; - using Microsoft.Extensions.Options; -``` - -add the following code in `public void ConfigureServices(IServiceCollection services)`: -``` - BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard)); - BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3; - // requires using Microsoft.Extensions.Options - services.Configure<**insert classname of DatabaseSettings in Services**>( - Configuration.GetSection(nameof(**insert classname of DatabaseSettings in Services**))); - services.AddSingleton<**insert interface of DatabaseSettings in Services**>(sp => - sp.GetRequiredService>().Value); - services.AddSingleton<**insert classname of service class in Services**>(); -``` - -replace -``` - opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - opts.SerializerSettings.Converters.Add(new StringEnumConverter - { - NamingStrategy = new CamelCaseNamingStrategy() - }); -``` -by -``` - opts.SerializerSettings.ContractResolver = new DefaultContractResolver(); -``` - -### - file `appsettings.json` -add Database settings in `appsettings.json`, like -``` - "TrackableDatabaseSettings": { - "CollectionName": "Trackables", - "ConnectionString": "mongodb://localhost:27017", - "DatabaseName": "TrackablesDatabase" - }, -``` - -## MongoDB -if you don't have a MongoDB add the folders -* server/programs/MongoDB (for MongoDB) -* server/data/ (to store database of MongoDB) - -and put MongoDB in folder `server/programs/MongoDB` (download MongoDB as zip-file from https://www.mongodb.com/try/download/community and unzip the file into this directory, so that the bin-directory is in this folder) - ---- - -# Update -## File adaptations: +### File adaptations: change version number in all files if a new version is provided ### - folder `Controllers`: -change `public class` to `public abstract class` +change "`public class`" to "`public abstract class`" -compare files in `ControllersImpl` with the corresponding files in `Controllers` +compare files in "`ControllersImpl`" with the corresponding files in "`Controllers`" and adapt if necessary -methods should be the same with `override` instead of `virtual` +methods should be the same with "`override`" instead of "`virtual`" ### - folder `Models`: add: @@ -193,18 +49,18 @@ at the value that is to become the MongoDB ID, add: [BsonRepresentation(BsonType.String)] ``` -### Solution -open `NuGet Package Manager` and add `MongoDB.Driver` +# MongoDB +if you don't have a MongoDB, follow the instructions in `readme.txt` in `server/programs/MongoDB` + +and put MongoDB in folder `server/programs/MongoDB` (download MongoDB as zip-file from https://www.mongodb.com/try/download/community and unzip the file into this directory, so that the bin-directory is in this folder) ---- # Use in Visual Studio -make sure, that in instance of MongoDB is running (have a look in the above mentioned zip-file `additions.zip`: in the sub-folder `programs/MongoDB` you find a description, of how to install and run MongoDB for Windows) +make sure, that an instance of MongoDB is running start application with IIS Express ---- # Use in Docker remove the substring `src/Org.OpenAPITools/` in Dockerfile (if not already done) @@ -217,18 +73,13 @@ open a command shell and generate docker by executing in `server/src/Org.OpenAPI ## to start: the easiest way is to use docker-compose: -if not already done (i.e. by using the above mentioned zip-file `additions.zip`): -* copy file `docker-compose.yml` and folder `docker` from the above mentioned zip-file `additions.zip` or - * create a folder `docker` - * create a sub-folder `data-dump` - * copy appsettings.json into the folder `docker` and adapt the connectionString for MongoDB for the usage in docker - * create a file docker-compose.yml for the above created image and MongoDB-image or copy it from the above mentioned zip-file `additions.zip` - open a command shell and use docker-compose (if necessary adapt docker-compose.yml) by executing in `server/src/Org.OpenAPITools`: ``` docker-compose up ``` +open http://localhost:8080/openapi/index.html in a web-browser, if you want to check the functionalities using SwaggerUI + ## to stop: open a command shell by executing in `server/src/Org.OpenAPITools`: ``` diff --git a/server/.openapi-generator-ignore b/server/.openapi-generator-ignore new file mode 100644 index 0000000..cbd23cf --- /dev/null +++ b/server/.openapi-generator-ignore @@ -0,0 +1,37 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md + + +**/Startup.cs +**/appsettings.json +**/Dockerfile +**/docker-compose.yml +**/.openapi-generator-ignore + + +# ARF +# Implementation of REST request and database functionalities +# +**/ControllersImpl +**/Services diff --git a/server/programs/MongoDB/kill_MongoDB.bat b/server/programs/MongoDB/kill_MongoDB.bat new file mode 100644 index 0000000..8aae66b --- /dev/null +++ b/server/programs/MongoDB/kill_MongoDB.bat @@ -0,0 +1 @@ +taskkill -im mongod.exe \ No newline at end of file diff --git a/server/programs/MongoDB/readme.txt b/server/programs/MongoDB/readme.txt new file mode 100644 index 0000000..3d74654 --- /dev/null +++ b/server/programs/MongoDB/readme.txt @@ -0,0 +1,3 @@ +1. download MongoDB as zip-file from https://www.mongodb.com/try/download/community +2. unzip the file into this directory, so that the bin-directory is in this folder (where you found this readme.txt) +3. before starting startMongoDB.bat create data-directory and adjust - if necessary - data path in startMongoDB.bat \ No newline at end of file diff --git a/server/programs/MongoDB/startMongoDB.bat b/server/programs/MongoDB/startMongoDB.bat new file mode 100644 index 0000000..1202cf1 --- /dev/null +++ b/server/programs/MongoDB/startMongoDB.bat @@ -0,0 +1,3 @@ +cd bin +call "cmd /c start mongod.exe --dbpath ../../../data" +cd .. \ No newline at end of file diff --git a/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs new file mode 100644 index 0000000..ec72c77 --- /dev/null +++ b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs @@ -0,0 +1,63 @@ +/* + * World Storage API + * + * API ensuring interoperability between an authoring tool and a World Storage service + * + * The version of the OpenAPI document: 0.0.3 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Http; +using Swashbuckle.AspNetCore.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using Newtonsoft.Json; +using Org.OpenAPITools.Attributes; +using Org.OpenAPITools.Models; +using Microsoft.OpenApi.Models; + +namespace Org.OpenAPITools.Controllers +{ + /// + /// + /// + [ApiController] + public class DefaultApiControllerImpl : DefaultApiController + { + /// + /// Get the version of the API + /// + /// OK world storage. + [HttpGet] + [Route("/admin")] + [ValidateModelState] + [SwaggerOperation("GetVersion")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK world storage.")] + public override IActionResult GetVersion() + { + string version = "world storage 0.0.3"; + return new ObjectResult(version); + //return StatusCode(200, new ObjectResult(version)); + } + + /// + /// Test the server availability + /// + /// OK + [HttpGet] + [Route("/ping")] + [ValidateModelState] + [SwaggerOperation("PingGet")] + public override IActionResult PingGet() + { + string answer = "pong"; + return new ObjectResult(answer); +// return StatusCode(200, new ObjectResult(answer)); + } + } +} diff --git a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs new file mode 100644 index 0000000..a27b4e0 --- /dev/null +++ b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs @@ -0,0 +1,128 @@ +/* + * World Storage API + * + * API ensuring interoperability between an authoring tool and a World Storage service + * + * The version of the OpenAPI document: 0.0.3 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Http; +using Swashbuckle.AspNetCore.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using Newtonsoft.Json; +using Org.OpenAPITools.Attributes; +using Org.OpenAPITools.Models; +using Org.OpenAPITools.Services; +using MongoDB.Driver; + +namespace Org.OpenAPITools.Controllers +{ + /// + /// + /// + [ApiController] + public class TrackablesApiControllerImpl : TrackablesApiController + { + + private readonly TrackableService _trackableService; + + /// + /// + /// + public TrackablesApiControllerImpl(TrackableService trackableService) + { + _trackableService = trackableService; + } + + + /// + /// Create a trackable + /// + /// the trackable to be added to the world storage + /// OK returns the UUID of the Trackable defined by the world storage. + /// Null response + /// unexpected error + [HttpPost] + [Route("/trackables")] + [Consumes("application/json", "application/xml")] + [ValidateModelState] + [SwaggerOperation("AddTrackable")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK returns the UUID of the Trackable defined by the world storage.")] + [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "unexpected error")] + public override IActionResult AddTrackable([FromBody] Trackable trackable) + { + if (String.IsNullOrEmpty(trackable.UID.ToString())) + { + trackable.UID = Guid.NewGuid(); + } + try + { + Trackable mytrackable = _trackableService.Create(trackable); + return new ObjectResult(mytrackable); + } catch (Exception e) + { + return StatusCode(400, e.Message); + } + } + + /// + /// Deletes a trackable + /// + /// trackable id to delete + /// OK + /// Invalid ID supplied + /// trackable not found + [HttpDelete] + [Route("/trackables/{trackableId}")] + [ValidateModelState] + [SwaggerOperation("DeleteTrackable")] + public override IActionResult DeleteTrackable([FromRoute(Name = "trackableId")][Required] string trackableId) + { + DeleteResult answer = _trackableService.Remove(Guid.Parse(trackableId)); + return (answer.IsAcknowledged && answer.DeletedCount > 0) ? new ObjectResult("ok") : new ObjectResult("failed"); + } + + /// + /// Find a trackable by his ID + /// + /// ID of the trackable to retrieve + /// successful operation + /// Invalid ID supplied + /// Trackable not found + [HttpGet] + [Route("/trackables/{trackableId}")] + [ValidateModelState] + [SwaggerOperation("GetTrackableById")] + [SwaggerResponse(statusCode: 200, type: typeof(Trackable), description: "successful operation")] + public override IActionResult GetTrackableById([FromRoute(Name = "trackableId")][Required] string trackableId) + { + Trackable trackable = _trackableService.Get(Guid.Parse(trackableId)); + return (null != trackable) ? new ObjectResult(trackable) : new ObjectResult("not found"); + } + + /// + /// returns the list of all trackables defined by the world storage. + /// + /// OK returns all the Trackables defined by the world storage. + /// Null response + /// unexpected error + [HttpGet] + [Route("/trackables")] + [ValidateModelState] + [SwaggerOperation("GetTrackables")] + [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK returns all the Trackables defined by the world storage.")] + [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "unexpected error")] + public override IActionResult GetTrackables() + { + List trackablelist = _trackableService.Get(); + return new ObjectResult(trackablelist); + } + } +} diff --git a/server/src/Org.OpenAPITools/Dockerfile b/server/src/Org.OpenAPITools/Dockerfile new file mode 100644 index 0000000..267d1df --- /dev/null +++ b/server/src/Org.OpenAPITools/Dockerfile @@ -0,0 +1,32 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +# Container we use for final publish +FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +# Build container +FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build + +# Copy the code into the container +WORKDIR /src +COPY ["Org.OpenAPITools.csproj", "Org.OpenAPITools/"] + +# NuGet restore +RUN dotnet restore "Org.OpenAPITools/Org.OpenAPITools.csproj" +COPY [".", "Org.OpenAPITools/"] + +# Build the API +WORKDIR "Org.OpenAPITools" +RUN dotnet build "Org.OpenAPITools.csproj" -c Release -o /app/build + +# Publish it +FROM build AS publish +RUN dotnet publish "Org.OpenAPITools.csproj" -c Release -o /app/publish + +# Make the final image for publishing +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Org.OpenAPITools.dll"] diff --git a/server/src/Org.OpenAPITools/Services/TrackableDatabaseSettings.cs b/server/src/Org.OpenAPITools/Services/TrackableDatabaseSettings.cs new file mode 100644 index 0000000..70b4cdc --- /dev/null +++ b/server/src/Org.OpenAPITools/Services/TrackableDatabaseSettings.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Org.OpenAPITools.Services +{ + public class TrackableDatabaseSettings : ITrackableDatabaseSettings + { + public string CollectionName { get; set; } + public string ConnectionString { get; set; } + public string DatabaseName { get; set; } + } + + public interface ITrackableDatabaseSettings + { + string CollectionName { get; set; } + string ConnectionString { get; set; } + string DatabaseName { get; set; } + } +} diff --git a/server/src/Org.OpenAPITools/Services/TrackableService.cs b/server/src/Org.OpenAPITools/Services/TrackableService.cs new file mode 100644 index 0000000..4d37cf6 --- /dev/null +++ b/server/src/Org.OpenAPITools/Services/TrackableService.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Org.OpenAPITools.Models; +using MongoDB.Driver; + +namespace Org.OpenAPITools.Services +{ + public class TrackableService + { + private readonly IMongoCollection _trackables; + + /// + /// + /// + public TrackableService(ITrackableDatabaseSettings settings) + { + var client = new MongoClient(settings.ConnectionString); + var database = client.GetDatabase(settings.DatabaseName); + + _trackables = database.GetCollection(settings.CollectionName); + } + + public List Get() => + _trackables.Find(trackable => true).ToList(); + + public List Get(int limit) => + _trackables.Find(trackable => true).Limit(limit).ToList(); + + public Trackable Get(Guid UID) => + _trackables.Find(trackable => trackable.UID == UID).FirstOrDefault(); + + public Trackable Create(Trackable trackable) + { + _trackables.InsertOne(trackable); + return trackable; + } + + public ReplaceOneResult Update(Guid UID, Trackable trackableIn) => + _trackables.ReplaceOne(trackable => trackable.UID == UID, trackableIn); + + public DeleteResult Remove(Trackable trackableIn) => + _trackables.DeleteOne(trackable => trackable.UID == trackableIn.UID); + + public DeleteResult Remove(Guid UID) => + _trackables.DeleteOne(trackable => trackable.UID == UID); + } +} + diff --git a/server/src/Org.OpenAPITools/Startup.cs b/server/src/Org.OpenAPITools/Startup.cs new file mode 100644 index 0000000..57bf7e3 --- /dev/null +++ b/server/src/Org.OpenAPITools/Startup.cs @@ -0,0 +1,157 @@ +/* + * World Storage API + * + * API ensuring interoperability between an authoring tool and a World Storage service + * + * The version of the OpenAPI document: 0.0.3 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.IO; +using System.Reflection; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.OpenApi.Models; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Serialization; +using Org.OpenAPITools.Authentication; +using Org.OpenAPITools.Filters; +using Org.OpenAPITools.OpenApi; +using Org.OpenAPITools.Formatters; +using Org.OpenAPITools.Services; +using MongoDB.Bson.Serialization; +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Serializers; +using Microsoft.Extensions.Options; + +namespace Org.OpenAPITools +{ + /// + /// Startup + /// + public class Startup + { + /// + /// Constructor + /// + /// + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + /// + /// The application configuration. + /// + public IConfiguration Configuration { get; } + + /// + /// This method gets called by the runtime. Use this method to add services to the container. + /// + /// + public void ConfigureServices(IServiceCollection services) + { + BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard)); + BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3; + // requires using Microsoft.Extensions.Options + services.Configure( + Configuration.GetSection(nameof(TrackableDatabaseSettings))); + services.AddSingleton(sp => + sp.GetRequiredService>().Value); + services.AddSingleton(); + // Add framework services. + services + // Don't need the full MVC stack for an API, see https://andrewlock.net/comparing-startup-between-the-asp-net-core-3-templates/ + .AddControllers(options => + { + options.InputFormatters.Insert(0, new InputFormatterStream()); + }) + .AddNewtonsoftJson(opts => + { + opts.SerializerSettings.ContractResolver = new DefaultContractResolver(); +/* opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + opts.SerializerSettings.Converters.Add(new StringEnumConverter + { + NamingStrategy = new CamelCaseNamingStrategy() + });*/ + }); + + services + .AddSwaggerGen(c => + { + c.SwaggerDoc("0.0.3", new OpenApiInfo + { + Title = "World Storage API", + Description = "World Storage API (ASP.NET Core 3.1)", + TermsOfService = new Uri("https://github.com/openapitools/openapi-generator"), + Contact = new OpenApiContact + { + Name = "OpenAPI-Generator Contributors", + Url = new Uri("https://github.com/openapitools/openapi-generator"), + Email = "" + }, + License = new OpenApiLicense + { + Name = "NoLicense", + Url = new Uri("https://opensource.org/licenses/BSD-3-Clause") + }, + Version = "0.0.3", + }); + c.CustomSchemaIds(type => type.FriendlyId(true)); + c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{Assembly.GetEntryAssembly().GetName().Name}.xml"); + + // Include DataAnnotation attributes on Controller Action parameters as OpenAPI validation rules (e.g required, pattern, ..) + // Use [ValidateModelState] on Actions to actually validate it in C# as well! + c.OperationFilter(); + }); + services + .AddSwaggerGenNewtonsoftSupport(); + } + + /// + /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + /// + /// + /// + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + app.UseHsts(); + } + + app.UseHttpsRedirection(); + app.UseDefaultFiles(); + app.UseStaticFiles(); + app.UseSwagger(c => + { + c.RouteTemplate = "openapi/{documentName}/openapi.json"; + }) + .UseSwaggerUI(c => + { + // set route prefix to openapi, e.g. http://localhost:8080/openapi/index.html + c.RoutePrefix = "openapi"; + //TODO: Either use the SwaggerGen generated OpenAPI contract (generated from C# classes) + c.SwaggerEndpoint("/openapi/0.0.3/openapi.json", "World Storage API"); + + //TODO: Or alternatively use the original OpenAPI contract that's included in the static files + // c.SwaggerEndpoint("/openapi-original.json", "World Storage API Original"); + }); + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/server/src/Org.OpenAPITools/appsettings.json b/server/src/Org.OpenAPITools/appsettings.json new file mode 100644 index 0000000..bed3078 --- /dev/null +++ b/server/src/Org.OpenAPITools/appsettings.json @@ -0,0 +1,13 @@ +{ + "TrackableDatabaseSettings": { + "CollectionName": "Trackables", + "ConnectionString": "mongodb://localhost:27017", + "DatabaseName": "TrackablesDatabase" + }, + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/server/src/Org.OpenAPITools/docker-compose.yml b/server/src/Org.OpenAPITools/docker-compose.yml new file mode 100644 index 0000000..4bf9963 --- /dev/null +++ b/server/src/Org.OpenAPITools/docker-compose.yml @@ -0,0 +1,41 @@ +# Please refer https://aka.ms/HTTPSinContainer on how to setup an https developer certificate for your ASP .NET Core service. + +version: '3.4' + +networks: + vpcbr: + ipam: + config: + - subnet: 10.10.20.0/24 + +services: + worldstorageapi: + image: org.openapitools:latest + volumes: + - ./docker/appsettings.json:/app/appsettings.json:rw + ports: + - 8080:8080 + networks: + vpcbr: + ipv4_address: 10.10.20.101 + restart: unless-stopped + + mongodatabase: + image: mongo:latest + container_name: mongodatabase + environment: + - PUID=1000 + - PGID=1000 + volumes: + - mongodbdata:/data/db:rw + - ./docker/data-dump:/data-dump + ports: + - 27017:27017 + - 28017:28017 + networks: + vpcbr: + ipv4_address: 10.10.20.100 + restart: unless-stopped + +volumes: + mongodbdata: \ No newline at end of file diff --git a/server/src/Org.OpenAPITools/docker/appsettings.json b/server/src/Org.OpenAPITools/docker/appsettings.json new file mode 100644 index 0000000..46ecd9c --- /dev/null +++ b/server/src/Org.OpenAPITools/docker/appsettings.json @@ -0,0 +1,13 @@ +{ + "TrackableDatabaseSettings": { + "CollectionName": "Trackables", + "ConnectionString": "mongodb://10.10.20.100:27017", + "DatabaseName": "TrackablesDatabase" + }, + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} -- GitLab From 27dc7e5f28964af7f8988e44b31fe10e120027f6 Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Thu, 24 Mar 2022 09:05:10 +0100 Subject: [PATCH 04/35] first checkin for version 0.0.4 --- OpenAPI.yaml | 579 +++++++++++++++--- openapitools.json | 2 +- readme.md | 25 +- .../ControllersImpl/DefaultApiImpl.cs | 37 +- .../ControllersImpl/TrackablesApiImpl.cs | 90 +-- .../ControllersImpl/WorldAnchorsApiImpl.cs | 148 +++++ .../ControllersImpl/WorldLinksApiImpl.cs | 163 +++++ .../Services/DatabaseSettings.cs | 25 + .../Services/TrackableDatabaseSettings.cs | 21 - .../Services/TrackableService.cs | 39 +- .../Services/WorldAnchorService.cs | 61 ++ .../Services/WorldLinkService.cs | 63 ++ server/src/Org.OpenAPITools/Startup.cs | 19 +- server/src/Org.OpenAPITools/appsettings.json | 10 +- .../Org.OpenAPITools/docker/appsettings.json | 8 +- 15 files changed, 1110 insertions(+), 180 deletions(-) create mode 100644 server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs create mode 100644 server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs create mode 100644 server/src/Org.OpenAPITools/Services/DatabaseSettings.cs delete mode 100644 server/src/Org.OpenAPITools/Services/TrackableDatabaseSettings.cs create mode 100644 server/src/Org.OpenAPITools/Services/WorldAnchorService.cs create mode 100644 server/src/Org.OpenAPITools/Services/WorldLinkService.cs diff --git a/OpenAPI.yaml b/OpenAPI.yaml index c71f46a..8eef38e 100644 --- a/OpenAPI.yaml +++ b/OpenAPI.yaml @@ -1,6 +1,21 @@ openapi: "3.0.0" +# +# API for the Augmented Reality Framework (ARF) +# Working group: ETSI ISG ARF +# STF group: STF620 (validation) +# (C) ETSI - 2022 +# +# References: +# - Explaination UUID: https://en.wikipedia.org/wiki/Universally_unique_identifier / https://fr.wikipedia.org/wiki/Universally_unique_identifier +# - UUID formats: 8-4-4-4-12 format string, lower case (but case insensitive on input) +# - UUID RFC4122: https://datatracker.ietf.org/doc/html/rfc4122#section-3 +# - Rules for RESTful error code RFC2616: https://datatracker.ietf.org/doc/html/rfc2616#section-10 +# - Guide: https://restfulapi.net/http-status-codes/ +# +# Last Version: 04.03.2022 +# info: - version: 0.0.3 + version: 0.0.4 title: World Storage API description: API ensuring interoperability between an authoring tool and a World Storage service license: @@ -12,155 +27,524 @@ paths: /ping: get: summary: Test the server availability + operationId: getPing responses: '200': - description: OK + description: OK, world storage alive. /admin: get: - summary: Get the version of the API + summary: Get the version of the API. operationId: getVersion responses: '200': - description: OK world storage. + description: OK, world storage ready. content: text/plain: schema: type: string + +############## +# TRACKABLES # +############## /trackables: post: - summary: Create a trackable + summary: Create a trackable. operationId: addTrackable tags: - trackables requestBody: - description: the trackable to be added to the world storage + description: The trackable to be added to the world storage. required: true content: application/json: schema: - $ref: '#/components/schemas/trackable' - application/xml: - schema: - $ref: '#/components/schemas/trackable' + $ref: '#/components/schemas/Trackable' + #application/xml: + # schema: + # $ref: '#/components/schemas/Trackable' responses: '200': - description: OK returns the UUID of the Trackable defined by the world storage. + description: OK, returns the UUID of the Trackable defined by the world storage. content: text/plain: schema: type: string '201': - description: Null response + description: Null response. + '400': + $ref: '#/components/responses/400_BadRequest' + '409': + $ref: '#/components/responses/409_NotEmptyUUID' + 'default': + $ref: '#/components/responses/4xx_UnexpectedError' + get: + summary: Returns the list of all trackables defined by the world storage. + operationId: getTrackables + tags: + - trackables + responses: + '200': + description: OK, returns all the Trackables defined by the world storage. + content: + application/json: + schema: + type : array + items : + $ref: "#/components/schemas/Trackable" + '201': + description: Null response. default: - description: unexpected error + $ref: '#/components/responses/4xx_UnexpectedError' + + /trackables/{trackableUUID}: + get: + summary: Find a trackable by its UUID. + operationId: getTrackableById + tags: + - trackables + parameters: + - name: trackableUUID + in: path + description: UUID of the trackable to retrieve. + required: true + schema: + type: string + format: uuid + responses: + '200': + description: Successful operation. content: application/json: schema: - $ref: '#/components/schemas/Error' + $ref: '#/components/schemas/Trackable' + '400': + $ref: '#/components/responses/400_InvalidUUID' + '404': + $ref: '#/components/responses/404_NotFoundUUID' + delete: + summary: Deletes a trackable. + operationId: deleteTrackable + tags: + - trackables + parameters: + - name: trackableUUID + in: path + description: Trackable UUID to delete. + required: true + schema: + type: string + format: uuid + responses: + '200': + description: OK, delete successful. + '400': + $ref: '#/components/responses/400_InvalidUUID' + '404': + $ref: '#/components/responses/404_NotFoundUUID' + +################# +# WORLD ANCHORS # +################# + /worldAnchors: + post: + summary: Create a world anchor. + operationId: addWorldAnchor + tags: + - world anchors + requestBody: + description: The world anchor to be added to the world storage. + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/WorldAnchor' + #application/xml: + # schema: + # $ref: '#/components/schemas/WorldAnchor' + responses: + '200': + description: OK, returns the UUID of the World Anchor defined by the world storage. + content: + text/plain: + schema: + type: string + '201': + description: Null response. + '400': + $ref: '#/components/responses/400_BadRequest' + '409': + $ref: '#/components/responses/409_NotEmptyUUID' + 'default': + $ref: '#/components/responses/4xx_UnexpectedError' get: - summary: returns the list of all trackables defined by the world storage. - operationId: getTrackables + summary: Returns the list of all world anchors defined by the world storage. + operationId: getWorldAnchors tags: - - trackables + - world anchors responses: - 200: - description: OK returns all the Trackables defined by the world storage. + '200': + description: OK, returns all the world anchors defined by the world storage. content: application/json: schema: type : array items : - $ref: "#/components/schemas/trackable" - 201: - description: Null response + $ref: "#/components/schemas/WorldAnchor" + '201': + description: Null response. default: - description: unexpected error + $ref: '#/components/responses/4xx_UnexpectedError' + + /worldAnchors/{worldAnchorUUID}: + get: + summary: Find a world anchor by its UUID. + operationId: getWorldAnchorById + tags: + - world anchors + parameters: + - name: worldAnchorUUID + in: path + description: UUID of the world anchor to retrieve. + required: true + schema: + type: string + format: uuid + responses: + '200': + description: Successful operation. + content: + application/json: + schema: + $ref: '#/components/schemas/WorldAnchor' + '400': + $ref: '#/components/responses/400_InvalidUUID' + '404': + $ref: '#/components/responses/404_NotFoundUUID' + delete: + summary: Deletes a world anchor. + operationId: deleteWorldAnchor + tags: + - world anchors + parameters: + - name: worldAnchorUUID + in: path + description: World anchor UUID to delete. + required: true + schema: + type: string + format: uuid + responses: + '200': + description: OK, delete successful. + '400': + $ref: '#/components/responses/400_InvalidUUID' + '404': + $ref: '#/components/responses/404_NotFoundUUID' + +############### +# WORLD LINKS # +############### + /worldLinks: + post: + summary: Create a link between world anchors and trackables. + operationId: addWorldLink + tags: + - world links + requestBody: + description: The link to be added to the world storage. + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/WorldLink' + #application/xml: + # schema: + # $ref: '#/components/schemas/WorldLink' + responses: + '200': + description: OK, returns the UUID of the link defined by the world storage. + content: + text/plain: + schema: + type: string + '201': + description: Null response + '400': + $ref: '#/components/responses/400_BadRequest' + '409': + $ref: '#/components/responses/409_NotEmptyUUID' + 'default': + $ref: '#/components/responses/4xx_UnexpectedError' + get: + summary: Returns the list of all links defined by the world storage. + operationId: getWorldLinks + tags: + - world links + responses: + '200': + description: OK returns all the worldLinks defined by the world storage. content: application/json: schema: - $ref: "#/components/schemas/Error" - /trackables/{trackableId}: + type : array + items : + $ref: "#/components/schemas/WorldLink" + '201': + description: Null response + default: + $ref: '#/components/responses/4xx_UnexpectedError' + + /worldLinks/{worldLinkUUID}: get: - summary: Find a trackable by his ID - operationId: getTrackableById + summary: Find a link by its UUID. + operationId: getWorldLinkById tags: - - trackables + - world links parameters: - - name: trackableId + - name: worldLinkUUID in: path - description: ID of the trackable to retrieve + description: UUID of the link to retrieve. required: true schema: type: string + format: uuid responses: '200': - description: "successful operation" + description: Successful operation. content: application/json: schema: - $ref: '#/components/schemas/trackable' + $ref: '#/components/schemas/WorldLink' '400': - description: "Invalid ID supplied" + $ref: '#/components/responses/400_InvalidUUID' '404': - description: "Trackable not found" + $ref: '#/components/responses/404_NotFoundUUID' delete: - summary: Deletes a trackable - operationId: deleteTrackable + summary: Deletes a worldLink. + operationId: deleteWorldLink tags: - - trackables + - world links parameters: - - name: trackableId + - name: worldLinkUUID in: path - description: trackable id to delete + description: link id to delete required: true schema: type: string + format: uuid responses: '200': description: OK '400': - description: Invalid ID supplied + $ref: '#/components/responses/400_InvalidUUID' + '404': + $ref: '#/components/responses/404_NotFoundUUID' + + /worldLinks/attached/{worldLinkUUID}: + get: + summary: Retrieve end objects connected to this world link by its UUID. + operationId: getAttachedObjectsFromUUID + tags: + - world links + parameters: + - name: worldLinkUUID + in: path + description: UUID of the link from which you will retrieve the end objects. + required: true + schema: + type: string + format: uuid + responses: + '200': + description: Successful operation. + content: + application/json: + schema: + $ref: '#/components/schemas/AttachedObjects' + '400': + $ref: '#/components/responses/400_InvalidUUID' '404': - description: trackable not found + $ref: '#/components/responses/404_NotFoundUUID' + +# COMPONENTS ############################################### components: + #------------------------------- + # Reusable operation parameters + #------------------------------- + parameters: + UUIDParams: + name: UUID + in: path + required: true + description: A Universally Unique IDentifier identifying the object + schema: + type: string + format: uuid + default: "00000000-0000-0000-0000-000000000000" + + #------------------------------- + # Reusable schemas (data models) + #------------------------------- schemas: - trackable: + Trackable: type: object required: - - UID - - creatorUID + - creatorUUID - trackableType - trackableEncodingInformation - trackablePayload - - unitSystem - - trackableDimension + - localCRS + - unit + - trackableSize - keyvalueTagList properties: - UID: - description: A Universally Unique IDentifier identifying the trackable + UUID: + description: A Universally Unique IDentifier identifying the trackable (RFC 4122). type: string format: uuid - example: c75f6324-77a0-11ec-90d6-0242ac120001 - creatorUID: - description: A Universally Unique IDentifier identifying the creator of the trackable + example: fa8bbe40-8052-11ec-a8a3-0242ac120002 + creatorUUID: + description: A Universally Unique IDentifier identifying the creator of the trackable (a person, a team or a company). type: string format: uuid example: c75f6324-77a0-11ec-90d6-0242ac120003 trackableType: - description: Extensible list of trackable types possibly handled by complient World Storage implementation + description: Extensible list of trackable types possibly handled by complient World Storage implementation. type: string enum: [FIDUCIAL_MARKER, IMAGE_MARKER, MAP, OTHER] example: FIDUCIAL_MARKER trackableEncodingInformation: - description: Identifies targeted framework and version of the format. - $ref: '#/components/schemas/encodingInformationStructure' + $ref: '#/components/schemas/EncodingInformationStructure' trackablePayload: description: The data provided to create the trackable in a specific format handled by the World Storage service. type: string format: byte example: "10110101" localCRS: - description: Coordinate reference system of the trackable, a 4*4 matrix (rowmajor) represented by a float vector + $ref: '#/components/schemas/Transform3D' + unit: + $ref: '#/components/schemas/UnitSystem' + trackableSize: + $ref: '#/components/schemas/Size' + keyvalueTags: + $ref: '#/components/schemas/KeyvalueTagList' + + WorldAnchor: + type: object + required: + - creatorUUID + - localCRS + - unit + - worldAnchorSize + - keyvalueTagList + properties: + UUID: + description: A Universally Unique IDentifier identifying the world anchor (RFC 4122). + type: string + format: uuid + example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 + creatorUUID: + description: A Universally Unique IDentifier identifying the creator of the world anchor. + type: string + format: uuid + example: c75f6324-77a0-11ec-90d6-0242ac120003 + localCRS: + $ref: '#/components/schemas/Transform3D' + unit: + $ref: '#/components/schemas/UnitSystem' + worldAnchorSize: + $ref: '#/components/schemas/Size' + keyvalueTags: + $ref: '#/components/schemas/KeyvalueTagList' + + WorldLink: + type: object + required: + - creatorUUID + - UUIDFrom + - UUIDTo + - transform + - unit + - linkSize + - keyvalueTags + properties: + UUID: + description: A Universally Unique IDentifier identifying the link (RFC 4122). + type: string + format: uuid + example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 + creatorUUID: + description: A Universally Unique IDentifier identifying the creator of the link. + type: string + format: uuid + example: c75f6324-77a0-11ec-90d6-0242ac120003 + UUIDFrom: + description: A Universally Unique IDentifier identifying a world anchor or trackable. + type: string + format: uuid + example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 + UUIDTo: + description: A Universally Unique IDentifier identifying a world anchor or trackable. + type: string + format: uuid + example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 + transform: + $ref: '#/components/schemas/Transform3D' + unit: + $ref: '#/components/schemas/UnitSystem' + linkSize: + $ref: '#/components/schemas/Size' + keyvalueTags: + description: List of additional parameters to be stored + $ref: '#/components/schemas/KeyvalueTagList' + example: { "LinkType" : ["Hierarchy"]} + + AttachedObjects: + type: object + required: + - UUID + - UUIDFrom + - UUIDTo + - TypeFrom + - TypeTo + properties: + UUID: + description: A Universally Unique IDentifier identifying the link. + type: string + format: uuid + example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 + UUIDFrom: + description: A Universally Unique IDentifier identifying a world anchor or trackable. + type: string + format: uuid + example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 + UUIDTo: + description: A Universally Unique IDentifier identifying a world anchor or trackable. + type: string + format: uuid + example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 + TypeFrom: + $ref: '#/components/schemas/ObjectType' + TypeTo: + $ref: '#/components/schemas/ObjectType' + + EncodingInformationStructure: + required: + - dataFormat + - version + properties: + dataFormat: + description: Identifier of the target framework + type: string + enum: [HOLOLENS, ARKIT, ARCORE] + example : "HOLOLENS" + version: + description: The version of the format + type: string + example : "1.01" + + Transform3D: + description: Coordinate reference system of the world anchor, a 4*4 matrix (rowmajor) represented by a float vector type: array minItems: 16 maxItems: 16 @@ -171,13 +555,21 @@ components: 4, 4, 4, 2, 1, 0, -2, 1, -1, -2, 0, 0] - unitSystem: - description: Unit of length + + ObjectType: + description: Type of an world representaion object. + type: string + enum: [Trackable, WorldAnchor, WorldLink] + example: Trackable + + UnitSystem: + description: Unit of length. type: string enum: [MM, CM, DM, M, DAM, HM, KM, INCH, FOOT, YARD, MILE] example: M - trackableDimension: - description: Bounding box of the Trackable, {width, length, 0} for 2D trackables, {width, length, depth} for 3D trackables + + Size: + description: Size {width, length, depth}. type: array items: type: number @@ -185,7 +577,8 @@ components: minItems: 3 maxItems: 3 example: [1,5,0] - keyvalueTagList: + + KeyvalueTagList: description: List of additional parameters to be stored with the trackable. type: object additionalProperties: @@ -193,21 +586,8 @@ components: items: type: string minItems: 1 - example: { "author" : ["james","donovan"], "image" : ["skater"]} - encodingInformationStructure: - required: - - dataFormat - - version - properties: - dataFormat: - description: Identifier of the target framework - type: string - enum: [HOLOLENS, ARKIT, ARCORE] - example : "HOLOLENS" - version: - description: The version of the format - type: string - example : "1.01" + example: { "Place" : ["Museum 1"], "room" : ["B4"]} + Error: required: - code @@ -217,4 +597,51 @@ components: type: integer format: int32 message: - type: string \ No newline at end of file + type: string + #------------------------------- + # Reusable responses + #------------------------------- + responses: + ####################### + # 1xx : Informational # + ####################### + + ################# + # 2xx : Success # + ################# + + ##################### + # 3xx : Redirection # + ##################### + + ####################### + # 4xx : Client Errors # + ####################### + 400_BadRequest: + description: Bad request. + + 400_InvalidUUID: + description: Invalid UUID supplied. + + 404_NotFoundUUID: + description: Not found, could not find UUID in database. + + 409_NotEmptyUUID: + description: Invalid UUID, id must be a Nil value. + + 4xx_UnexpectedError: # Can be referenced as '#/components/responses/GenericError' + description: Unexpected error. + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + ######################## + # 5xx : Server Errors # + ######################## + 5xx_UnexpectedError: + description: Unexpected server error. + content: + application/json: + schema: + $ref: '#/components/schemas/Error' diff --git a/openapitools.json b/openapitools.json index 2774f45..3b40e47 100644 --- a/openapitools.json +++ b/openapitools.json @@ -2,6 +2,6 @@ "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json", "spaces": 2, "generator-cli": { - "version": "5.3.1" + "version": "5.3.0" } } diff --git a/readme.md b/readme.md index 8ceacee..c6b0ba7 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# Description of version 0.0.3 +# Description of version 0.0.4 auto-generated ASP.NET server code @@ -36,6 +36,25 @@ compare files in "`ControllersImpl`" with the corresponding files in "`Controlle methods should be the same with "`override`" instead of "`virtual`" +#### - if files are missing: +copy them from folder `Controllers`, rename them (append `Impl`) and handle them like the already existing files, i.e.: +change classnames by appending `Impl` to the original classnames (and change filenames accordingly) and inherit from original class in `Controllers` (instead of `ControllerBase`) + +and replace `virtual` by `override` with all methods. + +Add +``` + using Org.OpenAPITools.Services; + using MongoDB.Driver; +``` + +Add a private readonly service class variable like in the already existing files + +Add a constructor with this service class variable like in the already existing files + +remove sample code and replace it by using the appropriate methods of the corresponding classes in the folder `Services` +(which you may be have to create) + ### - folder `Models`: add: ``` @@ -49,6 +68,10 @@ at the value that is to become the MongoDB ID, add: [BsonRepresentation(BsonType.String)] ``` +### - folder `Services` +the folder `Services` should contain one common class with the DatabaseSettings (`DatabaseSettings.cs`) and one with the database-access-methods (create, get, update, remove) for each API. If some are missing create them like the ones you find there. Be aware to add the reference to these in the file `startup.cs` in this case. + +the naming in the DatabaseSettings is the same as defined in `appsettings.json`, which you have to extend when creating new classes in this folder. changed `appsettings.json` in the folder `docker` accordingly. Make sure that the ConnectionString for the database contains the correct IP address as specified in `docker-compose.yml`. # MongoDB if you don't have a MongoDB, follow the instructions in `readme.txt` in `server/programs/MongoDB` diff --git a/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs index ec72c77..6476543 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.3 + * The version of the OpenAPI document: 0.0.4 * * Generated by: https://openapi-generator.tech */ @@ -30,34 +30,35 @@ namespace Org.OpenAPITools.Controllers public class DefaultApiControllerImpl : DefaultApiController { /// - /// Get the version of the API + /// Test the server availability /// - /// OK world storage. + /// OK, world storage alive. [HttpGet] - [Route("/admin")] + [Route("/ping")] [ValidateModelState] - [SwaggerOperation("GetVersion")] - [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK world storage.")] - public override IActionResult GetVersion() + [SwaggerOperation("GetPing")] + public override IActionResult GetPing() { - string version = "world storage 0.0.3"; - return new ObjectResult(version); - //return StatusCode(200, new ObjectResult(version)); + string answer = "OK, world storage alive."; + return new ObjectResult(answer); + // return StatusCode(200, new ObjectResult(answer)); } /// - /// Test the server availability + /// Get the version of the API. /// - /// OK + /// OK, world storage ready. [HttpGet] - [Route("/ping")] + [Route("/admin")] [ValidateModelState] - [SwaggerOperation("PingGet")] - public override IActionResult PingGet() + [SwaggerOperation("GetVersion")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, world storage ready.")] + public override IActionResult GetVersion() { - string answer = "pong"; - return new ObjectResult(answer); -// return StatusCode(200, new ObjectResult(answer)); + string version = "OK world storage 0.0.4 ready"; + return new ObjectResult(version); + //return StatusCode(200, new ObjectResult(version)); } + } } diff --git a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs index a27b4e0..d4be291 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.3 + * The version of the OpenAPI document: 0.0.4 * * Generated by: https://openapi-generator.tech */ @@ -45,80 +45,100 @@ namespace Org.OpenAPITools.Controllers /// /// Create a trackable /// - /// the trackable to be added to the world storage - /// OK returns the UUID of the Trackable defined by the world storage. - /// Null response - /// unexpected error + /// The trackable to be added to the world storage. + /// OK, returns the UUID of the Trackable defined by the world storage. + /// Null response. + /// Bad request. + /// Invalid UUID, id must be a Nil value. + /// Unexpected error. [HttpPost] [Route("/trackables")] - [Consumes("application/json", "application/xml")] + [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("AddTrackable")] - [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK returns the UUID of the Trackable defined by the world storage.")] - [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "unexpected error")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, returns the UUID of the Trackable defined by the world storage.")] + [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] public override IActionResult AddTrackable([FromBody] Trackable trackable) { - if (String.IsNullOrEmpty(trackable.UID.ToString())) + if (String.IsNullOrEmpty(trackable.UUID.ToString())) { - trackable.UID = Guid.NewGuid(); + trackable.UUID = Guid.NewGuid(); } try { Trackable mytrackable = _trackableService.Create(trackable); return new ObjectResult(mytrackable); - } catch (Exception e) + } + catch (Exception e) { return StatusCode(400, e.Message); } } /// - /// Deletes a trackable + /// Deletes a trackable. /// - /// trackable id to delete - /// OK - /// Invalid ID supplied - /// trackable not found + /// Trackable UUID to delete. + /// OK, delete successful. + /// Invalid UUID supplied. + /// Not found, could not find UUID in database. [HttpDelete] - [Route("/trackables/{trackableId}")] + [Route("/trackables/{trackableUUID}")] [ValidateModelState] [SwaggerOperation("DeleteTrackable")] - public override IActionResult DeleteTrackable([FromRoute(Name = "trackableId")][Required] string trackableId) + public override IActionResult DeleteTrackable([FromRoute(Name = "trackableUUID")][Required] Guid trackableUUID) + { + DeleteResult answer = _trackableService.Remove(trackableUUID); + // check, if used in WorldLink + string result = "ok"; + string worldlinkinfo = ""; + List worldlinklistfrom = _trackableService.GetWorldLinkUUIDFrom(trackableUUID); + List worldlinklistto = _trackableService.GetWorldLinkUUIDTo(trackableUUID); + foreach(WorldLink worldlink in worldlinklistfrom) + { + worldlinkinfo += worldlink.UUID.ToString() + "; "; + } + foreach (WorldLink worldlink in worldlinklistto) { - DeleteResult answer = _trackableService.Remove(Guid.Parse(trackableId)); - return (answer.IsAcknowledged && answer.DeletedCount > 0) ? new ObjectResult("ok") : new ObjectResult("failed"); + worldlinkinfo += worldlink.UUID.ToString() + "; "; + } + if (worldlinkinfo.Length > 1) + { + result += ", but removed object is still referenced in " + worldlinkinfo; + } + return (answer.IsAcknowledged && answer.DeletedCount > 0) ? new ObjectResult(result) : StatusCode(404, "Not found, could not find UUID in database."); } /// - /// Find a trackable by his ID + /// Find a trackable by its UUID. /// - /// ID of the trackable to retrieve - /// successful operation - /// Invalid ID supplied - /// Trackable not found + /// UUID of the trackable to retrieve. + /// Successful operation. + /// Invalid UUID supplied. + /// Not found, could not find UUID in database. [HttpGet] - [Route("/trackables/{trackableId}")] + [Route("/trackables/{trackableUUID}")] [ValidateModelState] [SwaggerOperation("GetTrackableById")] - [SwaggerResponse(statusCode: 200, type: typeof(Trackable), description: "successful operation")] - public override IActionResult GetTrackableById([FromRoute(Name = "trackableId")][Required] string trackableId) + [SwaggerResponse(statusCode: 200, type: typeof(Trackable), description: "Successful operation.")] + public override IActionResult GetTrackableById([FromRoute(Name = "trackableUUID")][Required] Guid trackableUUID) { - Trackable trackable = _trackableService.Get(Guid.Parse(trackableId)); - return (null != trackable) ? new ObjectResult(trackable) : new ObjectResult("not found"); + Trackable trackable = _trackableService.Get(trackableUUID); + return (null != trackable) ? new ObjectResult(trackable) : StatusCode(404, "Not found, could not find UUID in database."); } /// /// returns the list of all trackables defined by the world storage. /// - /// OK returns all the Trackables defined by the world storage. - /// Null response - /// unexpected error + /// OK, returns all the Trackables defined by the world storage. + /// Null response. + /// Unexpected error. [HttpGet] [Route("/trackables")] [ValidateModelState] [SwaggerOperation("GetTrackables")] - [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK returns all the Trackables defined by the world storage.")] - [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "unexpected error")] + [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK, returns all the Trackables defined by the world storage.")] + [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] public override IActionResult GetTrackables() { List trackablelist = _trackableService.Get(); diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs new file mode 100644 index 0000000..e557fce --- /dev/null +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs @@ -0,0 +1,148 @@ +/* + * World Storage API + * + * API ensuring interoperability between an authoring tool and a World Storage service + * + * The version of the OpenAPI document: 0.0.4 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Http; +using Swashbuckle.AspNetCore.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using Newtonsoft.Json; +using Org.OpenAPITools.Attributes; +using Org.OpenAPITools.Models; +using Org.OpenAPITools.Services; +using MongoDB.Driver; + +namespace Org.OpenAPITools.Controllers +{ + /// + /// + /// + [ApiController] + public class WorldAnchorsApiControllerImpl : WorldAnchorsApiController + { + + private readonly WorldAnchorService _worldAnchorService; + + /// + /// + /// + public WorldAnchorsApiControllerImpl(WorldAnchorService worldAnchorService) + { + _worldAnchorService = worldAnchorService; + } + + + /// + /// Create a world anchor. + /// + /// The world anchor to be added to the world storage. + /// OK, returns the UUID of the World Anchor defined by the world storage. + /// Null response. + /// Bad request. + /// Invalid UUID, id must be a Nil value. + /// Unexpected error. + [HttpPost] + [Route("/worldAnchors")] + [Consumes("application/json")] + [ValidateModelState] + [SwaggerOperation("AddWorldAnchor")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, returns the UUID of the World Anchor defined by the world storage.")] + [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] + public override IActionResult AddWorldAnchor([FromBody] WorldAnchor worldAnchor) + { + if (String.IsNullOrEmpty(worldAnchor.UUID.ToString())) + { + worldAnchor.UUID = Guid.NewGuid(); + } + try + { + WorldAnchor myworldanchor = _worldAnchorService.Create(worldAnchor); + return new ObjectResult(myworldanchor); + } + catch (Exception e) + { + return StatusCode(400, e.Message); + } + } + + /// + /// Deletes a world anchor. + /// + /// World anchor UUID to delete. + /// OK, delete successful. + /// Invalid UUID supplied. + /// Not found, could not find UUID in database. + [HttpDelete] + [Route("/worldAnchors/{worldAnchorUUID}")] + [ValidateModelState] + [SwaggerOperation("DeleteWorldAnchor")] + public override IActionResult DeleteWorldAnchor([FromRoute(Name = "worldAnchorUUID")][Required] Guid worldAnchorUUID) + { + DeleteResult answer = _worldAnchorService.Remove((worldAnchorUUID)); + // check, if used in WorldLink + string result = "ok"; + string worldlinkinfo = ""; + List worldlinklistfrom = _worldAnchorService.GetWorldLinkUUIDFrom(worldAnchorUUID); + List worldlinklistto = _worldAnchorService.GetWorldLinkUUIDTo(worldAnchorUUID); + foreach (WorldLink worldlink in worldlinklistfrom) + { + worldlinkinfo += worldlink.UUID.ToString() + "; "; + } + foreach (WorldLink worldlink in worldlinklistto) + { + worldlinkinfo += worldlink.UUID.ToString() + "; "; + } + if (worldlinkinfo.Length > 1) + { + result += ", but removed object is still referenced in " + worldlinkinfo; + } + return (answer.IsAcknowledged && answer.DeletedCount > 0) ? new ObjectResult(result) : StatusCode(404, "Not found, could not find UUID in database."); + } + + /// + /// Find a world anchor by its UUID. + /// + /// UUID of the world anchor to retrieve. + /// Successful operation. + /// Invalid UUID supplied. + /// Not found, could not find UUID in database. + [HttpGet] + [Route("/worldAnchors/{worldAnchorUUID}")] + [ValidateModelState] + [SwaggerOperation("GetWorldAnchorById")] + [SwaggerResponse(statusCode: 200, type: typeof(WorldAnchor), description: "Successful operation.")] + public override IActionResult GetWorldAnchorById([FromRoute(Name = "worldAnchorUUID")][Required] Guid worldAnchorUUID) + { + WorldAnchor myworldanchor = _worldAnchorService.Get(worldAnchorUUID); + return (null != myworldanchor) ? new ObjectResult(myworldanchor) : StatusCode(404, "Not found, could not find UUID in database."); + } + + /// + /// Returns the list of all world anchors defined by the world storage. + /// + /// OK, returns all the world anchors defined by the world storage. + /// Null response. + /// Unexpected error. + [HttpGet] + [Route("/worldAnchors")] + [ValidateModelState] + [SwaggerOperation("GetWorldAnchors")] + [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK, returns all the world anchors defined by the world storage.")] + [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] + public override IActionResult GetWorldAnchors() + { + List worldanchorlist = _worldAnchorService.Get(); + return new ObjectResult(worldanchorlist); + } + } +} diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs new file mode 100644 index 0000000..10731c6 --- /dev/null +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs @@ -0,0 +1,163 @@ +/* + * World Storage API + * + * API ensuring interoperability between an authoring tool and a World Storage service + * + * The version of the OpenAPI document: 0.0.4 + * + * Generated by: https://openapi-generator.tech + */ + +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Http; +using Swashbuckle.AspNetCore.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using Newtonsoft.Json; +using Org.OpenAPITools.Attributes; +using Org.OpenAPITools.Models; +using Org.OpenAPITools.Services; +using MongoDB.Driver; + +namespace Org.OpenAPITools.Controllers +{ + /// + /// + /// + [ApiController] + public class WorldLinksApiControllerImpl : WorldLinksApiController + { + + private readonly WorldLinkService _worldLinkService; + + /// + /// + /// + public WorldLinksApiControllerImpl(WorldLinkService worldLinkService) + { + _worldLinkService = worldLinkService; + } + + /// + /// Create a link between world anchors and trackables. + /// + /// The link to be added to the world storage. + /// OK, returns the UUID of the link defined by the world storage. + /// Null response + /// Bad request. + /// Invalid UUID, id must be a Nil value. + /// Unexpected error. + [HttpPost] + [Route("/worldLinks")] + [Consumes("application/json")] + [ValidateModelState] + [SwaggerOperation("AddWorldLink")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, returns the UUID of the link defined by the world storage.")] + [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] + public override IActionResult AddWorldLink([FromBody] WorldLink worldLink) + { + if (String.IsNullOrEmpty(worldLink.UUID.ToString())) + { + worldLink.UUID = Guid.NewGuid(); + } + try + { + WorldLink myworldlink = _worldLinkService.Create(worldLink); + return new ObjectResult(myworldlink); + } + catch (Exception e) + { + return StatusCode(400, e.Message); + } + } + + /// + /// Deletes a worldLink. + /// + /// link id to delete + /// OK + /// Invalid UUID supplied. + /// Not found, could not find UUID in database. + [HttpDelete] + [Route("/worldLinks/{worldLinkUUID}")] + [ValidateModelState] + [SwaggerOperation("DeleteWorldLink")] + public override IActionResult DeleteWorldLink([FromRoute(Name = "worldLinkUUID")][Required] Guid worldLinkUUID) + { + DeleteResult answer = _worldLinkService.Remove((worldLinkUUID)); + return (answer.IsAcknowledged && answer.DeletedCount > 0) ? new ObjectResult("ok") : StatusCode(404, "Not found, could not find UUID in database."); + } + + /// + /// Retrieve end objects connected to this world link by its UUID. + /// + /// UUID of the link from which you will retrieve the end objects. + /// Successful operation. + /// Invalid UUID supplied. + /// Not found, could not find UUID in database. + [HttpGet] + [Route("/worldLinks/attached/{worldLinkUUID}")] + [ValidateModelState] + [SwaggerOperation("GetAttachedObjectsFromUUID")] + [SwaggerResponse(statusCode: 200, type: typeof(AttachedObjects), description: "Successful operation.")] + public override IActionResult GetAttachedObjectsFromUUID([FromRoute(Name = "worldLinkUUID")][Required] Guid worldLinkUUID) + { + WorldLink myworldlink = _worldLinkService.Get(worldLinkUUID); + if (null == myworldlink) + { + return StatusCode(404, "not found, could not find UUID in database"); + } + AttachedObjects attachedobjects = new AttachedObjects(); + attachedobjects.UUID = myworldlink.UUID; + attachedobjects.UUIDFrom = myworldlink.UUIDFrom; + attachedobjects.UUIDTo = myworldlink.UUIDTo; + if (null != _worldLinkService.Get(attachedobjects.UUIDFrom)) attachedobjects.TypeFrom = ObjectType.WorldLinkEnum; + if (null != _worldLinkService.GetAnchor(attachedobjects.UUIDFrom)) attachedobjects.TypeFrom = ObjectType.WorldAnchorEnum; + if (null != _worldLinkService.GetTrackable(attachedobjects.UUIDFrom)) attachedobjects.TypeFrom = ObjectType.TrackableEnum; + if (null != _worldLinkService.Get(attachedobjects.UUIDTo)) attachedobjects.TypeTo = ObjectType.WorldLinkEnum; + if (null != _worldLinkService.GetAnchor(attachedobjects.UUIDTo)) attachedobjects.TypeTo = ObjectType.WorldAnchorEnum; + if (null != _worldLinkService.GetTrackable(attachedobjects.UUIDTo)) attachedobjects.TypeTo = ObjectType.TrackableEnum; + + return new ObjectResult(attachedobjects); + } + + /// + /// Find a link by its UUID. + /// + /// UUID of the link to retrieve. + /// Successful operation. + /// Invalid UUID supplied. + /// Not found, could not find UUID in database. + [HttpGet] + [Route("/worldLinks/{worldLinkUUID}")] + [ValidateModelState] + [SwaggerOperation("GetWorldLinkById")] + [SwaggerResponse(statusCode: 200, type: typeof(WorldLink), description: "Successful operation.")] + public override IActionResult GetWorldLinkById([FromRoute(Name = "worldLinkUUID")][Required] Guid worldLinkUUID) + { + WorldLink myworldlink = _worldLinkService.Get(worldLinkUUID); + return (null != myworldlink) ? new ObjectResult(myworldlink) : StatusCode(404, "Not found, could not find UUID in database."); + } + + /// + /// Returns the list of all links defined by the world storage. + /// + /// OK returns all the worldLinks defined by the world storage. + /// Null response + /// Unexpected error. + [HttpGet] + [Route("/worldLinks")] + [ValidateModelState] + [SwaggerOperation("GetWorldLinks")] + [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK returns all the worldLinks defined by the world storage.")] + [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] + public override IActionResult GetWorldLinks() + { + List worldlinklist = _worldLinkService.Get(); + return new ObjectResult(worldlinklist); + } + } +} diff --git a/server/src/Org.OpenAPITools/Services/DatabaseSettings.cs b/server/src/Org.OpenAPITools/Services/DatabaseSettings.cs new file mode 100644 index 0000000..336639b --- /dev/null +++ b/server/src/Org.OpenAPITools/Services/DatabaseSettings.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Org.OpenAPITools.Services +{ + public class DatabaseSettings : IDatabaseSettings + { + public string CollectionNameWorldLink { get; set; } + public string CollectionNameTrackables { get; set; } + public string CollectionNameWorldAnchor { get; set; } + public string ConnectionString { get; set; } + public string DatabaseName { get; set; } + } + + public interface IDatabaseSettings + { + string CollectionNameWorldLink { get; set; } + string CollectionNameTrackables { get; set; } + string CollectionNameWorldAnchor { get; set; } + string ConnectionString { get; set; } + string DatabaseName { get; set; } + } +} \ No newline at end of file diff --git a/server/src/Org.OpenAPITools/Services/TrackableDatabaseSettings.cs b/server/src/Org.OpenAPITools/Services/TrackableDatabaseSettings.cs deleted file mode 100644 index 70b4cdc..0000000 --- a/server/src/Org.OpenAPITools/Services/TrackableDatabaseSettings.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Org.OpenAPITools.Services -{ - public class TrackableDatabaseSettings : ITrackableDatabaseSettings - { - public string CollectionName { get; set; } - public string ConnectionString { get; set; } - public string DatabaseName { get; set; } - } - - public interface ITrackableDatabaseSettings - { - string CollectionName { get; set; } - string ConnectionString { get; set; } - string DatabaseName { get; set; } - } -} diff --git a/server/src/Org.OpenAPITools/Services/TrackableService.cs b/server/src/Org.OpenAPITools/Services/TrackableService.cs index 4d37cf6..4fc12b2 100644 --- a/server/src/Org.OpenAPITools/Services/TrackableService.cs +++ b/server/src/Org.OpenAPITools/Services/TrackableService.cs @@ -9,42 +9,55 @@ namespace Org.OpenAPITools.Services { public class TrackableService { - private readonly IMongoCollection _trackables; + private readonly IMongoCollection _trackablecollection; + private readonly IMongoCollection _worldlinkcollection; /// /// /// - public TrackableService(ITrackableDatabaseSettings settings) + public TrackableService(IDatabaseSettings settings) { var client = new MongoClient(settings.ConnectionString); var database = client.GetDatabase(settings.DatabaseName); - _trackables = database.GetCollection(settings.CollectionName); + _trackablecollection = database.GetCollection(settings.CollectionNameTrackables); + _worldlinkcollection = database.GetCollection(settings.CollectionNameWorldLink); } public List Get() => - _trackables.Find(trackable => true).ToList(); + _trackablecollection.Find(trackable => true).ToList(); public List Get(int limit) => - _trackables.Find(trackable => true).Limit(limit).ToList(); + _trackablecollection.Find(trackable => true).Limit(limit).ToList(); - public Trackable Get(Guid UID) => - _trackables.Find(trackable => trackable.UID == UID).FirstOrDefault(); + public Trackable Get(Guid UUID) => + _trackablecollection.Find(trackable => trackable.UUID == UUID).FirstOrDefault(); public Trackable Create(Trackable trackable) { - _trackables.InsertOne(trackable); + _trackablecollection.InsertOne(trackable); return trackable; } - public ReplaceOneResult Update(Guid UID, Trackable trackableIn) => - _trackables.ReplaceOne(trackable => trackable.UID == UID, trackableIn); + public ReplaceOneResult Update(Guid UUID, Trackable trackableIn) => + _trackablecollection.ReplaceOne(trackable => trackable.UUID == UUID, trackableIn); public DeleteResult Remove(Trackable trackableIn) => - _trackables.DeleteOne(trackable => trackable.UID == trackableIn.UID); + _trackablecollection.DeleteOne(trackable => trackable.UUID == trackableIn.UUID); + + public DeleteResult Remove(Guid UUID) => + _trackablecollection.DeleteOne(trackable => trackable.UUID == UUID); + + + + /* WorldLink */ + public List GetWorldLinkUUIDFrom(Guid UUID) => + _worldlinkcollection.Find(worldlink => worldlink.UUIDFrom == UUID).ToList(); + + public List GetWorldLinkUUIDTo(Guid UUID) => + _worldlinkcollection.Find(worldlink => worldlink.UUIDTo == UUID).ToList(); - public DeleteResult Remove(Guid UID) => - _trackables.DeleteOne(trackable => trackable.UID == UID); } + } diff --git a/server/src/Org.OpenAPITools/Services/WorldAnchorService.cs b/server/src/Org.OpenAPITools/Services/WorldAnchorService.cs new file mode 100644 index 0000000..a7c9da3 --- /dev/null +++ b/server/src/Org.OpenAPITools/Services/WorldAnchorService.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Org.OpenAPITools.Models; +using MongoDB.Driver; + +namespace Org.OpenAPITools.Services +{ + public class WorldAnchorService + { + private readonly IMongoCollection _worldanchorcollection; + private readonly IMongoCollection _worldlinkcollection; + + /// + /// + /// + public WorldAnchorService(IDatabaseSettings settings) + { + var client = new MongoClient(settings.ConnectionString); + var database = client.GetDatabase(settings.DatabaseName); + + _worldanchorcollection = database.GetCollection(settings.CollectionNameWorldAnchor); + _worldlinkcollection = database.GetCollection(settings.CollectionNameWorldLink); + } + + public List Get() => + _worldanchorcollection.Find(worldanchor => true).ToList(); + + public List Get(int limit) => + _worldanchorcollection.Find(worldanchor => true).Limit(limit).ToList(); + + public WorldAnchor Get(Guid UUID) => + _worldanchorcollection.Find(worldanchor => worldanchor.UUID == UUID).FirstOrDefault(); + + public WorldAnchor Create(WorldAnchor worldanchor) + { + _worldanchorcollection.InsertOne(worldanchor); + return worldanchor; + } + + public ReplaceOneResult Update(Guid UUID, WorldAnchor worldanchorIn) => + _worldanchorcollection.ReplaceOne(worldanchor => worldanchor.UUID == UUID, worldanchorIn); + + public DeleteResult Remove(WorldAnchor worldanchorIn) => + _worldanchorcollection.DeleteOne(worldanchor => worldanchor.UUID == worldanchorIn.UUID); + + public DeleteResult Remove(Guid UUID) => + _worldanchorcollection.DeleteOne(worldanchor => worldanchor.UUID == UUID); + + + /* WorldLink */ + public List GetWorldLinkUUIDFrom(Guid UUID) => + _worldlinkcollection.Find(worldlink => worldlink.UUIDFrom == UUID).ToList(); + + public List GetWorldLinkUUIDTo(Guid UUID) => + _worldlinkcollection.Find(worldlink => worldlink.UUIDTo == UUID).ToList(); + } + +} + diff --git a/server/src/Org.OpenAPITools/Services/WorldLinkService.cs b/server/src/Org.OpenAPITools/Services/WorldLinkService.cs new file mode 100644 index 0000000..1df2aa9 --- /dev/null +++ b/server/src/Org.OpenAPITools/Services/WorldLinkService.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Org.OpenAPITools.Models; +using MongoDB.Driver; + +namespace Org.OpenAPITools.Services +{ + public class WorldLinkService + { + private readonly IMongoCollection _worldlinkcollection; + private readonly IMongoCollection _worldanchorcollection; + private readonly IMongoCollection _trackablecollection; + + /// + /// + /// + public WorldLinkService(IDatabaseSettings settings) + { + var client = new MongoClient(settings.ConnectionString); + var database = client.GetDatabase(settings.DatabaseName); + + _worldlinkcollection = database.GetCollection(settings.CollectionNameWorldLink); + _worldanchorcollection = database.GetCollection(settings.CollectionNameWorldAnchor); + _trackablecollection = database.GetCollection(settings.CollectionNameTrackables); + } + + public List Get() => + _worldlinkcollection.Find(worldlink => true).ToList(); + + public List Get(int limit) => + _worldlinkcollection.Find(worldlink => true).Limit(limit).ToList(); + + public WorldLink Get(Guid UUID) => + _worldlinkcollection.Find(worldlink => worldlink.UUID == UUID).FirstOrDefault(); + + public WorldLink Create(WorldLink worldlink) + { + _worldlinkcollection.InsertOne(worldlink); + return worldlink; + } + + public ReplaceOneResult Update(Guid UUID, WorldLink worldlinkIn) => + _worldlinkcollection.ReplaceOne(worldlink => worldlink.UUID == UUID, worldlinkIn); + + public DeleteResult Remove(WorldLink worldlinkIn) => + _worldlinkcollection.DeleteOne(worldlink => worldlink.UUID == worldlinkIn.UUID); + + public DeleteResult Remove(Guid UUID) => + _worldlinkcollection.DeleteOne(worldlink => worldlink.UUID == UUID); + + + /*********************/ + public WorldAnchor GetAnchor(Guid UUID) => + _worldanchorcollection.Find(worldanchor => worldanchor.UUID == UUID).FirstOrDefault(); + + public Trackable GetTrackable(Guid UUID) => + _trackablecollection.Find(trackable => trackable.UUID == UUID).FirstOrDefault(); + + } +} + diff --git a/server/src/Org.OpenAPITools/Startup.cs b/server/src/Org.OpenAPITools/Startup.cs index 57bf7e3..1e524f5 100644 --- a/server/src/Org.OpenAPITools/Startup.cs +++ b/server/src/Org.OpenAPITools/Startup.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.3 + * The version of the OpenAPI document: 0.0.4 * * Generated by: https://openapi-generator.tech */ @@ -60,11 +60,14 @@ namespace Org.OpenAPITools BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard)); BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3; // requires using Microsoft.Extensions.Options - services.Configure( - Configuration.GetSection(nameof(TrackableDatabaseSettings))); - services.AddSingleton(sp => - sp.GetRequiredService>().Value); + services.Configure( + Configuration.GetSection(nameof(DatabaseSettings))); + services.AddSingleton(sp => + sp.GetRequiredService>().Value); services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + // Add framework services. services // Don't need the full MVC stack for an API, see https://andrewlock.net/comparing-startup-between-the-asp-net-core-3-templates/ @@ -85,7 +88,7 @@ namespace Org.OpenAPITools services .AddSwaggerGen(c => { - c.SwaggerDoc("0.0.3", new OpenApiInfo + c.SwaggerDoc("0.0.4", new OpenApiInfo { Title = "World Storage API", Description = "World Storage API (ASP.NET Core 3.1)", @@ -101,7 +104,7 @@ namespace Org.OpenAPITools Name = "NoLicense", Url = new Uri("https://opensource.org/licenses/BSD-3-Clause") }, - Version = "0.0.3", + Version = "0.0.4", }); c.CustomSchemaIds(type => type.FriendlyId(true)); c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{Assembly.GetEntryAssembly().GetName().Name}.xml"); @@ -142,7 +145,7 @@ namespace Org.OpenAPITools // set route prefix to openapi, e.g. http://localhost:8080/openapi/index.html c.RoutePrefix = "openapi"; //TODO: Either use the SwaggerGen generated OpenAPI contract (generated from C# classes) - c.SwaggerEndpoint("/openapi/0.0.3/openapi.json", "World Storage API"); + c.SwaggerEndpoint("/openapi/0.0.4/openapi.json", "World Storage API"); //TODO: Or alternatively use the original OpenAPI contract that's included in the static files // c.SwaggerEndpoint("/openapi-original.json", "World Storage API Original"); diff --git a/server/src/Org.OpenAPITools/appsettings.json b/server/src/Org.OpenAPITools/appsettings.json index bed3078..4efe6e7 100644 --- a/server/src/Org.OpenAPITools/appsettings.json +++ b/server/src/Org.OpenAPITools/appsettings.json @@ -1,8 +1,10 @@ -{ - "TrackableDatabaseSettings": { - "CollectionName": "Trackables", +{ + "DatabaseSettings": { + "CollectionNameWorldLink": "WorldLink", + "CollectionNameTrackables": "Trackables", + "CollectionNameWorldAnchor": "WorldAnchor", "ConnectionString": "mongodb://localhost:27017", - "DatabaseName": "TrackablesDatabase" + "DatabaseName": "WorldStorageAPI" }, "Logging": { "LogLevel": { diff --git a/server/src/Org.OpenAPITools/docker/appsettings.json b/server/src/Org.OpenAPITools/docker/appsettings.json index 46ecd9c..28066ba 100644 --- a/server/src/Org.OpenAPITools/docker/appsettings.json +++ b/server/src/Org.OpenAPITools/docker/appsettings.json @@ -1,8 +1,10 @@ { - "TrackableDatabaseSettings": { - "CollectionName": "Trackables", + "DatabaseSettings": { + "CollectionNameWorldLink": "WorldLink", + "CollectionNameTrackables": "Trackables", + "CollectionNameWorldAnchor": "WorldAnchor", "ConnectionString": "mongodb://10.10.20.100:27017", - "DatabaseName": "TrackablesDatabase" + "DatabaseName": "WorldStorageAPI" }, "Logging": { "LogLevel": { -- GitLab From a1e2bd16948b8ea73078a269506c44feb977a134 Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Tue, 5 Apr 2022 13:59:18 +0200 Subject: [PATCH 05/35] renamed readme.txt in server/programs/MongoDB/ to readme.md --- readme.md | 16 ++++++++++------ server/programs/MongoDB/readme.md | 4 ++++ server/programs/MongoDB/readme.txt | 3 --- 3 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 server/programs/MongoDB/readme.md delete mode 100644 server/programs/MongoDB/readme.txt diff --git a/readme.md b/readme.md index c6b0ba7..5efc95a 100644 --- a/readme.md +++ b/readme.md @@ -29,14 +29,16 @@ open `NuGet Package Manager` and add `MongoDB.Driver` ### File adaptations: change version number in all files if a new version is provided -### - folder `Controllers`: +### folder `Controllers`: change "`public class`" to "`public abstract class`" compare files in "`ControllersImpl`" with the corresponding files in "`Controllers`" and adapt if necessary methods should be the same with "`override`" instead of "`virtual`" -#### - if files are missing: +--- + +#### - if files are missing (and only then): copy them from folder `Controllers`, rename them (append `Impl`) and handle them like the already existing files, i.e.: change classnames by appending `Impl` to the original classnames (and change filenames accordingly) and inherit from original class in `Controllers` (instead of `ControllerBase`) @@ -55,7 +57,9 @@ Add a constructor with this service class variable like in the already existing remove sample code and replace it by using the appropriate methods of the corresponding classes in the folder `Services` (which you may be have to create) -### - folder `Models`: +--- + +### folder `Models`: add: ``` using MongoDB.Bson; @@ -68,13 +72,13 @@ at the value that is to become the MongoDB ID, add: [BsonRepresentation(BsonType.String)] ``` -### - folder `Services` +### folder `Services` the folder `Services` should contain one common class with the DatabaseSettings (`DatabaseSettings.cs`) and one with the database-access-methods (create, get, update, remove) for each API. If some are missing create them like the ones you find there. Be aware to add the reference to these in the file `startup.cs` in this case. the naming in the DatabaseSettings is the same as defined in `appsettings.json`, which you have to extend when creating new classes in this folder. changed `appsettings.json` in the folder `docker` accordingly. Make sure that the ConnectionString for the database contains the correct IP address as specified in `docker-compose.yml`. # MongoDB -if you don't have a MongoDB, follow the instructions in `readme.txt` in `server/programs/MongoDB` +if you don't have a MongoDB, follow the instructions in `readme.md` in `server/programs/MongoDB` and put MongoDB in folder `server/programs/MongoDB` (download MongoDB as zip-file from https://www.mongodb.com/try/download/community and unzip the file into this directory, so that the bin-directory is in this folder) @@ -98,7 +102,7 @@ the easiest way is to use docker-compose: open a command shell and use docker-compose (if necessary adapt docker-compose.yml) by executing in `server/src/Org.OpenAPITools`: ``` - docker-compose up + docker-compose up --force-recreate --remove-orphan --detach ``` open http://localhost:8080/openapi/index.html in a web-browser, if you want to check the functionalities using SwaggerUI diff --git a/server/programs/MongoDB/readme.md b/server/programs/MongoDB/readme.md new file mode 100644 index 0000000..b93d699 --- /dev/null +++ b/server/programs/MongoDB/readme.md @@ -0,0 +1,4 @@ +# Installation of MongoDB +1. download MongoDB as zip-file from https://www.mongodb.com/try/download/community +2. unzip the file into this directory, so that the bin-directory is in this folder (where you found this readme.md) +3. before starting `startMongoDB.bat` create data-directory and adjust - if necessary - data path in startMongoDB.bat \ No newline at end of file diff --git a/server/programs/MongoDB/readme.txt b/server/programs/MongoDB/readme.txt deleted file mode 100644 index 3d74654..0000000 --- a/server/programs/MongoDB/readme.txt +++ /dev/null @@ -1,3 +0,0 @@ -1. download MongoDB as zip-file from https://www.mongodb.com/try/download/community -2. unzip the file into this directory, so that the bin-directory is in this folder (where you found this readme.txt) -3. before starting startMongoDB.bat create data-directory and adjust - if necessary - data path in startMongoDB.bat \ No newline at end of file -- GitLab From 76ff6ad72c63a7bdc5fbb4d3b7412f08ac47055c Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Tue, 5 Apr 2022 15:31:04 +0200 Subject: [PATCH 06/35] OpenAPI arf005 file as submodule --- .gitmodules | 3 + OpenAPI.yaml | 647 --------------------------------------------------- arf005 | 1 + 3 files changed, 4 insertions(+), 647 deletions(-) create mode 100644 .gitmodules delete mode 100644 OpenAPI.yaml create mode 160000 arf005 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..520b5d7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "arf005"] + path = arf005 + url = git@forge.etsi.org:arf/arf005.git diff --git a/OpenAPI.yaml b/OpenAPI.yaml deleted file mode 100644 index 8eef38e..0000000 --- a/OpenAPI.yaml +++ /dev/null @@ -1,647 +0,0 @@ -openapi: "3.0.0" -# -# API for the Augmented Reality Framework (ARF) -# Working group: ETSI ISG ARF -# STF group: STF620 (validation) -# (C) ETSI - 2022 -# -# References: -# - Explaination UUID: https://en.wikipedia.org/wiki/Universally_unique_identifier / https://fr.wikipedia.org/wiki/Universally_unique_identifier -# - UUID formats: 8-4-4-4-12 format string, lower case (but case insensitive on input) -# - UUID RFC4122: https://datatracker.ietf.org/doc/html/rfc4122#section-3 -# - Rules for RESTful error code RFC2616: https://datatracker.ietf.org/doc/html/rfc2616#section-10 -# - Guide: https://restfulapi.net/http-status-codes/ -# -# Last Version: 04.03.2022 -# -info: - version: 0.0.4 - title: World Storage API - description: API ensuring interoperability between an authoring tool and a World Storage service - license: - name: BSD-3-clause - url: https://opensource.org/licenses/BSD-3-Clause -servers: - - url: http://localhost:8080 -paths: - /ping: - get: - summary: Test the server availability - operationId: getPing - responses: - '200': - description: OK, world storage alive. - /admin: - get: - summary: Get the version of the API. - operationId: getVersion - responses: - '200': - description: OK, world storage ready. - content: - text/plain: - schema: - type: string - -############## -# TRACKABLES # -############## - /trackables: - post: - summary: Create a trackable. - operationId: addTrackable - tags: - - trackables - requestBody: - description: The trackable to be added to the world storage. - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/Trackable' - #application/xml: - # schema: - # $ref: '#/components/schemas/Trackable' - responses: - '200': - description: OK, returns the UUID of the Trackable defined by the world storage. - content: - text/plain: - schema: - type: string - '201': - description: Null response. - '400': - $ref: '#/components/responses/400_BadRequest' - '409': - $ref: '#/components/responses/409_NotEmptyUUID' - 'default': - $ref: '#/components/responses/4xx_UnexpectedError' - get: - summary: Returns the list of all trackables defined by the world storage. - operationId: getTrackables - tags: - - trackables - responses: - '200': - description: OK, returns all the Trackables defined by the world storage. - content: - application/json: - schema: - type : array - items : - $ref: "#/components/schemas/Trackable" - '201': - description: Null response. - default: - $ref: '#/components/responses/4xx_UnexpectedError' - - /trackables/{trackableUUID}: - get: - summary: Find a trackable by its UUID. - operationId: getTrackableById - tags: - - trackables - parameters: - - name: trackableUUID - in: path - description: UUID of the trackable to retrieve. - required: true - schema: - type: string - format: uuid - responses: - '200': - description: Successful operation. - content: - application/json: - schema: - $ref: '#/components/schemas/Trackable' - '400': - $ref: '#/components/responses/400_InvalidUUID' - '404': - $ref: '#/components/responses/404_NotFoundUUID' - delete: - summary: Deletes a trackable. - operationId: deleteTrackable - tags: - - trackables - parameters: - - name: trackableUUID - in: path - description: Trackable UUID to delete. - required: true - schema: - type: string - format: uuid - responses: - '200': - description: OK, delete successful. - '400': - $ref: '#/components/responses/400_InvalidUUID' - '404': - $ref: '#/components/responses/404_NotFoundUUID' - -################# -# WORLD ANCHORS # -################# - /worldAnchors: - post: - summary: Create a world anchor. - operationId: addWorldAnchor - tags: - - world anchors - requestBody: - description: The world anchor to be added to the world storage. - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/WorldAnchor' - #application/xml: - # schema: - # $ref: '#/components/schemas/WorldAnchor' - responses: - '200': - description: OK, returns the UUID of the World Anchor defined by the world storage. - content: - text/plain: - schema: - type: string - '201': - description: Null response. - '400': - $ref: '#/components/responses/400_BadRequest' - '409': - $ref: '#/components/responses/409_NotEmptyUUID' - 'default': - $ref: '#/components/responses/4xx_UnexpectedError' - get: - summary: Returns the list of all world anchors defined by the world storage. - operationId: getWorldAnchors - tags: - - world anchors - responses: - '200': - description: OK, returns all the world anchors defined by the world storage. - content: - application/json: - schema: - type : array - items : - $ref: "#/components/schemas/WorldAnchor" - '201': - description: Null response. - default: - $ref: '#/components/responses/4xx_UnexpectedError' - - /worldAnchors/{worldAnchorUUID}: - get: - summary: Find a world anchor by its UUID. - operationId: getWorldAnchorById - tags: - - world anchors - parameters: - - name: worldAnchorUUID - in: path - description: UUID of the world anchor to retrieve. - required: true - schema: - type: string - format: uuid - responses: - '200': - description: Successful operation. - content: - application/json: - schema: - $ref: '#/components/schemas/WorldAnchor' - '400': - $ref: '#/components/responses/400_InvalidUUID' - '404': - $ref: '#/components/responses/404_NotFoundUUID' - delete: - summary: Deletes a world anchor. - operationId: deleteWorldAnchor - tags: - - world anchors - parameters: - - name: worldAnchorUUID - in: path - description: World anchor UUID to delete. - required: true - schema: - type: string - format: uuid - responses: - '200': - description: OK, delete successful. - '400': - $ref: '#/components/responses/400_InvalidUUID' - '404': - $ref: '#/components/responses/404_NotFoundUUID' - -############### -# WORLD LINKS # -############### - /worldLinks: - post: - summary: Create a link between world anchors and trackables. - operationId: addWorldLink - tags: - - world links - requestBody: - description: The link to be added to the world storage. - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/WorldLink' - #application/xml: - # schema: - # $ref: '#/components/schemas/WorldLink' - responses: - '200': - description: OK, returns the UUID of the link defined by the world storage. - content: - text/plain: - schema: - type: string - '201': - description: Null response - '400': - $ref: '#/components/responses/400_BadRequest' - '409': - $ref: '#/components/responses/409_NotEmptyUUID' - 'default': - $ref: '#/components/responses/4xx_UnexpectedError' - get: - summary: Returns the list of all links defined by the world storage. - operationId: getWorldLinks - tags: - - world links - responses: - '200': - description: OK returns all the worldLinks defined by the world storage. - content: - application/json: - schema: - type : array - items : - $ref: "#/components/schemas/WorldLink" - '201': - description: Null response - default: - $ref: '#/components/responses/4xx_UnexpectedError' - - /worldLinks/{worldLinkUUID}: - get: - summary: Find a link by its UUID. - operationId: getWorldLinkById - tags: - - world links - parameters: - - name: worldLinkUUID - in: path - description: UUID of the link to retrieve. - required: true - schema: - type: string - format: uuid - responses: - '200': - description: Successful operation. - content: - application/json: - schema: - $ref: '#/components/schemas/WorldLink' - '400': - $ref: '#/components/responses/400_InvalidUUID' - '404': - $ref: '#/components/responses/404_NotFoundUUID' - delete: - summary: Deletes a worldLink. - operationId: deleteWorldLink - tags: - - world links - parameters: - - name: worldLinkUUID - in: path - description: link id to delete - required: true - schema: - type: string - format: uuid - responses: - '200': - description: OK - '400': - $ref: '#/components/responses/400_InvalidUUID' - '404': - $ref: '#/components/responses/404_NotFoundUUID' - - /worldLinks/attached/{worldLinkUUID}: - get: - summary: Retrieve end objects connected to this world link by its UUID. - operationId: getAttachedObjectsFromUUID - tags: - - world links - parameters: - - name: worldLinkUUID - in: path - description: UUID of the link from which you will retrieve the end objects. - required: true - schema: - type: string - format: uuid - responses: - '200': - description: Successful operation. - content: - application/json: - schema: - $ref: '#/components/schemas/AttachedObjects' - '400': - $ref: '#/components/responses/400_InvalidUUID' - '404': - $ref: '#/components/responses/404_NotFoundUUID' - -# COMPONENTS ############################################### -components: - #------------------------------- - # Reusable operation parameters - #------------------------------- - parameters: - UUIDParams: - name: UUID - in: path - required: true - description: A Universally Unique IDentifier identifying the object - schema: - type: string - format: uuid - default: "00000000-0000-0000-0000-000000000000" - - #------------------------------- - # Reusable schemas (data models) - #------------------------------- - schemas: - Trackable: - type: object - required: - - creatorUUID - - trackableType - - trackableEncodingInformation - - trackablePayload - - localCRS - - unit - - trackableSize - - keyvalueTagList - properties: - UUID: - description: A Universally Unique IDentifier identifying the trackable (RFC 4122). - type: string - format: uuid - example: fa8bbe40-8052-11ec-a8a3-0242ac120002 - creatorUUID: - description: A Universally Unique IDentifier identifying the creator of the trackable (a person, a team or a company). - type: string - format: uuid - example: c75f6324-77a0-11ec-90d6-0242ac120003 - trackableType: - description: Extensible list of trackable types possibly handled by complient World Storage implementation. - type: string - enum: [FIDUCIAL_MARKER, IMAGE_MARKER, MAP, OTHER] - example: FIDUCIAL_MARKER - trackableEncodingInformation: - $ref: '#/components/schemas/EncodingInformationStructure' - trackablePayload: - description: The data provided to create the trackable in a specific format handled by the World Storage service. - type: string - format: byte - example: "10110101" - localCRS: - $ref: '#/components/schemas/Transform3D' - unit: - $ref: '#/components/schemas/UnitSystem' - trackableSize: - $ref: '#/components/schemas/Size' - keyvalueTags: - $ref: '#/components/schemas/KeyvalueTagList' - - WorldAnchor: - type: object - required: - - creatorUUID - - localCRS - - unit - - worldAnchorSize - - keyvalueTagList - properties: - UUID: - description: A Universally Unique IDentifier identifying the world anchor (RFC 4122). - type: string - format: uuid - example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 - creatorUUID: - description: A Universally Unique IDentifier identifying the creator of the world anchor. - type: string - format: uuid - example: c75f6324-77a0-11ec-90d6-0242ac120003 - localCRS: - $ref: '#/components/schemas/Transform3D' - unit: - $ref: '#/components/schemas/UnitSystem' - worldAnchorSize: - $ref: '#/components/schemas/Size' - keyvalueTags: - $ref: '#/components/schemas/KeyvalueTagList' - - WorldLink: - type: object - required: - - creatorUUID - - UUIDFrom - - UUIDTo - - transform - - unit - - linkSize - - keyvalueTags - properties: - UUID: - description: A Universally Unique IDentifier identifying the link (RFC 4122). - type: string - format: uuid - example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 - creatorUUID: - description: A Universally Unique IDentifier identifying the creator of the link. - type: string - format: uuid - example: c75f6324-77a0-11ec-90d6-0242ac120003 - UUIDFrom: - description: A Universally Unique IDentifier identifying a world anchor or trackable. - type: string - format: uuid - example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 - UUIDTo: - description: A Universally Unique IDentifier identifying a world anchor or trackable. - type: string - format: uuid - example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 - transform: - $ref: '#/components/schemas/Transform3D' - unit: - $ref: '#/components/schemas/UnitSystem' - linkSize: - $ref: '#/components/schemas/Size' - keyvalueTags: - description: List of additional parameters to be stored - $ref: '#/components/schemas/KeyvalueTagList' - example: { "LinkType" : ["Hierarchy"]} - - AttachedObjects: - type: object - required: - - UUID - - UUIDFrom - - UUIDTo - - TypeFrom - - TypeTo - properties: - UUID: - description: A Universally Unique IDentifier identifying the link. - type: string - format: uuid - example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 - UUIDFrom: - description: A Universally Unique IDentifier identifying a world anchor or trackable. - type: string - format: uuid - example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 - UUIDTo: - description: A Universally Unique IDentifier identifying a world anchor or trackable. - type: string - format: uuid - example: ce8ccd80-56ee-2a5c-a8a3-0242ac150d002 - TypeFrom: - $ref: '#/components/schemas/ObjectType' - TypeTo: - $ref: '#/components/schemas/ObjectType' - - EncodingInformationStructure: - required: - - dataFormat - - version - properties: - dataFormat: - description: Identifier of the target framework - type: string - enum: [HOLOLENS, ARKIT, ARCORE] - example : "HOLOLENS" - version: - description: The version of the format - type: string - example : "1.01" - - Transform3D: - description: Coordinate reference system of the world anchor, a 4*4 matrix (rowmajor) represented by a float vector - type: array - minItems: 16 - maxItems: 16 - items: - type: number - format: float - example: [-2, 1, -3, 4, - 4, 4, 4, 2, - 1, 0, -2, 1, - -1, -2, 0, 0] - - ObjectType: - description: Type of an world representaion object. - type: string - enum: [Trackable, WorldAnchor, WorldLink] - example: Trackable - - UnitSystem: - description: Unit of length. - type: string - enum: [MM, CM, DM, M, DAM, HM, KM, INCH, FOOT, YARD, MILE] - example: M - - Size: - description: Size {width, length, depth}. - type: array - items: - type: number - format: double - minItems: 3 - maxItems: 3 - example: [1,5,0] - - KeyvalueTagList: - description: List of additional parameters to be stored with the trackable. - type: object - additionalProperties: - type: array - items: - type: string - minItems: 1 - example: { "Place" : ["Museum 1"], "room" : ["B4"]} - - Error: - required: - - code - - message - properties: - code: - type: integer - format: int32 - message: - type: string - #------------------------------- - # Reusable responses - #------------------------------- - responses: - ####################### - # 1xx : Informational # - ####################### - - ################# - # 2xx : Success # - ################# - - ##################### - # 3xx : Redirection # - ##################### - - ####################### - # 4xx : Client Errors # - ####################### - 400_BadRequest: - description: Bad request. - - 400_InvalidUUID: - description: Invalid UUID supplied. - - 404_NotFoundUUID: - description: Not found, could not find UUID in database. - - 409_NotEmptyUUID: - description: Invalid UUID, id must be a Nil value. - - 4xx_UnexpectedError: # Can be referenced as '#/components/responses/GenericError' - description: Unexpected error. - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - - ######################## - # 5xx : Server Errors # - ######################## - 5xx_UnexpectedError: - description: Unexpected server error. - content: - application/json: - schema: - $ref: '#/components/schemas/Error' diff --git a/arf005 b/arf005 new file mode 160000 index 0000000..aaf4295 --- /dev/null +++ b/arf005 @@ -0,0 +1 @@ +Subproject commit aaf4295668539d5ce805dfd9fa1c4679377e8038 -- GitLab From a8c324f348291a07fc0d0deb16112c09ed921eba Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Tue, 5 Apr 2022 15:41:12 +0200 Subject: [PATCH 07/35] Updated readme.md --- arf005 | 2 +- readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arf005 b/arf005 index aaf4295..c09b5e3 160000 --- a/arf005 +++ b/arf005 @@ -1 +1 @@ -Subproject commit aaf4295668539d5ce805dfd9fa1c4679377e8038 +Subproject commit c09b5e3bfc9d20ef8f477c7731eec04f984b2d30 diff --git a/readme.md b/readme.md index 5efc95a..cc07320 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,7 @@ we provided the file `.openapi-generator-ignore` in `server`, which prevents ope ## auto-generate server code open a command shell and execute ``` - openapi-generator-cli generate -i OpenAPI.yaml -g aspnetcore -o server + openapi-generator-cli generate -i arf005\API\openapi.yaml -g aspnetcore -o server ``` open the solution `Org.OpenAPITools.sln` (folder `server`) in Visual Studio -- GitLab From 2aece267ea60d082c52ef100920e47912d47c9b6 Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Tue, 12 Apr 2022 08:44:47 +0200 Subject: [PATCH 08/35] bugfix in OpenAPI.yaml --- OpenAPI.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenAPI.yaml b/OpenAPI.yaml index 8eef38e..3eb65a2 100644 --- a/OpenAPI.yaml +++ b/OpenAPI.yaml @@ -396,7 +396,7 @@ components: - localCRS - unit - trackableSize - - keyvalueTagList + - keyvalueTags properties: UUID: description: A Universally Unique IDentifier identifying the trackable (RFC 4122). @@ -436,7 +436,7 @@ components: - localCRS - unit - worldAnchorSize - - keyvalueTagList + - keyvalueTags properties: UUID: description: A Universally Unique IDentifier identifying the world anchor (RFC 4122). -- GitLab From 63413770cba0bb9af100c4ab26a22ed898d2344d Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Tue, 12 Apr 2022 08:56:37 +0200 Subject: [PATCH 09/35] corrected indentation in OpenAPI.yaml --- OpenAPI.yaml | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/OpenAPI.yaml b/OpenAPI.yaml index 3eb65a2..56e161e 100644 --- a/OpenAPI.yaml +++ b/OpenAPI.yaml @@ -545,13 +545,13 @@ components: Transform3D: description: Coordinate reference system of the world anchor, a 4*4 matrix (rowmajor) represented by a float vector - type: array - minItems: 16 - maxItems: 16 - items: + type: array + minItems: 16 + maxItems: 16 + items: type: number format: float - example: [-2, 1, -3, 4, + example: [-2, 1, -3, 4, 4, 4, 4, 2, 1, 0, -2, 1, -1, -2, 0, 0] @@ -564,28 +564,28 @@ components: UnitSystem: description: Unit of length. - type: string - enum: [MM, CM, DM, M, DAM, HM, KM, INCH, FOOT, YARD, MILE] - example: M + type: string + enum: [MM, CM, DM, M, DAM, HM, KM, INCH, FOOT, YARD, MILE] + example: M Size: description: Size {width, length, depth}. - type: array - items: + type: array + items: type: number format: double - minItems: 3 - maxItems: 3 - example: [1,5,0] + minItems: 3 + maxItems: 3 + example: [1,5,0] KeyvalueTagList: - description: List of additional parameters to be stored with the trackable. - type: object - additionalProperties: - type: array - items: + description: List of additional parameters to be stored with the trackable. + type: object + additionalProperties: + type: array + items: type: string - minItems: 1 + minItems: 1 example: { "Place" : ["Museum 1"], "room" : ["B4"]} Error: -- GitLab From 8487ed28c78baca3b7e247a11a5f73f5002ac006 Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Tue, 12 Apr 2022 09:00:57 +0200 Subject: [PATCH 10/35] next attempt to correct indentation in OpenAPI.yaml --- OpenAPI.yaml | 70 ++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/OpenAPI.yaml b/OpenAPI.yaml index 56e161e..2b1f08b 100644 --- a/OpenAPI.yaml +++ b/OpenAPI.yaml @@ -544,49 +544,49 @@ components: example : "1.01" Transform3D: - description: Coordinate reference system of the world anchor, a 4*4 matrix (rowmajor) represented by a float vector - type: array - minItems: 16 - maxItems: 16 - items: - type: number - format: float - example: [-2, 1, -3, 4, - 4, 4, 4, 2, - 1, 0, -2, 1, - -1, -2, 0, 0] + description: Coordinate reference system of the world anchor, a 4*4 matrix (rowmajor) represented by a float vector + type: array + minItems: 16 + maxItems: 16 + items: + type: number + format: float + example: [-2, 1, -3, 4, + 4, 4, 4, 2, + 1, 0, -2, 1, + -1, -2, 0, 0] ObjectType: - description: Type of an world representaion object. - type: string - enum: [Trackable, WorldAnchor, WorldLink] - example: Trackable + description: Type of an world representaion object. + type: string + enum: [Trackable, WorldAnchor, WorldLink] + example: Trackable UnitSystem: - description: Unit of length. - type: string - enum: [MM, CM, DM, M, DAM, HM, KM, INCH, FOOT, YARD, MILE] - example: M + description: Unit of length. + type: string + enum: [MM, CM, DM, M, DAM, HM, KM, INCH, FOOT, YARD, MILE] + example: M Size: - description: Size {width, length, depth}. - type: array - items: - type: number - format: double - minItems: 3 - maxItems: 3 - example: [1,5,0] + description: Size {width, length, depth}. + type: array + items: + type: number + format: double + minItems: 3 + maxItems: 3 + example: [1,5,0] KeyvalueTagList: - description: List of additional parameters to be stored with the trackable. - type: object - additionalProperties: - type: array - items: - type: string - minItems: 1 - example: { "Place" : ["Museum 1"], "room" : ["B4"]} + description: List of additional parameters to be stored with the trackable. + type: object + additionalProperties: + type: array + items: + type: string + minItems: 1 + example: { "Place" : ["Museum 1"], "room" : ["B4"]} Error: required: -- GitLab From 7cf1d2b07963477c7c5ad4401179c1759d1c8bba Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Tue, 12 Apr 2022 10:02:59 +0200 Subject: [PATCH 11/35] added .gitignore --- .gitignore | 40 ++++++++++++++++++++++++++++++++++++++++ readme.md | 4 ++-- 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8cfb7fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +## Ignore .openapi-generator Folder +## +.openapi-generator/ +server/src/Org.OpenAPITools/.gitignore + +# Visual Studio cache/options directory +.vs/ + +# Visual Studio solution +*.sln + +# build-jobs +build.* + +# database data directory +data/ + +#generated readme +server/README.md + +# all generated directories +Attributes/ +Authentication/ +Controllers/ +Converters/ +Filters/ +Formatters/ +Models/ +OpenAPI/ +Properties/ +wwwroot/ + +# generated project-files +*.csproj + +# generated Program.cs +Program.cs + +# backup-files +*.bak diff --git a/readme.md b/readme.md index 5efc95a..1988151 100644 --- a/readme.md +++ b/readme.md @@ -60,13 +60,13 @@ remove sample code and replace it by using the appropriate methods of the corres --- ### folder `Models`: -add: +add to the classes to be stored in the database (i.e. `Trackable.cs`, `WorldAnchor.cs`, `WorldLink.cs`) : ``` using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; ``` -at the value that is to become the MongoDB ID, add: +and at the value that is to become the MongoDB ID, add: ``` [BsonId] [BsonRepresentation(BsonType.String)] -- GitLab From 64996bb29db96eb0ea13081513e4ae36c96c0a19 Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Tue, 12 Apr 2022 10:13:41 +0200 Subject: [PATCH 12/35] added individual MongoDB installation to .gitignore --- .gitignore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8cfb7fb..1ade888 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,13 @@ server/src/Org.OpenAPITools/.gitignore build.* # database data directory -data/ +server/data/ + +# database directory +server/programs/MongoDB/ +!server/programs/MongoDB/kill_MongoDB.bat +!server/programs/MongoDB/startMongoDB.bat +!server/programs/MongoDB/readme.md #generated readme server/README.md -- GitLab From fe410fc41ce8103edf8e0feb1c93dbca514a95ba Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Mon, 2 May 2022 17:05:34 +0200 Subject: [PATCH 13/35] Test --- server/src/Org.OpenAPITools/appsettings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/Org.OpenAPITools/appsettings.json b/server/src/Org.OpenAPITools/appsettings.json index 4efe6e7..05ce266 100644 --- a/server/src/Org.OpenAPITools/appsettings.json +++ b/server/src/Org.OpenAPITools/appsettings.json @@ -1,9 +1,9 @@ -{ +{ "DatabaseSettings": { "CollectionNameWorldLink": "WorldLink", "CollectionNameTrackables": "Trackables", "CollectionNameWorldAnchor": "WorldAnchor", - "ConnectionString": "mongodb://localhost:27017", + "ConnectionString": "mongodb://vm009254.fe.hhi.de:27017", "DatabaseName": "WorldStorageAPI" }, "Logging": { -- GitLab From e73df64cefa72b79833658e368dead9c423bcf03 Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Mon, 2 May 2022 17:16:43 +0200 Subject: [PATCH 14/35] New API. --- arf005 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arf005 b/arf005 index c09b5e3..c8802a3 160000 --- a/arf005 +++ b/arf005 @@ -1 +1 @@ -Subproject commit c09b5e3bfc9d20ef8f477c7731eec04f984b2d30 +Subproject commit c8802a3a9846a3b82f9e88cf002d01c324c91b13 -- GitLab From 1c02fdbbbf173f92aede2f35b4a94cb097108545 Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Tue, 3 May 2022 09:04:46 +0200 Subject: [PATCH 15/35] Update to version 0.0.5 --- .../ControllersImpl/DefaultApiImpl.cs | 29 +++++++++++++++---- .../ControllersImpl/TrackablesApiImpl.cs | 2 +- .../ControllersImpl/WorldAnchorsApiImpl.cs | 2 +- .../ControllersImpl/WorldLinksApiImpl.cs | 4 ++- server/src/Org.OpenAPITools/Startup.cs | 8 ++--- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs index 6476543..d9e0699 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.4 + * The version of the OpenAPI document: 0.0.5 * * Generated by: https://openapi-generator.tech */ @@ -29,6 +29,23 @@ namespace Org.OpenAPITools.Controllers [ApiController] public class DefaultApiControllerImpl : DefaultApiController { + + /// + /// Get the version of the server. + /// + /// OK, world storage server ready. + [HttpGet] + [Route("/admin")] + [ValidateModelState] + [SwaggerOperation("GetAdmin")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, world storage server ready.")] + public override IActionResult GetAdmin() + { + string version = "OK world storage server ready"; + return new ObjectResult(version); + //return StatusCode(200, new ObjectResult(version)); + } + /// /// Test the server availability /// @@ -45,17 +62,17 @@ namespace Org.OpenAPITools.Controllers } /// - /// Get the version of the API. + /// Get the version of the ARF API. /// - /// OK, world storage ready. + /// Current version. [HttpGet] - [Route("/admin")] + [Route("/version")] [ValidateModelState] [SwaggerOperation("GetVersion")] - [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, world storage ready.")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "Current version.")] public override IActionResult GetVersion() { - string version = "OK world storage 0.0.4 ready"; + string version = "0.0.5"; return new ObjectResult(version); //return StatusCode(200, new ObjectResult(version)); } diff --git a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs index d4be291..03d4989 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.4 + * The version of the OpenAPI document: 0.0.5 * * Generated by: https://openapi-generator.tech */ diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs index e557fce..4b11b38 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.4 + * The version of the OpenAPI document: 0.0.5 * * Generated by: https://openapi-generator.tech */ diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs index 10731c6..ce6ef68 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.4 + * The version of the OpenAPI document: 0.0.5 * * Generated by: https://openapi-generator.tech */ @@ -114,6 +114,8 @@ namespace Org.OpenAPITools.Controllers attachedobjects.UUID = myworldlink.UUID; attachedobjects.UUIDFrom = myworldlink.UUIDFrom; attachedobjects.UUIDTo = myworldlink.UUIDTo; + attachedobjects.TypeFrom = ObjectType.NotIdentifiedEnum; + attachedobjects.TypeTo = ObjectType.NotIdentifiedEnum; if (null != _worldLinkService.Get(attachedobjects.UUIDFrom)) attachedobjects.TypeFrom = ObjectType.WorldLinkEnum; if (null != _worldLinkService.GetAnchor(attachedobjects.UUIDFrom)) attachedobjects.TypeFrom = ObjectType.WorldAnchorEnum; if (null != _worldLinkService.GetTrackable(attachedobjects.UUIDFrom)) attachedobjects.TypeFrom = ObjectType.TrackableEnum; diff --git a/server/src/Org.OpenAPITools/Startup.cs b/server/src/Org.OpenAPITools/Startup.cs index 1e524f5..61c87dd 100644 --- a/server/src/Org.OpenAPITools/Startup.cs +++ b/server/src/Org.OpenAPITools/Startup.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.4 + * The version of the OpenAPI document: 0.0.5 * * Generated by: https://openapi-generator.tech */ @@ -88,7 +88,7 @@ namespace Org.OpenAPITools services .AddSwaggerGen(c => { - c.SwaggerDoc("0.0.4", new OpenApiInfo + c.SwaggerDoc("0.0.5", new OpenApiInfo { Title = "World Storage API", Description = "World Storage API (ASP.NET Core 3.1)", @@ -104,7 +104,7 @@ namespace Org.OpenAPITools Name = "NoLicense", Url = new Uri("https://opensource.org/licenses/BSD-3-Clause") }, - Version = "0.0.4", + Version = "0.0.5", }); c.CustomSchemaIds(type => type.FriendlyId(true)); c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{Assembly.GetEntryAssembly().GetName().Name}.xml"); @@ -145,7 +145,7 @@ namespace Org.OpenAPITools // set route prefix to openapi, e.g. http://localhost:8080/openapi/index.html c.RoutePrefix = "openapi"; //TODO: Either use the SwaggerGen generated OpenAPI contract (generated from C# classes) - c.SwaggerEndpoint("/openapi/0.0.4/openapi.json", "World Storage API"); + c.SwaggerEndpoint("/openapi/0.0.5/openapi.json", "World Storage API"); //TODO: Or alternatively use the original OpenAPI contract that's included in the static files // c.SwaggerEndpoint("/openapi-original.json", "World Storage API Original"); -- GitLab From 370a2d1f6f9e79ef7fedceed3465e879c16ba6f5 Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Thu, 5 May 2022 08:31:43 +0200 Subject: [PATCH 16/35] changed version no in readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index bd7b1ec..579bfde 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# Description of version 0.0.4 +# Description of version 0.0.5 auto-generated ASP.NET server code -- GitLab From d628d8ae5c3cfcd19ef9c83e67cd520afbfb9207 Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Wed, 18 May 2022 10:44:02 +0200 Subject: [PATCH 17/35] update to version 0.0.6 --- .gitmodules | 1 + arf005 | 2 +- readme.md | 2 +- .../ControllersImpl/DefaultApiImpl.cs | 4 +-- .../ControllersImpl/TrackablesApiImpl.cs | 2 +- .../ControllersImpl/WorldAnchorsApiImpl.cs | 2 +- .../ControllersImpl/WorldLinksApiImpl.cs | 36 +------------------ server/src/Org.OpenAPITools/Startup.cs | 8 ++--- 8 files changed, 12 insertions(+), 45 deletions(-) diff --git a/.gitmodules b/.gitmodules index 520b5d7..0b8e82d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "arf005"] path = arf005 url = git@forge.etsi.org:arf/arf005.git + branch = feature/elementNameAndNewObjectType \ No newline at end of file diff --git a/arf005 b/arf005 index c8802a3..8b13db3 160000 --- a/arf005 +++ b/arf005 @@ -1 +1 @@ -Subproject commit c8802a3a9846a3b82f9e88cf002d01c324c91b13 +Subproject commit 8b13db35ec8349a8bf513f9ad1d35d6a24699a00 diff --git a/readme.md b/readme.md index 579bfde..46a84cd 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# Description of version 0.0.5 +# Description of version 0.0.6 auto-generated ASP.NET server code diff --git a/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs index d9e0699..5d7c9fa 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.5 + * The version of the OpenAPI document: 0.0.6 * * Generated by: https://openapi-generator.tech */ @@ -72,7 +72,7 @@ namespace Org.OpenAPITools.Controllers [SwaggerResponse(statusCode: 200, type: typeof(string), description: "Current version.")] public override IActionResult GetVersion() { - string version = "0.0.5"; + string version = "0.0.6"; return new ObjectResult(version); //return StatusCode(200, new ObjectResult(version)); } diff --git a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs index 03d4989..b788c68 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.5 + * The version of the OpenAPI document: 0.0.6 * * Generated by: https://openapi-generator.tech */ diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs index 4b11b38..1fc7c34 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.5 + * The version of the OpenAPI document: 0.0.6 * * Generated by: https://openapi-generator.tech */ diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs index ce6ef68..491bc46 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.5 + * The version of the OpenAPI document: 0.0.6 * * Generated by: https://openapi-generator.tech */ @@ -91,40 +91,6 @@ namespace Org.OpenAPITools.Controllers return (answer.IsAcknowledged && answer.DeletedCount > 0) ? new ObjectResult("ok") : StatusCode(404, "Not found, could not find UUID in database."); } - /// - /// Retrieve end objects connected to this world link by its UUID. - /// - /// UUID of the link from which you will retrieve the end objects. - /// Successful operation. - /// Invalid UUID supplied. - /// Not found, could not find UUID in database. - [HttpGet] - [Route("/worldLinks/attached/{worldLinkUUID}")] - [ValidateModelState] - [SwaggerOperation("GetAttachedObjectsFromUUID")] - [SwaggerResponse(statusCode: 200, type: typeof(AttachedObjects), description: "Successful operation.")] - public override IActionResult GetAttachedObjectsFromUUID([FromRoute(Name = "worldLinkUUID")][Required] Guid worldLinkUUID) - { - WorldLink myworldlink = _worldLinkService.Get(worldLinkUUID); - if (null == myworldlink) - { - return StatusCode(404, "not found, could not find UUID in database"); - } - AttachedObjects attachedobjects = new AttachedObjects(); - attachedobjects.UUID = myworldlink.UUID; - attachedobjects.UUIDFrom = myworldlink.UUIDFrom; - attachedobjects.UUIDTo = myworldlink.UUIDTo; - attachedobjects.TypeFrom = ObjectType.NotIdentifiedEnum; - attachedobjects.TypeTo = ObjectType.NotIdentifiedEnum; - if (null != _worldLinkService.Get(attachedobjects.UUIDFrom)) attachedobjects.TypeFrom = ObjectType.WorldLinkEnum; - if (null != _worldLinkService.GetAnchor(attachedobjects.UUIDFrom)) attachedobjects.TypeFrom = ObjectType.WorldAnchorEnum; - if (null != _worldLinkService.GetTrackable(attachedobjects.UUIDFrom)) attachedobjects.TypeFrom = ObjectType.TrackableEnum; - if (null != _worldLinkService.Get(attachedobjects.UUIDTo)) attachedobjects.TypeTo = ObjectType.WorldLinkEnum; - if (null != _worldLinkService.GetAnchor(attachedobjects.UUIDTo)) attachedobjects.TypeTo = ObjectType.WorldAnchorEnum; - if (null != _worldLinkService.GetTrackable(attachedobjects.UUIDTo)) attachedobjects.TypeTo = ObjectType.TrackableEnum; - - return new ObjectResult(attachedobjects); - } /// /// Find a link by its UUID. diff --git a/server/src/Org.OpenAPITools/Startup.cs b/server/src/Org.OpenAPITools/Startup.cs index 61c87dd..2ac047b 100644 --- a/server/src/Org.OpenAPITools/Startup.cs +++ b/server/src/Org.OpenAPITools/Startup.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.5 + * The version of the OpenAPI document: 0.0.6 * * Generated by: https://openapi-generator.tech */ @@ -88,7 +88,7 @@ namespace Org.OpenAPITools services .AddSwaggerGen(c => { - c.SwaggerDoc("0.0.5", new OpenApiInfo + c.SwaggerDoc("0.0.6", new OpenApiInfo { Title = "World Storage API", Description = "World Storage API (ASP.NET Core 3.1)", @@ -104,7 +104,7 @@ namespace Org.OpenAPITools Name = "NoLicense", Url = new Uri("https://opensource.org/licenses/BSD-3-Clause") }, - Version = "0.0.5", + Version = "0.0.6", }); c.CustomSchemaIds(type => type.FriendlyId(true)); c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{Assembly.GetEntryAssembly().GetName().Name}.xml"); @@ -145,7 +145,7 @@ namespace Org.OpenAPITools // set route prefix to openapi, e.g. http://localhost:8080/openapi/index.html c.RoutePrefix = "openapi"; //TODO: Either use the SwaggerGen generated OpenAPI contract (generated from C# classes) - c.SwaggerEndpoint("/openapi/0.0.5/openapi.json", "World Storage API"); + c.SwaggerEndpoint("/openapi/0.0.6/openapi.json", "World Storage API"); //TODO: Or alternatively use the original OpenAPI contract that's included in the static files // c.SwaggerEndpoint("/openapi-original.json", "World Storage API Original"); -- GitLab From 15861cadb9dffc42708a2a85e78cdaa89e7eb3cd Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Wed, 18 May 2022 17:19:30 +0200 Subject: [PATCH 18/35] introduced some logic (check, if elements of Link (to and from) exist) --- .../ControllersImpl/TrackablesApiImpl.cs | 14 +++- .../ControllersImpl/WorldAnchorsApiImpl.cs | 12 ++- .../ControllersImpl/WorldLinksApiImpl.cs | 74 +++++++++++++++++++ .../Services/TrackableService.cs | 3 + .../Services/WorldAnchorService.cs | 4 +- server/src/Org.OpenAPITools/Startup.cs | 30 ++++---- 6 files changed, 114 insertions(+), 23 deletions(-) diff --git a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs index b788c68..4068462 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs @@ -93,18 +93,24 @@ namespace Org.OpenAPITools.Controllers string result = "ok"; string worldlinkinfo = ""; List worldlinklistfrom = _trackableService.GetWorldLinkUUIDFrom(trackableUUID); - List worldlinklistto = _trackableService.GetWorldLinkUUIDTo(trackableUUID); - foreach(WorldLink worldlink in worldlinklistfrom) + foreach (WorldLink worldlink in worldlinklistfrom) { worldlinkinfo += worldlink.UUID.ToString() + "; "; + worldlink.UUIDFrom = Guid.Empty; + worldlink.TypeFrom = ObjectType.NotIdentifiedEnum; + _trackableService.UpdateWorldLink(worldlink.UUID, worldlink); } + List worldlinklistto = _trackableService.GetWorldLinkUUIDTo(trackableUUID); foreach (WorldLink worldlink in worldlinklistto) - { + { worldlinkinfo += worldlink.UUID.ToString() + "; "; + worldlink.UUIDTo = Guid.Empty; + worldlink.TypeTo = ObjectType.NotIdentifiedEnum; + _trackableService.UpdateWorldLink(worldlink.UUID, worldlink); } if (worldlinkinfo.Length > 1) { - result += ", but removed object is still referenced in " + worldlinkinfo; + result += ", removed object was referenced in " + worldlinkinfo + " and removed there as well"; } return (answer.IsAcknowledged && answer.DeletedCount > 0) ? new ObjectResult(result) : StatusCode(404, "Not found, could not find UUID in database."); } diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs index 1fc7c34..003a748 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs @@ -93,20 +93,26 @@ namespace Org.OpenAPITools.Controllers string result = "ok"; string worldlinkinfo = ""; List worldlinklistfrom = _worldAnchorService.GetWorldLinkUUIDFrom(worldAnchorUUID); - List worldlinklistto = _worldAnchorService.GetWorldLinkUUIDTo(worldAnchorUUID); foreach (WorldLink worldlink in worldlinklistfrom) { worldlinkinfo += worldlink.UUID.ToString() + "; "; + worldlink.UUIDFrom = Guid.Empty; + worldlink.TypeFrom = ObjectType.NotIdentifiedEnum; + _worldAnchorService.UpdateWorldLink(worldlink.UUID, worldlink); } + List worldlinklistto = _worldAnchorService.GetWorldLinkUUIDTo(worldAnchorUUID); foreach (WorldLink worldlink in worldlinklistto) { worldlinkinfo += worldlink.UUID.ToString() + "; "; + worldlink.UUIDTo = Guid.Empty; + worldlink.TypeTo = ObjectType.NotIdentifiedEnum; + _worldAnchorService.UpdateWorldLink(worldlink.UUID, worldlink); } if (worldlinkinfo.Length > 1) { - result += ", but removed object is still referenced in " + worldlinkinfo; + result += ", but removed object was referenced in " + worldlinkinfo + " and removed there as well"; } - return (answer.IsAcknowledged && answer.DeletedCount > 0) ? new ObjectResult(result) : StatusCode(404, "Not found, could not find UUID in database."); + return (answer.IsAcknowledged && answer.DeletedCount > 0) ? new ObjectResult(result) : StatusCode(404, "Not found, could not find UUID in database."); } /// diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs index 491bc46..14cb079 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs @@ -107,6 +107,43 @@ namespace Org.OpenAPITools.Controllers public override IActionResult GetWorldLinkById([FromRoute(Name = "worldLinkUUID")][Required] Guid worldLinkUUID) { WorldLink myworldlink = _worldLinkService.Get(worldLinkUUID); + if (null != myworldlink) + { + // check TypeFrom + if (myworldlink.TypeFrom == ObjectType.TrackableEnum) + { + if (null == _worldLinkService.GetTrackable(myworldlink.UUIDFrom)) + { + myworldlink.TypeFrom = ObjectType.NotIdentifiedEnum; + myworldlink.UUIDFrom = Guid.Empty; + } + } + else if (myworldlink.TypeFrom == ObjectType.WorldAnchorEnum) + { + if (null == _worldLinkService.GetAnchor(myworldlink.UUIDFrom)) + { + myworldlink.TypeFrom = ObjectType.NotIdentifiedEnum; + myworldlink.UUIDFrom = Guid.Empty; + } + } + // check TypeTo + if (myworldlink.TypeTo == ObjectType.TrackableEnum) + { + if (null == _worldLinkService.GetTrackable(myworldlink.UUIDTo)) + { + myworldlink.TypeTo = ObjectType.NotIdentifiedEnum; + myworldlink.UUIDTo = Guid.Empty; + } + } + else if (myworldlink.TypeTo == ObjectType.WorldAnchorEnum) + { + if (null == _worldLinkService.GetAnchor(myworldlink.UUIDTo)) + { + myworldlink.TypeTo = ObjectType.NotIdentifiedEnum; + myworldlink.UUIDTo = Guid.Empty; + } + } + } return (null != myworldlink) ? new ObjectResult(myworldlink) : StatusCode(404, "Not found, could not find UUID in database."); } @@ -125,6 +162,43 @@ namespace Org.OpenAPITools.Controllers public override IActionResult GetWorldLinks() { List worldlinklist = _worldLinkService.Get(); + foreach (WorldLink myworldlink in worldlinklist) + { + // check TypeFrom + if (myworldlink.TypeFrom == ObjectType.TrackableEnum) + { + if (null == _worldLinkService.GetTrackable(myworldlink.UUIDFrom)) + { + myworldlink.TypeFrom = ObjectType.NotIdentifiedEnum; + myworldlink.UUIDFrom = Guid.Empty; + } + } + else if (myworldlink.TypeFrom == ObjectType.WorldAnchorEnum) + { + if (null == _worldLinkService.GetAnchor(myworldlink.UUIDFrom)) + { + myworldlink.TypeFrom = ObjectType.NotIdentifiedEnum; + myworldlink.UUIDFrom = Guid.Empty; + } + } + // check TypeTo + if (myworldlink.TypeTo == ObjectType.TrackableEnum) + { + if (null == _worldLinkService.GetTrackable(myworldlink.UUIDTo)) + { + myworldlink.TypeTo = ObjectType.NotIdentifiedEnum; + myworldlink.UUIDTo = Guid.Empty; + } + } + else if (myworldlink.TypeTo == ObjectType.WorldAnchorEnum) + { + if (null == _worldLinkService.GetAnchor(myworldlink.UUIDTo)) + { + myworldlink.TypeTo = ObjectType.NotIdentifiedEnum; + myworldlink.UUIDTo = Guid.Empty; + } + } + } return new ObjectResult(worldlinklist); } } diff --git a/server/src/Org.OpenAPITools/Services/TrackableService.cs b/server/src/Org.OpenAPITools/Services/TrackableService.cs index 4fc12b2..7d5c799 100644 --- a/server/src/Org.OpenAPITools/Services/TrackableService.cs +++ b/server/src/Org.OpenAPITools/Services/TrackableService.cs @@ -57,6 +57,9 @@ namespace Org.OpenAPITools.Services public List GetWorldLinkUUIDTo(Guid UUID) => _worldlinkcollection.Find(worldlink => worldlink.UUIDTo == UUID).ToList(); + public ReplaceOneResult UpdateWorldLink(Guid UUID, WorldLink worldlinkIn) => + _worldlinkcollection.ReplaceOne(worldlink => worldlink.UUID == UUID, worldlinkIn); + } } diff --git a/server/src/Org.OpenAPITools/Services/WorldAnchorService.cs b/server/src/Org.OpenAPITools/Services/WorldAnchorService.cs index a7c9da3..f7efda2 100644 --- a/server/src/Org.OpenAPITools/Services/WorldAnchorService.cs +++ b/server/src/Org.OpenAPITools/Services/WorldAnchorService.cs @@ -55,7 +55,9 @@ namespace Org.OpenAPITools.Services public List GetWorldLinkUUIDTo(Guid UUID) => _worldlinkcollection.Find(worldlink => worldlink.UUIDTo == UUID).ToList(); - } + public ReplaceOneResult UpdateWorldLink(Guid UUID, WorldLink worldlinkIn) => + _worldlinkcollection.ReplaceOne(worldlink => worldlink.UUID == UUID, worldlinkIn); + } } diff --git a/server/src/Org.OpenAPITools/Startup.cs b/server/src/Org.OpenAPITools/Startup.cs index 2ac047b..718268b 100644 --- a/server/src/Org.OpenAPITools/Startup.cs +++ b/server/src/Org.OpenAPITools/Startup.cs @@ -77,12 +77,12 @@ namespace Org.OpenAPITools }) .AddNewtonsoftJson(opts => { - opts.SerializerSettings.ContractResolver = new DefaultContractResolver(); -/* opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - opts.SerializerSettings.Converters.Add(new StringEnumConverter - { - NamingStrategy = new CamelCaseNamingStrategy() - });*/ + opts.SerializerSettings.ContractResolver = new DefaultContractResolver(); + /* opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + opts.SerializerSettings.Converters.Add(new StringEnumConverter + { + NamingStrategy = new CamelCaseNamingStrategy() + });*/ }); services @@ -109,9 +109,9 @@ namespace Org.OpenAPITools c.CustomSchemaIds(type => type.FriendlyId(true)); c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{Assembly.GetEntryAssembly().GetName().Name}.xml"); - // Include DataAnnotation attributes on Controller Action parameters as OpenAPI validation rules (e.g required, pattern, ..) - // Use [ValidateModelState] on Actions to actually validate it in C# as well! - c.OperationFilter(); + // Include DataAnnotation attributes on Controller Action parameters as OpenAPI validation rules (e.g required, pattern, ..) + // Use [ValidateModelState] on Actions to actually validate it in C# as well! + c.OperationFilter(); }); services .AddSwaggerGenNewtonsoftSupport(); @@ -142,14 +142,14 @@ namespace Org.OpenAPITools }) .UseSwaggerUI(c => { - // set route prefix to openapi, e.g. http://localhost:8080/openapi/index.html - c.RoutePrefix = "openapi"; - //TODO: Either use the SwaggerGen generated OpenAPI contract (generated from C# classes) + // set route prefix to openapi, e.g. http://localhost:8080/openapi/index.html + c.RoutePrefix = "openapi"; + //TODO: Either use the SwaggerGen generated OpenAPI contract (generated from C# classes) c.SwaggerEndpoint("/openapi/0.0.6/openapi.json", "World Storage API"); - //TODO: Or alternatively use the original OpenAPI contract that's included in the static files - // c.SwaggerEndpoint("/openapi-original.json", "World Storage API Original"); - }); + //TODO: Or alternatively use the original OpenAPI contract that's included in the static files + //c.SwaggerEndpoint("/openapi-original.json", "World Storage API Original"); + }); app.UseRouting(); app.UseEndpoints(endpoints => { -- GitLab From af39c70483df96869fff5f58cabe5b831a6042ad Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Thu, 19 May 2022 09:27:54 +0200 Subject: [PATCH 19/35] changed reference in Startup.cs to use the original OpenAPI contract that's included in the static files (instead of using generated from C# classes) to get the provided sample requests --- readme.md | 5 ++++- server/src/Org.OpenAPITools/Startup.cs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 46a84cd..d8e60a6 100644 --- a/readme.md +++ b/readme.md @@ -32,7 +32,7 @@ change version number in all files if a new version is provided ### folder `Controllers`: change "`public class`" to "`public abstract class`" -compare files in "`ControllersImpl`" with the corresponding files in "`Controllers`" and adapt if necessary +compare files folder in "`ControllersImpl`" with the corresponding files in "`Controllers`" and adapt if necessary methods should be the same with "`override`" instead of "`virtual`" @@ -77,6 +77,9 @@ the folder `Services` should contain one common class with the DatabaseSettings the naming in the DatabaseSettings is the same as defined in `appsettings.json`, which you have to extend when creating new classes in this folder. changed `appsettings.json` in the folder `docker` accordingly. Make sure that the ConnectionString for the database contains the correct IP address as specified in `docker-compose.yml`. +### folder `wwwroot` +add in `openapi-original.json` in section `servers` the urls of the servers you want to use with swagger-ui + # MongoDB if you don't have a MongoDB, follow the instructions in `readme.md` in `server/programs/MongoDB` diff --git a/server/src/Org.OpenAPITools/Startup.cs b/server/src/Org.OpenAPITools/Startup.cs index 718268b..c9e1470 100644 --- a/server/src/Org.OpenAPITools/Startup.cs +++ b/server/src/Org.OpenAPITools/Startup.cs @@ -145,10 +145,10 @@ namespace Org.OpenAPITools // set route prefix to openapi, e.g. http://localhost:8080/openapi/index.html c.RoutePrefix = "openapi"; //TODO: Either use the SwaggerGen generated OpenAPI contract (generated from C# classes) - c.SwaggerEndpoint("/openapi/0.0.6/openapi.json", "World Storage API"); + //c.SwaggerEndpoint("/openapi/0.0.6/openapi.json", "World Storage API"); //TODO: Or alternatively use the original OpenAPI contract that's included in the static files - //c.SwaggerEndpoint("/openapi-original.json", "World Storage API Original"); + c.SwaggerEndpoint("/openapi-original.json", "World Storage API Original"); }); app.UseRouting(); app.UseEndpoints(endpoints => -- GitLab From e693e1ea332e6a4635c0c74334e177e0d9d8da4b Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Thu, 2 Jun 2022 11:51:40 +0200 Subject: [PATCH 20/35] version 1.0.0 --- readme.md | 4 +-- .../ControllersImpl/DefaultApiImpl.cs | 4 +-- .../ControllersImpl/TrackablesApiImpl.cs | 34 +++++++++++++++++-- .../ControllersImpl/WorldAnchorsApiImpl.cs | 34 ++++++++++++++++++- .../ControllersImpl/WorldLinksApiImpl.cs | 32 ++++++++++++++++- server/src/Org.OpenAPITools/Startup.cs | 8 ++--- server/src/Org.OpenAPITools/appsettings.json | 2 +- 7 files changed, 105 insertions(+), 13 deletions(-) diff --git a/readme.md b/readme.md index d8e60a6..1e37de1 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# Description of version 0.0.6 +# Description of version 1.0.0 auto-generated ASP.NET server code @@ -75,7 +75,7 @@ and at the value that is to become the MongoDB ID, add: ### folder `Services` the folder `Services` should contain one common class with the DatabaseSettings (`DatabaseSettings.cs`) and one with the database-access-methods (create, get, update, remove) for each API. If some are missing create them like the ones you find there. Be aware to add the reference to these in the file `startup.cs` in this case. -the naming in the DatabaseSettings is the same as defined in `appsettings.json`, which you have to extend when creating new classes in this folder. changed `appsettings.json` in the folder `docker` accordingly. Make sure that the ConnectionString for the database contains the correct IP address as specified in `docker-compose.yml`. +the naming in the DatabaseSettings is the same as defined in `appsettings.json`, which you have to extend when creating new classes in this folder. Change `appsettings.json` in the folder `docker` accordingly. Make sure that the ConnectionString for the database contains the correct IP address as specified in `docker-compose.yml`. ### folder `wwwroot` add in `openapi-original.json` in section `servers` the urls of the servers you want to use with swagger-ui diff --git a/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs index 5d7c9fa..05d7b2c 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.6 + * The version of the OpenAPI document: 1.0.0 * * Generated by: https://openapi-generator.tech */ @@ -72,7 +72,7 @@ namespace Org.OpenAPITools.Controllers [SwaggerResponse(statusCode: 200, type: typeof(string), description: "Current version.")] public override IActionResult GetVersion() { - string version = "0.0.6"; + string version = "1.0.0"; return new ObjectResult(version); //return StatusCode(200, new ObjectResult(version)); } diff --git a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs index 4068462..8564cff 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.6 + * The version of the OpenAPI document: 1.0.0 * * Generated by: https://openapi-generator.tech */ @@ -70,7 +70,7 @@ namespace Org.OpenAPITools.Controllers return new ObjectResult(mytrackable); } catch (Exception e) - { + { return StatusCode(400, e.Message); } } @@ -150,5 +150,35 @@ namespace Org.OpenAPITools.Controllers List trackablelist = _trackableService.Get(); return new ObjectResult(trackablelist); } + + + + /// + /// Modify a Trackable. + /// + /// Modify an existing Trackable given a json object containing all the required informations. <br> **Please note that ID of the object is required in the JSON** + /// The Trackable to be modified in the world storage. + /// OK, return the UUID of the modified Trackable. + /// Bad request. + /// Not found, could not find UUID in database. + /// Unexpected error. + [HttpPut] + [Route("/trackables")] + [Consumes("application/json")] + [ValidateModelState] + [SwaggerOperation("ModifyTrackable")] + [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] + public override IActionResult ModifyTrackable([FromBody] Trackable trackable) + { + ReplaceOneResult result = _trackableService.Update(trackable.UUID, trackable); + if (result.MatchedCount == 0) + { + return StatusCode(404, "Not found, could not find UUID in database."); + } + else + { + return StatusCode(200, trackable.UUID); + } + } } } diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs index 003a748..890aebd 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.6 + * The version of the OpenAPI document: 1.0.0 * * Generated by: https://openapi-generator.tech */ @@ -150,5 +150,37 @@ namespace Org.OpenAPITools.Controllers List worldanchorlist = _worldAnchorService.Get(); return new ObjectResult(worldanchorlist); } + + + + /// + /// Modify a World Anchor. + /// + /// Modify an existing World Anchor given a json object containing all the required informations. <br> **Please note that ID of the object is required in the JSON** + /// The World Anchor to be modified in the world storage. + /// OK, return the UUID of the modified World Anchor. + /// Bad request. + /// Not found, could not find UUID in database. + /// Unexpected error. + [HttpPut] + [Route("/worldAnchors")] + [Consumes("application/json")] + [ValidateModelState] + [SwaggerOperation("ModifyWorldAnchor")] + [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] + public override IActionResult ModifyWorldAnchor([FromBody] WorldAnchor worldAnchor) + { + ReplaceOneResult result = _worldAnchorService.Update(worldAnchor.UUID, worldAnchor); + if (result.MatchedCount == 0) + { + return StatusCode(404, "Not found, could not find UUID in database."); + } + else + { + return StatusCode(200, worldAnchor.UUID); + } + } + + } } diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs index 14cb079..60d1335 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.6 + * The version of the OpenAPI document: 1.0.0 * * Generated by: https://openapi-generator.tech */ @@ -201,5 +201,35 @@ namespace Org.OpenAPITools.Controllers } return new ObjectResult(worldlinklist); } + + + + /// + /// Modify a World Link. + /// + /// Modify an existing World Link given a json object containing all the required informations. <br> **Please note that ID of the object is required in the JSON** + /// The World Link to be modified in the world storage. + /// OK, return the UUID of the modified World Link. + /// Bad request. + /// Not found, could not find UUID in database. + /// Unexpected error. + [HttpPut] + [Route("/worldLinks")] + [Consumes("application/json")] + [ValidateModelState] + [SwaggerOperation("ModifyWorldLink")] + [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] + public override IActionResult ModifyWorldLink([FromBody] WorldLink worldLink) + { + ReplaceOneResult result = _worldLinkService.Update(worldLink.UUID, worldLink); + if (result.MatchedCount == 0) + { + return StatusCode(404, "Not found, could not find UUID in database."); + } + else + { + return StatusCode(200, worldLink.UUID); + } + } } } diff --git a/server/src/Org.OpenAPITools/Startup.cs b/server/src/Org.OpenAPITools/Startup.cs index c9e1470..02e91fd 100644 --- a/server/src/Org.OpenAPITools/Startup.cs +++ b/server/src/Org.OpenAPITools/Startup.cs @@ -3,7 +3,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 0.0.6 + * The version of the OpenAPI document: 1.0.0 * * Generated by: https://openapi-generator.tech */ @@ -88,7 +88,7 @@ namespace Org.OpenAPITools services .AddSwaggerGen(c => { - c.SwaggerDoc("0.0.6", new OpenApiInfo + c.SwaggerDoc("1.0.0", new OpenApiInfo { Title = "World Storage API", Description = "World Storage API (ASP.NET Core 3.1)", @@ -104,7 +104,7 @@ namespace Org.OpenAPITools Name = "NoLicense", Url = new Uri("https://opensource.org/licenses/BSD-3-Clause") }, - Version = "0.0.6", + Version = "1.0.0", }); c.CustomSchemaIds(type => type.FriendlyId(true)); c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{Assembly.GetEntryAssembly().GetName().Name}.xml"); @@ -145,7 +145,7 @@ namespace Org.OpenAPITools // set route prefix to openapi, e.g. http://localhost:8080/openapi/index.html c.RoutePrefix = "openapi"; //TODO: Either use the SwaggerGen generated OpenAPI contract (generated from C# classes) - //c.SwaggerEndpoint("/openapi/0.0.6/openapi.json", "World Storage API"); + //c.SwaggerEndpoint("/openapi/1.0.0/openapi.json", "World Storage API"); //TODO: Or alternatively use the original OpenAPI contract that's included in the static files c.SwaggerEndpoint("/openapi-original.json", "World Storage API Original"); diff --git a/server/src/Org.OpenAPITools/appsettings.json b/server/src/Org.OpenAPITools/appsettings.json index 05ce266..aebd1bb 100644 --- a/server/src/Org.OpenAPITools/appsettings.json +++ b/server/src/Org.OpenAPITools/appsettings.json @@ -3,7 +3,7 @@ "CollectionNameWorldLink": "WorldLink", "CollectionNameTrackables": "Trackables", "CollectionNameWorldAnchor": "WorldAnchor", - "ConnectionString": "mongodb://vm009254.fe.hhi.de:27017", + "ConnectionString": "mongodb://localhost:27017", "DatabaseName": "WorldStorageAPI" }, "Logging": { -- GitLab From aa4423d6d77805bbd88c800dd02d1b8c3009883c Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Thu, 2 Jun 2022 15:30:47 +0200 Subject: [PATCH 21/35] submodule changed to develop --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 0b8e82d..120fcda 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "arf005"] path = arf005 url = git@forge.etsi.org:arf/arf005.git - branch = feature/elementNameAndNewObjectType \ No newline at end of file + branch = develop \ No newline at end of file -- GitLab From 89c0cc8e02d3cd3ba9725462e5a47b5bbfcad246 Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Thu, 2 Jun 2022 16:17:54 +0200 Subject: [PATCH 22/35] updated submodule --- arf005 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arf005 b/arf005 index 8b13db3..5b1f626 160000 --- a/arf005 +++ b/arf005 @@ -1 +1 @@ -Subproject commit 8b13db35ec8349a8bf513f9ad1d35d6a24699a00 +Subproject commit 5b1f626df42db4f8cb0fd4eba8142affda3c3af5 -- GitLab From c862e47e59d94a7e769c23b80079cdab9328bf8c Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Thu, 2 Jun 2022 16:04:46 +0000 Subject: [PATCH 23/35] Update DefaultApiImpl.cs --- .../ControllersImpl/DefaultApiImpl.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs index 05d7b2c..846deae 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs @@ -1,3 +1,23 @@ +// +// ARF - Augmented Reality Framework (ETSI ISG ARF) +// +// Copyright 2022 ETSI +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Last change: June 2022 +// + /* * World Storage API * -- GitLab From dccbc22180f50b6a4211c3a544e02a6ca7b09b0a Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Thu, 2 Jun 2022 16:05:09 +0000 Subject: [PATCH 24/35] Update TrackablesApiImpl.cs --- .../ControllersImpl/TrackablesApiImpl.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs index 8564cff..ea8dd3e 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs @@ -1,3 +1,23 @@ +// +// ARF - Augmented Reality Framework (ETSI ISG ARF) +// +// Copyright 2022 ETSI +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Last change: June 2022 +// + /* * World Storage API * -- GitLab From 8ced0ac86d50ae57df785355e7ad275ecd26fb64 Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Thu, 2 Jun 2022 16:05:24 +0000 Subject: [PATCH 25/35] Update WorldAnchorsApiImpl.cs --- .../ControllersImpl/WorldAnchorsApiImpl.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs index 890aebd..2fc64cf 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs @@ -1,3 +1,23 @@ +// +// ARF - Augmented Reality Framework (ETSI ISG ARF) +// +// Copyright 2022 ETSI +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Last change: June 2022 +// + /* * World Storage API * -- GitLab From b83a5434057facb025e7dcf5247b61e664887cc6 Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Thu, 2 Jun 2022 16:05:41 +0000 Subject: [PATCH 26/35] Update WorldLinksApiImpl.cs --- .../ControllersImpl/WorldLinksApiImpl.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs index 60d1335..ae751cf 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs @@ -1,3 +1,23 @@ +// +// ARF - Augmented Reality Framework (ETSI ISG ARF) +// +// Copyright 2022 ETSI +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Last change: June 2022 +// + /* * World Storage API * -- GitLab From 20cc96803ef7f920ba76f976c8d006e3c9fc3724 Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Thu, 2 Jun 2022 16:06:11 +0000 Subject: [PATCH 27/35] Update WorldLinkService.cs --- .../Services/WorldLinkService.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/server/src/Org.OpenAPITools/Services/WorldLinkService.cs b/server/src/Org.OpenAPITools/Services/WorldLinkService.cs index 1df2aa9..073c597 100644 --- a/server/src/Org.OpenAPITools/Services/WorldLinkService.cs +++ b/server/src/Org.OpenAPITools/Services/WorldLinkService.cs @@ -1,4 +1,24 @@ -using System; +// +// ARF - Augmented Reality Framework (ETSI ISG ARF) +// +// Copyright 2022 ETSI +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Last change: June 2022 +// + +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -- GitLab From e4a41f206ca240aef6e11e77dcfa7fc56078cdd2 Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Thu, 2 Jun 2022 16:06:26 +0000 Subject: [PATCH 28/35] Update WorldAnchorService.cs --- .../Services/WorldAnchorService.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/server/src/Org.OpenAPITools/Services/WorldAnchorService.cs b/server/src/Org.OpenAPITools/Services/WorldAnchorService.cs index f7efda2..8a6e7c6 100644 --- a/server/src/Org.OpenAPITools/Services/WorldAnchorService.cs +++ b/server/src/Org.OpenAPITools/Services/WorldAnchorService.cs @@ -1,4 +1,24 @@ -using System; +// +// ARF - Augmented Reality Framework (ETSI ISG ARF) +// +// Copyright 2022 ETSI +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Last change: June 2022 +// + +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -- GitLab From 2e2395fe6a3d30b57b074311fcf4d9cdcea2f639 Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Thu, 2 Jun 2022 16:06:39 +0000 Subject: [PATCH 29/35] Update TrackableService.cs --- .../Services/TrackableService.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/server/src/Org.OpenAPITools/Services/TrackableService.cs b/server/src/Org.OpenAPITools/Services/TrackableService.cs index 7d5c799..a115449 100644 --- a/server/src/Org.OpenAPITools/Services/TrackableService.cs +++ b/server/src/Org.OpenAPITools/Services/TrackableService.cs @@ -1,4 +1,24 @@ -using System; +// +// ARF - Augmented Reality Framework (ETSI ISG ARF) +// +// Copyright 2022 ETSI +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Last change: June 2022 +// + +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -- GitLab From 5d997da5a1d734db9640c1a349644f585e9385db Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Thu, 2 Jun 2022 16:06:57 +0000 Subject: [PATCH 30/35] Update DatabaseSettings.cs --- .../Services/DatabaseSettings.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/server/src/Org.OpenAPITools/Services/DatabaseSettings.cs b/server/src/Org.OpenAPITools/Services/DatabaseSettings.cs index 336639b..93f177d 100644 --- a/server/src/Org.OpenAPITools/Services/DatabaseSettings.cs +++ b/server/src/Org.OpenAPITools/Services/DatabaseSettings.cs @@ -1,4 +1,24 @@ -using System; +// +// ARF - Augmented Reality Framework (ETSI ISG ARF) +// +// Copyright 2022 ETSI +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Last change: June 2022 +// + +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -22,4 +42,4 @@ namespace Org.OpenAPITools.Services string ConnectionString { get; set; } string DatabaseName { get; set; } } -} \ No newline at end of file +} -- GitLab From ee43791f2997458ce351815ad6bcd0733321823d Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Thu, 2 Jun 2022 16:07:51 +0000 Subject: [PATCH 31/35] Update Startup.cs --- server/src/Org.OpenAPITools/Startup.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/server/src/Org.OpenAPITools/Startup.cs b/server/src/Org.OpenAPITools/Startup.cs index 02e91fd..a3ee347 100644 --- a/server/src/Org.OpenAPITools/Startup.cs +++ b/server/src/Org.OpenAPITools/Startup.cs @@ -1,3 +1,23 @@ +// +// ARF - Augmented Reality Framework (ETSI ISG ARF) +// +// Copyright 2022 ETSI +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Last change: June 2022 +// + /* * World Storage API * -- GitLab From 3f2d420f88d6d74dabe7ac3751ad6dc4b0cc10a2 Mon Sep 17 00:00:00 2001 From: Detlef Runde Date: Fri, 3 Jun 2022 12:55:20 +0200 Subject: [PATCH 32/35] returning only UUID with POST-requests (instead of returning the complete object) --- .../ControllersImpl/DefaultApiImpl.cs | 7 +-- .../ControllersImpl/TrackablesApiImpl.cs | 42 +++++++++++------ .../ControllersImpl/WorldAnchorsApiImpl.cs | 42 +++++++++++------ .../ControllersImpl/WorldLinksApiImpl.cs | 46 +++++++++++++------ 4 files changed, 93 insertions(+), 44 deletions(-) diff --git a/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs index 05d7b2c..f2805b3 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs @@ -31,7 +31,7 @@ namespace Org.OpenAPITools.Controllers { /// - /// Get the version of the server. + /// Get the state of the server. /// /// OK, world storage server ready. [HttpGet] @@ -47,13 +47,14 @@ namespace Org.OpenAPITools.Controllers } /// - /// Test the server availability + /// Test the server availability. /// - /// OK, world storage alive. + /// Ok, returns a string message. [HttpGet] [Route("/ping")] [ValidateModelState] [SwaggerOperation("GetPing")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "Ok, returns a string message.")] public override IActionResult GetPing() { string answer = "OK, world storage alive."; diff --git a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs index 8564cff..44d96e0 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs @@ -43,10 +43,11 @@ namespace Org.OpenAPITools.Controllers /// - /// Create a trackable + /// Create a Trackable. /// - /// The trackable to be added to the world storage. - /// OK, returns the UUID of the Trackable defined by the world storage. + /// Create a new Trackable from a json object containing all the required informations and add it to the world storage. <br>As a result you will get the ID of the newly created Trackable. + /// The Trackable to be added to the world storage. + /// OK, return the UUID of the Trackable defined by the world storage. /// Null response. /// Bad request. /// Invalid UUID, id must be a Nil value. @@ -56,7 +57,10 @@ namespace Org.OpenAPITools.Controllers [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("AddTrackable")] - [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, returns the UUID of the Trackable defined by the world storage.")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, return the UUID of the Trackable defined by the world storage.")] + [SwaggerResponse(statusCode: 201, type: typeof(string), description: "Null response.")] + [SwaggerResponse(statusCode: 400, type: typeof(string), description: "Bad request.")] + [SwaggerResponse(statusCode: 409, type: typeof(string), description: "Invalid UUID, id must be a Nil value.")] [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] public override IActionResult AddTrackable([FromBody] Trackable trackable) { @@ -67,17 +71,18 @@ namespace Org.OpenAPITools.Controllers try { Trackable mytrackable = _trackableService.Create(trackable); - return new ObjectResult(mytrackable); + return StatusCode(200, mytrackable.UUID.ToString()); } catch (Exception e) - { + { return StatusCode(400, e.Message); } } /// - /// Deletes a trackable. + /// Delete a Trackable. /// + /// Delete a single Trackable stored in the world storage from its ID. /// Trackable UUID to delete. /// OK, delete successful. /// Invalid UUID supplied. @@ -86,6 +91,9 @@ namespace Org.OpenAPITools.Controllers [Route("/trackables/{trackableUUID}")] [ValidateModelState] [SwaggerOperation("DeleteTrackable")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, delete successful.")] + [SwaggerResponse(statusCode: 400, type: typeof(string), description: "Invalid UUID supplied.")] + [SwaggerResponse(statusCode: 404, type: typeof(string), description: "Not found, could not find UUID in database.")] public override IActionResult DeleteTrackable([FromRoute(Name = "trackableUUID")][Required] Guid trackableUUID) { DeleteResult answer = _trackableService.Remove(trackableUUID); @@ -116,9 +124,10 @@ namespace Org.OpenAPITools.Controllers } /// - /// Find a trackable by its UUID. + /// Find a Trackable by its UUID. /// - /// UUID of the trackable to retrieve. + /// Get a single Trackable stored in the world storage from its ID. + /// UUID of the Trackable to retrieve. /// Successful operation. /// Invalid UUID supplied. /// Not found, could not find UUID in database. @@ -127,6 +136,8 @@ namespace Org.OpenAPITools.Controllers [ValidateModelState] [SwaggerOperation("GetTrackableById")] [SwaggerResponse(statusCode: 200, type: typeof(Trackable), description: "Successful operation.")] + [SwaggerResponse(statusCode: 400, type: typeof(string), description: "Invalid UUID supplied.")] + [SwaggerResponse(statusCode: 404, type: typeof(string), description: "Not found, could not find UUID in database.")] public override IActionResult GetTrackableById([FromRoute(Name = "trackableUUID")][Required] Guid trackableUUID) { Trackable trackable = _trackableService.Get(trackableUUID); @@ -134,16 +145,18 @@ namespace Org.OpenAPITools.Controllers } /// - /// returns the list of all trackables defined by the world storage. + /// Return all the Trackables. /// - /// OK, returns all the Trackables defined by the world storage. + /// Get all the Trackables currently being stored in the world storage. + /// OK, return all the Trackables defined by the world storage. /// Null response. /// Unexpected error. [HttpGet] [Route("/trackables")] [ValidateModelState] [SwaggerOperation("GetTrackables")] - [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK, returns all the Trackables defined by the world storage.")] + [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK, return all the Trackables defined by the world storage.")] + [SwaggerResponse(statusCode: 201, type: typeof(string), description: "Null response.")] [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] public override IActionResult GetTrackables() { @@ -167,6 +180,9 @@ namespace Org.OpenAPITools.Controllers [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("ModifyTrackable")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, return the UUID of the modified Trackable.")] + [SwaggerResponse(statusCode: 400, type: typeof(string), description: "Bad request.")] + [SwaggerResponse(statusCode: 404, type: typeof(string), description: "Not found, could not find UUID in database.")] [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] public override IActionResult ModifyTrackable([FromBody] Trackable trackable) { @@ -177,7 +193,7 @@ namespace Org.OpenAPITools.Controllers } else { - return StatusCode(200, trackable.UUID); + return StatusCode(200, trackable.UUID.ToString()); } } } diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs index 890aebd..be55581 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs @@ -43,10 +43,11 @@ namespace Org.OpenAPITools.Controllers /// - /// Create a world anchor. + /// Create a World Anchor. /// - /// The world anchor to be added to the world storage. - /// OK, returns the UUID of the World Anchor defined by the world storage. + /// Create a new World Anchor from a json object containing all the required informations and add it to the world storage. <br>As a result you will get the ID of the newly created World Anchor. + /// The World Anchor to be added to the world storage. + /// OK, return the UUID of the World Anchor defined by the world storage. /// Null response. /// Bad request. /// Invalid UUID, id must be a Nil value. @@ -56,7 +57,10 @@ namespace Org.OpenAPITools.Controllers [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("AddWorldAnchor")] - [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, returns the UUID of the World Anchor defined by the world storage.")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, return the UUID of the World Anchor defined by the world storage.")] + [SwaggerResponse(statusCode: 201, type: typeof(string), description: "Null response.")] + [SwaggerResponse(statusCode: 400, type: typeof(string), description: "Bad request.")] + [SwaggerResponse(statusCode: 409, type: typeof(string), description: "Invalid UUID, id must be a Nil value.")] [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] public override IActionResult AddWorldAnchor([FromBody] WorldAnchor worldAnchor) { @@ -67,7 +71,7 @@ namespace Org.OpenAPITools.Controllers try { WorldAnchor myworldanchor = _worldAnchorService.Create(worldAnchor); - return new ObjectResult(myworldanchor); + return StatusCode(200, myworldanchor.UUID.ToString()); } catch (Exception e) { @@ -76,9 +80,10 @@ namespace Org.OpenAPITools.Controllers } /// - /// Deletes a world anchor. + /// Delete a World Anchor. /// - /// World anchor UUID to delete. + /// Delete a single World Anchor stored in the world storage from its ID. + /// World Anchor UUID to delete. /// OK, delete successful. /// Invalid UUID supplied. /// Not found, could not find UUID in database. @@ -86,6 +91,9 @@ namespace Org.OpenAPITools.Controllers [Route("/worldAnchors/{worldAnchorUUID}")] [ValidateModelState] [SwaggerOperation("DeleteWorldAnchor")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, delete successful.")] + [SwaggerResponse(statusCode: 400, type: typeof(string), description: "Invalid UUID supplied.")] + [SwaggerResponse(statusCode: 404, type: typeof(string), description: "Not found, could not find UUID in database.")] public override IActionResult DeleteWorldAnchor([FromRoute(Name = "worldAnchorUUID")][Required] Guid worldAnchorUUID) { DeleteResult answer = _worldAnchorService.Remove((worldAnchorUUID)); @@ -116,9 +124,10 @@ namespace Org.OpenAPITools.Controllers } /// - /// Find a world anchor by its UUID. + /// Find a World Anchor by its UUID. /// - /// UUID of the world anchor to retrieve. + /// Get a single World Anchor stored in the world storage from its ID. + /// UUID of the World Anchor to retrieve. /// Successful operation. /// Invalid UUID supplied. /// Not found, could not find UUID in database. @@ -127,6 +136,8 @@ namespace Org.OpenAPITools.Controllers [ValidateModelState] [SwaggerOperation("GetWorldAnchorById")] [SwaggerResponse(statusCode: 200, type: typeof(WorldAnchor), description: "Successful operation.")] + [SwaggerResponse(statusCode: 400, type: typeof(string), description: "Invalid UUID supplied.")] + [SwaggerResponse(statusCode: 404, type: typeof(string), description: "Not found, could not find UUID in database.")] public override IActionResult GetWorldAnchorById([FromRoute(Name = "worldAnchorUUID")][Required] Guid worldAnchorUUID) { WorldAnchor myworldanchor = _worldAnchorService.Get(worldAnchorUUID); @@ -134,16 +145,18 @@ namespace Org.OpenAPITools.Controllers } /// - /// Returns the list of all world anchors defined by the world storage. + /// Return all the World Anchors. /// - /// OK, returns all the world anchors defined by the world storage. + /// Get all the World Anchors currently being stored in the world storage. + /// OK, return all the World Anchors defined by the world storage. /// Null response. /// Unexpected error. [HttpGet] [Route("/worldAnchors")] [ValidateModelState] [SwaggerOperation("GetWorldAnchors")] - [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK, returns all the world anchors defined by the world storage.")] + [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK, return all the World Anchors defined by the world storage.")] + [SwaggerResponse(statusCode: 201, type: typeof(string), description: "Null response.")] [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] public override IActionResult GetWorldAnchors() { @@ -167,6 +180,9 @@ namespace Org.OpenAPITools.Controllers [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("ModifyWorldAnchor")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, return the UUID of the modified World Anchor.")] + [SwaggerResponse(statusCode: 400, type: typeof(string), description: "Bad request.")] + [SwaggerResponse(statusCode: 404, type: typeof(string), description: "Not found, could not find UUID in database.")] [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] public override IActionResult ModifyWorldAnchor([FromBody] WorldAnchor worldAnchor) { @@ -177,7 +193,7 @@ namespace Org.OpenAPITools.Controllers } else { - return StatusCode(200, worldAnchor.UUID); + return StatusCode(200, worldAnchor.UUID.ToString()); } } diff --git a/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs index 60d1335..1c31a85 100644 --- a/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs +++ b/server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs @@ -42,11 +42,12 @@ namespace Org.OpenAPITools.Controllers } /// - /// Create a link between world anchors and trackables. + /// Create a World Link between elements (world anchors and/or trackables). /// + /// Create a new World Link from a json object containing all the required informations and add it to the world storage. <br>As a result you will get the ID of the newly created World Link. /// The link to be added to the world storage. - /// OK, returns the UUID of the link defined by the world storage. - /// Null response + /// OK, return the UUID of the World Link defined by the world storage. + /// Null response. /// Bad request. /// Invalid UUID, id must be a Nil value. /// Unexpected error. @@ -55,7 +56,10 @@ namespace Org.OpenAPITools.Controllers [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("AddWorldLink")] - [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, returns the UUID of the link defined by the world storage.")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, return the UUID of the World Link defined by the world storage.")] + [SwaggerResponse(statusCode: 201, type: typeof(string), description: "Null response.")] + [SwaggerResponse(statusCode: 400, type: typeof(string), description: "Bad request.")] + [SwaggerResponse(statusCode: 409, type: typeof(string), description: "Invalid UUID, id must be a Nil value.")] [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] public override IActionResult AddWorldLink([FromBody] WorldLink worldLink) { @@ -66,7 +70,7 @@ namespace Org.OpenAPITools.Controllers try { WorldLink myworldlink = _worldLinkService.Create(worldLink); - return new ObjectResult(myworldlink); + return StatusCode(200, myworldlink.UUID.ToString()); } catch (Exception e) { @@ -75,16 +79,20 @@ namespace Org.OpenAPITools.Controllers } /// - /// Deletes a worldLink. + /// Delete a World Link. /// - /// link id to delete - /// OK + /// Delete a single World Link stored in the world storage from its ID. + /// World Link id to delete. + /// OK, delete successful. /// Invalid UUID supplied. /// Not found, could not find UUID in database. [HttpDelete] [Route("/worldLinks/{worldLinkUUID}")] [ValidateModelState] [SwaggerOperation("DeleteWorldLink")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, delete successful.")] + [SwaggerResponse(statusCode: 400, type: typeof(string), description: "Invalid UUID supplied.")] + [SwaggerResponse(statusCode: 404, type: typeof(string), description: "Not found, could not find UUID in database.")] public override IActionResult DeleteWorldLink([FromRoute(Name = "worldLinkUUID")][Required] Guid worldLinkUUID) { DeleteResult answer = _worldLinkService.Remove((worldLinkUUID)); @@ -93,9 +101,10 @@ namespace Org.OpenAPITools.Controllers /// - /// Find a link by its UUID. + /// Find a World Link by its UUID. /// - /// UUID of the link to retrieve. + /// Get a single World Link stored in the world storage from its ID. + /// UUID of the World Link to retrieve. /// Successful operation. /// Invalid UUID supplied. /// Not found, could not find UUID in database. @@ -104,6 +113,8 @@ namespace Org.OpenAPITools.Controllers [ValidateModelState] [SwaggerOperation("GetWorldLinkById")] [SwaggerResponse(statusCode: 200, type: typeof(WorldLink), description: "Successful operation.")] + [SwaggerResponse(statusCode: 400, type: typeof(string), description: "Invalid UUID supplied.")] + [SwaggerResponse(statusCode: 404, type: typeof(string), description: "Not found, could not find UUID in database.")] public override IActionResult GetWorldLinkById([FromRoute(Name = "worldLinkUUID")][Required] Guid worldLinkUUID) { WorldLink myworldlink = _worldLinkService.Get(worldLinkUUID); @@ -148,16 +159,18 @@ namespace Org.OpenAPITools.Controllers } /// - /// Returns the list of all links defined by the world storage. + /// Return all World Links. /// - /// OK returns all the worldLinks defined by the world storage. - /// Null response + /// Get all the World Links currently being stored in the world storage. + /// OK return all the World Links defined by the world storage. + /// Null response. /// Unexpected error. [HttpGet] [Route("/worldLinks")] [ValidateModelState] [SwaggerOperation("GetWorldLinks")] - [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK returns all the worldLinks defined by the world storage.")] + [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK return all the World Links defined by the world storage.")] + [SwaggerResponse(statusCode: 201, type: typeof(string), description: "Null response.")] [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] public override IActionResult GetWorldLinks() { @@ -218,6 +231,9 @@ namespace Org.OpenAPITools.Controllers [Consumes("application/json")] [ValidateModelState] [SwaggerOperation("ModifyWorldLink")] + [SwaggerResponse(statusCode: 200, type: typeof(string), description: "OK, return the UUID of the modified World Link.")] + [SwaggerResponse(statusCode: 400, type: typeof(string), description: "Bad request.")] + [SwaggerResponse(statusCode: 404, type: typeof(string), description: "Not found, could not find UUID in database.")] [SwaggerResponse(statusCode: 0, type: typeof(Error), description: "Unexpected error.")] public override IActionResult ModifyWorldLink([FromBody] WorldLink worldLink) { @@ -228,7 +244,7 @@ namespace Org.OpenAPITools.Controllers } else { - return StatusCode(200, worldLink.UUID); + return StatusCode(200, worldLink.UUID.ToString()); } } } -- GitLab From bc01e404904e287030ddd2148cb038afc5c20bbc Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Mon, 13 Jun 2022 17:38:03 +0200 Subject: [PATCH 33/35] Use now API v1.0.0 --- arf005 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arf005 b/arf005 index 5b1f626..533b9d3 160000 --- a/arf005 +++ b/arf005 @@ -1 +1 @@ -Subproject commit 5b1f626df42db4f8cb0fd4eba8142affda3c3af5 +Subproject commit 533b9d3198b772c7b628b0ab0e0a144b89966b46 -- GitLab From f453db1714d3f10fa11a746558a4ba45097a7e7a Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Mon, 13 Jun 2022 18:08:38 +0200 Subject: [PATCH 34/35] Some changes in readme.md --- readme.md | 89 +++++++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/readme.md b/readme.md index 1e37de1..e747cc6 100644 --- a/readme.md +++ b/readme.md @@ -1,48 +1,48 @@ # Description of version 1.0.0 -auto-generated ASP.NET server code - -includes description and code for a fully functional server with MongoDB integration +This project construct a complete ASP-Net REST server compliant to the ARF World Storage API. It uses auto-generated ASP.NET server code. We propose to use the open source OpenAPI-Generator for this. +It includes description and code for a fully functional server with MongoDB integration. # Prerequisites -1. installed npm: https://phoenixnap.com/kb/install-node-js-npm-on-windows +What you need: + +1. Installed npm: https://phoenixnap.com/kb/install-node-js-npm-on-windows 2. Installed openapi generator with npm: https://openapi-generator.tech/docs/installation/ 3. Installed docker (if you want to use it): https://www.docker.com/get-started - # Generate or update the server -we provided the file `.openapi-generator-ignore` in `server`, which prevents openapi-generator to override some adapted files +We provided the file `.openapi-generator-ignore` in `server`, which prevents openapi-generator to override some adapted files. -## auto-generate server code -open a command shell and execute +## Auto-generate server code +Open a command shell and execute: ``` openapi-generator-cli generate -i arf005\API\openapi.yaml -g aspnetcore -o server ``` -open the solution `Org.OpenAPITools.sln` (folder `server`) in Visual Studio +Open the solution `Org.OpenAPITools.sln` (folder `server`) in Visual Studio: ## In Visual Studio: -open `NuGet Package Manager` and add `MongoDB.Driver` +Open `NuGet Package Manager` and add `MongoDB.Driver`. ### File adaptations: -change version number in all files if a new version is provided +Change version number in all files if a new version is provided. -### folder `Controllers`: -change "`public class`" to "`public abstract class`" +### In the folder `Controllers`: +Change "`public class`" to "`public abstract class`". -compare files folder in "`ControllersImpl`" with the corresponding files in "`Controllers`" and adapt if necessary +Compare files folder in "`ControllersImpl`" with the corresponding files in "`Controllers`" and adapt if necessary. -methods should be the same with "`override`" instead of "`virtual`" +Methods should be the same with "`override`" instead of "`virtual`". --- #### - if files are missing (and only then): -copy them from folder `Controllers`, rename them (append `Impl`) and handle them like the already existing files, i.e.: -change classnames by appending `Impl` to the original classnames (and change filenames accordingly) and inherit from original class in `Controllers` (instead of `ControllerBase`) +Copy them from folder `Controllers`, rename them (append `Impl`) and handle them like the already existing files, i.e.: +Change classnames by appending `Impl` to the original classnames (and change filenames accordingly) and inherit from original class in `Controllers` (instead of `ControllerBase`) -and replace `virtual` by `override` with all methods. +..and replace `virtual` by `override` with all methods. Add ``` @@ -50,17 +50,16 @@ Add using MongoDB.Driver; ``` -Add a private readonly service class variable like in the already existing files +Add a private readonly service class variable like in the already existing files. -Add a constructor with this service class variable like in the already existing files +Add a constructor with this service class variable like in the already existing files. -remove sample code and replace it by using the appropriate methods of the corresponding classes in the folder `Services` -(which you may be have to create) +Remove sample code and replace it by using the appropriate methods of the corresponding classes in the folder `Services` (which you may be have to create). --- -### folder `Models`: -add to the classes to be stored in the database (i.e. `Trackable.cs`, `WorldAnchor.cs`, `WorldLink.cs`) : +### In the folder `Models`: +Add to the classes to be stored in the database (i.e. `Trackable.cs`, `WorldAnchor.cs`, `WorldLink.cs`) : ``` using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; @@ -72,58 +71,58 @@ and at the value that is to become the MongoDB ID, add: [BsonRepresentation(BsonType.String)] ``` -### folder `Services` -the folder `Services` should contain one common class with the DatabaseSettings (`DatabaseSettings.cs`) and one with the database-access-methods (create, get, update, remove) for each API. If some are missing create them like the ones you find there. Be aware to add the reference to these in the file `startup.cs` in this case. +### Folder `Services` +The folder `Services` should contain one common class with the DatabaseSettings (`DatabaseSettings.cs`) and one with the database-access-methods (create, get, update, remove) for each API. If some are missing create them like the ones you find there. Be aware to add the reference to these in the file `startup.cs` in this case. -the naming in the DatabaseSettings is the same as defined in `appsettings.json`, which you have to extend when creating new classes in this folder. Change `appsettings.json` in the folder `docker` accordingly. Make sure that the ConnectionString for the database contains the correct IP address as specified in `docker-compose.yml`. +The naming in the DatabaseSettings is the same as defined in `appsettings.json`, which you have to extend when creating new classes in this folder. Change `appsettings.json` in the folder `docker` accordingly. Make sure that the ConnectionString for the database contains the correct IP address as specified in `docker-compose.yml`. -### folder `wwwroot` -add in `openapi-original.json` in section `servers` the urls of the servers you want to use with swagger-ui +### In the folder `wwwroot` +Add in `openapi-original.json` in section `servers` the urls of the servers you want to use with swagger-ui # MongoDB -if you don't have a MongoDB, follow the instructions in `readme.md` in `server/programs/MongoDB` +If you don't have a MongoDB, follow the instructions in `readme.md` in `server/programs/MongoDB` -and put MongoDB in folder `server/programs/MongoDB` (download MongoDB as zip-file from https://www.mongodb.com/try/download/community and unzip the file into this directory, so that the bin-directory is in this folder) +...and put MongoDB in folder `server/programs/MongoDB` (download MongoDB as zip-file from https://www.mongodb.com/try/download/community and unzip the file into this directory, so that the bin-directory is in this folder). # Use in Visual Studio -make sure, that an instance of MongoDB is running +Make sure, that an instance of MongoDB is running. -start application with IIS Express +Start application with IIS Express. -# Use in Docker -remove the substring `src/Org.OpenAPITools/` in Dockerfile (if not already done) +# Use within a Docker +Remove the substring `src/Org.OpenAPITools/` in Dockerfile (if not already done) open a command shell and generate docker by executing in `server/src/Org.OpenAPITools`: ``` docker build -t org.openapitools . ``` -## to start: -the easiest way is to use docker-compose: +## How to start: +The easiest way is to use docker-compose: -open a command shell and use docker-compose (if necessary adapt docker-compose.yml) by executing in `server/src/Org.OpenAPITools`: +Open a command shell and use docker-compose (if necessary adapt docker-compose.yml) by executing in `server/src/Org.OpenAPITools`: ``` docker-compose up --force-recreate --remove-orphan --detach ``` -open http://localhost:8080/openapi/index.html in a web-browser, if you want to check the functionalities using SwaggerUI +Open http://localhost:8080/openapi/index.html in a web-browser, if you want to check the functionalities using SwaggerUI -## to stop: -open a command shell by executing in `server/src/Org.OpenAPITools`: +## How to stop: +Open a command shell by executing in `server/src/Org.OpenAPITools`: ``` docker-compose down ``` -## to dump database -execute the following command in docker: +## How to dump database +Execute the following command in docker: ``` mongodump --db **insert database_name** --out /data-dump/`date +"%Y-%m-%d"` ``` -## to import database: -execute the following command in docker: +## How to import database: +Execute the following command in docker: ``` mongorestore --db **insert database_name** **insert path_to_bson_file** ``` \ No newline at end of file -- GitLab From a730abe0c444b5b791f130c1573236eb457de894 Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Mon, 13 Jun 2022 18:09:47 +0200 Subject: [PATCH 35/35] Some correctures --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index e747cc6..bc84c31 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # Description of version 1.0.0 -This project construct a complete ASP-Net REST server compliant to the ARF World Storage API. It uses auto-generated ASP.NET server code. We propose to use the open source OpenAPI-Generator for this. +This project should be used to construct a complete ASP-Net REST server compliant to the ARF World Storage API. It uses auto-generated ASP.NET server code. We propose to use the open source OpenAPI-Generator for this. It includes description and code for a fully functional server with MongoDB integration. -- GitLab