Skip to content
Snippets Groups Projects
Commit 40b39dc6 authored by Sylvain Renault's avatar Sylvain Renault
Browse files

Merge branch 'develop' into 'main'

Use now API v1.0.0

See merge request !2
parents 20ebd617 a730abe0
No related branches found
No related tags found
2 merge requests!5Main,!2Use now API v1.0.0
Showing
with 1570 additions and 0 deletions
## 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
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
# 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
[submodule "arf005"]
path = arf005
url = git@forge.etsi.org:arf/arf005.git
branch = develop
\ No newline at end of file
arf005 @ 533b9d31
Subproject commit 533b9d3198b772c7b628b0ab0e0a144b89966b46
{
"$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "5.3.0"
}
}
readme.md 0 → 100644
# Description of version 1.0.0
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.
# Prerequisites
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.
## 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:
## In Visual Studio:
Open `NuGet Package Manager` and add `MongoDB.Driver`.
### File adaptations:
Change version number in all files if a new version is provided.
### 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.
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`)
..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).
---
### 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;
```
and at the value that is to become the MongoDB ID, add:
```
[BsonId]
[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. 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`.
### 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`
...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.
Start application with IIS Express.
# 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 .
```
## 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`:
```
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
## How to stop:
Open a command shell by executing in `server/src/Org.OpenAPITools`:
```
docker-compose down
```
## How to dump database
Execute the following command in docker:
```
mongodump --db **insert database_name** --out /data-dump/`date +"%Y-%m-%d"`
```
## 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
# 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
taskkill -im mongod.exe
\ No newline at end of file
# 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
cd bin
call "cmd /c start mongod.exe --dbpath ../../../data"
cd ..
\ No newline at end of file
//
// 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
*
* API ensuring interoperability between an authoring tool and a World Storage service
*
* The version of the OpenAPI document: 1.0.0
*
* 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
{
/// <summary>
///
/// </summary>
[ApiController]
public class DefaultApiControllerImpl : DefaultApiController
{
/// <summary>
/// Get the state of the server.
/// </summary>
/// <response code="200">OK, world storage server ready.</response>
[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));
}
/// <summary>
/// Test the server availability.
/// </summary>
/// <response code="200">Ok, returns a string message.</response>
[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.";
return new ObjectResult(answer);
// return StatusCode(200, new ObjectResult(answer));
}
/// <summary>
/// Get the version of the ARF API.
/// </summary>
/// <response code="200">Current version.</response>
[HttpGet]
[Route("/version")]
[ValidateModelState]
[SwaggerOperation("GetVersion")]
[SwaggerResponse(statusCode: 200, type: typeof(string), description: "Current version.")]
public override IActionResult GetVersion()
{
string version = "1.0.0";
return new ObjectResult(version);
//return StatusCode(200, new ObjectResult(version));
}
}
}
//
// 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
*
* API ensuring interoperability between an authoring tool and a World Storage service
*
* The version of the OpenAPI document: 1.0.0
*
* 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
{
/// <summary>
///
/// </summary>
[ApiController]
public class TrackablesApiControllerImpl : TrackablesApiController
{
private readonly TrackableService _trackableService;
/// <summary>
///
/// </summary>
public TrackablesApiControllerImpl(TrackableService trackableService)
{
_trackableService = trackableService;
}
/// <summary>
/// Create a Trackable.
/// </summary>
/// <remarks>Create a new Trackable from a json object containing all the required informations and add it to the world storage. &lt;br&gt;As a result you will get the ID of the newly created Trackable.</remarks>
/// <param name="trackable">The Trackable to be added to the world storage.</param>
/// <response code="200">OK, return the UUID of the Trackable defined by the world storage.</response>
/// <response code="201">Null response.</response>
/// <response code="400">Bad request.</response>
/// <response code="409">Invalid UUID, id must be a Nil value.</response>
/// <response code="0">Unexpected error.</response>
[HttpPost]
[Route("/trackables")]
[Consumes("application/json")]
[ValidateModelState]
[SwaggerOperation("AddTrackable")]
[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)
{
if (String.IsNullOrEmpty(trackable.UUID.ToString()))
{
trackable.UUID = Guid.NewGuid();
}
try
{
Trackable mytrackable = _trackableService.Create(trackable);
return StatusCode(200, mytrackable.UUID.ToString());
}
catch (Exception e)
{
return StatusCode(400, e.Message);
}
}
/// <summary>
/// Delete a Trackable.
/// </summary>
/// <remarks>Delete a single Trackable stored in the world storage from its ID.</remarks>
/// <param name="trackableUUID">Trackable UUID to delete.</param>
/// <response code="200">OK, delete successful.</response>
/// <response code="400">Invalid UUID supplied.</response>
/// <response code="404">Not found, could not find UUID in database.</response>
[HttpDelete]
[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);
// check, if used in WorldLink
string result = "ok";
string worldlinkinfo = "";
List<WorldLink> worldlinklistfrom = _trackableService.GetWorldLinkUUIDFrom(trackableUUID);
foreach (WorldLink worldlink in worldlinklistfrom)
{
worldlinkinfo += worldlink.UUID.ToString() + "; ";
worldlink.UUIDFrom = Guid.Empty;
worldlink.TypeFrom = ObjectType.NotIdentifiedEnum;
_trackableService.UpdateWorldLink(worldlink.UUID, worldlink);
}
List<WorldLink> 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 += ", 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.");
}
/// <summary>
/// Find a Trackable by its UUID.
/// </summary>
/// <remarks>Get a single Trackable stored in the world storage from its ID.</remarks>
/// <param name="trackableUUID">UUID of the Trackable to retrieve.</param>
/// <response code="200">Successful operation.</response>
/// <response code="400">Invalid UUID supplied.</response>
/// <response code="404">Not found, could not find UUID in database.</response>
[HttpGet]
[Route("/trackables/{trackableUUID}")]
[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);
return (null != trackable) ? new ObjectResult(trackable) : StatusCode(404, "Not found, could not find UUID in database.");
}
/// <summary>
/// Return all the Trackables.
/// </summary>
/// <remarks>Get all the Trackables currently being stored in the world storage.</remarks>
/// <response code="200">OK, return all the Trackables defined by the world storage.</response>
/// <response code="201">Null response.</response>
/// <response code="0">Unexpected error.</response>
[HttpGet]
[Route("/trackables")]
[ValidateModelState]
[SwaggerOperation("GetTrackables")]
[SwaggerResponse(statusCode: 200, type: typeof(List<Trackable>), 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()
{
List<Trackable> trackablelist = _trackableService.Get();
return new ObjectResult(trackablelist);
}
/// <summary>
/// Modify a Trackable.
/// </summary>
/// <remarks>Modify an existing Trackable given a json object containing all the required informations. &lt;br&gt; **Please note that ID of the object is required in the JSON**</remarks>
/// <param name="trackable">The Trackable to be modified in the world storage.</param>
/// <response code="200">OK, return the UUID of the modified Trackable.</response>
/// <response code="400">Bad request.</response>
/// <response code="404">Not found, could not find UUID in database.</response>
/// <response code="0">Unexpected error.</response>
[HttpPut]
[Route("/trackables")]
[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)
{
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.ToString());
}
}
}
}
//
// 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
*
* API ensuring interoperability between an authoring tool and a World Storage service
*
* The version of the OpenAPI document: 1.0.0
*
* 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
{
/// <summary>
///
/// </summary>
[ApiController]
public class WorldAnchorsApiControllerImpl : WorldAnchorsApiController
{
private readonly WorldAnchorService _worldAnchorService;
/// <summary>
///
/// </summary>
public WorldAnchorsApiControllerImpl(WorldAnchorService worldAnchorService)
{
_worldAnchorService = worldAnchorService;
}
/// <summary>
/// Create a World Anchor.
/// </summary>
/// <remarks>Create a new World Anchor from a json object containing all the required informations and add it to the world storage. &lt;br&gt;As a result you will get the ID of the newly created World Anchor.</remarks>
/// <param name="worldAnchor">The World Anchor to be added to the world storage.</param>
/// <response code="200">OK, return the UUID of the World Anchor defined by the world storage.</response>
/// <response code="201">Null response.</response>
/// <response code="400">Bad request.</response>
/// <response code="409">Invalid UUID, id must be a Nil value.</response>
/// <response code="0">Unexpected error.</response>
[HttpPost]
[Route("/worldAnchors")]
[Consumes("application/json")]
[ValidateModelState]
[SwaggerOperation("AddWorldAnchor")]
[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)
{
if (String.IsNullOrEmpty(worldAnchor.UUID.ToString()))
{
worldAnchor.UUID = Guid.NewGuid();
}
try
{
WorldAnchor myworldanchor = _worldAnchorService.Create(worldAnchor);
return StatusCode(200, myworldanchor.UUID.ToString());
}
catch (Exception e)
{
return StatusCode(400, e.Message);
}
}
/// <summary>
/// Delete a World Anchor.
/// </summary>
/// <remarks>Delete a single World Anchor stored in the world storage from its ID.</remarks>
/// <param name="worldAnchorUUID">World Anchor UUID to delete.</param>
/// <response code="200">OK, delete successful.</response>
/// <response code="400">Invalid UUID supplied.</response>
/// <response code="404">Not found, could not find UUID in database.</response>
[HttpDelete]
[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));
// check, if used in WorldLink
string result = "ok";
string worldlinkinfo = "";
List<WorldLink> worldlinklistfrom = _worldAnchorService.GetWorldLinkUUIDFrom(worldAnchorUUID);
foreach (WorldLink worldlink in worldlinklistfrom)
{
worldlinkinfo += worldlink.UUID.ToString() + "; ";
worldlink.UUIDFrom = Guid.Empty;
worldlink.TypeFrom = ObjectType.NotIdentifiedEnum;
_worldAnchorService.UpdateWorldLink(worldlink.UUID, worldlink);
}
List<WorldLink> 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 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.");
}
/// <summary>
/// Find a World Anchor by its UUID.
/// </summary>
/// <remarks>Get a single World Anchor stored in the world storage from its ID.</remarks>
/// <param name="worldAnchorUUID">UUID of the World Anchor to retrieve.</param>
/// <response code="200">Successful operation.</response>
/// <response code="400">Invalid UUID supplied.</response>
/// <response code="404">Not found, could not find UUID in database.</response>
[HttpGet]
[Route("/worldAnchors/{worldAnchorUUID}")]
[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);
return (null != myworldanchor) ? new ObjectResult(myworldanchor) : StatusCode(404, "Not found, could not find UUID in database.");
}
/// <summary>
/// Return all the World Anchors.
/// </summary>
/// <remarks>Get all the World Anchors currently being stored in the world storage.</remarks>
/// <response code="200">OK, return all the World Anchors defined by the world storage.</response>
/// <response code="201">Null response.</response>
/// <response code="0">Unexpected error.</response>
[HttpGet]
[Route("/worldAnchors")]
[ValidateModelState]
[SwaggerOperation("GetWorldAnchors")]
[SwaggerResponse(statusCode: 200, type: typeof(List<WorldAnchor>), 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()
{
List<WorldAnchor> worldanchorlist = _worldAnchorService.Get();
return new ObjectResult(worldanchorlist);
}
/// <summary>
/// Modify a World Anchor.
/// </summary>
/// <remarks>Modify an existing World Anchor given a json object containing all the required informations. &lt;br&gt; **Please note that ID of the object is required in the JSON**</remarks>
/// <param name="worldAnchor">The World Anchor to be modified in the world storage.</param>
/// <response code="200">OK, return the UUID of the modified World Anchor.</response>
/// <response code="400">Bad request.</response>
/// <response code="404">Not found, could not find UUID in database.</response>
/// <response code="0">Unexpected error.</response>
[HttpPut]
[Route("/worldAnchors")]
[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)
{
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.ToString());
}
}
}
}
//
// 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
*
* API ensuring interoperability between an authoring tool and a World Storage service
*
* The version of the OpenAPI document: 1.0.0
*
* 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
{
/// <summary>
///
/// </summary>
[ApiController]
public class WorldLinksApiControllerImpl : WorldLinksApiController
{
private readonly WorldLinkService _worldLinkService;
/// <summary>
///
/// </summary>
public WorldLinksApiControllerImpl(WorldLinkService worldLinkService)
{
_worldLinkService = worldLinkService;
}
/// <summary>
/// Create a World Link between elements (world anchors and/or trackables).
/// </summary>
/// <remarks>Create a new World Link from a json object containing all the required informations and add it to the world storage. &lt;br&gt;As a result you will get the ID of the newly created World Link.</remarks>
/// <param name="worldLink">The link to be added to the world storage.</param>
/// <response code="200">OK, return the UUID of the World Link defined by the world storage.</response>
/// <response code="201">Null response.</response>
/// <response code="400">Bad request.</response>
/// <response code="409">Invalid UUID, id must be a Nil value.</response>
/// <response code="0">Unexpected error.</response>
[HttpPost]
[Route("/worldLinks")]
[Consumes("application/json")]
[ValidateModelState]
[SwaggerOperation("AddWorldLink")]
[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)
{
if (String.IsNullOrEmpty(worldLink.UUID.ToString()))
{
worldLink.UUID = Guid.NewGuid();
}
try
{
WorldLink myworldlink = _worldLinkService.Create(worldLink);
return StatusCode(200, myworldlink.UUID.ToString());
}
catch (Exception e)
{
return StatusCode(400, e.Message);
}
}
/// <summary>
/// Delete a World Link.
/// </summary>
/// <remarks>Delete a single World Link stored in the world storage from its ID.</remarks>
/// <param name="worldLinkUUID">World Link id to delete.</param>
/// <response code="200">OK, delete successful.</response>
/// <response code="400">Invalid UUID supplied.</response>
/// <response code="404">Not found, could not find UUID in database.</response>
[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));
return (answer.IsAcknowledged && answer.DeletedCount > 0) ? new ObjectResult("ok") : StatusCode(404, "Not found, could not find UUID in database.");
}
/// <summary>
/// Find a World Link by its UUID.
/// </summary>
/// <remarks>Get a single World Link stored in the world storage from its ID.</remarks>
/// <param name="worldLinkUUID">UUID of the World Link to retrieve.</param>
/// <response code="200">Successful operation.</response>
/// <response code="400">Invalid UUID supplied.</response>
/// <response code="404">Not found, could not find UUID in database.</response>
[HttpGet]
[Route("/worldLinks/{worldLinkUUID}")]
[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);
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.");
}
/// <summary>
/// Return all World Links.
/// </summary>
/// <remarks>Get all the World Links currently being stored in the world storage.</remarks>
/// <response code="200">OK return all the World Links defined by the world storage.</response>
/// <response code="201">Null response.</response>
/// <response code="0">Unexpected error.</response>
[HttpGet]
[Route("/worldLinks")]
[ValidateModelState]
[SwaggerOperation("GetWorldLinks")]
[SwaggerResponse(statusCode: 200, type: typeof(List<WorldLink>), 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()
{
List<WorldLink> 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);
}
/// <summary>
/// Modify a World Link.
/// </summary>
/// <remarks>Modify an existing World Link given a json object containing all the required informations. &lt;br&gt; **Please note that ID of the object is required in the JSON**</remarks>
/// <param name="worldLink">The World Link to be modified in the world storage.</param>
/// <response code="200">OK, return the UUID of the modified World Link.</response>
/// <response code="400">Bad request.</response>
/// <response code="404">Not found, could not find UUID in database.</response>
/// <response code="0">Unexpected error.</response>
[HttpPut]
[Route("/worldLinks")]
[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)
{
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.ToString());
}
}
}
}
#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"]
//
// 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;
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; }
}
}
//
// 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;
using Org.OpenAPITools.Models;
using MongoDB.Driver;
namespace Org.OpenAPITools.Services
{
public class TrackableService
{
private readonly IMongoCollection<Trackable> _trackablecollection;
private readonly IMongoCollection<WorldLink> _worldlinkcollection;
/// <summary>
///
/// </summary>
public TrackableService(IDatabaseSettings settings)
{
var client = new MongoClient(settings.ConnectionString);
var database = client.GetDatabase(settings.DatabaseName);
_trackablecollection = database.GetCollection<Trackable>(settings.CollectionNameTrackables);
_worldlinkcollection = database.GetCollection<WorldLink>(settings.CollectionNameWorldLink);
}
public List<Trackable> Get() =>
_trackablecollection.Find(trackable => true).ToList();
public List<Trackable> Get(int limit) =>
_trackablecollection.Find(trackable => true).Limit(limit).ToList();
public Trackable Get(Guid UUID) =>
_trackablecollection.Find<Trackable>(trackable => trackable.UUID == UUID).FirstOrDefault();
public Trackable Create(Trackable trackable)
{
_trackablecollection.InsertOne(trackable);
return trackable;
}
public ReplaceOneResult Update(Guid UUID, Trackable trackableIn) =>
_trackablecollection.ReplaceOne(trackable => trackable.UUID == UUID, trackableIn);
public DeleteResult Remove(Trackable trackableIn) =>
_trackablecollection.DeleteOne(trackable => trackable.UUID == trackableIn.UUID);
public DeleteResult Remove(Guid UUID) =>
_trackablecollection.DeleteOne(trackable => trackable.UUID == UUID);
/* WorldLink */
public List<WorldLink> GetWorldLinkUUIDFrom(Guid UUID) =>
_worldlinkcollection.Find<WorldLink>(worldlink => worldlink.UUIDFrom == UUID).ToList();
public List<WorldLink> GetWorldLinkUUIDTo(Guid UUID) =>
_worldlinkcollection.Find<WorldLink>(worldlink => worldlink.UUIDTo == UUID).ToList();
public ReplaceOneResult UpdateWorldLink(Guid UUID, WorldLink worldlinkIn) =>
_worldlinkcollection.ReplaceOne(worldlink => worldlink.UUID == UUID, worldlinkIn);
}
}
//
// 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;
using Org.OpenAPITools.Models;
using MongoDB.Driver;
namespace Org.OpenAPITools.Services
{
public class WorldAnchorService
{
private readonly IMongoCollection<WorldAnchor> _worldanchorcollection;
private readonly IMongoCollection<WorldLink> _worldlinkcollection;
/// <summary>
///
/// </summary>
public WorldAnchorService(IDatabaseSettings settings)
{
var client = new MongoClient(settings.ConnectionString);
var database = client.GetDatabase(settings.DatabaseName);
_worldanchorcollection = database.GetCollection<WorldAnchor>(settings.CollectionNameWorldAnchor);
_worldlinkcollection = database.GetCollection<WorldLink>(settings.CollectionNameWorldLink);
}
public List<WorldAnchor> Get() =>
_worldanchorcollection.Find(worldanchor => true).ToList();
public List<WorldAnchor> Get(int limit) =>
_worldanchorcollection.Find(worldanchor => true).Limit(limit).ToList();
public WorldAnchor Get(Guid UUID) =>
_worldanchorcollection.Find<WorldAnchor>(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<WorldLink> GetWorldLinkUUIDFrom(Guid UUID) =>
_worldlinkcollection.Find<WorldLink>(worldlink => worldlink.UUIDFrom == UUID).ToList();
public List<WorldLink> GetWorldLinkUUIDTo(Guid UUID) =>
_worldlinkcollection.Find<WorldLink>(worldlink => worldlink.UUIDTo == UUID).ToList();
public ReplaceOneResult UpdateWorldLink(Guid UUID, WorldLink worldlinkIn) =>
_worldlinkcollection.ReplaceOne(worldlink => worldlink.UUID == UUID, worldlinkIn);
}
}
//
// 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;
using Org.OpenAPITools.Models;
using MongoDB.Driver;
namespace Org.OpenAPITools.Services
{
public class WorldLinkService
{
private readonly IMongoCollection<WorldLink> _worldlinkcollection;
private readonly IMongoCollection<WorldAnchor> _worldanchorcollection;
private readonly IMongoCollection<Trackable> _trackablecollection;
/// <summary>
///
/// </summary>
public WorldLinkService(IDatabaseSettings settings)
{
var client = new MongoClient(settings.ConnectionString);
var database = client.GetDatabase(settings.DatabaseName);
_worldlinkcollection = database.GetCollection<WorldLink>(settings.CollectionNameWorldLink);
_worldanchorcollection = database.GetCollection<WorldAnchor>(settings.CollectionNameWorldAnchor);
_trackablecollection = database.GetCollection<Trackable>(settings.CollectionNameTrackables);
}
public List<WorldLink> Get() =>
_worldlinkcollection.Find(worldlink => true).ToList();
public List<WorldLink> Get(int limit) =>
_worldlinkcollection.Find(worldlink => true).Limit(limit).ToList();
public WorldLink Get(Guid UUID) =>
_worldlinkcollection.Find<WorldLink>(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 => worldanchor.UUID == UUID).FirstOrDefault();
public Trackable GetTrackable(Guid UUID) =>
_trackablecollection.Find<Trackable>(trackable => trackable.UUID == UUID).FirstOrDefault();
}
}
//
// 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
*
* API ensuring interoperability between an authoring tool and a World Storage service
*
* The version of the OpenAPI document: 1.0.0
*
* 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
{
/// <summary>
/// Startup
/// </summary>
public class Startup
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="configuration"></param>
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
/// <summary>
/// The application configuration.
/// </summary>
public IConfiguration Configuration { get; }
/// <summary>
/// This method gets called by the runtime. Use this method to add services to the container.
/// </summary>
/// <param name="services"></param>
public void ConfigureServices(IServiceCollection services)
{
BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard));
BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3;
// requires using Microsoft.Extensions.Options
services.Configure<DatabaseSettings>(
Configuration.GetSection(nameof(DatabaseSettings)));
services.AddSingleton<IDatabaseSettings>(sp =>
sp.GetRequiredService<IOptions<DatabaseSettings>>().Value);
services.AddSingleton<TrackableService>();
services.AddSingleton<WorldAnchorService>();
services.AddSingleton<WorldLinkService>();
// 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("1.0.0", 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 = "1.0.0",
});
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<GeneratePathParamsValidationFilter>();
});
services
.AddSwaggerGenNewtonsoftSupport();
}
/// <summary>
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
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/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");
});
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
{
"DatabaseSettings": {
"CollectionNameWorldLink": "WorldLink",
"CollectionNameTrackables": "Trackables",
"CollectionNameWorldAnchor": "WorldAnchor",
"ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "WorldStorageAPI"
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment