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());
}
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());
}
}
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;
}
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;
}
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;
});
}
Aggregations