use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class HtmlLinkProcessor method getStyleDescriptors.
private StyleDescriptors getStyleDescriptors(final PortalRequest portalRequest) {
final ImmutableList.Builder<ApplicationKey> applicationKeyList = new ImmutableList.Builder<ApplicationKey>().add(SYSTEM_APPLICATION_KEY);
if (portalRequest != null) {
final Site site = portalRequest.getSite();
if (site != null) {
final ImmutableSet<ApplicationKey> siteApplicationKeySet = site.getSiteConfigs().getApplicationKeys();
applicationKeyList.addAll(siteApplicationKeySet);
}
}
final ApplicationKeys applicationKeys = ApplicationKeys.from(applicationKeyList.build());
return styleDescriptorService.getByApplications(applicationKeys);
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class DeployDirectoryWatcher method uninstallApplication.
private void uninstallApplication(final File file) {
// Removes the mapping fileName -> applicationKey
final String path = file.getPath();
final ApplicationKey applicationKey = applicationKeyByPath.remove(path);
this.pathsByApplicationKey.computeIfPresent(applicationKey, (applicationKeyParam, fileNameStack) -> {
// Retrieve the file name for the currently installed application
final String lastInstalledFile = fileNameStack.isEmpty() ? null : fileNameStack.peek();
// If the file removed is currently installed
if (path.equals(lastInstalledFile)) {
// Uninstall the corresponding application
DeployHelper.runAsAdmin(() -> this.applicationService.uninstallApplication(applicationKey, false));
fileNameStack.pop();
// If there is a previous file with the same applicationKey
if (!fileNameStack.isEmpty()) {
// Installs this previous application
final String previousInstalledFile = fileNameStack.peek();
final ByteSource byteSource = Files.asByteSource(new File(previousInstalledFile));
DeployHelper.runAsAdmin(() -> {
try {
applicationService.installLocalApplication(byteSource, previousInstalledFile);
} catch (Exception e) {
LOGGER.warn("Failed to reinstall local application [" + previousInstalledFile + "]", e);
}
});
}
} else {
fileNameStack.remove(path);
}
return fileNameStack.isEmpty() ? null : fileNameStack;
});
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ScriptRuntimeFactoryImplTest method invalidate.
@Test
void invalidate() {
final ScriptRuntimeFactoryImpl scriptRuntimeFactory = spy(new ScriptRuntimeFactoryImpl(applicationService, resourceService, scriptAsyncService));
final ScriptRuntimeImpl scriptRuntime = mock(ScriptRuntimeImpl.class);
when(scriptRuntimeFactory.doCreate(any())).thenReturn(scriptRuntime);
scriptRuntimeFactory.create(ScriptSettings.create().build());
final ApplicationKey applicationKey = ApplicationKey.from("myapp");
scriptRuntimeFactory.invalidate(applicationKey, ApplicationInvalidationLevel.FULL);
verify(scriptRuntime).invalidate(eq(applicationKey));
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ScriptRuntimeImplTest method executeAsync.
@Test
void executeAsync() {
final ApplicationKey applicationKey = ApplicationKey.from("myApp");
when(scriptExecutorFactory.apply(applicationKey)).thenReturn(scriptExecutor);
final ScriptRuntimeImpl scriptRuntime = new ScriptRuntimeImpl(scriptExecutorFactory);
final ResourceKey resourceKey = ResourceKey.from(applicationKey, "/main.js");
scriptRuntime.executeAsync(resourceKey);
verify(scriptExecutor, Mockito.times(1)).executeMainAsync(resourceKey);
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ResourceKeyTest method fromApplicationAndPath.
private void fromApplicationAndPath(final String input, final String uri, final String path, final String ext, final boolean root) {
final ApplicationKey applicationKey = ApplicationKey.from("myapplication-1.0.0");
final ResourceKey key = ResourceKey.from(applicationKey, input);
assertNotNull(key);
assertEquals(uri, key.toString());
assertEquals(uri, key.getUri());
assertEquals(path, key.getPath());
assertEquals(ext, key.getExtension());
assertEquals(applicationKey.toString(), key.getApplicationKey().toString());
assertEquals(root, key.isRoot());
}
Aggregations