use of org.xwiki.refactoring.job.RestoreRequest in project xwiki-platform by xwiki.
the class RestoreJobTest method restoreBatchAndDocuments.
@Test
public void restoreBatchAndDocuments() throws Throwable {
// Batch documents.
long deletedDocumentId1 = 13;
long deletedDocumentId2 = 42;
String batchId = "abc123";
// Individual documents.
// Note: A has the same ID as a document in the batch, so it should be restored only once.
long deletedDocumentIdA = deletedDocumentId2;
long deletedDocumentIdB = 7;
long deletedDocumentIdC = 3;
when(modelBridge.getDeletedDocumentIds(batchId)).thenReturn(Arrays.asList(deletedDocumentId1, deletedDocumentId2));
RestoreRequest request = createRequest();
request.setBatchId(batchId);
request.setDeletedDocumentIds(Arrays.asList(deletedDocumentIdA, deletedDocumentIdB, deletedDocumentIdC));
run(request);
verifyContext();
// Verify that each document is restored exactly 1 time.
verify(this.modelBridge, atMost(1)).restoreDeletedDocument(deletedDocumentId1, request.isCheckRights());
verify(this.modelBridge, atMost(1)).restoreDeletedDocument(deletedDocumentId2, request.isCheckRights());
verify(this.modelBridge, atMost(1)).restoreDeletedDocument(deletedDocumentIdB, request.isCheckRights());
verify(this.modelBridge, atMost(1)).restoreDeletedDocument(deletedDocumentIdC, request.isCheckRights());
}
use of org.xwiki.refactoring.job.RestoreRequest in project xwiki-platform by xwiki.
the class RestoreJobTest method jobGroupAtWikiLevel.
@Test
public void jobGroupAtWikiLevel() throws Exception {
RestoreRequest request = createRequest();
RestoreJob job = (RestoreJob) getMocker().getComponentUnderTest();
job.initialize(request);
JobGroupPath expectedJobGroupPath = new JobGroupPath(wikiReference.getName(), RestoreJob.ROOT_GROUP);
assertEquals(expectedJobGroupPath, job.getGroupPath());
}
use of org.xwiki.refactoring.job.RestoreRequest in project xwiki-platform by xwiki.
the class RestoreJob method initialize.
@Override
public void initialize(Request request) {
super.initialize(request);
// Build the job group path.
// Note: Because of the nature of the RestoreJob that works with with DeletedDocument IDs and BatchIDs (and not
// with EntityReferences), the only way we can try to avoid executing operation at the same time on the same
// reference is to use a group path at the wiki level, hoping most restore operations are fast and do not block
// for long.
WikiReference wikiReference = ((RestoreRequest) request).getWikiReference();
if (wikiReference != null) {
// Note:
this.groupPath = new JobGroupPath(wikiReference.getName(), ROOT_GROUP);
}
}
use of org.xwiki.refactoring.job.RestoreRequest in project xwiki-platform by xwiki.
the class RefactoringScriptService method createRestoreRequest.
/**
* Creates a request to restore a specified batch of deleted documents from the recycle bin.
*
* @param batchId the ID of the batch of deleted documents to restore
* @return the restore request
* @since 9.4RC1
*/
public RestoreRequest createRestoreRequest(String batchId) {
RestoreRequest request = initializeRestoreRequest();
request.setBatchId(batchId);
return request;
}
use of org.xwiki.refactoring.job.RestoreRequest in project xwiki-platform by xwiki.
the class RefactoringScriptService method createRestoreRequest.
/**
* Creates a request to restore a specified list of deleted documents from the recycle bin.
*
* @param deletedDocumentIds the list of IDs of the deleted documents to restore
* @return the restore request
* @since 9.4RC1
*/
public RestoreRequest createRestoreRequest(List<Long> deletedDocumentIds) {
RestoreRequest request = initializeRestoreRequest();
request.setDeletedDocumentIds(deletedDocumentIds);
return request;
}
Aggregations