New API generated code using abstract class instead of virtual.

New folder for all custom classes. New batch files to quickly start the creation of the docker and docker-compose. Use config file instead of CLI parameters to generate te server.

Merge request reports

Loading
+0 −102
Changes for server/src/Org.OpenAPITools/ControllersImpl/DefaultApiImpl.cs: 0 added lines, 102 removed lines.
Original line number Diff line number Diff line
//
// 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));
    }

  }
}
+0 −220
Changes for server/src/Org.OpenAPITools/ControllersImpl/TrackablesApiImpl.cs: 0 added lines, 220 removed lines.
Original line number Diff line number Diff line
//
// 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());
      }
    }
  }
}
+0 −222
Changes for server/src/Org.OpenAPITools/ControllersImpl/WorldAnchorsApiImpl.cs: 0 added lines, 222 removed lines.
Original line number Diff line number Diff line
//
// 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());
      }
    }


  }
}
+0 −271
Changes for server/src/Org.OpenAPITools/ControllersImpl/WorldLinksApiImpl.cs: 0 added lines, 271 removed lines.
Original line number Diff line number Diff line
//
// 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());
      }
    }
  }
}
+0 −86
Changes for server/src/Org.OpenAPITools/Services/TrackableService.cs: 0 added lines, 86 removed lines.
Original line number Diff line number Diff line
//
// 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);

  }

}
Loading
Loading