Skip to content

Commit 93b1c83

Browse files
committed
Refactor API queries in AAS Repository
- Updated the submodel identifier parameter in "Get Submodel by submodelId and aaslId.bru" to use a custom submodel identifier. - Added query parameters for level and extent in "Get Submodel-element by idshort and aasID.bru". - Introduced query parameters for limit and cursor in "Get Submodel-elements by aasID.bru".
1 parent 4ceccfc commit 93b1c83

19 files changed

Lines changed: 9031 additions & 14 deletions

example/apiCollection/Aas Repository/Product1/Get Submodel-elements by aasID.bru

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ meta {
55
}
66

77
get {
8-
url: {{DataEngineBaseUrl}}/shells/:aasIdentifier/submodels/:submodelIdentifier/submodel-elements
8+
url: {{DataEngineBaseUrl}}/shells/:aasIdentifier/submodels/:submodelIdentifier/submodel-elements?limit=&cursor=
99
body: none
1010
auth: inherit
1111
}
1212

13+
params:query {
14+
limit:
15+
cursor:
16+
}
17+
1318
params:path {
1419
aasIdentifier: {{aasIdentifier-1}}
1520
submodelIdentifier: {{submodelIdentifierNameplate-1}}

example/apiCollection/Aas Repository/Product2/Get Submodel-element by idshort and aasID.bru

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ meta {
55
}
66

77
get {
8-
url: {{DataEngineBaseUrl}}/shells/:aasIdentifier/submodels/:submodelIdentifier/submodel-elements/:idShortPath
8+
url: {{DataEngineBaseUrl}}/shells/:aasIdentifier/submodels/:submodelIdentifier/submodel-elements/:idShortPath?extent=&level=
99
body: none
1010
auth: inherit
1111
}
1212

13+
params:query {
14+
extent:
15+
level:
16+
}
17+
1318
params:path {
1419
idShortPath: ManufacturerName
1520
aasIdentifier: {{aasIdentifier-2}}

example/apiCollection/Aas Repository/Product2/Get Submodel-elements by aasID.bru

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ meta {
55
}
66

77
get {
8-
url: {{DataEngineBaseUrl}}/shells/:aasIdentifier/submodels/:submodelIdentifier/submodel-elements
8+
url: {{DataEngineBaseUrl}}/shells/:aasIdentifier/submodels/:submodelIdentifier/submodel-elements?cursor=&limit=
99
body: none
1010
auth: inherit
1111
}
1212

13+
params:query {
14+
cursor:
15+
limit:
16+
}
17+
1318
params:path {
1419
aasIdentifier: {{aasIdentifier-2}}
1520
submodelIdentifier: {{submodelIdentifierNameplate-2}}

example/apiCollection/Aas Repository/Product3/Get Submodel-element by idshort and aasID.bru

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ get {
1010
auth: inherit
1111
}
1212

13+
params:query {
14+
~level:
15+
~extent:
16+
}
17+
1318
params:path {
1419
idShortPath: ManufacturerName
1520
aasIdentifier: {{aasIdentifier-3}}

example/apiCollection/Aas Repository/Product3/Get Submodel-elements by aasID.bru

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ get {
1010
auth: inherit
1111
}
1212

13+
params:query {
14+
~limit:
15+
~cursor:
16+
}
17+
1318
params:path {
1419
aasIdentifier: {{aasIdentifier-3}}
1520
submodelIdentifier: {{submodelIdentifierNameplate-3}}

source/AAS.TwinEngine.DataEngine/Api/AasRegistry/Handler/ShellDescriptorHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Task<SubmodelDescriptorsDto> GetAllSubmodelDescriptorsByAasId(GetSubmodel
4747
request?.AasIdentifier,
4848
"submodel descriptors by AasId",
4949
aasId => shellDescriptorService.GetAllSubmodelDescriptorsByAasIdAsync(
50-
aasId!,
50+
aasId,
5151
request.Limit,
5252
request.Cursor,
5353
cancellationToken),
@@ -75,9 +75,9 @@ private async Task<TDto> GetResourceAsync<TModel, TDto>(
7575
var decodedSubmodelId = encodedSubmodelId?.DecodeBase64Url(logger);
7676
logger.LogInformation("Get {ResourceName} for AAS: {AasId}, Submodel: {SubmodelId}", resourceName, decodedAasId, decodedSubmodelId);
7777

78-
var result = await fetchFunc(decodedAasId!, decodedSubmodelId!).ConfigureAwait(false);
78+
var result = await fetchFunc(decodedAasId, decodedSubmodelId).ConfigureAwait(false);
7979
ValidateResourceExists(result, resourceName);
80-
return mapFunc(result!);
80+
return mapFunc(result);
8181
}
8282

8383
private async Task<TDto> GetResourceAsync<TModel, TDto>(

source/AAS.TwinEngine.DataEngine/Api/AasRepository/Handler/AasRepositoryHandler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public Task<JsonElement> GetSubmodelRefByIdAsync(GetSubmodelRefRequest request,
7272

7373
public Task<ISubmodel> GetSubmodelByAasIdAsync(GetSubmodelByAasRequest request, CancellationToken cancellationToken)
7474
{
75-
var queryOptions = request?.Level is not null || request?.Extent is not null ? new SubmodelQueryOptions(request.Level.ToString(), request.Extent.ToString()) : null;
75+
var queryOptions = new SubmodelQueryOptions(request.Level.ToString(), request.Extent.ToString());
7676

7777
return GetResourceByIdAsync(
7878
request?.AasIdentifier,
@@ -88,7 +88,7 @@ public Task<SubmodelElementsDto> GetAllSubmodelElementsByAasIdAsync(
8888
request?.Limit.ValidateLimit(logger);
8989
request?.Cursor?.ValidateCursor(logger);
9090

91-
var queryOptions = request?.Level is not null || request?.Extent is not null ? new SubmodelQueryOptions(request.Level.ToString(), request.Extent.ToString()) : null;
91+
var queryOptions = new SubmodelQueryOptions(request.Level.ToString(), request.Extent.ToString());
9292

9393
return GetResourceByIdAsync(
9494
request?.AasIdentifier,
@@ -144,12 +144,12 @@ private async Task<T> GetResourceByIdAsync<T>(
144144

145145
logger.LogInformation("Start executing get request for {ResourceName}. AAS: {AasId}, Submodel: {SubmodelId}", resourceName, decodedAasId, decodedSubmodelId);
146146

147-
var result = await fetchFunc(decodedAasId!, decodedSubmodelId!)
147+
var result = await fetchFunc(decodedAasId, decodedSubmodelId)
148148
.ConfigureAwait(false);
149149

150-
ValidateResourceExists(result, resourceName, decodedSubmodelId!);
150+
ValidateResourceExists(result, resourceName, decodedSubmodelId);
151151

152-
return result!;
152+
return result;
153153
}
154154

155155
private void ValidateResourceExists<T>(T? result, string resourceName, string decodedId)

source/AAS.TwinEngine.DataEngine/ApplicationLogic/Services/AasRegistry/ShellDescriptorService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public class ShellDescriptorService(
123123
.OfType<SubmodelDescriptor>()
124124
.ToList();
125125

126-
var (items, pagingMetaData) = PagingExtensions.GetPagedResult(descriptors, descriptor => descriptor.Id!, limit, cursor);
126+
var (items, pagingMetaData) = PagingExtensions.GetPagedResult(descriptors, descriptor => descriptor.Id, limit, cursor);
127127

128128
return new SubmodelDescriptors
129129
{

source/AAS.TwinEngine.Plugin.TestPlugin.PlaywrightTests/AAS.TwinEngine.Plugin.TestPlugin.PlaywrightTests.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
<None Update="AasRegistry\TestData\GetShellDescriptorById_Expected.json">
3434
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3535
</None>
36+
<None Update="AasRegistry\TestData\GetAllSubmodelDescriptorsByAasId_Expected.json">
37+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
38+
</None>
39+
<None Update="AasRegistry\TestData\GetSubmodelDescriptorByAasId_Expected.json">
40+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
41+
</None>
3642
<None Update="AasRepository\TestData\GetAssetInformationById_Expected.json">
3743
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3844
</None>
@@ -63,6 +69,15 @@
6369
<None Update="AasRepository\TestData\GetAssetInformationById_Expected.json">
6470
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6571
</None>
72+
<None Update="AasRepository\TestData\GetAllSubmodelElementsByAasId_WithCursor_Expected.json">
73+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
74+
</None>
75+
<None Update="AasRepository\TestData\GetAllSubmodelElementsByAasId_Expected.json">
76+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
77+
</None>
78+
<None Update="AasRepository\TestData\GetSubmodelByAasId_Expected.json">
79+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
80+
</None>
6681
<None Update="Discovery\TestData\SearchShellByAssetLink_Expected.json">
6782
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6883
</None>

source/AAS.TwinEngine.Plugin.TestPlugin.PlaywrightTests/AasRegistry/AasRegistryTests.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,71 @@ public async Task GetShellDescriptorById_ShouldReturnSuccess_ContentAsExpected()
8484

8585
await CompareJsonAsync(actualDoc, Path.Combine(Directory.GetCurrentDirectory(), "AasRegistry", "TestData", "GetShellDescriptorById_Expected.json"));
8686
}
87+
88+
[Fact]
89+
public async Task GetAllSubmodelDescriptorsByAasId_ShouldReturnSuccess_ContentAsExpected()
90+
{
91+
// Arrange
92+
var url = $"/shell-descriptors/{AasIdentifier}/submodel-descriptors";
93+
94+
// Act
95+
var response = await ApiContext.GetAsync(url);
96+
97+
// Assert
98+
AssertSuccessResponse(response);
99+
100+
var content = await response.TextAsync();
101+
Assert.False(string.IsNullOrEmpty(content));
102+
103+
var actualDoc = JsonDocument.Parse(content);
104+
Assert.NotNull(actualDoc);
105+
106+
await CompareJsonAsync(actualDoc, Path.Combine(Directory.GetCurrentDirectory(), "AasRegistry", "TestData", "GetAllSubmodelDescriptorsByAasId_Expected.json"));
107+
}
108+
109+
[Fact]
110+
public async Task GetAllSubmodelDescriptorsByAasId_WithPagination()
111+
{
112+
// Arrange
113+
var urlLimit2 = $"/shell-descriptors/{AasIdentifier}/submodel-descriptors?limit=2";
114+
var urlLimit3 = $"/shell-descriptors/{AasIdentifier}/submodel-descriptors?limit=3";
115+
116+
// Act
117+
var responseLimit2 = await ApiContext.GetAsync(urlLimit2);
118+
var responseLimit3 = await ApiContext.GetAsync(urlLimit3);
119+
120+
// Assert
121+
AssertSuccessResponse(responseLimit2);
122+
AssertSuccessResponse(responseLimit3);
123+
124+
var jsonLimit2 = JsonDocument.Parse(await responseLimit2.TextAsync());
125+
var jsonLimit3 = JsonDocument.Parse(await responseLimit3.TextAsync());
126+
127+
var resultLimit2 = jsonLimit2.RootElement.GetProperty("result");
128+
var resultLimit3 = jsonLimit3.RootElement.GetProperty("result");
129+
130+
Assert.Equal(resultLimit2.GetArrayLength() + 1, resultLimit3.GetArrayLength());
131+
}
132+
133+
[Fact]
134+
public async Task GetSubmodelDescriptorByAasId_ShouldReturnSuccess_ContentAsExpected()
135+
{
136+
// Arrange
137+
var url =
138+
$"/shell-descriptors/{AasIdentifier}/submodel-descriptors/{SubmodelIdentifierHandoverDocumentation}";
139+
140+
// Act
141+
var response = await ApiContext.GetAsync(url);
142+
143+
// Assert
144+
AssertSuccessResponse(response);
145+
146+
var content = await response.TextAsync();
147+
Assert.False(string.IsNullOrEmpty(content));
148+
149+
var actualDoc = JsonDocument.Parse(content);
150+
Assert.NotNull(actualDoc);
151+
152+
await CompareJsonAsync(actualDoc, Path.Combine(Directory.GetCurrentDirectory(), "AasRegistry", "TestData", "GetSubmodelDescriptorByAasId_Expected.json"));
153+
}
87154
}

0 commit comments

Comments
 (0)