public static void deleteChildrenNotInCollection ( Resource resource , ConfigurationCollectionPersistData data ) { Set < String > collectionItemNames = data . getItems ( ) . stream ( ) . map ( item -> item . getCollectionItemName ( ) ) . collect ( Collectors . toSet ( ) ) ; for ( Resource child : resource . getChildren ( ) ) { if ( ! collectionItemNames . contains ( child . getName ( ) ) && ! StringUtils . equals ( JCR_CONTENT , child . getName ( ) ) ) { deletePageOrResource ( child ) ; } } }
Delete children that are no longer contained in list of collection items .