Search in sources :

Example 61 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class DefaultSolrReferenceResolver method getResover.

/**
 * @param reference the reference
 * @return the resolver associated to the reference type
 * @throws SolrIndexerException when failed to find a resolve associated to the passed reference
 */
private SolrReferenceResolver getResover(EntityReference reference) throws SolrIndexerException {
    EntityType type = reference.getType();
    SolrReferenceResolver resolver;
    try {
        resolver = this.componentManager.getInstance(SolrReferenceResolver.class, type.getLowerCase());
    } catch (ComponentLookupException e) {
        throw new SolrIndexerException("Failed to get SolrDocumentReferenceResolver corresponding to entity type [" + type + "]", e);
    }
    return resolver;
}
Also used : EntityType(org.xwiki.model.EntityType) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 62 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class DefaultWikiProvisioningJobExecutor method createAndExecuteJob.

@Override
public WikiProvisioningJob createAndExecuteJob(String wikiId, String provisioningJobName, Object parameter) throws WikiProvisioningJobException {
    try {
        // Get the context
        XWikiContext xcontext = xcontextProvider.get();
        // Create the job
        WikiProvisioningJob job = componentManager.getInstance(Job.class, provisioningJobName);
        // Id of the new job
        List<String> jobId = new ArrayList<String>();
        jobId.add("wiki");
        jobId.add("provisioning");
        jobId.add(provisioningJobName);
        jobId.add(wikiId);
        // Initialize it
        job.initialize(new WikiProvisioningJobRequest(jobId, wikiId, parameter, xcontext.getUserReference()));
        // Add it to the list of jobs
        jobs.put(jobId, job);
        // Pass it to the executor
        jobExecutor.execute(job);
        // Return the job
        return job;
    } catch (ComponentLookupException e) {
        throw new WikiProvisioningJobException(String.format("Failed to lookup provisioning job component for role [%s]", provisioningJobName), e);
    }
}
Also used : WikiProvisioningJobException(org.xwiki.wiki.provisioning.WikiProvisioningJobException) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) WikiProvisioningJobRequest(org.xwiki.wiki.provisioning.WikiProvisioningJobRequest) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) WikiProvisioningJob(org.xwiki.wiki.provisioning.WikiProvisioningJob)

Example 63 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException 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 64 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException 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)

Example 65 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class ChartMacro method generateChart.

/**
 * Builds the chart image according to the specifications passed in.
 *
 * @param parameters the macro parameters
 * @param content the macro content
 * @param context the macro transformation context, used for example to find out the current document reference
 * @throws MacroExecutionException if an error occurs while generating / saving the chart image
 */
private void generateChart(ChartMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
    String source = computeSource(parameters.getSource(), content);
    DataSource dataSource;
    try {
        dataSource = this.componentManager.getInstance(DataSource.class, source);
    } catch (ComponentLookupException e) {
        throw new MacroExecutionException(String.format("Invalid source parameter [%s]", parameters.getSource()), e);
    }
    Map<String, String> sourceParameters = getSourceParameters(parameters, source);
    dataSource.buildDataset(content, sourceParameters, context);
    try {
        this.imageWriter.writeImage(new ImageId(parameters), this.chartGenerator.generate(dataSource.getChartModel(), sourceParameters));
    } catch (ChartGeneratorException e) {
        throw new MacroExecutionException("Error while rendering chart", e);
    }
}
Also used : ChartGeneratorException(org.xwiki.chart.ChartGeneratorException) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DataSource(org.xwiki.rendering.internal.macro.chart.source.DataSource)

Aggregations

ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)104 ComponentManager (org.xwiki.component.manager.ComponentManager)24 Test (org.junit.Test)15 DocumentReference (org.xwiki.model.reference.DocumentReference)12 XWikiContext (com.xpn.xwiki.XWikiContext)10 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)10 InitializationException (org.xwiki.component.phase.InitializationException)8 ArrayList (java.util.ArrayList)7 XWikiException (com.xpn.xwiki.XWikiException)5 HashMap (java.util.HashMap)5 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)5 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)5 FilterException (org.xwiki.filter.FilterException)5 ExtendedURL (org.xwiki.url.ExtendedURL)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 Type (java.lang.reflect.Type)4 HashSet (java.util.HashSet)4 WikiComponentException (org.xwiki.component.wiki.WikiComponentException)4 ExecutionContext (org.xwiki.context.ExecutionContext)4 WikiReference (org.xwiki.model.reference.WikiReference)4