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);
}
}
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());
}
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);
}
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);
}
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);
}
Aggregations