Skip to content

Commit

Permalink
Bugfix: GlobalAssetId in shell response for full access to the twin.
Browse files Browse the repository at this point in the history
  • Loading branch information
tunacicek committed Aug 28, 2023
1 parent 4b718d0 commit e3dd28c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Optional<Shell> findByIdExternalAndExternalSubjectId( @Param( "idExternal" ) Str
@Query( value = "select s.id_external from shell s where s.id in (" +
"select si.fk_shell_id from shell_identifier si " +
"where concat(si.namespace,si.identifier) in (:keyValueCombinations) " +
"and (:tenantId = :owningTenantId or exists (" +
"and (:tenantId = :owningTenantId or si.namespace= :globalAssetId or exists (" +
"Select sider.ref_key_value from SHELL_IDENTIFIER_EXTERNAL_SUBJECT_REFERENCE_KEY sider where (sider.ref_key_value = :tenantId or (sider.ref_key_value = :publicWildcardPrefix and si.namespace in (:publicWildcardAllowedTypes) )) and sider.FK_SI_EXTERNAL_SUBJECT_REFERENCE_ID="+
"(select sies.id from SHELL_IDENTIFIER_EXTERNAL_SUBJECT_REFERENCE sies where sies.FK_SHELL_IDENTIFIER_EXTERNAL_SUBJECT_ID=si.id)"+
")) group by si.fk_shell_id " +
Expand All @@ -87,7 +87,8 @@ List<String> findExternalShellIdsByIdentifiersByExactMatch(@Param("keyValueCombi
@Param("tenantId") String tenantId,
@Param ("publicWildcardPrefix") String publicWildcardPrefix,
@Param ("publicWildcardAllowedTypes") List<String> publicWildcardAllowedTypes,
@Param("owningTenantId") String owningTenantId);
@Param("owningTenantId") String owningTenantId,
@Param("globalAssetId") String globalAssetId);

/**
* Returns external shell ids for the given keyValueCombinations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ public Shell filterShellProperties( Shell shell, String externalSubjectId ) {
);

if ( hasOnlyPublicAccess ) {
// Filter out globalAssetId from specificAssetId. TODO: implement to save globalAssetId in separate database column
// GlobalAssetId is set via mapper. In case of only read access, no globalAssetId should be shown.
Set<ShellIdentifier> filteredIdentifiersWithNoGlobalAssetId = filteredIdentifiers.stream().filter(
shellIdentifier -> !shellIdentifier.getKey().equals( ShellIdentifier.GLOBAL_ASSET_ID_KEY ) )
.collect( Collectors.toSet() );
return new Shell()
.withIdentifiers( filteredIdentifiers )
.withIdentifiers(filteredIdentifiersWithNoGlobalAssetId)
.withSubmodels( shell.getSubmodels() )
.withIdExternal( shell.getIdExternal() )
.withId( shell.getId() )
Expand All @@ -89,6 +94,10 @@ private Set<ShellIdentifier> filterSpecificAssetIdsByTenantId( Set<ShellIdentifi

Set<ShellIdentifier> externalSubjectIdSet = new HashSet<>();
for ( ShellIdentifier identifier : shellIdentifiers ) {
// Check if specificAssetId is globalAssetId -> TODO: implement to save globalAssetId in separate database column
if(identifier.getKey().equals( ShellIdentifier.GLOBAL_ASSET_ID_KEY )){
externalSubjectIdSet.add( identifier );
}
if ( identifier.getExternalSubjectId() != null ) {
Set<ShellIdentifierExternalSubjectReferenceKey> optionalReferenceKey =
identifier.getExternalSubjectId().getKeys().stream().filter( shellIdentifierExternalSubjectReferenceKey ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public GetAllAssetAdministrationShellIdsByAssetLink200Response findExternalShell
List<String> keyValueCombinations = shellIdentifiers.stream().map( shellIdentifier -> shellIdentifier.getKey() + shellIdentifier.getValue() ).toList();

List<String> queryResult = shellRepository.findExternalShellIdsByIdentifiersByExactMatch( keyValueCombinations,
keyValueCombinations.size(), externalSubjectId, externalSubjectIdWildcardPrefix, externalSubjectIdWildcardAllowedTypes, owningTenantId );
keyValueCombinations.size(), externalSubjectId, externalSubjectIdWildcardPrefix, externalSubjectIdWildcardAllowedTypes, owningTenantId, ShellIdentifier.GLOBAL_ASSET_ID_KEY );
pageSize = getPageSize( pageSize );

int startIndex = getCursorDecoded( cursor, queryResult );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,8 @@ public void testGetShellByExternalIdByOwningTenantId() throws Exception {
.andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.description[*]").isNotEmpty())
.andExpect(jsonPath("$.idShort",is(shellPayload.getIdShort())));
.andExpect(jsonPath("$.idShort",is(shellPayload.getIdShort())))
.andExpect(jsonPath("$.globalAssetId",is(shellPayload.getGlobalAssetId())));

// Request with TenantId (TENANT_TWO) returns no shell, because the shell not includes the externalSubjectId of Tenant_two as specificId
mvc.perform(
Expand Down Expand Up @@ -1218,6 +1219,7 @@ public void testGetAllShellByExternalIdWithPublicAccessByTenantId() throws Excep
.andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.description[*]").isNotEmpty())
.andExpect(jsonPath("$.globalAssetId",is(shellPayload.getGlobalAssetId())))
.andExpect(jsonPath("$.idShort",is(shellPayload.getIdShort())))
.andExpect(jsonPath("$.id",is( shellPayload.getId() )))
.andExpect(jsonPath("$.submodelDescriptors[*]").exists())
Expand All @@ -1236,6 +1238,7 @@ public void testGetAllShellByExternalIdWithPublicAccessByTenantId() throws Excep
.andExpect(status().isOk())
.andExpect(jsonPath("$.description[*]").doesNotExist())
.andExpect(jsonPath("$.idShort").doesNotExist())
.andExpect(jsonPath("$.globalAssetId").doesNotExist())
.andExpect(jsonPath("$.id",is( shellPayload.getId() )))
.andExpect(jsonPath("$.submodelDescriptors[*]").exists())
.andExpect(jsonPath("$.specificAssetIds[*]").exists());
Expand Down

0 comments on commit e3dd28c

Please sign in to comment.