Search in sources :

Example 1 with EntityRequest

use of org.xwiki.refactoring.job.EntityRequest in project xwiki-platform by xwiki.

the class DeleteAction method startDeleteJob.

private Job startDeleteJob(EntityReference entityReference, XWikiContext context) throws XWikiException {
    RefactoringScriptService refactoring = (RefactoringScriptService) Utils.getComponent(ScriptService.class, "refactoring");
    EntityRequest deleteRequest = refactoring.createDeleteRequest(Arrays.asList(entityReference));
    deleteRequest.setInteractive(isAsync(context.getRequest()));
    try {
        JobExecutor jobExecutor = Utils.getComponent(JobExecutor.class);
        return jobExecutor.execute(RefactoringJobs.DELETE, deleteRequest);
    } catch (JobException e) {
        throw new XWikiException(String.format("Failed to schedule the delete job for [%s]", entityReference), e);
    }
}
Also used : RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) ScriptService(org.xwiki.script.service.ScriptService) JobException(org.xwiki.job.JobException) EntityRequest(org.xwiki.refactoring.job.EntityRequest) JobExecutor(org.xwiki.job.JobExecutor) RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with EntityRequest

use of org.xwiki.refactoring.job.EntityRequest in project xwiki-platform by xwiki.

the class RefactoringScriptServiceTest method delete.

@Test
public void delete() throws Exception {
    WikiReference source = new WikiReference("math");
    getService().delete(source);
    ArgumentCaptor<EntityRequest> request = ArgumentCaptor.forClass(EntityRequest.class);
    verify(this.jobExecutor).execute(eq(RefactoringJobs.DELETE), request.capture());
    assertEquals(RefactoringJobs.DELETE, request.getValue().getJobType());
    assertEquals(Arrays.asList(source), request.getValue().getEntityReferences());
    assertFalse(request.getValue().isDeep());
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 3 with EntityRequest

use of org.xwiki.refactoring.job.EntityRequest in project xwiki-platform by xwiki.

the class DeleteJobTest method deleteDocument.

@Test
public void deleteDocument() throws Throwable {
    DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
    when(this.modelBridge.exists(documentReference)).thenReturn(true);
    DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
    EntityRequest request = createRequest(documentReference);
    request.setCheckRights(false);
    request.setUserReference(userReference);
    run(request);
    verify(this.modelBridge).setContextUserReference(userReference);
    verify(this.modelBridge).delete(documentReference);
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 4 with EntityRequest

use of org.xwiki.refactoring.job.EntityRequest in project xwiki-platform by xwiki.

the class EntityJobTest method processEachEntity.

@Test
public void processEachEntity() {
    final List<EntityReference> references = new ArrayList<>();
    NoopEntityJob job = new NoopEntityJob() {

        @Override
        protected void process(EntityReference entityReference) {
            references.add(entityReference);
        }
    };
    DocumentReference documentReference = new DocumentReference("chess", Arrays.asList("Path", "To"), "Success");
    EntityRequest request = new EntityRequest();
    request.setEntityReferences(documentReference.getReversedReferenceChain());
    initialize(job, request);
    job.run();
    assertEquals(request.getEntityReferences(), references);
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 5 with EntityRequest

use of org.xwiki.refactoring.job.EntityRequest in project xwiki-platform by xwiki.

the class EntityJobTest method visitDocuments.

@Test
public void visitDocuments() {
    DocumentReference alice = new DocumentReference("foo", "Alice", "WebHome");
    DocumentReference alicePrefs = new DocumentReference("WebPreferences", alice.getLastSpaceReference());
    DocumentReference aliceBio = new DocumentReference("Bio", alice.getLastSpaceReference());
    DocumentReference bob = new DocumentReference("foo", Arrays.asList("Alice", "Bob"), "WebHome");
    DocumentReference bobPrefs = new DocumentReference("WebPreferences", bob.getLastSpaceReference());
    DocumentReference bobBio = new DocumentReference("Bio", bob.getLastSpaceReference());
    DocumentReference carolBio = new DocumentReference("bar", Arrays.asList("Users", "Carol"), "Bio");
    SpaceReference spaceReference = mock(SpaceReference.class);
    when(this.modelBridge.getDocumentReferences(spaceReference)).thenReturn(Arrays.asList(alice, alicePrefs, aliceBio, bob, bobPrefs, bobBio, carolBio));
    NoopEntityJob job = new NoopEntityJob();
    initialize(job, new EntityRequest());
    final List<DocumentReference> documentReferences = new ArrayList<>();
    job.visitDocuments(spaceReference, new Visitor<DocumentReference>() {

        @Override
        public void visit(DocumentReference documentReference) {
            documentReferences.add(documentReference);
        }
    });
    // Space preferences documents are handled after their siblings.
    assertEquals(Arrays.asList(carolBio, aliceBio, bobBio, bob, bobPrefs, alice, alicePrefs), documentReferences);
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest) SpaceReference(org.xwiki.model.reference.SpaceReference) ArrayList(java.util.ArrayList) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

EntityRequest (org.xwiki.refactoring.job.EntityRequest)11 Test (org.junit.Test)8 DocumentReference (org.xwiki.model.reference.DocumentReference)7 ArrayList (java.util.ArrayList)2 XWikiException (com.xpn.xwiki.XWikiException)1 JobException (org.xwiki.job.JobException)1 JobExecutor (org.xwiki.job.JobExecutor)1 JobGroupPath (org.xwiki.job.JobGroupPath)1 EntityReference (org.xwiki.model.reference.EntityReference)1 SpaceReference (org.xwiki.model.reference.SpaceReference)1 WikiReference (org.xwiki.model.reference.WikiReference)1 RefactoringScriptService (org.xwiki.refactoring.script.RefactoringScriptService)1 ScriptService (org.xwiki.script.service.ScriptService)1