-
Notifications
You must be signed in to change notification settings - Fork 63
Fixes a error in the assetIds Query Parameter of the /shells endpoint #771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
4d970ce
94ec98b
8d64fd8
8395bc0
8d85804
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,3 +90,5 @@ local.properties | |
| /.env | ||
|
|
||
| **.iml | ||
|
|
||
| .DS_Store | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "paging_metadata": {}, | ||
| "result": [ | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -117,6 +117,9 @@ public Iterable<AssetAdministrationShell> getAllAas(List<SpecificAssetId> assetI | |||||||||||||||||||||||||||
| List<AssetAdministrationShell> filteredAas = new java.util.ArrayList<>(); | ||||||||||||||||||||||||||||
| String globalAssetId = null; | ||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||
| if(assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).count() > 1){ | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| if(assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).count() > 1){ | |
| if (assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).count() > 1) { |
Outdated
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stream is being traversed twice unnecessarily. The first traversal counts globalAssetId entries, and line 123 traverses the stream again to find the first one. Consider storing the filtered list once and checking its size to avoid redundant stream operations.
| if(assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).count() > 1){ | |
| return filteredAas; | |
| } | |
| globalAssetId = assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).findFirst().get().getValue(); | |
| List<SpecificAssetId> globalAssetIdList = assetIds.stream() | |
| .filter(assetId -> assetId.getName().equals("globalAssetId")) | |
| .collect(Collectors.toList()); | |
| if(globalAssetIdList.size() > 1){ | |
| return filteredAas; | |
| } | |
| if(!globalAssetIdList.isEmpty()) { | |
| globalAssetId = globalAssetIdList.get(0).getValue(); | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,13 +240,11 @@ private List<Criteria> buildAasFilterCriteria(List<SpecificAssetId> assetIds, St | |
| List<Criteria> criteriaList = new ArrayList<>(); | ||
|
|
||
| // Extract globalAssetId from assetIds | ||
| String globalAssetId = null; | ||
| List<SpecificAssetId> globalAssetIds = new ArrayList<>(); | ||
| try { | ||
| globalAssetId = assetIds.stream() | ||
| globalAssetIds = assetIds.stream() | ||
| .filter(assetId -> "globalAssetId".equals(assetId.getName())) | ||
| .findFirst() | ||
| .map(SpecificAssetId::getValue) | ||
| .orElse(null); | ||
| .toList(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just out of curiosity - in what scenario could there be multiple
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you provide an assetId with name globalAssetId it will always be interpreted as globalAssetId. Therefore this mistake will only happen if two globalAssetIds are intentionally provided via the request
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a fix that correctly handles the case that two globalAssetIds are provided (even tho this should not happen in the first place) |
||
|
|
||
| assetIds = assetIds.stream() | ||
| .filter(assetId -> !"globalAssetId".equals(assetId.getName())) | ||
|
|
@@ -267,8 +265,8 @@ private List<Criteria> buildAasFilterCriteria(List<SpecificAssetId> assetIds, St | |
| } | ||
|
|
||
| // Match globalAssetId if present | ||
| if (globalAssetId != null && !globalAssetId.isEmpty()) { | ||
| criteriaList.add(Criteria.where("assetInformation.globalAssetId").is(globalAssetId)); | ||
| for (SpecificAssetId globalAssetId : globalAssetIds) { | ||
| criteriaList.add(Criteria.where("assetInformation.globalAssetId").is(globalAssetId.getValue())); | ||
| } | ||
|
Comment on lines
+268
to
270
|
||
|
|
||
| return criteriaList; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test method name "getAllAasWithMultipleAssetIds" is ambiguous. It doesn't clearly indicate that it's specifically testing multiple globalAssetIds (not multiple specificAssetIds). Consider renaming to "getAllAasWithMultipleGlobalAssetIds" to better reflect what is being tested.