Search in sources :

Example 1 with RestoreRequest

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());
}
Also used : RestoreRequest(org.xwiki.refactoring.job.RestoreRequest) Test(org.junit.Test)

Example 2 with RestoreRequest

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());
}
Also used : RestoreRequest(org.xwiki.refactoring.job.RestoreRequest) JobGroupPath(org.xwiki.job.JobGroupPath) Test(org.junit.Test)

Example 3 with RestoreRequest

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);
    }
}
Also used : RestoreRequest(org.xwiki.refactoring.job.RestoreRequest) JobGroupPath(org.xwiki.job.JobGroupPath) WikiReference(org.xwiki.model.reference.WikiReference)

Example 4 with RestoreRequest

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;
}
Also used : RestoreRequest(org.xwiki.refactoring.job.RestoreRequest)

Example 5 with RestoreRequest

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;
}
Also used : RestoreRequest(org.xwiki.refactoring.job.RestoreRequest)

Aggregations

RestoreRequest (org.xwiki.refactoring.job.RestoreRequest)12 Test (org.junit.Test)5 JobGroupPath (org.xwiki.job.JobGroupPath)2 XWikiException (com.xpn.xwiki.XWikiException)1 JobException (org.xwiki.job.JobException)1 JobExecutor (org.xwiki.job.JobExecutor)1 WikiReference (org.xwiki.model.reference.WikiReference)1 RefactoringScriptService (org.xwiki.refactoring.script.RefactoringScriptService)1 ScriptService (org.xwiki.script.service.ScriptService)1