Search in sources :

Example 61 with ApplicationKey

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);
}
Also used : Site(com.enonic.xp.site.Site) ApplicationKey(com.enonic.xp.app.ApplicationKey) ApplicationKeys(com.enonic.xp.app.ApplicationKeys) ImmutableList(com.google.common.collect.ImmutableList)

Example 62 with ApplicationKey

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;
    });
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ByteSource(com.google.common.io.ByteSource) File(java.io.File)

Example 63 with ApplicationKey

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));
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) Test(org.junit.jupiter.api.Test)

Example 64 with 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);
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 65 with ApplicationKey

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());
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey)

Aggregations

ApplicationKey (com.enonic.xp.app.ApplicationKey)78 Test (org.junit.jupiter.api.Test)40 Application (com.enonic.xp.app.Application)16 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)12 Bundle (org.osgi.framework.Bundle)10 ResourceKey (com.enonic.xp.resource.ResourceKey)6 PropertyTree (com.enonic.xp.data.PropertyTree)5 ExtraData (com.enonic.xp.content.ExtraData)4 Site (com.enonic.xp.site.Site)4 Node (com.enonic.xp.node.Node)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 PortalRequest (com.enonic.xp.portal.PortalRequest)3 PortalResponse (com.enonic.xp.portal.PortalResponse)3 XDataName (com.enonic.xp.schema.xdata.XDataName)3 ByteSource (com.google.common.io.ByteSource)3 ApplicationInvalidator (com.enonic.xp.app.ApplicationInvalidator)2 ExtraDatas (com.enonic.xp.content.ExtraDatas)2 PropertySet (com.enonic.xp.data.PropertySet)2 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)2 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)2