Search in sources :

Example 1 with ReplayRequest

use of org.xwiki.extension.job.history.ReplayRequest in project xwiki-platform by xwiki.

the class ExtensionHistoryScriptServiceTest method replayWithoutAdmin.

@Test
public void replayWithoutAdmin() throws Exception {
    InstallRequest installRequest = new InstallRequest();
    installRequest.addNamespace("wiki:dev");
    ExtensionJobHistoryRecord install = new ExtensionJobHistoryRecord("install", installRequest, null, null, null);
    List<ExtensionJobHistoryRecord> records = Arrays.asList(install);
    when(this.xcontext.getWikiId()).thenReturn("dev");
    when(this.authorization.hasAccess(Right.ADMIN, new WikiReference("dev"))).thenReturn(false);
    Job replayJob = mock(Job.class);
    ArgumentCaptor<ReplayRequest> requestCaptor = ArgumentCaptor.forClass(ReplayRequest.class);
    when(jobExecutor.execute(eq(ReplayJob.JOB_TYPE), requestCaptor.capture())).thenReturn(replayJob);
    assertSame(replayJob, this.mocker.getComponentUnderTest().replay(records));
    ReplayRequest request = requestCaptor.getValue();
    assertTrue(request.getRecords().isEmpty());
}
Also used : ExtensionJobHistoryRecord(org.xwiki.extension.job.history.ExtensionJobHistoryRecord) ReplayRequest(org.xwiki.extension.job.history.ReplayRequest) InstallRequest(org.xwiki.extension.job.InstallRequest) WikiReference(org.xwiki.model.reference.WikiReference) ReplayJob(org.xwiki.extension.job.history.internal.ReplayJob) Job(org.xwiki.job.Job) Test(org.junit.Test)

Example 2 with ReplayRequest

use of org.xwiki.extension.job.history.ReplayRequest in project xwiki-platform by xwiki.

the class ExtensionHistoryScriptServiceTest method replayWithAdminButNoPR.

@Test
public void replayWithAdminButNoPR() throws Exception {
    InstallRequest installRequest = new InstallRequest();
    installRequest.addNamespace("wiki:drafts");
    installRequest.setProperty("user.reference", new DocumentReference("drafts", "Users", "Alice"));
    ExtensionJobHistoryRecord install = new ExtensionJobHistoryRecord("install", installRequest, null, null, null);
    List<ExtensionJobHistoryRecord> records = Arrays.asList(install);
    when(this.xcontext.getWikiId()).thenReturn("dev");
    when(this.documentAccessBridge.getCurrentUserReference()).thenReturn(new DocumentReference("dev", "Users", "Bob"));
    when(this.authorization.hasAccess(Right.ADMIN, new WikiReference("dev"))).thenReturn(true);
    when(this.authorization.hasAccess(Right.PROGRAM)).thenReturn(false);
    Job replayJob = mock(Job.class);
    ArgumentCaptor<ReplayRequest> requestCaptor = ArgumentCaptor.forClass(ReplayRequest.class);
    when(jobExecutor.execute(eq(ReplayJob.JOB_TYPE), requestCaptor.capture())).thenReturn(replayJob);
    assertSame(replayJob, this.mocker.getComponentUnderTest().replay(records));
    ReplayRequest request = requestCaptor.getValue();
    assertEquals(Arrays.asList(install), request.getRecords());
    assertEquals(Arrays.asList("wiki:dev"), install.getRequest().getNamespaces());
    assertEquals(this.documentAccessBridge.getCurrentUserReference(), install.getRequest().getProperty("user.reference"));
}
Also used : ExtensionJobHistoryRecord(org.xwiki.extension.job.history.ExtensionJobHistoryRecord) ReplayRequest(org.xwiki.extension.job.history.ReplayRequest) InstallRequest(org.xwiki.extension.job.InstallRequest) WikiReference(org.xwiki.model.reference.WikiReference) ReplayJob(org.xwiki.extension.job.history.internal.ReplayJob) Job(org.xwiki.job.Job) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 3 with ReplayRequest

use of org.xwiki.extension.job.history.ReplayRequest in project xwiki-platform by xwiki.

the class ExtensionHistoryScriptService method replay.

/**
 * Replay the given list of extension history records.
 *
 * @param records the history records to replay
 * @return the {@link Job} object that can be used to monitor the progress of the replay process, or {@code null} in
 *         case of failure
 */
public Job replay(List<ExtensionJobHistoryRecord> records) {
    setError(null);
    ReplayRequest request = createReplayRequest(createReplayPlan(records, true, null));
    try {
        return this.jobExecutor.execute(ReplayJob.JOB_TYPE, request);
    } catch (JobException e) {
        setError(e);
        return null;
    }
}
Also used : JobException(org.xwiki.job.JobException) ReplayRequest(org.xwiki.extension.job.history.ReplayRequest)

Example 4 with ReplayRequest

use of org.xwiki.extension.job.history.ReplayRequest in project xwiki-platform by xwiki.

the class ExtensionHistoryScriptService method createReplayRequest.

private ReplayRequest createReplayRequest(List<ExtensionJobHistoryRecord> records) {
    ReplayRequest request = new ReplayRequest();
    String suffix = new Date().getTime() + "-" + ThreadLocalRandom.current().nextInt(100, 1000);
    request.setId(getReplayJobId(suffix));
    // There may be questions for which there isn't a specified answer.
    request.setInteractive(true);
    request.setRecords(records);
    contextualize(request);
    setRightsProperties(request);
    return request;
}
Also used : ReplayRequest(org.xwiki.extension.job.history.ReplayRequest) Date(java.util.Date)

Example 5 with ReplayRequest

use of org.xwiki.extension.job.history.ReplayRequest in project xwiki-platform by xwiki.

the class ExtensionHistoryScriptServiceTest method replayWithPR.

@Test
public void replayWithPR() throws Exception {
    InstallRequest installRequest = new InstallRequest();
    installRequest.addNamespace("wiki:drafts");
    installRequest.setProperty("user.reference", new DocumentReference("drafts", "Users", "Alice"));
    ExtensionJobHistoryRecord install = new ExtensionJobHistoryRecord("install", installRequest, null, null, null);
    List<ExtensionJobHistoryRecord> records = Arrays.asList(install);
    when(this.xcontext.getWikiId()).thenReturn("dev");
    when(this.xcontext.getAction()).thenReturn("foo");
    when(this.documentAccessBridge.getCurrentUserReference()).thenReturn(new DocumentReference("dev", "Users", "Bob"));
    when(this.authorization.hasAccess(Right.ADMIN, new WikiReference("dev"))).thenReturn(true);
    when(this.authorization.hasAccess(Right.PROGRAM)).thenReturn(true);
    Job replayJob = mock(Job.class);
    ArgumentCaptor<ReplayRequest> requestCaptor = ArgumentCaptor.forClass(ReplayRequest.class);
    when(jobExecutor.execute(eq(ReplayJob.JOB_TYPE), requestCaptor.capture())).thenReturn(replayJob);
    assertSame(replayJob, this.mocker.getComponentUnderTest().replay(records));
    ReplayRequest request = requestCaptor.getValue();
    assertTrue(StringUtils.join(request.getId(), '/').startsWith("extension/history/"));
    assertTrue(request.isInteractive());
    assertEquals(Arrays.asList(install), request.getRecords());
    assertEquals(this.xcontext.getWikiId(), request.getProperty("context.wiki"));
    assertEquals(this.xcontext.getAction(), request.getProperty("context.action"));
    assertEquals(this.documentAccessBridge.getCurrentUserReference(), request.getProperty("user.reference"));
    assertEquals(Arrays.asList("wiki:drafts"), install.getRequest().getNamespaces());
    assertEquals(new DocumentReference("drafts", "Users", "Alice"), install.getRequest().getProperty("user.reference"));
}
Also used : ExtensionJobHistoryRecord(org.xwiki.extension.job.history.ExtensionJobHistoryRecord) ReplayRequest(org.xwiki.extension.job.history.ReplayRequest) InstallRequest(org.xwiki.extension.job.InstallRequest) WikiReference(org.xwiki.model.reference.WikiReference) ReplayJob(org.xwiki.extension.job.history.internal.ReplayJob) Job(org.xwiki.job.Job) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

ReplayRequest (org.xwiki.extension.job.history.ReplayRequest)5 Test (org.junit.Test)3 InstallRequest (org.xwiki.extension.job.InstallRequest)3 ExtensionJobHistoryRecord (org.xwiki.extension.job.history.ExtensionJobHistoryRecord)3 ReplayJob (org.xwiki.extension.job.history.internal.ReplayJob)3 Job (org.xwiki.job.Job)3 WikiReference (org.xwiki.model.reference.WikiReference)3 DocumentReference (org.xwiki.model.reference.DocumentReference)2 Date (java.util.Date)1 JobException (org.xwiki.job.JobException)1