-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathAssetAdministrationShellRepositoryAPIApi.cs
2824 lines (2516 loc) · 183 KB
/
AssetAdministrationShellRepositoryAPIApi.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* DotAAS Part 2 | HTTP/REST | Asset Administration Shell Repository Service Specification
*
* The Full Profile of the Asset Administration Shell Repository Service Specification as part of the [Specification of the Asset Administration Shell: Part 2](http://industrialdigitaltwin.org/en/content-hub). Publisher: Industrial Digital Twin Association (IDTA) April 2023
*
* OpenAPI spec version: V3.0.1_SSP-001
* Contact: info@idtwin.org
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/
using AasSecurity.Exceptions;
using AasxServer;
using AasxServerStandardBib.Interfaces;
using AasxServerStandardBib.Logging;
using AdminShellNS.Lib.V3.Models;
using DataTransferObjects.MetadataDTOs;
using DataTransferObjects.ValueDTOs;
using IO.Swagger.Attributes;
using IO.Swagger.Lib.V3.Interfaces;
using IO.Swagger.Lib.V3.Models;
using IO.Swagger.Lib.V3.SerializationModifiers.Mappers;
using IO.Swagger.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Security.Claims;
namespace IO.Swagger.Controllers;
using System.Threading.Tasks;
/// <summary>
///
/// </summary>
[Authorize(AuthenticationSchemes = "AasSecurityAuth")]
[ApiController]
public class AssetAdministrationShellRepositoryAPIApiController : ControllerBase
{
private readonly IAppLogger<AssetAdministrationShellRepositoryAPIApiController> _logger;
private readonly IAssetAdministrationShellService _aasService;
private readonly IBase64UrlDecoderService _decoderService;
private readonly IReferenceModifierService _referenceModifierService;
private readonly IMappingService _mappingService;
private readonly IPathModifierService _pathModifierService;
private readonly ILevelExtentModifierService _levelExtentModifierService;
private readonly IPaginationService _paginationService;
private readonly IAuthorizationService _authorizationService;
/// <summary>
///
/// </summary>
/// <param name="logger"></param>
/// <param name="aasService"></param>
/// <param name="decoderService"></param>
/// <param name="referenceModifierService"></param>
/// <param name="mappingService"></param>
/// <param name="pathModifierService"></param>
/// <param name="levelExtentModifierService"></param>
/// <param name="paginationService"></param>
/// <param name="authorizationService"></param>
/// <exception cref="ArgumentNullException"></exception>
public AssetAdministrationShellRepositoryAPIApiController(IAppLogger<AssetAdministrationShellRepositoryAPIApiController> logger,
IAssetAdministrationShellService aasService, IBase64UrlDecoderService decoderService,
IReferenceModifierService referenceModifierService,
IMappingService mappingService, IPathModifierService pathModifierService,
ILevelExtentModifierService levelExtentModifierService, IPaginationService paginationService,
IAuthorizationService authorizationService)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_aasService = aasService ?? throw new ArgumentNullException(nameof(aasService));
_decoderService = decoderService ?? throw new ArgumentNullException(nameof(decoderService));
_referenceModifierService = referenceModifierService ?? throw new ArgumentNullException(nameof(referenceModifierService));
_mappingService = mappingService ?? throw new ArgumentNullException(nameof(mappingService));
_pathModifierService = pathModifierService ?? throw new ArgumentNullException(nameof(pathModifierService));
_levelExtentModifierService = levelExtentModifierService ?? throw new ArgumentNullException(nameof(levelExtentModifierService));
_paginationService = paginationService ?? throw new ArgumentNullException(nameof(paginationService));
_authorizationService = authorizationService ?? throw new ArgumentNullException(nameof(authorizationService));
}
/// <summary>
/// Deletes an Asset Administration Shell
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <response code="204">Asset Administration Shell deleted successfully</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpDelete]
[Route("/shells/{aasIdentifier}")]
[ValidateModelState]
[SwaggerOperation("DeleteAssetAdministrationShellById")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult DeleteAssetAdministrationShellById([FromRoute] [Required] string aasIdentifier)
{
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
_logger.LogInformation($"Received request to delete AAS with id {decodedAasIdentifier}");
_aasService.DeleteAssetAdministrationShellById(decodedAasIdentifier);
return NoContent();
}
/// <summary>
/// Deletes file content of an existing submodel element at a specified path within submodel elements hierarchy
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="submodelIdentifier">The Submodel’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="idShortPath">IdShort path to the submodel element (dot-separated)</param>
/// <response code="200">Submodel element updated successfully</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpDelete]
[Route("/shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/attachment")]
[ValidateModelState]
[SwaggerOperation("DeleteFileByPathAasRepository")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult DeleteFileByPathAasRepository([FromRoute] [Required] string aasIdentifier, [FromRoute] [Required] string submodelIdentifier,
[FromRoute] [Required] string idShortPath)
{
_logger.LogInformation($"Received request to delete a file from AAS");
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
var decodedSmIdentifier = _decoderService.Decode("submodelIdentifier", submodelIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
if (decodedSmIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedSmIdentifier)} is null");
}
if (!Program.noSecurity)
{
var submodel = _aasService.GetSubmodelById(decodedAasIdentifier, decodedSmIdentifier);
User.Claims.ToList().Add(new Claim("idShortPath", $"{submodel.IdShort}.{idShortPath}"));
var claimsList = new List<Claim>(User.Claims) {new("IdShortPath", $"{submodel.IdShort}.{idShortPath}")};
var identity = new ClaimsIdentity(claimsList, "AasSecurityAuth");
var principal = new System.Security.Principal.GenericPrincipal(identity, null);
var authResult = _authorizationService.AuthorizeAsync(principal, submodel, "SecurityPolicy").Result;
if (!authResult.Succeeded)
{
throw new NotAllowed(authResult.Failure.FailureReasons.FirstOrDefault()?.Message ?? string.Empty);
}
}
_aasService.DeleteFileByPath(decodedAasIdentifier, decodedSmIdentifier, idShortPath);
return NoContent();
}
/// <summary>
/// Deletes the submodel from the Asset Administration Shell and the Repository.
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="submodelIdentifier">The Submodel’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <response code="204">Submodel deleted successfully</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpDelete]
[Route("/shells/{aasIdentifier}/submodels/{submodelIdentifier}")]
[ValidateModelState]
[SwaggerOperation("DeleteSubmodelByIdAasRepository")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult DeleteSubmodelByIdAasRepository([FromRoute] [Required] string aasIdentifier, [FromRoute] [Required] string submodelIdentifier)
{
_logger.LogInformation($"Received request to delete a submodel from AAS");
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
var decodedSmIdentifier = _decoderService.Decode("submodelIdentifier", submodelIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
if (decodedSmIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedSmIdentifier)} is null");
}
_aasService.DeleteSubmodelById(decodedAasIdentifier, decodedSmIdentifier);
return NoContent();
}
/// <summary>
/// Deletes a submodel element at a specified path within the submodel elements hierarchy
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="submodelIdentifier">The Submodel’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="idShortPath">IdShort path to the submodel element (dot-separated)</param>
/// <response code="204">Submodel element deleted successfully</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpDelete]
[Route("/shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}")]
[ValidateModelState]
[SwaggerOperation("DeleteSubmodelElementByPathAasRepository")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult DeleteSubmodelElementByPathAasRepository([FromRoute] [Required] string aasIdentifier, [FromRoute] [Required] string submodelIdentifier,
[FromRoute] [Required] string idShortPath)
{
_logger.LogInformation($"Received request to delete a SubmodelElement from AAS");
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
var decodedSmIdentifier = _decoderService.Decode("submodelIdentifier", submodelIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
if (decodedSmIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedSmIdentifier)} is null");
}
if (!Program.noSecurity)
{
var submodel = _aasService.GetSubmodelById(decodedAasIdentifier, decodedSmIdentifier);
User.Claims.ToList().Add(new Claim("idShortPath", $"{submodel.IdShort}.{idShortPath}"));
var claimsList = new List<Claim>(User.Claims) {new("IdShortPath", $"{submodel.IdShort}.{idShortPath}")};
var identity = new ClaimsIdentity(claimsList, "AasSecurityAuth");
var principal = new System.Security.Principal.GenericPrincipal(identity, null);
var authResult = _authorizationService.AuthorizeAsync(principal, submodel, "SecurityPolicy").Result;
if (!authResult.Succeeded)
{
throw new NotAllowed(authResult.Failure.FailureReasons.FirstOrDefault()?.Message ?? string.Empty);
}
}
_aasService.DeleteSubmodelElementByPath(decodedAasIdentifier, decodedSmIdentifier, idShortPath);
return NoContent();
}
/// <summary>
/// Deletes the submodel reference from the Asset Administration Shell. Does not delete the submodel itself!
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="submodelIdentifier">The Submodel’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <response code="204">Submodel reference deleted successfully</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpDelete]
[Route("/shells/{aasIdentifier}/submodel-refs/{submodelIdentifier}")]
[ValidateModelState]
[SwaggerOperation("DeleteSubmodelReferenceByIdAasRepository")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult DeleteSubmodelReferenceByIdAasRepository([FromRoute] [Required] string aasIdentifier, [FromRoute] [Required] string submodelIdentifier)
{
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
var decodedSmIdentifier = _decoderService.Decode("submodelIdentifier", submodelIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
if (decodedSmIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedSmIdentifier)} is null");
}
_logger.LogInformation($"Received request to delete submodel reference with id {submodelIdentifier} from the AAS with id {aasIdentifier}.");
_aasService.DeleteSubmodelReferenceById(decodedAasIdentifier, decodedSmIdentifier);
return NoContent();
}
/// <summary>
///
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <response code="200">Thumbnail deletion successful</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpDelete]
[Route("/shells/{aasIdentifier}/asset-information/thumbnail")]
[ValidateModelState]
[SwaggerOperation("DeleteThumbnailAasRepository")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult DeleteThumbnailAasRepository([FromRoute] [Required] string aasIdentifier)
{
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
_logger.LogInformation($"Received request to delete the thumbnail from the AAS with id {decodedAasIdentifier}.");
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
_aasService.DeleteThumbnail(decodedAasIdentifier);
return NoContent();
}
/// <summary>
/// Returns all Asset Administration Shells
/// </summary>
/// <param name="assetIds">A list of specific Asset identifiers. Each Asset identifier is a base64-url-encoded [SpecificAssetId](https://api.swaggerhub.com/domains/Plattform_i40/Part1-MetaModel-Schemas/V3.0.1#/components/schemas/SpecificAssetId)</param>
/// <param name="idShort">The Asset Administration Shell’s IdShort</param>
/// <param name="limit">The maximum number of elements in the response array</param>
/// <param name="cursor">A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue</param>
/// <response code="200">Requested Asset Administration Shells</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpGet]
[Route("/shells")]
[ValidateModelState]
[SwaggerOperation("GetAllAssetAdministrationShells")]
[SwaggerResponse(statusCode: 200, type: typeof(PagedResult), description: "Requested Asset Administration Shells")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
// TODO (jtikekar, 2023-09-04): assetIds: string or specific asset id, and what about Base64Uel encoding
public virtual IActionResult GetAllAssetAdministrationShells([FromQuery] List<SpecificAssetId>? assetIds, [FromQuery] string? idShort, [FromQuery] int? limit,
[FromQuery] string? cursor)
{
_logger.LogInformation($"Received the request to get all Asset Administration Shells.");
var aasList = _aasService.GetAllAssetAdministrationShells(assetIds, idShort);
var output = _paginationService.GetPaginatedList(aasList, new PaginationParameters(cursor, limit));
return new ObjectResult(output);
}
/// <summary>
/// Returns References to all Asset Administration Shells
/// </summary>
/// <param name="assetIds">A list of specific Asset identifiers. Each Asset identifier is a base64-url-encoded [SpecificAssetId](https://api.swaggerhub.com/domains/Plattform_i40/Part1-MetaModel-Schemas/V3.0.1#/components/schemas/SpecificAssetId)</param>
/// <param name="idShort">The Asset Administration Shell’s IdShort</param>
/// <param name="limit">The maximum number of elements in the response array</param>
/// <param name="cursor">A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue</param>
/// <response code="200">Requested Asset Administration Shells as a list of References</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpGet]
[Route("/shells/$reference")]
[ValidateModelState]
[SwaggerOperation("GetAllAssetAdministrationShellsReference")]
[SwaggerResponse(statusCode: 200, type: typeof(GetReferencesResult), description: "Requested Asset Administration Shells as a list of References")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
// TODO (jtikekar, 2023-09-04): assetIds: string or specific asset id, and what about Base64Uel encoding
//public virtual IActionResult GetAllAssetAdministrationShellsReference([FromQuery] List<string> assetIds, [FromQuery] string idShort, [FromQuery] int? limit, [FromQuery] string cursor)
public virtual IActionResult GetAllAssetAdministrationShellsReference([FromQuery] List<SpecificAssetId>? assetIds, [FromQuery] string? idShort, [FromQuery] int? limit,
[FromQuery] string? cursor)
{
_logger.LogInformation($"Received the request to get all Asset Administration Shells.");
var aasList = _aasService.GetAllAssetAdministrationShells(assetIds, idShort);
var aasPaginatedList = _paginationService.GetPaginatedList(aasList, new PaginationParameters(cursor, limit));
var references = _referenceModifierService.GetReferenceResult(aasPaginatedList.result.ConvertAll(a => (IReferable)a));
var output = new ReferencePagedResult(references, aasPaginatedList.paging_metadata);
return new ObjectResult(output);
}
/// <summary>
/// Returns all submodel elements including their hierarchy
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="submodelIdentifier">The Submodel’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="limit">The maximum number of elements in the response array</param>
/// <param name="cursor">A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue</param>
/// <param name="level">Determines the structural depth of the respective resource content</param>
/// <param name="extent">Determines to which extent the resource is being serialized</param>
/// <response code="200">List of found submodel elements</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpGet]
[Route("/shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements")]
[ValidateModelState]
[SwaggerOperation("GetAllSubmodelElementsAasRepository")]
[SwaggerResponse(statusCode: 200, type: typeof(GetSubmodelElementsResult), description: "List of found submodel elements")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult GetAllSubmodelElementsAasRepository([FromRoute] [Required] string aasIdentifier, [FromRoute] [Required] string submodelIdentifier,
[FromQuery] int? limit, [FromQuery] string? cursor, [FromQuery] LevelEnum level,
[FromQuery] ExtentEnum extent)
{
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
var decodedSmIdentifier = _decoderService.Decode("submodelIdentifier", submodelIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
if (decodedSmIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedSmIdentifier)} is null");
}
_logger.LogInformation($"Received request to get all the submodel elements from submodel with id {submodelIdentifier} and the AAS with id {aasIdentifier}.");
if (!Program.noSecurity)
{
var submodel = _aasService.GetSubmodelById(decodedAasIdentifier, decodedSmIdentifier);
var authResult = _authorizationService.AuthorizeAsync(User, submodel, "SecurityPolicy").Result;
if (!authResult.Succeeded)
{
throw new NotAllowed(authResult.Failure.FailureReasons.FirstOrDefault()?.Message ?? string.Empty);
}
}
var submodelElements = _aasService.GetAllSubmodelElements(decodedAasIdentifier, decodedSmIdentifier);
var smePaginated = _paginationService.GetPaginatedList(submodelElements, new PaginationParameters(cursor, limit));
var smeLevelList = _levelExtentModifierService.ApplyLevelExtent(smePaginated.result ?? [], level, extent);
var output = new PagedResult() {result = smeLevelList.ConvertAll(sme => sme), paging_metadata = smePaginated.paging_metadata};
return new ObjectResult(output);
}
/// <summary>
/// Returns all submodel elements including their hierarchy
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="submodelIdentifier">The Submodel’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="limit">The maximum number of elements in the response array</param>
/// <param name="cursor">A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue</param>
/// <param name="level">Determines the structural depth of the respective resource content</param>
/// <response code="200">List of found submodel elements</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpGet]
[Route("/shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/$metadata")]
[ValidateModelState]
[SwaggerOperation("GetAllSubmodelElementsMetadataAasRepository")]
[SwaggerResponse(statusCode: 200, type: typeof(MetadataPagedResult), description: "List of found submodel elements")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult GetAllSubmodelElementsMetadataAasRepository([FromRoute] [Required] string aasIdentifier, [FromRoute] [Required] string submodelIdentifier,
[FromQuery] int? limit, [FromQuery] [Required] string cursor, [FromQuery] LevelEnum level)
{
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
var decodedSubmodelIdentifier = _decoderService.Decode("submodelIdentifier", submodelIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
if (decodedSubmodelIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedSubmodelIdentifier)} is null");
}
_logger.LogInformation($"Received request to get metadata of all the submodel elements from the submodel with id {decodedSubmodelIdentifier} and AAS with id {decodedAasIdentifier}");
if (!Program.noSecurity)
{
var submodel = _aasService.GetSubmodelById(decodedAasIdentifier, decodedSubmodelIdentifier);
var authResult = _authorizationService.AuthorizeAsync(User, submodel, "SecurityPolicy").Result;
if (!authResult.Succeeded)
{
throw new NotAllowed(authResult.Failure.FailureReasons.FirstOrDefault()?.Message ?? string.Empty);
}
}
var smeList = _aasService.GetAllSubmodelElements(decodedAasIdentifier, decodedSubmodelIdentifier);
var smePaginated = _paginationService.GetPaginatedList(smeList, new PaginationParameters(cursor, limit));
var smeLevelList = _levelExtentModifierService.ApplyLevelExtent(smePaginated.result ?? [], level);
var smeMetadataList = _mappingService.Map(smeLevelList, "metadata");
var output = new MetadataPagedResult {result = smeMetadataList.ConvertAll(sme => (IMetadataDTO)sme), paging_metadata = smePaginated.paging_metadata};
return new ObjectResult(output);
}
/// <summary>
/// Returns all submodel elements including their hierarchy
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="submodelIdentifier">The Submodel’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="limit">The maximum number of elements in the response array</param>
/// <param name="cursor">A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue</param>
/// <param name="level">Determines the structural depth of the respective resource content</param>
/// <param name="extent">Determines to which extent the resource is being serialized</param>
/// <response code="200">List of found submodel elements in the Path notation</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpGet]
[Route("/shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/$path")]
[ValidateModelState]
[SwaggerOperation("GetAllSubmodelElementsPathAasRepository")]
[SwaggerResponse(statusCode: 200, type: typeof(GetPathItemsResult), description: "List of found submodel elements in the Path notation")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult GetAllSubmodelElementsPathAasRepository([FromRoute] [Required] string aasIdentifier, [FromRoute] [Required] string submodelIdentifier,
[FromQuery] int? limit, [FromQuery] string? cursor, [FromQuery] LevelEnum level,
[FromQuery] ExtentEnum extent)
{
var decodedAasIdentifier = _decoderService.Decode($"aasIdentifier", aasIdentifier);
var decodedSubmodelIdentifier = _decoderService.Decode($"submodelIdentifier", submodelIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
if (decodedSubmodelIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedSubmodelIdentifier)} is null");
}
_logger.LogInformation($"Received a request to get path for all the submodel elements from the submodel with id {decodedSubmodelIdentifier} and aas with id {decodedAasIdentifier}");
if (!Program.noSecurity)
{
var submodel = _aasService.GetSubmodelById(decodedAasIdentifier, decodedSubmodelIdentifier);
var authResult = _authorizationService.AuthorizeAsync(User, submodel, "SecurityPolicy").Result;
if (!authResult.Succeeded)
{
throw new NotAllowed(authResult.Failure.FailureReasons.FirstOrDefault()?.Message ?? string.Empty);
}
}
var submodelElementsList = _aasService.GetAllSubmodelElements(decodedAasIdentifier, decodedSubmodelIdentifier);
var smePaginated = _paginationService.GetPaginatedList(submodelElementsList, new PaginationParameters(cursor, limit));
var smeLevelList = _levelExtentModifierService.ApplyLevelExtent(smePaginated.result ?? [], level, extent);
var smePathList = _pathModifierService.ToIdShortPath(smeLevelList.ConvertAll(sme => (ISubmodelElement)sme));
var output = new PathPagedResult {result = smePathList, paging_metadata = smePaginated.paging_metadata};
return new ObjectResult(output);
}
/// <summary>
/// Returns all submodel elements as a list of References
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="submodelIdentifier">The Submodel’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="limit">The maximum number of elements in the response array</param>
/// <param name="cursor">A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue</param>
/// <param name="level">Determines the structural depth of the respective resource content</param>
/// <param name="extent"></param>
/// <response code="200">List of References of the found submodel elements</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpGet]
[Route("/shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/$reference")]
[ValidateModelState]
[SwaggerOperation("GetAllSubmodelElementsReferenceAasRepository")]
[SwaggerResponse(statusCode: 200, type: typeof(ReferencePagedResult), description: "List of References of the found submodel elements")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult GetAllSubmodelElementsReferenceAasRepository([FromRoute] [Required] string aasIdentifier, [FromRoute] [Required] string submodelIdentifier,
[FromQuery] int? limit, [FromQuery] string? cursor, [FromQuery] LevelEnum level,
[FromQuery] ExtentEnum extent)
{
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
var decodedSubmodelIdentifier = _decoderService.Decode("submodelIdentifier", submodelIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
if (decodedSubmodelIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedSubmodelIdentifier)} is null");
}
_logger.LogInformation($"Received request to get references of all the submodel elements from submodel with id {submodelIdentifier} and the AAS with id {aasIdentifier}.");
if (!Program.noSecurity)
{
var submodel = _aasService.GetSubmodelById(decodedAasIdentifier, decodedSubmodelIdentifier);
var authResult = _authorizationService.AuthorizeAsync(User, submodel, "SecurityPolicy").Result;
if (!authResult.Succeeded)
{
throw new NotAllowed(authResult.Failure.FailureReasons.FirstOrDefault()?.Message ?? string.Empty);
}
}
var smeList = _aasService.GetAllSubmodelElements(decodedAasIdentifier, decodedSubmodelIdentifier);
// TODO (jtikekar, 2023-09-04): check performace imapct due to ConvertAll
var smePaginated = _paginationService.GetPaginatedList(smeList, new PaginationParameters(cursor, limit));
var smeReferenceList = _referenceModifierService.GetReferenceResult(smePaginated.result.ConvertAll(sme => (IReferable)sme));
var output = new ReferencePagedResult(smeReferenceList, smePaginated.paging_metadata);
return new ObjectResult(output);
}
/// <summary>
/// Returns all submodel elements including their hierarchy in the ValueOnly representation
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="submodelIdentifier">The Submodel’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="limit">The maximum number of elements in the response array</param>
/// <param name="cursor">A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue</param>
/// <param name="level">Determines the structural depth of the respective resource content</param>
/// <param name="extent"></param>
/// <response code="200">List of found submodel elements in their ValueOnly representation</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpGet]
[Route("/shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/$value")]
[ValidateModelState]
[SwaggerOperation("GetAllSubmodelElementsValueOnlyAasRepository")]
[SwaggerResponse(statusCode: 200, type: typeof(ValueOnlyPagedResult), description: "List of found submodel elements in their ValueOnly representation")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult GetAllSubmodelElementsValueOnlyAasRepository([FromRoute] [Required] string aasIdentifier, [FromRoute] [Required] string submodelIdentifier,
[FromQuery] int? limit, [FromQuery] string? cursor, [FromQuery] LevelEnum level,
[FromQuery] ExtentEnum extent)
{
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
var decodedSubmodelIdentifier = _decoderService.Decode("submodelIdentifier", submodelIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
if (decodedSubmodelIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedSubmodelIdentifier)} is null");
}
_logger.LogInformation($"Received request to get the value of all the submodel elements from the submodel with id {decodedSubmodelIdentifier} and aas with id {decodedAasIdentifier}");
if (!Program.noSecurity)
{
var submodel = _aasService.GetSubmodelById(decodedAasIdentifier, decodedSubmodelIdentifier);
var authResult = _authorizationService.AuthorizeAsync(User, submodel, "SecurityPolicy").Result;
if (!authResult.Succeeded)
{
throw new NotAllowed(authResult.Failure.FailureReasons.FirstOrDefault()?.Message ?? string.Empty);
}
}
var submodelElements = _aasService.GetAllSubmodelElements(decodedAasIdentifier, decodedSubmodelIdentifier);
var smePaginated = _paginationService.GetPaginatedList(submodelElements, new PaginationParameters(cursor, limit));
var smeLevelList = _levelExtentModifierService.ApplyLevelExtent(smePaginated.result, level);
var smeValueList = _mappingService.Map(smeLevelList, "value");
var output = new ValueOnlyPagedResult {result = smeValueList.ConvertAll(sme => (IValueDTO)sme), paging_metadata = smePaginated.paging_metadata};
return new ObjectResult(output);
}
/// <summary>
/// Returns all submodel references
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="limit">The maximum number of elements in the response array</param>
/// <param name="cursor">A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue</param>
/// <response code="200">Requested submodel references</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpGet]
[Route("/shells/{aasIdentifier}/submodel-refs")]
[ValidateModelState]
[SwaggerOperation("GetAllSubmodelReferencesAasRepository")]
[SwaggerResponse(statusCode: 200, type: typeof(GetReferencesResult), description: "Requested submodel references")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult GetAllSubmodelReferencesAasRepository([FromRoute] [Required] string aasIdentifier, [FromQuery] int? limit, [FromQuery] string? cursor)
{
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
_logger.LogInformation($"Received request to get all the submodel references from the AAS with id {aasIdentifier}.");
var submodels = _aasService.GetAllSubmodelReferencesFromAas(decodedAasIdentifier);
var output = _paginationService.GetPaginatedList(submodels, new PaginationParameters(cursor, limit));
return new ObjectResult(output);
}
/// <summary>
/// Returns a specific Asset Administration Shell
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <response code="200">Requested Asset Administration Shell</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpGet]
[Route("/shells/{aasIdentifier}")]
[ValidateModelState]
[SwaggerOperation("GetAssetAdministrationShellById")]
[SwaggerResponse(statusCode: 200, type: typeof(AssetAdministrationShell), description: "Requested Asset Administration Shell")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult GetAssetAdministrationShellById([FromRoute] [Required] string aasIdentifier)
{
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
_logger.LogInformation($"Received request to get the AAS with id {aasIdentifier}.");
var aas = _aasService.GetAssetAdministrationShellById(decodedAasIdentifier);
/* Turn off AAS security to have existing demos run
var authResult = _authorizationService.AuthorizeAsync(User, aas, "SecurityPolicy").Result;
if (!authResult.Succeeded)
{
var failedReasons = authResult.Failure.FailureReasons;
if (failedReasons != null && failedReasons.Any())
{
throw new NotAllowed(failedReasons.First().Message);
}
}
*/
return new ObjectResult(aas);
}
/// <summary>
/// Returns a specific Asset Administration Shell as a Reference
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <response code="200">Requested Asset Administration Shell</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpGet]
[Route("/shells/{aasIdentifier}/$reference")]
[ValidateModelState]
[SwaggerOperation("GetAssetAdministrationShellByIdReferenceAasRepository")]
[SwaggerResponse(statusCode: 200, type: typeof(Reference), description: "Requested Asset Administration Shell")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult GetAssetAdministrationShellByIdReferenceAasRepository([FromRoute] [Required] string aasIdentifier)
{
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
_logger.LogInformation($"Received request to get the reference of AAS with id {aasIdentifier}.");
var aas = _aasService.GetAssetAdministrationShellById(decodedAasIdentifier);
var output = _referenceModifierService.GetReferenceResult(aas);
return new ObjectResult(output);
}
/// <summary>
/// Returns the Asset Information
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <response code="200">Requested Asset Information</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpGet]
[Route("/shells/{aasIdentifier}/asset-information")]
[ValidateModelState]
[SwaggerOperation("GetAssetInformationAasRepository")]
[SwaggerResponse(statusCode: 200, type: typeof(AssetInformation), description: "Requested Asset Information")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual IActionResult GetAssetInformationAasRepository([FromRoute] [Required] string aasIdentifier)
{
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
_logger.LogInformation($"Received request to get the AAS with id {decodedAasIdentifier}.");
var output = _aasService.GetAssetInformation(decodedAasIdentifier);
return new ObjectResult(output);
}
/// <summary>
/// Downloads file content from a specific submodel element from the Submodel at a specified path
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="submodelIdentifier">The Submodel’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="idShortPath">IdShort path to the submodel element (dot-separated)</param>
/// <response code="200">Requested file</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>
/// <response code="401">Unauthorized, e.g. the server refused the authorization attempt.</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Not Found</response>
/// <response code="500">Internal Server Error</response>
/// <response code="0">Default error handling for unmentioned status codes</response>
[HttpGet]
[Route("/shells/{aasIdentifier}/submodels/{submodelIdentifier}/submodel-elements/{idShortPath}/attachment")]
[ValidateModelState]
[SwaggerOperation("GetFileByPathAasRepository")]
[SwaggerResponse(statusCode: 200, type: typeof(byte[]), description: "Requested file")]
[SwaggerResponse(statusCode: 400, type: typeof(Result), description: "Bad Request, e.g. the request parameters of the format of the request body is wrong.")]
[SwaggerResponse(statusCode: 401, type: typeof(Result), description: "Unauthorized, e.g. the server refused the authorization attempt.")]
[SwaggerResponse(statusCode: 403, type: typeof(Result), description: "Forbidden")]
[SwaggerResponse(statusCode: 404, type: typeof(Result), description: "Not Found")]
[SwaggerResponse(statusCode: 500, type: typeof(Result), description: "Internal Server Error")]
[SwaggerResponse(statusCode: 0, type: typeof(Result), description: "Default error handling for unmentioned status codes")]
public virtual async Task<IActionResult> GetFileByPathAasRepository([FromRoute] [Required] string aasIdentifier, [FromRoute] [Required] string submodelIdentifier,
[FromRoute] [Required] string idShortPath)
{
var decodedAasIdentifier = _decoderService.Decode("aasIdentifier", aasIdentifier);
var decodedSubmodelIdentifier = _decoderService.Decode("submodelIdentifier", submodelIdentifier);
if (decodedAasIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasIdentifier)} is null");
}
if (decodedSubmodelIdentifier == null)
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedSubmodelIdentifier)} is null");
}
_logger.LogInformation($"Received request to get file by path at the submodel element {idShortPath} from submodel with id {submodelIdentifier} and the AAS with id {aasIdentifier}.");
if (!Program.noSecurity)
{
var submodel = _aasService.GetSubmodelById(decodedAasIdentifier, decodedSubmodelIdentifier);
User.Claims.ToList().Add(new Claim("idShortPath", $"{submodel.IdShort}.{idShortPath}"));
var claimsList = new List<Claim>(User.Claims) {new("IdShortPath", $"{submodel.IdShort}.{idShortPath}")};
var identity = new ClaimsIdentity(claimsList, "AasSecurityAuth");
var principal = new System.Security.Principal.GenericPrincipal(identity, null);
var authResult = _authorizationService.AuthorizeAsync(principal, submodel, "SecurityPolicy").Result;
if (!authResult.Succeeded)
{
throw new NotAllowed(authResult.Failure.FailureReasons.FirstOrDefault()?.Message ?? string.Empty);
}
}
var fileName = _aasService.GetFileByPath(decodedAasIdentifier, decodedSubmodelIdentifier, idShortPath, out var content, out var fileSize);
//content-disposition so that the aasx file can be downloaded from the web browser.
ContentDisposition contentDisposition = new() {FileName = fileName, Inline = fileName.ToLower().EndsWith(".pdf")};
HttpContext.Response.Headers.Append("Content-Disposition", contentDisposition.ToString());
HttpContext.Response.ContentLength = fileSize;
if (fileName.ToLower().EndsWith(".svg"))
{
HttpContext.Response.ContentType = "image/svg+xml";
}
if (fileName.ToLower().EndsWith(".pdf"))
{
HttpContext.Response.ContentType = "application/pdf";
}
await HttpContext.Response.Body.WriteAsync(content);
return new EmptyResult();
}
/// <summary>
/// Returns the Operation result of an asynchronous invoked Operation
/// </summary>
/// <param name="aasIdentifier">The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="submodelIdentifier">The Submodel’s unique id (UTF8-BASE64-URL-encoded)</param>
/// <param name="idShortPath">IdShort path to the submodel element (dot-separated)</param>
/// <param name="handleId">The returned handle id of an operation’s asynchronous invocation used to request the current state of the operation’s execution (UTF8-BASE64-URL-encoded)</param>
/// <response code="200">Operation result object</response>
/// <response code="400">Bad Request, e.g. the request parameters of the format of the request body is wrong.</response>