src/main/java/za/co/grindrodbank/dokuti/document/DocumentControllerImpl.java
private void removePermissionForGrantedBy(DocumentEntity documentEntity, List<DocumentAcl> permissions, String permission, UUID uuid) {

        List<DocumentAcl> removedList = new ArrayList<>();
        List<UUID> users = new ArrayList<>();
        
        for (DocumentAcl acl : permissions) {
            if (acl.getGrantedBy() != null && acl.getGrantedBy().equals(uuid) &&  acl.getPermission() != null && acl.getPermission().equals(permission) ) {
                removedList.add(acl);
                List<DocumentLifeTimeEntity> history = documentEntity.getDocumentHistory();
                for (DocumentLifeTimeEntity lt : history) {
                    if (uuid.equals(acl.getGrantedBy()) && lt.getPermission().equals(permission) && (lt.getRevokedBy()==null|| "".equals(lt.getRevokedBy().toString()))) {
                        lt.setRevokedBy(UUID.fromString(SecurityContextUtility.getUserIdFromJwt()));
                        lt.setRevokedOn(LocalDateTime.now());
                    }
                }                  
                users.add(acl.getUserId());
            }
        }
        permissions.removeAll(removedList);
        for (UUID userId : users) {
            removePermissionForGrantedBy(documentEntity, permissions, permission, userId);
        }
    }
// recursive "un-share" permission for grantedBy user
recursive "un-share" permission for grantedBy user
recursive " un - share " permission for grantedBy user
private void removePermissionForGrantedBy(DocumentEntity documentEntity, List<DocumentAcl> permissions, String permission, UUID uuid) {
        List<DocumentAcl> removedList = new ArrayList<>();
        List<UUID> users = new ArrayList<>();
        for (DocumentAcl acl : permissions) {
            if (acl.getGrantedBy() != null && acl.getGrantedBy().equals(uuid) &&  acl.getPermission() != null && acl.getPermission().equals(permission) ) {
                removedList.add(acl);
                List<DocumentLifeTimeEntity> history = documentEntity.getDocumentHistory();
                for (DocumentLifeTimeEntity lt : history) {
                    if (uuid.equals(acl.getGrantedBy()) && lt.getPermission().equals(permission) && (lt.getRevokedBy()==null|| "".equals(lt.getRevokedBy().toString()))) {
                        lt.setRevokedBy(UUID.fromString(SecurityContextUtility.getUserIdFromJwt()));
                        lt.setRevokedOn(LocalDateTime.now());
                    }
                }                  
                users.add(acl.getUserId());
            }
        }
        permissions.removeAll(removedList);
        for (UUID userId : users) {
            removePermissionForGrantedBy(documentEntity, permissions, permission, userId);
        }
    }
private void removePermissionForGrantedBy ( DocumentEntity documentEntity , List < DocumentAcl > permissions , String permission , UUID uuid ) { List < DocumentAcl > removedList = new ArrayList < > ( ) ; List < UUID > users = new ArrayList < > ( ) ; for ( DocumentAcl acl : permissions ) { if ( acl . getGrantedBy ( ) != null && acl . getGrantedBy ( ) . equals ( uuid ) && acl . getPermission ( ) != null && acl . getPermission ( ) . equals ( permission ) ) { removedList . add ( acl ) ; List < DocumentLifeTimeEntity > history = documentEntity . getDocumentHistory ( ) ; for ( DocumentLifeTimeEntity lt : history ) { if ( uuid . equals ( acl . getGrantedBy ( ) ) && lt . getPermission ( ) . equals ( permission ) && ( lt . getRevokedBy ( ) == null || "" . equals ( lt . getRevokedBy ( ) . toString ( ) ) ) ) { lt . setRevokedBy ( UUID . fromString ( SecurityContextUtility . getUserIdFromJwt ( ) ) ) ; lt . setRevokedOn ( LocalDateTime . now ( ) ) ; } } users . add ( acl . getUserId ( ) ) ; } } permissions . removeAll ( removedList ) ; for ( UUID userId : users ) { removePermissionForGrantedBy ( documentEntity , permissions , permission , userId ) ; } }
recursive "un-share" permission for grantedBy user
recursive " un - share " permission for grantedBy user