Skip to content
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

feat: Extend DTR APIs for Access management - Clean-up #310

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface ShellIdentifierRepository extends JpaRepository<ShellIdentifier, UUID> {

Expand All @@ -50,6 +51,52 @@ sid.shellId.id IN (
GROUP BY filtersid.shellId.id
HAVING COUNT(*) = :keyValueCombinationsSize
)
""")
""" )
List<ShellIdentifierMinimal> findMinimalShellIdsBySpecificAssetIds( List<String> keyValueCombinations, int keyValueCombinationsSize );

/**
* Returns external shell ids for the given keyValueCombinations.
* External shell ids matching the conditions below are returned:
* - specificAssetIds match exactly the keyValueCombinations
* - if externalSubjectId (tenantId) is not null it must match the tenantId
*
*
* To be able to properly index the key and value conditions, the query does not use any functions.
* Computed indexes cannot be created for mutable functions like CONCAT in Postgres.
*
* @param keyValueCombinations the keys values to search for as tuples
* @param keyValueCombinationsSize the size of the key value combinations
* @return external shell ids for the given key value combinations
*/
@Query( value = """
SELECT s.id_external
FROM shell s
JOIN shell_identifier si ON s.id = si.fk_shell_id
WHERE
CONCAT(si.namespace, si.identifier) IN (:keyValueCombinations)
AND (
:tenantId = :owningTenantId
OR si.namespace = :globalAssetId
OR EXISTS (
SELECT 1
FROM SHELL_IDENTIFIER_EXTERNAL_SUBJECT_REFERENCE_KEY sider
JOIN SHELL_IDENTIFIER_EXTERNAL_SUBJECT_REFERENCE sies ON sider.FK_SI_EXTERNAL_SUBJECT_REFERENCE_ID = sies.id
WHERE
(
sider.ref_key_value = :tenantId
OR ( sider.ref_key_value = :publicWildcardPrefix AND si.namespace IN (:publicWildcardAllowedTypes) )
)
AND sies.FK_SHELL_IDENTIFIER_EXTERNAL_SUBJECT_ID = si.id
)
)
GROUP BY s.id_external
HAVING COUNT(*) = :keyValueCombinationsSize
""", nativeQuery = true )
List<String> findExternalShellIdsByIdentifiersByExactMatch( @Param( "keyValueCombinations" ) List<String> keyValueCombinations,
@Param( "keyValueCombinationsSize" ) int keyValueCombinationsSize,
@Param( "tenantId" ) String tenantId,
@Param( "publicWildcardPrefix" ) String publicWildcardPrefix,
@Param( "publicWildcardAllowedTypes" ) List<String> publicWildcardAllowedTypes,
@Param( "owningTenantId" ) String owningTenantId,
@Param( "globalAssetId" ) String globalAssetId );
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,52 +79,6 @@ Optional<Shell> findByIdExternalAndExternalSubjectId( @Param( "idExternal" ) Str

List<Shell> findShellsByIdExternalIsIn( Set<String> idExternals );

/**
* Returns external shell ids for the given keyValueCombinations.
* External shell ids matching the conditions below are returned:
* - specificAssetIds match exactly the keyValueCombinations
* - if externalSubjectId (tenantId) is not null it must match the tenantId
*
*
* To be able to properly index the key and value conditions, the query does not use any functions.
* Computed indexes cannot be created for mutable functions like CONCAT in Postgres.
*
* @param keyValueCombinations the keys values to search for as tuples
* @param keyValueCombinationsSize the size of the key value combinations
* @return external shell ids for the given key value combinations
*/
@Query( value = """
SELECT s.id_external
FROM shell s
JOIN shell_identifier si ON s.id = si.fk_shell_id
WHERE
CONCAT(si.namespace, si.identifier) IN (:keyValueCombinations)
AND (
:tenantId = :owningTenantId
OR si.namespace = :globalAssetId
OR EXISTS (
SELECT 1
FROM SHELL_IDENTIFIER_EXTERNAL_SUBJECT_REFERENCE_KEY sider
JOIN SHELL_IDENTIFIER_EXTERNAL_SUBJECT_REFERENCE sies ON sider.FK_SI_EXTERNAL_SUBJECT_REFERENCE_ID = sies.id
WHERE
(
sider.ref_key_value = :tenantId
OR ( sider.ref_key_value = :publicWildcardPrefix AND si.namespace IN (:publicWildcardAllowedTypes) )
)
AND sies.FK_SHELL_IDENTIFIER_EXTERNAL_SUBJECT_ID = si.id
)
)
GROUP BY s.id_external
HAVING COUNT(*) = :keyValueCombinationsSize
""", nativeQuery = true )
List<String> findExternalShellIdsByIdentifiersByExactMatch( @Param( "keyValueCombinations" ) List<String> keyValueCombinations,
@Param( "keyValueCombinationsSize" ) int keyValueCombinationsSize,
@Param( "tenantId" ) String tenantId,
@Param( "publicWildcardPrefix" ) String publicWildcardPrefix,
@Param( "publicWildcardAllowedTypes" ) List<String> publicWildcardAllowedTypes,
@Param( "owningTenantId" ) String owningTenantId,
@Param( "globalAssetId" ) String globalAssetId );

/**
* Returns external shell ids for the given keyValueCombinations.
* External shell ids that match any keyValueCombinations are returned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public ShellCollectionDto findAllShells( Integer pageSize, String cursorVal, Str
Page<Shell> currentPage = shellRepository.findAll( specification, ofSize( fetchSize ) );
List<Shell> shells = shellAccessHandler.filterListOfShellProperties( currentPage.stream().toList(), externalSubjectId );
shells.stream()
.limit( (long) pageSize - foundList.size() )
.limit( (long) fetchSize - foundList.size() )
.forEach( foundList::add );
hasNext = currentPage.hasNext();
}
Expand Down Expand Up @@ -278,7 +278,7 @@ public GetAllAssetAdministrationShellIdsByAssetLink200Response findExternalShell
.forEach( assetIdList::add );
nextCursor = getCursorEncoded( allVisible, assetIdList );
} else {
List<String> queryResult = shellRepository.findExternalShellIdsByIdentifiersByExactMatch( keyValueCombinations,
List<String> queryResult = shellIdentifierRepository.findExternalShellIdsByIdentifiersByExactMatch( keyValueCombinations,
keyValueCombinations.size(), externalSubjectId, externalSubjectIdWildcardPrefix, externalSubjectIdWildcardAllowedTypes, owningTenantId,
ShellIdentifier.GLOBAL_ASSET_ID_KEY );
pageSize = getPageSize( pageSize );
Expand Down
Loading