use of org.xwiki.refactoring.job.CreateRequest in project xwiki-platform by xwiki.
the class RefactoringScriptServiceTest method create.
@Test
public void create() throws Exception {
DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
getService().create(documentReference);
ArgumentCaptor<CreateRequest> request = ArgumentCaptor.forClass(CreateRequest.class);
verify(this.jobExecutor).execute(eq(RefactoringJobs.CREATE), request.capture());
assertEquals(RefactoringJobs.CREATE, request.getValue().getJobType());
assertEquals(Arrays.asList(documentReference), request.getValue().getEntityReferences());
assertTrue(request.getValue().isDeep());
}
use of org.xwiki.refactoring.job.CreateRequest in project xwiki-platform by xwiki.
the class CreateJobTest method createRequest.
private CreateRequest createRequest(EntityReference targetReference, EntityReference templateReference) {
CreateRequest request = new CreateRequest();
request.setEntityReferences(Collections.singletonList(targetReference));
request.setTemplateReference(templateReference);
return request;
}
use of org.xwiki.refactoring.job.CreateRequest in project xwiki-platform by xwiki.
the class CreateJobTest method createSpaceFromTemplate.
@Test
public void createSpaceFromTemplate() throws Throwable {
SpaceReference newSpaceReference = new SpaceReference("wiki", "Space");
SpaceReference templateSpaceReference = new SpaceReference("wiki", "Code", "Template");
DocumentReference templateDocumentReference = new DocumentReference("Index", templateSpaceReference);
when(this.modelBridge.getDocumentReferences(templateSpaceReference)).thenReturn(Arrays.asList(templateDocumentReference));
when(this.modelBridge.exists(templateDocumentReference)).thenReturn(true);
DocumentReference newDocumentReference = new DocumentReference("Index", newSpaceReference);
when(this.modelBridge.exists(newDocumentReference)).thenReturn(false);
DocumentReference userReference = new DocumentReference("wiki", "Users", "Alice");
CreateRequest request = createRequest(newSpaceReference, templateSpaceReference);
request.setUserReference(userReference);
request.setCheckRights(false);
run(request);
verify(this.modelBridge).setContextUserReference(userReference);
verify(this.modelBridge).copy(templateDocumentReference, newDocumentReference);
verify(this.modelBridge, never()).removeLock(any(DocumentReference.class));
}
use of org.xwiki.refactoring.job.CreateRequest in project xwiki-platform by xwiki.
the class RefactoringScriptService method createCreateRequest.
/**
* Creates a request to create the specified entities.
*
* @param entityReferences the entities to create
* @return the create request
* @since 7.4M2
*/
public CreateRequest createCreateRequest(Collection<EntityReference> entityReferences) {
CreateRequest request = new CreateRequest();
initEntityRequest(request, RefactoringJobs.CREATE, entityReferences);
// Set deep create by default, to copy (if possible) any existing hierarchy of a specified template document.
// TODO: expose this in the create UI to advanced users to allow them to opt-out?
request.setDeep(true);
return request;
}
use of org.xwiki.refactoring.job.CreateRequest in project xwiki-platform by xwiki.
the class SaveAction method startCreateJob.
private Job startCreateJob(EntityReference entityReference, EditForm editForm) throws XWikiException {
if (StringUtils.isBlank(editForm.getTemplate())) {
// No template specified, nothing more to do.
return null;
}
// If a template is set in the request, then this is a create action which needs to be handled by a create job,
// but skipping the target document, which is now already saved by the save action.
RefactoringScriptService refactoring = (RefactoringScriptService) Utils.getComponent(ScriptService.class, "refactoring");
CreateRequest request = refactoring.createCreateRequest(Arrays.asList(entityReference));
// Set the target document.
request.setEntityReferences(Arrays.asList(entityReference));
// Set the template to use.
DocumentReferenceResolver<String> resolver = Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed");
EntityReference templateReference = resolver.resolve(editForm.getTemplate());
request.setTemplateReference(templateReference);
// We`ve already created and populated the fields of the target document, focus only on the remaining children
// specified in the template.
request.setSkippedEntities(Arrays.asList(entityReference));
Job createJob = refactoring.create(request);
if (createJob != null) {
return createJob;
} else {
throw new XWikiException(String.format("Failed to schedule the create job for [%s]", entityReference), refactoring.getLastError());
}
}
Aggregations