readme.md 5.55 KB
Newer Older
Nathan Chambron's avatar
Nathan Chambron committed
*This repository is part of the outcomes of the Specialist Task Force 620 focusing on the authoring of a World Representation as part of the ETSI ISG Augmented Reality Framework architecture (https://www.etsi.org/deliver/etsi_gs/ARF/001_099/003/01.01.01_60/gs_ARF003v010101p.pdf).*
*The set of the World Representation authoring components includes:*

*•	The C++ and C# source code for servers and clients  generated from OpenAPI available here (https://forge.etsi.org/rep/arf/arf005)*

*•	A Unity plugin and a Unity editor for authoring and accessing a World Representation hosted on a World Storage server.*

*All these components are available under the ETSI Labs group “World Storage API Helpers”: https://labs.etsi.org/rep/arf/world-storage-api-helpers*

---

Detlef Runde's avatar
Detlef Runde committed
# Description of version 1.0.0
Sylvain Renault's avatar
Sylvain Renault committed
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.
Detlef Runde's avatar
Detlef Runde committed

# Prerequisites
What you need:

1.	Installed npm: https://phoenixnap.com/kb/install-node-js-npm-on-windows
Detlef Runde's avatar
Detlef Runde committed
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:
Sylvain Renault's avatar
Sylvain Renault committed
  openapi-generator-cli generate -i arf005\API\openapi.yaml -g aspnetcore -o server
Open the solution `Org.OpenAPITools.sln` (folder `server`) in Visual Studio:
Sylvain Renault's avatar
Sylvain Renault committed
## In Visual Studio
Open `NuGet Package Manager` and add `MongoDB.Driver`.
Sylvain Renault's avatar
Sylvain Renault committed
### File adaptations
Change version number in all files if a new version is provided.
Sylvain Renault's avatar
Sylvain Renault committed
### 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`".
Sylvain Renault's avatar
Sylvain Renault committed
#### If some 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).
Sylvain Renault's avatar
Sylvain Renault committed
### 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;
```

Detlef Runde's avatar
Detlef Runde committed
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 .
```

Sylvain Renault's avatar
Sylvain Renault committed
## How to start
The easiest way is to use docker-compose:
Detlef Runde's avatar
Detlef Runde committed

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
Sylvain Renault's avatar
Sylvain Renault committed
## 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"`
```

Sylvain Renault's avatar
Sylvain Renault committed
## How to import database
Execute the following command in docker:
```
  mongorestore --db **insert database_name** **insert path_to_bson_file**
Nathan Chambron's avatar
Nathan Chambron committed
```