Skip to content

Commit 0330eb1

Browse files
authored
Support multi-segment Shell ID extraction (#96)
1 parent cb2231f commit 0330eb1

41 files changed

Lines changed: 1110 additions & 335 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

example/docker-compose.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ services:
5252
- TemplateManagement__TemplateMappingRules__SubmodelTemplateMappings__4__pattern__0=HandoverDocumentation
5353
- TemplateManagement__TemplateMappingRules__ShellTemplateMappings__0__templateId=https://mm-software.com/aas/aasTemplate
5454
- TemplateManagement__TemplateMappingRules__ShellTemplateMappings__0__pattern__0=
55-
- TemplateManagement__TemplateMappingRules__AasIdExtractionRules__0__Pattern=Regex
56-
- TemplateManagement__TemplateMappingRules__AasIdExtractionRules__0__Index=6
57-
- TemplateManagement__TemplateMappingRules__AasIdExtractionRules__0__Separator=/
55+
- TemplateManagement__TemplateMappingRules__AasIdExtractionRules__0__Strategy=Split
56+
- TemplateManagement__TemplateMappingRules__AasIdExtractionRules__0__Pattern=/
57+
- TemplateManagement__TemplateMappingRules__AasIdExtractionRules__0__Index=5
5858
- TemplateManagement__AasTemplateRepository__Name=AasTemplateRepository
5959
- TemplateManagement__AasTemplateRepository__baseUrl=http://template-repository:8081
6060
- TemplateManagement__AasTemplateRepository__headerMappings__0__source=Authorization
@@ -110,9 +110,10 @@ services:
110110
- ExtractionRules__SubmodelNameExtractionRules__4__pattern__0=CarbonFootprint
111111
- ExtractionRules__SubmodelNameExtractionRules__4__pattern__1=Footprint
112112
- ExtractionRules__SubmodelNameExtractionRules__4__pattern__2=Carbon
113-
- ExtractionRules__ProductIdExtractionRules__0__Pattern=Regex
113+
- ExtractionRules__ProductIdExtractionRules__0__Pattern=/
114114
- ExtractionRules__ProductIdExtractionRules__0__Index=5
115-
- ExtractionRules__ProductIdExtractionRules__0__Separator=/
115+
- ExtractionRules__ProductIdExtractionRules__0__Strategy=Split
116+
- ExtractionRules__ProductIdExtractionRules__0__Description=Default split by '/' segment 5
116117
networks:
117118
- twinengine-network
118119

source/AAS.TwinEngine.DataEngine.ModuleTests/Api/Services/AasRegistry/ShellDescriptorControllerTests.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Net;
1+
using System.Net;
22
using System.Net.Http.Json;
33
using System.Text;
44
using System.Text.Json.Nodes;
@@ -20,14 +20,14 @@
2020

2121
namespace AAS.TwinEngine.DataEngine.ModuleTests.Api.Services.AasRegistry;
2222

23-
public abstract class ShellDescriptorControllerTestsBase : IDisposable
23+
public abstract class ShellDescriptorControllerTests : IDisposable
2424
{
2525
private readonly ConfigTestFactory _factory;
2626
private readonly ITemplateProvider _mockTemplateProvider;
2727
private readonly HttpClient _client;
2828
private readonly ICreateClient _httpClientFactory;
2929

30-
protected ShellDescriptorControllerTestsBase(string configDir)
30+
protected ShellDescriptorControllerTests(string configDir)
3131
{
3232
_mockTemplateProvider = Substitute.For<ITemplateProvider>();
3333
var mockPluginManifestProvider = Substitute.For<IPluginManifestProvider>();
@@ -346,15 +346,9 @@ private static string EncodeBase64Url(string plainText)
346346
}
347347
}
348348

349-
public class ShellDescriptorControllerTests_V1Config : ShellDescriptorControllerTestsBase
350-
{
351-
public ShellDescriptorControllerTests_V1Config() : base("v1-config") { }
352-
}
349+
public class ShellDescriptorControllerTestsV1Config() : ShellDescriptorControllerTests("v1-config");
353350

354-
public class ShellDescriptorControllerTests_V2Config : ShellDescriptorControllerTestsBase
355-
{
356-
public ShellDescriptorControllerTests_V2Config() : base("v2-config") { }
357-
}
351+
public class ShellDescriptorControllerTestsV2Config() : ShellDescriptorControllerTests("v2-config");
358352

359353
public class FakeHttpMessageHandler(Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> send) : HttpMessageHandler
360354
{

source/AAS.TwinEngine.DataEngine.ModuleTests/Api/Services/AasRepository/AasRepositoryControllerTests.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Net;
1+
using System.Net;
22
using System.Net.Http.Json;
33
using System.Text;
44
using System.Text.Json.Nodes;
@@ -23,14 +23,14 @@
2323

2424
namespace AAS.TwinEngine.DataEngine.ModuleTests.Api.Services.AasRepository;
2525

26-
public abstract class AasRepositoryControllerTestsBase : IDisposable
26+
public abstract class AasRepositoryControllerTests : IDisposable
2727
{
2828
private readonly ConfigTestFactory _factory;
2929
private readonly ITemplateProvider _mockTemplateProvider;
3030
private readonly HttpClient _client;
3131
private readonly ICreateClient _httpClientFactory;
3232

33-
protected AasRepositoryControllerTestsBase(string configDir)
33+
protected AasRepositoryControllerTests(string configDir)
3434
{
3535
_mockTemplateProvider = Substitute.For<ITemplateProvider>();
3636
var mockPluginManifestProvider = Substitute.For<IPluginManifestProvider>();
@@ -60,7 +60,7 @@ public void Dispose()
6060
public async Task GetShellByIdAsync_ReturnsOkAsync()
6161
{
6262
// Arrange
63-
var aasIdentifier = "aHR0cHM6Ly9leGFtcGxlLmNvbS9pZHMvYWFzLzExNzBfMTE2MF8zMDUyXzY1NjgvdGVzdC9hYXM=";
63+
const string AasIdentifier = "aHR0cHM6Ly9leGFtcGxlLmNvbS9pZHMvYWFzLzExNzBfMTE2MF8zMDUyXzY1NjgvdGVzdC9hYXM=";
6464
var mockShellTemplate = TestData.CreateShellTemplate();
6565
var mockAssetInformationTemplate = TestData.CreateAssetInformationTemplate();
6666
using var messageHandler = new FakeHttpMessageHandler((_, _) => Task.FromResult(new HttpResponseMessage
@@ -80,7 +80,7 @@ public async Task GetShellByIdAsync_ReturnsOkAsync()
8080
_ = _mockTemplateProvider.GetAssetInformationTemplateAsync(Arg.Any<string>(), Arg.Any<CancellationToken>()).Returns(mockAssetInformationTemplate);
8181

8282
// Act
83-
var response = await _client.GetAsync($"/shells/{aasIdentifier}");
83+
var response = await _client.GetAsync($"/shells/{AasIdentifier}");
8484

8585
// Assert
8686
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -93,15 +93,15 @@ public async Task GetShellByIdAsync_ReturnsOkAsync()
9393
var expectedShell = TestData.CreateShellResponse();
9494
Assert.Equal(shellResponse, expectedShell);
9595
var productId = TestData.GetProductIdFromRule(shell.Submodels!.FirstOrDefault()?.Keys.FirstOrDefault()!.Value!, 5);
96-
var expectedProductId = TestData.GetProductIdFromRule(aasIdentifier.DecodeBase64Url(), 6);
96+
var expectedProductId = TestData.GetProductIdFromRule(AasIdentifier.DecodeBase64Url(), 6);
9797
Assert.Equal(productId, expectedProductId);
9898
}
9999

100100
[Fact]
101101
public async Task GetShellByIdAsync_ReturnsNotFoundAsync_WhenErrorWhileExtractionOfProductIdAsync()
102102
{
103103
// Arrange
104-
var aasIdentifier = "aHR0cHM6Ly9leGFtcGxlLmNvbS9pZHMvYWFz";
104+
const string AasIdentifier = "aHR0cHM6Ly9leGFtcGxlLmNvbS9pZHMvYWFz";
105105
var mockShellTemplate = TestData.CreateShellTemplate();
106106
var mockAssetInformationTemplate = TestData.CreateAssetInformationTemplate();
107107
using var messageHandler = new FakeHttpMessageHandler((_, _) => Task.FromResult(new HttpResponseMessage
@@ -121,7 +121,7 @@ public async Task GetShellByIdAsync_ReturnsNotFoundAsync_WhenErrorWhileExtractio
121121
_ = _mockTemplateProvider.GetAssetInformationTemplateAsync(Arg.Any<string>(), Arg.Any<CancellationToken>()).Returns(mockAssetInformationTemplate);
122122

123123
// Act
124-
var response = await _client.GetAsync($"/shells/{aasIdentifier}");
124+
var response = await _client.GetAsync($"/shells/{AasIdentifier}");
125125

126126
// Assert
127127
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
@@ -341,15 +341,9 @@ private static string EncodeBase64Url(string plainText)
341341
}
342342
}
343343

344-
public class AasRepositoryControllerTests_V1Config : AasRepositoryControllerTestsBase
345-
{
346-
public AasRepositoryControllerTests_V1Config() : base("v1-config") { }
347-
}
344+
public class AasRepositoryControllerTestsV1Config() : AasRepositoryControllerTests("v1-config");
348345

349-
public class AasRepositoryControllerTests_V2Config : AasRepositoryControllerTestsBase
350-
{
351-
public AasRepositoryControllerTests_V2Config() : base("v2-config") { }
352-
}
346+
public class AasRepositoryControllerTestsV2Config() : AasRepositoryControllerTests("v2-config");
353347

354348
public class FakeHttpMessageHandler(Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> send) : HttpMessageHandler
355349
{

source/AAS.TwinEngine.DataEngine.ModuleTests/Api/Services/AasRepository/TestData.cs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Text.Json.Nodes;
22

33
using AAS.TwinEngine.DataEngine.DomainModel.Plugin;
4-
using AAS.TwinEngine.DataEngine.Infrastructure.Providers.TemplateProvider.Config;
54

65
using AasCore.Aas3_0;
76

@@ -201,25 +200,12 @@ public static List<IReference> CreateSubmodelRefs()
201200

202201
public static string? GetProductIdFromRule(string aasIdentifier, int index)
203202
{
204-
var aasIdExtractionRules = new List<AasIdExtractionRules>
203+
var parts = aasIdentifier?.Split("/");
204+
if (parts is null || parts.Length < index || index < 1)
205205
{
206-
new() {
207-
Pattern = "Regex",
208-
Index = index,
209-
Separator = "/"
210-
}
211-
};
212-
213-
var productId = aasIdExtractionRules
214-
.Select(rule => new
215-
{
216-
Rule = rule,
217-
Parts = aasIdentifier?.Split(rule.Separator)
218-
})
219-
.Where(x => x.Parts is { Length: >= 1 } && x.Rule.Index > 0 && x.Parts.Length >= x.Rule.Index)
220-
.Select(x => x.Parts![x.Rule.Index - 1])
221-
.FirstOrDefault();
206+
return null;
207+
}
222208

223-
return productId;
209+
return parts[index - 1];
224210
}
225211
}

source/AAS.TwinEngine.DataEngine.ModuleTests/Api/Services/SubmodelRegistry/SubmodelDescriptorControllerTests.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
namespace AAS.TwinEngine.DataEngine.ModuleTests.Api.Services.SubmodelRegistry;
1818

19-
public abstract class SubmodelDescriptorControllerTestsBase : IDisposable
19+
public abstract class SubmodelDescriptorControllerTests : IDisposable
2020
{
2121
private readonly ConfigTestFactory _factory;
2222
private readonly ISubmodelDescriptorProvider _mockSubmodelDescriptorProvider;
2323
private readonly HttpClient _client;
2424

25-
protected SubmodelDescriptorControllerTestsBase(string configDir)
25+
protected SubmodelDescriptorControllerTests(string configDir)
2626
{
2727
_mockSubmodelDescriptorProvider = Substitute.For<ISubmodelDescriptorProvider>();
2828
var mockPluginManifestProvider = Substitute.For<IPluginManifestProvider>();
@@ -186,12 +186,6 @@ private static string EncodeBase64Url(string plainText)
186186
}
187187
}
188188

189-
public class SubmodelDescriptorControllerTests_V1Config : SubmodelDescriptorControllerTestsBase
190-
{
191-
public SubmodelDescriptorControllerTests_V1Config() : base("v1-config") { }
192-
}
189+
public class SubmodelDescriptorControllerTestsV1Config() : SubmodelDescriptorControllerTests("v1-config");
193190

194-
public class SubmodelDescriptorControllerTests_V2Config : SubmodelDescriptorControllerTestsBase
195-
{
196-
public SubmodelDescriptorControllerTests_V2Config() : base("v2-config") { }
197-
}
191+
public class SubmodelDescriptorControllerTestsV2Config() : SubmodelDescriptorControllerTests("v2-config");

source/AAS.TwinEngine.DataEngine.ModuleTests/Api/Services/SubmodelRepository/SerializationControllerTests.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
namespace AAS.TwinEngine.DataEngine.ModuleTests.Api.Services.SubmodelRepository;
1717

18-
public abstract class SerializationControllerTestsBase : IDisposable
18+
public abstract class SerializationControllerTests : IDisposable
1919
{
2020
private readonly ConfigTestFactory _factory;
2121
private readonly IAasRepositoryService _mockAasRepositoryService;
2222
private readonly ISubmodelRepositoryService _mockSubmodelRepositoryService;
2323
private readonly IConceptDescriptionService _mockConceptDescriptionService;
2424
private readonly HttpClient _client;
2525

26-
protected SerializationControllerTestsBase(string configDir)
26+
protected SerializationControllerTests(string configDir)
2727
{
2828
_mockAasRepositoryService = Substitute.For<IAasRepositoryService>();
2929
_mockSubmodelRepositoryService = Substitute.For<ISubmodelRepositoryService>();
@@ -242,12 +242,6 @@ private static string EncodeBase64Url(string plainText)
242242
}
243243
}
244244

245-
public class SerializationControllerTests_V1Config : SerializationControllerTestsBase
246-
{
247-
public SerializationControllerTests_V1Config() : base("v1-config") { }
248-
}
245+
public class SerializationControllerTestsV1Config() : SerializationControllerTests("v1-config");
249246

250-
public class SerializationControllerTests_V2Config : SerializationControllerTestsBase
251-
{
252-
public SerializationControllerTests_V2Config() : base("v2-config") { }
253-
}
247+
public class SerializationControllerTestsV2Config() : SerializationControllerTests("v2-config");

source/AAS.TwinEngine.DataEngine.ModuleTests/Api/Services/SubmodelRepository/SubmodelRepositoryControllerTests.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Net;
1+
using System.Net;
22
using System.Net.Http.Json;
33
using System.Text;
44
using System.Text.Json.Nodes;
@@ -20,14 +20,14 @@
2020

2121
namespace AAS.TwinEngine.DataEngine.ModuleTests.Api.Services.SubmodelRepository;
2222

23-
public abstract class SubmodelRepositoryControllerTestsBase : IDisposable
23+
public abstract class SubmodelRepositoryControllerTests : IDisposable
2424
{
2525
private readonly ConfigTestFactory _factory;
2626
private readonly ITemplateProvider _mockTemplateProvider;
2727
private readonly HttpClient _client;
2828
private readonly ICreateClient _httpClientFactory;
2929

30-
protected SubmodelRepositoryControllerTestsBase(string configDir)
30+
protected SubmodelRepositoryControllerTests(string configDir)
3131
{
3232
_mockTemplateProvider = Substitute.For<ITemplateProvider>();
3333
var mockPluginManifestProvider = Substitute.For<IPluginManifestProvider>();
@@ -328,15 +328,9 @@ private static string CreateSubmodelElementPath(string submodelIdentifier, strin
328328
=> $"/submodels/{submodelIdentifier}/submodel-elements/{Uri.EscapeDataString(idShortPath)}";
329329
}
330330

331-
public class SubmodelRepositoryControllerTests_V1Config : SubmodelRepositoryControllerTestsBase
332-
{
333-
public SubmodelRepositoryControllerTests_V1Config() : base("v1-config") { }
334-
}
331+
public class SubmodelRepositoryControllerTestsV1Config() : SubmodelRepositoryControllerTests("v1-config");
335332

336-
public class SubmodelRepositoryControllerTests_V2Config : SubmodelRepositoryControllerTestsBase
337-
{
338-
public SubmodelRepositoryControllerTests_V2Config() : base("v2-config") { }
339-
}
333+
public class SubmodelRepositoryControllerTestsV2Config() : SubmodelRepositoryControllerTests("v2-config");
340334

341335
public class FakeHttpMessageHandler(Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> send) : HttpMessageHandler
342336
{

source/AAS.TwinEngine.DataEngine.ModuleTests/TestData/v1-config/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
],
6363
"AasIdExtractionRules": [
6464
{
65-
"Pattern": "Regex",
66-
"Index": 6,
65+
"Pattern": "Split",
66+
"Index": 5,
6767
"Separator": "/"
6868
}
6969
]

source/AAS.TwinEngine.DataEngine.ModuleTests/TestData/v2-config/appsettings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@
111111
],
112112
"AasIdExtractionRules": [
113113
{
114-
"Pattern": "Regex",
115-
"Index": 6,
116-
"Separator": "/"
114+
"Strategy": "Split",
115+
"Pattern": "/",
116+
"Index": 5
117117
}
118118
]
119119
},

source/AAS.TwinEngine.DataEngine.UnitTests/Api/AasRegistry/MappingProfiles/ShellDescriptorMapperProfileTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using AAS.TwinEngine.DataEngine.Api.AasRegistry.MappingProfiles;
2-
using AAS.TwinEngine.DataEngine.DomainModel.AasRegistry;
32
using AAS.TwinEngine.DataEngine.UnitTests.Api.Shared.MappingProfiles;
43

54
using AasCore.Aas3_0;

0 commit comments

Comments
 (0)