use of org.xwiki.platform.wiki.creationjob.WikiCreationException in project xwiki-platform by xwiki.
the class ExtensionInstaller method installExtension.
/**
* Install an extension on a wiki.
*
* @param wikiId id of the wiki
* @param extensionId id of the extension to install
* @throws org.xwiki.platform.wiki.creationjob.WikiCreationException if problem occurs
*/
public void installExtension(String wikiId, ExtensionId extensionId) throws WikiCreationException {
try {
// Create the install request
InstallRequest installRequest = new InstallRequest();
installRequest.setId(Arrays.asList(WikiCreationJob.JOB_ID_PREFIX, "install", wikiId));
installRequest.addExtension(extensionId);
installRequest.addNamespace("wiki:" + wikiId);
// To avoid problem with Programming Rights, we install everything with superadmin
installRequest.setProperty(PROPERTY_USERREFERENCE, SUPERADMIN_REFERENCE);
InstallJob job = componentManager.getInstance(Job.class, InstallJob.JOBTYPE);
job.initialize(installRequest);
job.run();
} catch (ComponentLookupException e) {
throw new WikiCreationException(String.format("Failed to install the extension [%s] on the wiki [%s].", extensionId.toString(), wikiId), e);
}
}
use of org.xwiki.platform.wiki.creationjob.WikiCreationException in project xwiki-platform by xwiki.
the class WikiCreationJob method runInternal.
@Override
protected void runInternal() throws Exception {
try {
// Consider that the owner id is a serialized user reference and put it in the context as the current user
// so that all steps are executed under that user.
this.xcontextProvider.get().setUserReference(this.defaultDocumentReferenceResolver.resolve(getRequest().getOwnerId()));
List<WikiCreationStep> wikiCreationStepList = componentManager.getInstanceList(WikiCreationStep.class);
// Some extra steps needs to be executed AFTER some others, so we have introduce a getOrder() method in the
// interface. We use this method to sort the list of extra steps by this order.
Collections.sort(wikiCreationStepList, new Comparator<WikiCreationStep>() {
@Override
public int compare(WikiCreationStep o1, WikiCreationStep o2) {
return o1.getOrder() - o2.getOrder();
}
});
// Now we can execute these extra steps
this.progressManager.pushLevelProgress(wikiCreationStepList.size(), this);
for (WikiCreationStep step : wikiCreationStepList) {
this.progressManager.startStep(this);
step.execute(request);
this.progressManager.endStep(this);
}
this.progressManager.popLevelProgress(this);
} catch (WikiCreationException | ComponentLookupException e) {
throw new WikiCreationException(String.format("Failed to execute creation steps on the wiki [%s].", request.getWikiId()), e);
}
}
Aggregations