Skip to content

Commit

Permalink
Extend DTR APIs for Access management
Browse files Browse the repository at this point in the history
- Addresses some Sonar findings
  • Loading branch information
istvan-nagy-epam committed Feb 5, 2024
1 parent 6540113 commit 4b26187
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ public Shell findShellByExternalIdAndExternalSubjectId( String externalShellId,

@Transactional
public Shell findShellByExternalIdWithoutFiltering( String externalShellId ) {
return shellRepository.findByIdExternal( externalShellId )
.orElseThrow( () -> new EntityNotFoundException( String.format( "Shell for identifier %s not found", externalShellId ) ) );
return doFindShellByExternalIdWithoutFiltering( externalShellId );
}

@Transactional( readOnly = true )
Expand All @@ -202,7 +201,7 @@ public ShellCollectionDto findAllShells( Integer pageSize, String cursorVal, Str
currentPage.stream()
.map( shell -> shellAccessHandler.filterShellProperties( shell, externalSubjectId ) )
.filter( Objects::nonNull )
.limit( pageSize - resultList.size() )
.limit( (long) pageSize - resultList.size() )
.forEach( resultList::add );
hasNext = currentPage.hasNext();
}
Expand Down Expand Up @@ -351,7 +350,7 @@ public void deleteAllIdentifiers( String externalShellId ) {

@Transactional
public Set<ShellIdentifier> save( String externalShellId, Set<ShellIdentifier> shellIdentifiers, String externalSubjectId ) {
Shell shellFromDb = findShellByExternalIdWithoutFiltering( externalShellId );
Shell shellFromDb = doFindShellByExternalIdWithoutFiltering( externalShellId );

List<ShellIdentifier> identifiersToUpdate = shellIdentifiers.stream().map( identifier -> identifier.withShellId( shellFromDb ) )
.collect( Collectors.toList() );
Expand Down Expand Up @@ -387,7 +386,7 @@ private static void mapShellIdentifier( Stream<ShellIdentifier> identifiersToUpd

@Transactional
public Submodel save( String externalShellId, Submodel submodel, String externalSubjectId ) {
Shell shellFromDb = findShellByExternalIdWithoutFiltering( externalShellId );
Shell shellFromDb = doFindShellByExternalIdWithoutFiltering( externalShellId );
submodel.setShellId( shellFromDb );

//uniqueness on shellId and idShort
Expand All @@ -411,7 +410,7 @@ public Submodel saveSubmodel( Submodel submodel ) {

@Transactional
public void update( String externalShellId, Submodel submodel, String externalSubjectId ) {
Shell shellFromDb = findShellByExternalIdWithoutFiltering( externalShellId );
Shell shellFromDb = doFindShellByExternalIdWithoutFiltering( externalShellId );
shellFromDb.add( submodel );
submodel.setShellId( shellFromDb );
mapSubmodel( shellFromDb.getSubmodels() );
Expand All @@ -420,7 +419,7 @@ public void update( String externalShellId, Submodel submodel, String externalSu

@Transactional
public void deleteSubmodel( String externalShellId, String externalSubModelId, String externalSubjectId ) {
Shell shellFromDb = findShellByExternalIdWithoutFiltering( externalShellId );
Shell shellFromDb = doFindShellByExternalIdWithoutFiltering( externalShellId );
Submodel submodelId = findSubmodelMinimalByExternalId( shellFromDb.getId(), externalSubModelId );
shellFromDb.getSubmodels().remove( submodelId );
submodelRepository.deleteById( submodelId.getId() );
Expand Down Expand Up @@ -468,5 +467,9 @@ public List<BatchResultDto> saveBatch( List<Shell> shells ) {
}
} ).collect( Collectors.toList() );
}
private Shell doFindShellByExternalIdWithoutFiltering( String externalShellId ) {
return shellRepository.findByIdExternal( externalShellId )
.orElseThrow( () -> new EntityNotFoundException( String.format( "Shell for identifier %s not found", externalShellId ) ) );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void testFindExternalShellIdsBySpecificAssetIdsWithTenantBasedVisibilityE
super.testFindExternalShellIdsBySpecificAssetIdsWithTenantBasedVisibilityExpectSuccess();
}

@Test
//@Test
public void testFindExternalShellIdsBySpecificAssetIdsWithTenantBasedVisibilityAndWildcardExpectSuccess() throws Exception {
//TODO: enable when we are no longer using the file based access rules
// This test is using a random prefix in the the name of the specificAssetId that has to match
Expand All @@ -211,7 +211,7 @@ public void testGetAllShellsByOwningTenantId() throws Exception {
super.testGetAllShellsByOwningTenantId();
}

@Test
//@Test
public void testGetAllShellsWithPublicAccessByTenantId() throws Exception {
//TODO: enable when public access is implemented
//super.testGetAllShellsWithPublicAccessByTenantId();
Expand All @@ -222,7 +222,7 @@ public void testGetShellByExternalIdByOwningTenantId() throws Exception {
super.testGetShellByExternalIdByOwningTenantId();
}

@Test
//@Test
public void testGetAllShellByExternalIdWithPublicAccessByTenantId() throws Exception {
//TODO: enable when public access is implemented
//super.testGetAllShellByExternalIdWithPublicAccessByTenantId();
Expand Down

0 comments on commit 4b26187

Please sign in to comment.