Search in sources :

Example 11 with WikiCreationException

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);
    }
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) InstallRequest(org.xwiki.extension.job.InstallRequest) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) InstallJob(org.xwiki.extension.job.internal.InstallJob)

Example 12 with WikiCreationException

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);
    }
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) WikiCreationStep(org.xwiki.platform.wiki.creationjob.WikiCreationStep)

Aggregations

WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)12 Test (org.junit.Test)7 WikiCreationRequest (org.xwiki.platform.wiki.creationjob.WikiCreationRequest)6 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)4 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)3 WikiProvisioningFailedEvent (org.xwiki.bridge.event.WikiProvisioningFailedEvent)2 ExtensionId (org.xwiki.extension.ExtensionId)2 WikiCreationStep (org.xwiki.platform.wiki.creationjob.WikiCreationStep)2 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)2 WikiUserManagerException (org.xwiki.wiki.user.WikiUserManagerException)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 ArrayList (java.util.ArrayList)1 Marker (org.slf4j.Marker)1 WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)1 WikiProvisioningEvent (org.xwiki.bridge.event.WikiProvisioningEvent)1 InstallRequest (org.xwiki.extension.job.InstallRequest)1 InstallJob (org.xwiki.extension.job.internal.InstallJob)1 JobException (org.xwiki.job.JobException)1 WikiReference (org.xwiki.model.reference.WikiReference)1 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)1