Search in sources :

Example 31 with Application

use of com.enonic.xp.app.Application in project xp by enonic.

the class ScriptExecutorFactory method create.

public ScriptExecutor create(final ApplicationKey applicationKey) {
    LOG.debug("Create Script Executor for {}", applicationKey);
    final Application application = applicationService.getInstalledApplication(applicationKey);
    if (application == null || !application.isStarted() || application.getConfig() == null) {
        throw new ApplicationNotFoundException(applicationKey);
    }
    final ClassLoader classLoader = application.getClassLoader();
    final Bundle bundle = application.getBundle();
    final BundleContext bundleContext = Objects.requireNonNull(bundle.getBundleContext(), String.format("application bundle %s context must not be null", bundle.getBundleId()));
    return new ScriptExecutorImpl(scriptAsyncService.getAsyncExecutor(application.getKey()), scriptSettings, classLoader, new ServiceRegistryImpl(bundleContext), resourceService, application, RunMode.get());
}
Also used : ServiceRegistryImpl(com.enonic.xp.script.impl.service.ServiceRegistryImpl) ApplicationNotFoundException(com.enonic.xp.app.ApplicationNotFoundException) Bundle(org.osgi.framework.Bundle) Application(com.enonic.xp.app.Application) BundleContext(org.osgi.framework.BundleContext)

Example 32 with Application

use of com.enonic.xp.app.Application in project xp by enonic.

the class SseEntryPoint method handleEvent.

private void handleEvent(final Event event, final String eventSubType) {
    final SseContextHolder ctx = contextHolder;
    if (ctx == null) {
        LOG.debug("Skipping {} {}. Please to subscribe to send SSE events.", EVENT_TYPE, eventSubType);
        return;
    }
    if (event.getValue(APPLICATION_KEY_PARAM).isPresent()) {
        final OutboundSseEvent.Builder eventBuilder = ctx.sse.newEventBuilder().name(eventSubType).id(UUID.randomUUID().toString()).mediaType(MediaType.APPLICATION_JSON_TYPE);
        if (UNINSTALLED.equals(eventSubType)) {
            eventBuilder.data(ApplicationUninstalledJson.class, new ApplicationUninstalledJson(event.getValue(APPLICATION_KEY_PARAM).get().toString()));
        } else {
            final ApplicationKey applicationKey = ApplicationKey.from(event.getValue(APPLICATION_KEY_PARAM).get().toString());
            final Application application = applicationService.getInstalledApplication(applicationKey);
            if (application == null) {
                LOG.warn("Application \"{}\" not found", applicationKey);
                return;
            }
            final boolean localApplication = applicationService.isLocalApplication(application.getKey());
            eventBuilder.data(ApplicationInfoJson.class, new ApplicationInfoJson(application, localApplication));
        }
        ctx.broadcaster.broadcast(eventBuilder.build());
    }
}
Also used : ApplicationInfoJson(com.enonic.xp.impl.server.rest.model.ApplicationInfoJson) OutboundSseEvent(javax.ws.rs.sse.OutboundSseEvent) ApplicationKey(com.enonic.xp.app.ApplicationKey) ApplicationUninstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationUninstalledJson) Application(com.enonic.xp.app.Application)

Example 33 with Application

use of com.enonic.xp.app.Application in project xp by enonic.

the class ApplicationResource method installApplication.

private ApplicationInstallResultJson installApplication(final URL url, byte[] sha512) {
    final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
    try {
        final Application application = this.applicationService.installGlobalApplication(url, sha512);
        result.setApplicationInstalledJson(new ApplicationInstalledJson(application, false));
    } catch (Exception e) {
        final String failure = "Failed to process application from " + url;
        LOG.error(failure, e);
        result.setFailure(failure);
    }
    return result;
}
Also used : ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) ApplicationInstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson) Application(com.enonic.xp.app.Application) IOException(java.io.IOException)

Example 34 with Application

use of com.enonic.xp.app.Application in project xp by enonic.

the class ApplicationResource method installApplication.

private ApplicationInstallResultJson installApplication(final ByteSource byteSource, final String applicationName) {
    final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
    try {
        final Application application = this.applicationService.installGlobalApplication(byteSource, applicationName);
        result.setApplicationInstalledJson(new ApplicationInstalledJson(application, false));
    } catch (Exception e) {
        final String failure = "Failed to process application " + applicationName;
        LOG.error(failure, e);
        result.setFailure(failure);
    }
    return result;
}
Also used : ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) ApplicationInstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson) Application(com.enonic.xp.app.Application) IOException(java.io.IOException)

Example 35 with Application

use of com.enonic.xp.app.Application in project xp by enonic.

the class DeployDirectoryWatcher method installApplication.

private void installApplication(final File file) {
    // Installs the application
    final ByteSource byteSource = Files.asByteSource(file);
    final Application application = DeployHelper.runAsAdmin(() -> applicationService.installLocalApplication(byteSource, file.getName()));
    final ApplicationKey applicationKey = application.getKey();
    final String path = file.getPath();
    // Stores a mapping fileName -> applicationKey. Needed for uninstallation
    this.applicationKeyByPath.put(path, applicationKey);
    // Updates the mapping applicationKey -> stack<fileName>. Needed in some particular case for uninstallatioon
    this.pathsByApplicationKey.compute(applicationKey, (applicationKeyParam, fileNameStack) -> {
        if (fileNameStack == null) {
            fileNameStack = new Stack<>();
        }
        fileNameStack.remove(path);
        fileNameStack.push(path);
        return fileNameStack;
    });
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ByteSource(com.google.common.io.ByteSource) Application(com.enonic.xp.app.Application)

Aggregations

Application (com.enonic.xp.app.Application)68 Test (org.junit.jupiter.api.Test)42 ApplicationKey (com.enonic.xp.app.ApplicationKey)20 Node (com.enonic.xp.node.Node)16 Bundle (org.osgi.framework.Bundle)16 ByteSource (com.google.common.io.ByteSource)12 URL (java.net.URL)11 ResourceKey (com.enonic.xp.resource.ResourceKey)9 ApplicationService (com.enonic.xp.app.ApplicationService)8 ResourceService (com.enonic.xp.resource.ResourceService)8 BundleContext (org.osgi.framework.BundleContext)8 UrlResource (com.enonic.xp.resource.UrlResource)7 ScriptAsyncService (com.enonic.xp.script.impl.async.ScriptAsyncService)7 ScriptRuntimeFactoryImpl (com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl)7 PortalScriptServiceImpl (com.enonic.xp.portal.impl.script.PortalScriptServiceImpl)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 IOException (java.io.IOException)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 PropertyTree (com.enonic.xp.data.PropertyTree)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4