Skip to content

Commit

Permalink
Create AE/src/dest APIs to return 409 if entity already exists (#182)
Browse files Browse the repository at this point in the history
* gh-180 Config AE/src/dst APIs to return 409 if entity already exists
* Fix integration tests. Update licenses

Signed-off-by: Victor Chang <vicchang@nvidia.com>
  • Loading branch information
mocsharp committed Sep 30, 2022
1 parent d4b85ad commit 5c6ba1d
Show file tree
Hide file tree
Showing 25 changed files with 209 additions and 110 deletions.
2 changes: 2 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ header:
- 'src/Monai.Deploy.InformaticsGateway.sln'
- 'src/Database/Migrations/**'
- 'demos/**/.env/**'
- 'demos/**/*.txt'
- 'docs/templates/**'
- 'tests/Integration.Test/*.dev'
- 'tests/Integration.Test/data/**'
- 'guidelines/diagrams/*.txt'

comment: on-failure

Expand Down
50 changes: 7 additions & 43 deletions doc/dependency_decisions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,21 +336,9 @@
:why: MIT (https://github.com/microsoft/vstest/raw/main/LICENSE)
:versions:
- 17.1.0
:when: 2022-08-16 23:05:48.342748414 Z
- - :approve
- Microsoft.CodeCoverage
- :who: mocsharp
:why: MIT (https://github.com/microsoft/vstest/raw/main/LICENSE)
:versions:
- 17.2.0
:when: 2022-08-16 23:05:48.787754812 Z
- - :approve
- Microsoft.CodeCoverage
- :who: mocsharp
:why: MIT (https://github.com/microsoft/vstest/raw/main/LICENSE)
:versions:
- 17.3.1
:when: 2022-09-01 23:05:49.229587689 Z
- 17.3.2
:when: 2022-08-16 23:05:48.342748414 Z
- - :approve
- Microsoft.Data.Sqlite.Core
- :who: mocsharp
Expand Down Expand Up @@ -725,7 +713,7 @@
- :who: mocsharp
:why: MIT (https://raw.githubusercontent.com/microsoft/vstest/main/LICENSE)
:versions:
- 17.3.1
- 17.3.2
:when: 2022-09-01 23:06:13.008314524 Z
- - :approve
- Microsoft.NETCore.Platforms
Expand Down Expand Up @@ -775,42 +763,18 @@
:why: MIT (https://github.com/microsoft/vstest/raw/v17.1.0/LICENSE)
:versions:
- 17.1.0
:when: 2022-08-16 23:06:16.175705981 Z
- - :approve
- Microsoft.TestPlatform.ObjectModel
- :who: mocsharp
:why: MIT (https://github.com/microsoft/vstest/raw/v17.2.0/LICENSE)
:versions:
- 17.2.0
:when: 2022-08-16 23:06:16.642573372 Z
- - :approve
- Microsoft.TestPlatform.ObjectModel
- :who: mocsharp
:why: MIT (https://github.com/microsoft/vstest/raw/v17.3.1/LICENSE)
:versions:
- 17.3.1
:when: 2022-09-01 23:06:17.198633634 Z
- 17.3.2
:when: 2022-08-16 23:06:16.175705981 Z
- - :approve
- Microsoft.TestPlatform.TestHost
- :who: mocsharp
:why: MIT (https://github.com/microsoft/vstest/raw/v17.1.0/LICENSE)
:versions:
- 17.1.0
:when: 2022-08-16 23:06:17.671459450 Z
- - :approve
- Microsoft.TestPlatform.TestHost
- :who: mocsharp
:why: MIT (https://github.com/microsoft/vstest/raw/v17.2.0/LICENSE)
:versions:
- 17.2.0
:when: 2022-08-16 23:06:18.130472318 Z
- - :approve
- Microsoft.TestPlatform.TestHost
- :who: mocsharp
:why: MIT (https://github.com/microsoft/vstest/raw/v17.3.1/LICENSE)
:versions:
- 17.3.1
:when: 2022-09-01 23:06:18.619013325 Z
- 17.3.2
:when: 2022-08-16 23:06:17.671459450 Z
- - :approve
- Microsoft.Toolkit.HighPerformance
- :who: mocsharp
Expand Down
3 changes: 3 additions & 0 deletions docs/api/rest/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Response Content Type: JSON - Array of [MonaiApplicationEntity](xref:Monai.Deplo
| ---- | --------------------------------------------------------------------------------------------------------------------------------------- |
| 200 | AE Titles retrieved successfully. |
| 404 | AE Title not found. |
| 409 | Entity already exists with the same name or AE Title. |
| 500 | Server error. The response will be a [Problem details](https://datatracker.ietf.org/doc/html/rfc7807) object with server error details. |

### Example Request
Expand Down Expand Up @@ -136,6 +137,7 @@ Response Content Type: JSON - [MonaiApplicationEntity](xref:Monai.Deploy.Informa
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| 201 | AE Title created successfully. |
| 400 | Validation error. The response will be a [Problem details](https://datatracker.ietf.org/doc/html/rfc7807) object with server error details. |
| 409 | Entity already exists with the same name or entity already exists with the same AE Title and port combination. |
| 500 | Server error. The response will be a [Problem details](https://datatracker.ietf.org/doc/html/rfc7807) object with server error details. |

### Example Request
Expand Down Expand Up @@ -301,6 +303,7 @@ Response Content Type: JSON - [SourceApplicationEntity](xref:Monai.Deploy.Inform
| ---- | --------------------------------------------------------------------------------------------------------------------------------------- |
| 201 | AE Title created successfully. |
| 400 | Validation error. |
| 409 | Entity already exists with the same name or entity already exists with the same AE Title, host/IP address and port combination. |
| 500 | Server error. The response will be a [Problem details](https://datatracker.ietf.org/doc/html/rfc7807) object with server error details. |

### Example Request
Expand Down
32 changes: 16 additions & 16 deletions docs/compliance/third-party-licenses.md
Original file line number Diff line number Diff line change
Expand Up @@ -3014,15 +3014,15 @@ SOFTWARE.


<details>
<summary>Microsoft.CodeCoverage 17.3.1</summary>
<summary>Microsoft.CodeCoverage 17.3.2</summary>

## Microsoft.CodeCoverage

- Version: 17.3.1
- Version: 17.3.2
- Authors: Microsoft
- Owners: Microsoft
- Project URL: https://github.com/microsoft/vstest/
- Source: [NuGet](https://www.nuget.org/packages/Microsoft.CodeCoverage/17.3.1)
- Source: [NuGet](https://www.nuget.org/packages/Microsoft.CodeCoverage/17.3.2)
- License: [MIT](https://github.com/microsoft/vstest/raw/main/LICENSE)


Expand Down Expand Up @@ -5595,15 +5595,15 @@ SOFTWARE.


<details>
<summary>Microsoft.NET.Test.Sdk 17.3.1</summary>
<summary>Microsoft.NET.Test.Sdk 17.3.2</summary>

## Microsoft.NET.Test.Sdk

- Version: 17.3.1
- Version: 17.3.2
- Authors: Microsoft
- Owners: Microsoft
- Project URL: https://github.com/microsoft/vstest/
- Source: [NuGet](https://www.nuget.org/packages/Microsoft.NET.Test.Sdk/17.3.1)
- Source: [NuGet](https://www.nuget.org/packages/Microsoft.NET.Test.Sdk/17.3.2)
- License: [MIT](https://raw.githubusercontent.com/microsoft/vstest/main/LICENSE)


Expand Down Expand Up @@ -6394,7 +6394,7 @@ SOFTWARE.
- Owners: Microsoft
- Project URL: https://github.com/microsoft/vstest/
- Source: [NuGet](https://www.nuget.org/packages/Microsoft.TestPlatform.ObjectModel/17.2.0)
- License: [MIT](https://github.com/microsoft/vstest/raw/v17.2.0/LICENSE)
- License: [MIT](https://github.com/microsoft/vstest/raw/v17.1.0/LICENSE)


```
Expand Down Expand Up @@ -6423,16 +6423,16 @@ SOFTWARE.


<details>
<summary>Microsoft.TestPlatform.ObjectModel 17.3.1</summary>
<summary>Microsoft.TestPlatform.ObjectModel 17.3.2</summary>

## Microsoft.TestPlatform.ObjectModel

- Version: 17.3.1
- Version: 17.3.2
- Authors: Microsoft
- Owners: Microsoft
- Project URL: https://github.com/microsoft/vstest/
- Source: [NuGet](https://www.nuget.org/packages/Microsoft.TestPlatform.ObjectModel/17.3.1)
- License: [MIT](https://github.com/microsoft/vstest/raw/v17.3.1/LICENSE)
- Source: [NuGet](https://www.nuget.org/packages/Microsoft.TestPlatform.ObjectModel/17.3.2)
- License: [MIT](https://github.com/microsoft/vstest/raw/v17.1.0/LICENSE)


```
Expand Down Expand Up @@ -6508,7 +6508,7 @@ SOFTWARE.
- Owners: Microsoft
- Project URL: https://github.com/microsoft/vstest/
- Source: [NuGet](https://www.nuget.org/packages/Microsoft.TestPlatform.TestHost/17.2.0)
- License: [MIT](https://github.com/microsoft/vstest/raw/v17.2.0/LICENSE)
- License: [MIT](https://github.com/microsoft/vstest/raw/v17.1.0/LICENSE)


```
Expand Down Expand Up @@ -6537,16 +6537,16 @@ SOFTWARE.


<details>
<summary>Microsoft.TestPlatform.TestHost 17.3.1</summary>
<summary>Microsoft.TestPlatform.TestHost 17.3.2</summary>

## Microsoft.TestPlatform.TestHost

- Version: 17.3.1
- Version: 17.3.2
- Authors: Microsoft
- Owners: Microsoft
- Project URL: https://github.com/microsoft/vstest/
- Source: [NuGet](https://www.nuget.org/packages/Microsoft.TestPlatform.TestHost/17.3.1)
- License: [MIT](https://github.com/microsoft/vstest/raw/v17.3.1/LICENSE)
- Source: [NuGet](https://www.nuget.org/packages/Microsoft.TestPlatform.TestHost/17.3.2)
- License: [MIT](https://github.com/microsoft/vstest/raw/v17.1.0/LICENSE)


```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
<PackageReference Include="xRetry" Version="1.8.0" />
<PackageReference Include="xunit" Version="2.4.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xRetry" Version="1.8.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
<PackageReference Include="xunit" Version="2.4.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
<PackageReference Include="xunit" Version="2.4.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xRetry" Version="1.8.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
Expand Down
42 changes: 42 additions & 0 deletions src/InformaticsGateway/Common/ObjectExistsException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2021-2022 MONAI Consortium
* Copyright 2019-2020 NVIDIA Corporation
*
* 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.
*/

using System;
using System.Runtime.Serialization;

namespace Monai.Deploy.InformaticsGateway.Common
{
[Serializable]
internal class ObjectExistsException : Exception
{
public ObjectExistsException()
{
}

public ObjectExistsException(string message) : base(message)
{
}

public ObjectExistsException(string message, Exception innerException) : base(message, innerException)
{
}

protected ObjectExistsException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Monai.Deploy.InformaticsGateway.Api;
using Monai.Deploy.InformaticsGateway.Common;
using Monai.Deploy.InformaticsGateway.Configuration;
using Monai.Deploy.InformaticsGateway.Logging;
using Monai.Deploy.InformaticsGateway.Repositories;
Expand Down Expand Up @@ -142,6 +143,7 @@ public async Task<IActionResult> CEcho(string name)
[Consumes(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[Produces("application/json")]
public async Task<ActionResult<string>> Create(DestinationApplicationEntity item)
Expand All @@ -157,9 +159,13 @@ public async Task<ActionResult<string>> Create(DestinationApplicationEntity item
_logger.DestinationApplicationEntityAdded(item.AeTitle, item.HostIp);
return CreatedAtAction(nameof(GetAeTitle), new { name = item.Name }, item);
}
catch (ObjectExistsException ex)
{
return Problem(title: "DICOM destination already exists", statusCode: (int)System.Net.HttpStatusCode.Conflict, detail: ex.Message);
}
catch (ConfigurationException ex)
{
return Problem(title: "Validation error.", statusCode: (int)System.Net.HttpStatusCode.BadRequest, detail: ex.Message);
return Problem(title: "Validation error", statusCode: (int)System.Net.HttpStatusCode.BadRequest, detail: ex.Message);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -200,11 +206,11 @@ private void Validate(DestinationApplicationEntity item)
{
if (_repository.Any(p => p.Name.Equals(item.Name)))
{
throw new ConfigurationException($"A DICOM destination with the same name '{item.Name}' already exists.");
throw new ObjectExistsException($"A DICOM destination with the same name '{item.Name}' already exists.");
}
if (_repository.Any(p => p.AeTitle.Equals(item.AeTitle) && p.HostIp.Equals(item.HostIp) && p.Port.Equals(item.Port)))
{
throw new ConfigurationException($"A DICOM destination with the same AE Title '{item.AeTitle}', host/IP Address '{item.HostIp}' and port '{item.Port}' already exists.");
throw new ObjectExistsException($"A DICOM destination with the same AE Title '{item.AeTitle}', host/IP Address '{item.HostIp}' and port '{item.Port}' already exists.");
}
if (!item.IsValid(out var validationErrors))
{
Expand Down
Loading

0 comments on commit 5c6ba1d

Please sign in to comment.