Skip to content

Commit

Permalink
Set externalSubjectId as empty String if value is null.
Browse files Browse the repository at this point in the history
  • Loading branch information
tunacicek committed Jul 12, 2023
1 parent c7fbeb6 commit 704e9d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public ResponseEntity<GetAssetAdministrationShellDescriptorsResult> getAllAssetA
AssetKind assetKind, String assetType, @RequestHeader String externalSubjectId ) {
Integer page = 0 ;
Integer pageSize = 100;
ShellCollectionDto dto = shellService.findAllShells(page, pageSize,externalSubjectId);
ShellCollectionDto dto = shellService.findAllShells(page, pageSize,getExternalSubjectIdOrEmpty(externalSubjectId));
GetAssetAdministrationShellDescriptorsResult result = shellMapper.toApiDto(dto);
return new ResponseEntity<>(result, HttpStatus.OK);
}

@Override
// new todo: correct implementation
public ResponseEntity<GetSubmodelDescriptorsResult> getAllSubmodelDescriptorsThroughSuperpath( String aasIdentifier, Integer limit, String cursor, @RequestHeader String externalSubjectId ) {
Shell savedShell = shellService.findShellByExternalId(aasIdentifier, externalSubjectId);
Shell savedShell = shellService.findShellByExternalId(aasIdentifier, getExternalSubjectIdOrEmpty(externalSubjectId));
Set<Submodel> submodels = savedShell.getSubmodels();
List<SubmodelDescriptor> descriptorResults = submodelMapper.toApiDto( submodels );
GetSubmodelDescriptorsResult result = new GetSubmodelDescriptorsResult();
Expand All @@ -107,7 +107,7 @@ public ResponseEntity<GetSubmodelDescriptorsResult> getAllSubmodelDescriptorsThr

@Override
public ResponseEntity<AssetAdministrationShellDescriptor> getAssetAdministrationShellDescriptorById( String aasIdentifier, @RequestHeader String externalSubjectId ) {
Shell saved = shellService.findShellByExternalId(aasIdentifier, externalSubjectId);
Shell saved = shellService.findShellByExternalId(aasIdentifier, getExternalSubjectIdOrEmpty(externalSubjectId));
return new ResponseEntity<>(shellMapper.toApiDto(saved), HttpStatus.OK);
}

Expand Down Expand Up @@ -151,13 +151,13 @@ public ResponseEntity<List<String>> getAllAssetAdministrationShellIdsByAssetLink
if (assetIds == null || assetIds.isEmpty()) {
return new ResponseEntity<>(Collections.emptyList(), HttpStatus.OK);
}
List<String> externalIds = shellService.findExternalShellIdsByIdentifiersByExactMatch(shellMapper.fromApiDto(assetIds), externalSubjectId);
List<String> externalIds = shellService.findExternalShellIdsByIdentifiersByExactMatch(shellMapper.fromApiDto(assetIds), getExternalSubjectIdOrEmpty(externalSubjectId));
return new ResponseEntity<>(externalIds, HttpStatus.OK);
}

@Override
public ResponseEntity<List<SpecificAssetId>> getAllAssetLinksById(String aasIdentifier, @RequestHeader String externalSubjectId) {
Set<ShellIdentifier> identifiers = shellService.findShellIdentifiersByExternalShellId(aasIdentifier, externalSubjectId);
Set<ShellIdentifier> identifiers = shellService.findShellIdentifiersByExternalShellId(aasIdentifier, getExternalSubjectIdOrEmpty(externalSubjectId));
return new ResponseEntity<>(shellMapper.toApiDto(identifiers), HttpStatus.OK);
}

Expand All @@ -171,8 +171,12 @@ public ResponseEntity<List<SpecificAssetId>> postAllAssetLinksById(String aasIde
@Override
public ResponseEntity<List<String>> postQueryAllAssetAdministrationShellIds(ShellLookup shellLookup, @RequestHeader String externalSubjectId) {
List<SpecificAssetId> assetIds = shellLookup.getQuery().getAssetIds();
List<String> externalIds = shellService.findExternalShellIdsByIdentifiersByAnyMatch(shellMapper.fromApiDto(assetIds), externalSubjectId);
List<String> externalIds = shellService.findExternalShellIdsByIdentifiersByAnyMatch(shellMapper.fromApiDto(assetIds), getExternalSubjectIdOrEmpty(externalSubjectId));
return new ResponseEntity<>(externalIds, HttpStatus.OK);
}
}

private String getExternalSubjectIdOrEmpty(String externalSubjectId) {
return (null ==externalSubjectId) ? "" : externalSubjectId;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ private Page<Shell> filterSpecificAssetIdsByTenantId(Page<Shell> shells, String
return shells.map(shell -> shell.withIdentifiers(filterSpecificAssetIdsByTenantId(shell.getIdentifiers(), externalSubjectId)));
}

private Set<ShellIdentifier> filterSpecificAssetIdsByTenantId(Set<ShellIdentifier> shellIdentifiers, String externalSubjectId) {
String tenantId = (externalSubjectId == null) ? "" : externalSubjectId;
private Set<ShellIdentifier> filterSpecificAssetIdsByTenantId(Set<ShellIdentifier> shellIdentifiers, String tenantId) {
// the owning tenant should always see all identifiers
if(tenantId.equals(owningTenantId)){
return shellIdentifiers;
Expand Down

0 comments on commit 704e9d5

Please sign in to comment.