@Test void permanentlyDeleteAllDocuments() throws Exception { int nbDocs = 12; PermanentlyDeleteJob deleteJob = mock(PermanentlyDeleteJob.class); AbstractJobStatus jobStatus = mock(AbstractJobStatus.class); when(jobStatus.isCanceled()).thenReturn(false); when(deleteJob.getStatus()).thenReturn(jobStatus); DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class); when(deletedDocument.getDocumentReference()).thenReturn(documentReference); when(xwiki.getDeletedDocument(anyLong(), eq(xcontext))).thenReturn(deletedDocument); when(xwiki.exists(documentReference, xcontext)).thenReturn(false); when(xwiki.getRecycleBinStore()).thenReturn(recycleBin); when(recycleBin.getNumberOfDeletedDocuments(any())).thenReturn((long) nbDocs); when(recycleBin.getAllDeletedDocumentsIds(eq(this.xcontext), anyInt())) .thenReturn(new Long[]{ 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L }).thenReturn(new Long[]{ 11L, 12L }); when(request.isCheckRights()).thenReturn(false); when(request.isCheckAuthorRights()).thenReturn(false); assertTrue(this.modelBridge.permanentlyDeleteAllDocuments(deleteJob, request)); verify(this.progressManager).pushLevelProgress(nbDocs, deleteJob); verify(this.progressManager, times(12)).startStep(deleteJob); verify(this.progressManager, times(12)).endStep(deleteJob); for (int i = 1; i <= 12; i++) { verify(recycleBin).deleteFromRecycleBin(i, xcontext, true); assertLog(i - 1, Level.INFO, "Document [{}] has been permanently deleted.", documentReference); } }
@Override public boolean permanentlyDeleteAllDocuments(PermanentlyDeleteJob deleteJob, AbstractCheckRightsRequest request) { XWikiContext context = this.xcontextProvider.get(); XWiki xwiki = context.getWiki(); int limit = 10; XWikiRecycleBinStoreInterface recycleBinStore = xwiki.getRecycleBinStore(); try { long numberOfDocumentsToDelete = recycleBinStore.getNumberOfDeletedDocuments(context); int nbDocToDelete; if (numberOfDocumentsToDelete > Integer.MAX_VALUE) { logger.warn("Only [{}] file can be deleted at once. Please run again the job to delete everything.", Integer.MAX_VALUE); nbDocToDelete = Integer.MAX_VALUE; } else { nbDocToDelete = Integer.valueOf(numberOfDocumentsToDelete + ""); } progressManager.pushLevelProgress(nbDocToDelete, deleteJob); for (int i = 0; i < nbDocToDelete; i += limit) { Long[] allDeletedDocumentsIds = recycleBinStore.getAllDeletedDocumentsIds(context, limit); for (Long deletedDocumentsId : allDeletedDocumentsIds) { if (deleteJob.getStatus().isCanceled()) { return false; } else { this.progressManager.startStep(deleteJob); this.permanentlyDeleteDocument(deletedDocumentsId, request); this.progressManager.endStep(deleteJob); } } } return true; } catch (XWikiException e) { logger.error("Failed to permanently delete all documents", e); } return false; }
DefaultModelBridge implements ModelBridge { @Override public boolean permanentlyDeleteAllDocuments(PermanentlyDeleteJob deleteJob, AbstractCheckRightsRequest request) { XWikiContext context = this.xcontextProvider.get(); XWiki xwiki = context.getWiki(); int limit = 10; XWikiRecycleBinStoreInterface recycleBinStore = xwiki.getRecycleBinStore(); try { long numberOfDocumentsToDelete = recycleBinStore.getNumberOfDeletedDocuments(context); int nbDocToDelete; if (numberOfDocumentsToDelete > Integer.MAX_VALUE) { logger.warn("Only [{}] file can be deleted at once. Please run again the job to delete everything.", Integer.MAX_VALUE); nbDocToDelete = Integer.MAX_VALUE; } else { nbDocToDelete = Integer.valueOf(numberOfDocumentsToDelete + ""); } progressManager.pushLevelProgress(nbDocToDelete, deleteJob); for (int i = 0; i < nbDocToDelete; i += limit) { Long[] allDeletedDocumentsIds = recycleBinStore.getAllDeletedDocumentsIds(context, limit); for (Long deletedDocumentsId : allDeletedDocumentsIds) { if (deleteJob.getStatus().isCanceled()) { return false; } else { this.progressManager.startStep(deleteJob); this.permanentlyDeleteDocument(deletedDocumentsId, request); this.progressManager.endStep(deleteJob); } } } return true; } catch (XWikiException e) { logger.error("Failed to permanently delete all documents", e); } return false; } }
DefaultModelBridge implements ModelBridge { @Override public boolean permanentlyDeleteAllDocuments(PermanentlyDeleteJob deleteJob, AbstractCheckRightsRequest request) { XWikiContext context = this.xcontextProvider.get(); XWiki xwiki = context.getWiki(); int limit = 10; XWikiRecycleBinStoreInterface recycleBinStore = xwiki.getRecycleBinStore(); try { long numberOfDocumentsToDelete = recycleBinStore.getNumberOfDeletedDocuments(context); int nbDocToDelete; if (numberOfDocumentsToDelete > Integer.MAX_VALUE) { logger.warn("Only [{}] file can be deleted at once. Please run again the job to delete everything.", Integer.MAX_VALUE); nbDocToDelete = Integer.MAX_VALUE; } else { nbDocToDelete = Integer.valueOf(numberOfDocumentsToDelete + ""); } progressManager.pushLevelProgress(nbDocToDelete, deleteJob); for (int i = 0; i < nbDocToDelete; i += limit) { Long[] allDeletedDocumentsIds = recycleBinStore.getAllDeletedDocumentsIds(context, limit); for (Long deletedDocumentsId : allDeletedDocumentsIds) { if (deleteJob.getStatus().isCanceled()) { return false; } else { this.progressManager.startStep(deleteJob); this.permanentlyDeleteDocument(deletedDocumentsId, request); this.progressManager.endStep(deleteJob); } } } return true; } catch (XWikiException e) { logger.error("Failed to permanently delete all documents", e); } return false; }  }
DefaultModelBridge implements ModelBridge { @Override public boolean permanentlyDeleteAllDocuments(PermanentlyDeleteJob deleteJob, AbstractCheckRightsRequest request) { XWikiContext context = this.xcontextProvider.get(); XWiki xwiki = context.getWiki(); int limit = 10; XWikiRecycleBinStoreInterface recycleBinStore = xwiki.getRecycleBinStore(); try { long numberOfDocumentsToDelete = recycleBinStore.getNumberOfDeletedDocuments(context); int nbDocToDelete; if (numberOfDocumentsToDelete > Integer.MAX_VALUE) { logger.warn("Only [{}] file can be deleted at once. Please run again the job to delete everything.", Integer.MAX_VALUE); nbDocToDelete = Integer.MAX_VALUE; } else { nbDocToDelete = Integer.valueOf(numberOfDocumentsToDelete + ""); } progressManager.pushLevelProgress(nbDocToDelete, deleteJob); for (int i = 0; i < nbDocToDelete; i += limit) { Long[] allDeletedDocumentsIds = recycleBinStore.getAllDeletedDocumentsIds(context, limit); for (Long deletedDocumentsId : allDeletedDocumentsIds) { if (deleteJob.getStatus().isCanceled()) { return false; } else { this.progressManager.startStep(deleteJob); this.permanentlyDeleteDocument(deletedDocumentsId, request); this.progressManager.endStep(deleteJob); } } } return true; } catch (XWikiException e) { logger.error("Failed to permanently delete all documents", e); } return false; }  @Override boolean create(DocumentReference documentReference); @Override boolean copy(DocumentReference source, DocumentReference destination); @Override boolean delete(DocumentReference reference); @Override boolean delete(DocumentReference reference, boolean skipRecycleBin); @Override boolean removeLock(DocumentReference reference); @Override void createRedirect(DocumentReference oldReference, DocumentReference newReference); @Override boolean canOverwriteSilently(DocumentReference documentReference); @Override boolean exists(DocumentReference reference); @Override List<DocumentReference> getBackLinkedReferences(DocumentReference documentReference, String wikiId); @Override List<DocumentReference> getDocumentReferences(SpaceReference spaceReference); @Override boolean updateParentField(final DocumentReference oldParentReference,
        final DocumentReference newParentReference); @Override DocumentReference setContextUserReference(DocumentReference userReference); @Override void update(DocumentReference documentReference, Map<String, String> parameters); @Override boolean restoreDeletedDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override List<Long> getDeletedDocumentIds(String batchId); @Override boolean permanentlyDeleteDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override boolean permanentlyDeleteAllDocuments(PermanentlyDeleteJob deleteJob, AbstractCheckRightsRequest request); @Override boolean rename(DocumentReference source, DocumentReference destination); }
DefaultModelBridge implements ModelBridge { @Override public boolean permanentlyDeleteAllDocuments(PermanentlyDeleteJob deleteJob, AbstractCheckRightsRequest request) { XWikiContext context = this.xcontextProvider.get(); XWiki xwiki = context.getWiki(); int limit = 10; XWikiRecycleBinStoreInterface recycleBinStore = xwiki.getRecycleBinStore(); try { long numberOfDocumentsToDelete = recycleBinStore.getNumberOfDeletedDocuments(context); int nbDocToDelete; if (numberOfDocumentsToDelete > Integer.MAX_VALUE) { logger.warn("Only [{}] file can be deleted at once. Please run again the job to delete everything.", Integer.MAX_VALUE); nbDocToDelete = Integer.MAX_VALUE; } else { nbDocToDelete = Integer.valueOf(numberOfDocumentsToDelete + ""); } progressManager.pushLevelProgress(nbDocToDelete, deleteJob); for (int i = 0; i < nbDocToDelete; i += limit) { Long[] allDeletedDocumentsIds = recycleBinStore.getAllDeletedDocumentsIds(context, limit); for (Long deletedDocumentsId : allDeletedDocumentsIds) { if (deleteJob.getStatus().isCanceled()) { return false; } else { this.progressManager.startStep(deleteJob); this.permanentlyDeleteDocument(deletedDocumentsId, request); this.progressManager.endStep(deleteJob); } } } return true; } catch (XWikiException e) { logger.error("Failed to permanently delete all documents", e); } return false; }  @Override boolean create(DocumentReference documentReference); @Override boolean copy(DocumentReference source, DocumentReference destination); @Override boolean delete(DocumentReference reference); @Override boolean delete(DocumentReference reference, boolean skipRecycleBin); @Override boolean removeLock(DocumentReference reference); @Override void createRedirect(DocumentReference oldReference, DocumentReference newReference); @Override boolean canOverwriteSilently(DocumentReference documentReference); @Override boolean exists(DocumentReference reference); @Override List<DocumentReference> getBackLinkedReferences(DocumentReference documentReference, String wikiId); @Override List<DocumentReference> getDocumentReferences(SpaceReference spaceReference); @Override boolean updateParentField(final DocumentReference oldParentReference,
        final DocumentReference newParentReference); @Override DocumentReference setContextUserReference(DocumentReference userReference); @Override void update(DocumentReference documentReference, Map<String, String> parameters); @Override boolean restoreDeletedDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override List<Long> getDeletedDocumentIds(String batchId); @Override boolean permanentlyDeleteDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override boolean permanentlyDeleteAllDocuments(PermanentlyDeleteJob deleteJob, AbstractCheckRightsRequest request); @Override boolean rename(DocumentReference source, DocumentReference destination);  }