use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class WikiCreationJobScriptServicesTest method createWiki.
@Test
public void createWiki() throws Exception {
Job job = mock(Job.class);
when(wikiCreator.createWiki(any(WikiCreationRequest.class))).thenReturn(job);
WikiCreationRequest wikiCreationRequest = new WikiCreationRequest();
wikiCreationRequest.setExtensionId("authorized-extension", "1.0");
assertEquals(job, mocker.getComponentUnderTest().createWiki(wikiCreationRequest));
assertNull(mocker.getComponentUnderTest().getLastError());
}
use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class DefaultWikiCreator method getJobStatus.
@Override
public JobStatus getJobStatus(String wikiId) {
List<String> jobId = getJobId(wikiId);
Job job = jobExecutor.getJob(jobId);
if (job != null) {
return job.getStatus();
} else {
return jobStatusStore.getJobStatus(jobId);
}
}
use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class XarExtensionHandlerTest method uninstall.
private void uninstall(ExtensionId extensionId, String wiki) throws Throwable {
UninstallRequest uninstallRequest = new UninstallRequest();
uninstallRequest.setProperty("user.reference", getXWikiContext().getUserReference());
uninstallRequest.setProperty("checkrights", true);
uninstallRequest.addExtension(extensionId);
if (wiki != null) {
uninstallRequest.addNamespace("wiki:" + wiki);
}
Job uninstallJob = this.jobExecutor.execute(UninstallJob.JOBTYPE, uninstallRequest);
uninstallJob.join();
List<LogEvent> errors = uninstallJob.getStatus().getLog().getLogsFrom(LogLevel.WARN);
if (!errors.isEmpty()) {
if (errors.get(0).getThrowable() != null) {
throw errors.get(0).getThrowable();
} else {
throw new Exception(errors.get(0).getFormattedMessage());
}
}
}
use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class XarExtensionHandlerTest method installOnNamespace.
private XarInstalledExtension installOnNamespace(ExtensionId extensionId, String namespace, DocumentReference user) throws Throwable {
InstallRequest installRequest = new InstallRequest();
if (user != null) {
installRequest.setProperty("user.reference", getXWikiContext().getUserReference());
installRequest.setProperty("checkrights", true);
}
installRequest.addExtension(extensionId);
if (namespace != null) {
installRequest.addNamespace(namespace);
}
Job installJob = this.jobExecutor.execute(InstallJob.JOBTYPE, installRequest);
installJob.join();
List<LogEvent> errors = installJob.getStatus().getLog().getLogsFrom(LogLevel.WARN);
if (!errors.isEmpty()) {
if (errors.get(0).getThrowable() != null) {
throw errors.get(0).getThrowable();
} else {
throw new Exception(errors.get(0).getFormattedMessage());
}
}
return (XarInstalledExtension) this.xarExtensionRepository.resolve(extensionId);
}
use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class XarExtensionScriptService method repairInstalledExtension.
/**
* Make sure the provided XAR extension properly is registered in the installed extensions index.
* <p>
* Start an asynchronous Job.
*
* @param id the extension identifier
* @param version the extension version
* @param wiki the wiki where the extension is installed
* @return the {@link Job} object which can be used to monitor the progress of the installation process, or
* {@code null} in case of failure
*/
public Job repairInstalledExtension(String id, String version, String wiki) {
setError(null);
if (!this.authorization.hasAccess(Right.PROGRAM)) {
setError(new JobException("Need programming right to repair a XAR"));
return null;
}
String namespace = getWikiNamespace(wiki);
InstallRequest installRequest = new InstallRequest();
installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_ACTION_PREFIX, id, namespace));
DocumentReference currentUserReference = this.documentAccessBridge.getCurrentUserReference();
if (currentUserReference != null) {
installRequest.setProperty(PROPERTY_USER_REFERENCE, currentUserReference);
// We set the string value because the extension repository doesn't know how to serialize/parse an extension
// property whose value is a DocumentReference, and adding support for it requires considerable refactoring
// because ExtensionPropertySerializers are not components (they are currently hard-coded).
installRequest.setExtensionProperty(PROPERTY_USER_REFERENCE, currentUserReference.toString());
}
installRequest.addExtension(new ExtensionId(id, version));
if (StringUtils.isNotBlank(namespace)) {
installRequest.addNamespace(namespace);
}
Job job = null;
try {
job = this.jobExecutor.execute(RepairXarJob.JOBTYPE, installRequest);
} catch (Exception e) {
setError(e);
}
return job;
}
Aggregations