Search in sources :

Example 1 with ResourceKey

use of com.enonic.xp.resource.ResourceKey in project xp by enonic.

the class ImportHandler method execute.

public NodeImportResultMapper execute() {
    final ImportNodesParams.Builder paramsBuilder = ImportNodesParams.create().targetNodePath(NodePath.create(targetNodePath).build()).nodeImportListener(new FunctionBasedNodeImportListener(nodeImported, nodeResolved));
    if (source instanceof ResourceKey) {
        paramsBuilder.source(toVirtualFile((ResourceKey) source));
    } else {
        paramsBuilder.exportName(source.toString());
    }
    if (xslt instanceof ResourceKey) {
        paramsBuilder.xslt(toVirtualFile((ResourceKey) xslt));
    } else {
        paramsBuilder.xsltFileName(xslt.toString());
    }
    if (xsltParams != null) {
        paramsBuilder.xsltParams(xsltParams.getMap());
    }
    if (includeNodeIds != null) {
        paramsBuilder.includeNodeIds(includeNodeIds);
    }
    if (includePermissions != null) {
        paramsBuilder.includePermissions(includePermissions);
    }
    final NodeImportResult nodeImportResult = this.context.getService(ExportService.class).get().importNodes(paramsBuilder.build());
    return new NodeImportResultMapper(nodeImportResult);
}
Also used : ImportNodesParams(com.enonic.xp.export.ImportNodesParams) NodeImportResult(com.enonic.xp.export.NodeImportResult) ResourceKey(com.enonic.xp.resource.ResourceKey)

Example 2 with ResourceKey

use of com.enonic.xp.resource.ResourceKey in project xp by enonic.

the class ExceptionRendererImpl method renderApplicationCustomError.

private PortalResponse renderApplicationCustomError(final ApplicationKey appKey, final String errorScriptPath, final PortalError portalError, final String handlerMethod) {
    final ResourceKey script = getScript(appKey, errorScriptPath);
    if (script == null) {
        return null;
    }
    final ErrorHandlerScript errorHandlerScript = this.errorHandlerScriptFactory.errorScript(script);
    final PortalRequest request = portalError.getRequest();
    final ApplicationKey previousApp = request.getApplicationKey();
    // set application of the error handler in the current context PortalRequest
    try {
        request.setApplicationKey(appKey);
        return errorHandlerScript.execute(portalError, handlerMethod);
    } finally {
        request.setApplicationKey(previousApp);
    }
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ErrorHandlerScript(com.enonic.xp.portal.impl.error.ErrorHandlerScript) ResourceKey(com.enonic.xp.resource.ResourceKey) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 3 with ResourceKey

use of com.enonic.xp.resource.ResourceKey in project xp by enonic.

the class AbstractControllerTest method setup.

@BeforeEach
public void setup() throws Exception {
    this.portalRequest = new PortalRequest();
    this.portalResponse = PortalResponse.create().build();
    final BundleContext bundleContext = Mockito.mock(BundleContext.class);
    final Bundle bundle = Mockito.mock(Bundle.class);
    Mockito.when(bundle.getBundleContext()).thenReturn(bundleContext);
    final Application application = Mockito.mock(Application.class);
    Mockito.when(application.getBundle()).thenReturn(bundle);
    Mockito.when(application.getClassLoader()).thenReturn(getClass().getClassLoader());
    Mockito.when(application.isStarted()).thenReturn(true);
    Mockito.when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
    final ApplicationService applicationService = Mockito.mock(ApplicationService.class);
    Mockito.when(applicationService.getInstalledApplication(ApplicationKey.from("myapplication"))).thenReturn(application);
    this.resourceService = Mockito.mock(ResourceService.class);
    Mockito.when(resourceService.getResource(Mockito.any())).thenAnswer(invocation -> {
        final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
        final URL resourceUrl = AbstractControllerTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
        return new UrlResource(resourceKey, resourceUrl);
    });
    final ScriptAsyncService scriptAsyncService = Mockito.mock(ScriptAsyncService.class);
    final ScriptRuntimeFactoryImpl runtimeFactory = new ScriptRuntimeFactoryImpl(applicationService, this.resourceService, scriptAsyncService);
    final PortalScriptServiceImpl scriptService = new PortalScriptServiceImpl(runtimeFactory);
    scriptService.initialize();
    this.factory = new ControllerScriptFactoryImpl();
    this.factory.setScriptService(scriptService);
    this.postProcessor = new PostProcessorImpl();
    final HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
    ServletRequestHolder.setRequest(req);
}
Also used : Bundle(org.osgi.framework.Bundle) ResourceService(com.enonic.xp.resource.ResourceService) PortalScriptServiceImpl(com.enonic.xp.portal.impl.script.PortalScriptServiceImpl) URL(java.net.URL) PortalRequest(com.enonic.xp.portal.PortalRequest) ResourceKey(com.enonic.xp.resource.ResourceKey) ScriptRuntimeFactoryImpl(com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) UrlResource(com.enonic.xp.resource.UrlResource) ScriptAsyncService(com.enonic.xp.script.impl.async.ScriptAsyncService) PostProcessorImpl(com.enonic.xp.portal.impl.postprocess.PostProcessorImpl) Application(com.enonic.xp.app.Application) BundleContext(org.osgi.framework.BundleContext) ApplicationService(com.enonic.xp.app.ApplicationService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ResourceKey

use of com.enonic.xp.resource.ResourceKey in project xp by enonic.

the class IdProviderControllerServiceImplTest method setupPortalScriptService.

private PortalScriptService setupPortalScriptService() {
    final BundleContext bundleContext = Mockito.mock(BundleContext.class);
    final Bundle bundle = Mockito.mock(Bundle.class);
    Mockito.when(bundle.getBundleContext()).thenReturn(bundleContext);
    final Application application = Mockito.mock(Application.class);
    Mockito.when(application.getBundle()).thenReturn(bundle);
    Mockito.when(application.getClassLoader()).thenReturn(getClass().getClassLoader());
    Mockito.when(application.isStarted()).thenReturn(true);
    Mockito.when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
    final ApplicationService applicationService = Mockito.mock(ApplicationService.class);
    Mockito.when(applicationService.getInstalledApplication(ApplicationKey.from("defaultapplication"))).thenReturn(application);
    Mockito.when(applicationService.getInstalledApplication(ApplicationKey.from("myapplication"))).thenReturn(application);
    ResourceService resourceService = Mockito.mock(ResourceService.class);
    Mockito.when(resourceService.getResource(Mockito.any())).thenAnswer(invocation -> {
        final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
        final URL resourceUrl = AbstractControllerTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
        return new UrlResource(resourceKey, resourceUrl);
    });
    final ScriptAsyncService scriptAsyncService = Mockito.mock(ScriptAsyncService.class);
    final ScriptRuntimeFactoryImpl runtimeFactory = new ScriptRuntimeFactoryImpl(applicationService, resourceService, scriptAsyncService);
    final PortalScriptServiceImpl scriptService = new PortalScriptServiceImpl(runtimeFactory);
    scriptService.initialize();
    return scriptService;
}
Also used : ScriptRuntimeFactoryImpl(com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl) UrlResource(com.enonic.xp.resource.UrlResource) Bundle(org.osgi.framework.Bundle) ResourceService(com.enonic.xp.resource.ResourceService) ScriptAsyncService(com.enonic.xp.script.impl.async.ScriptAsyncService) PortalScriptServiceImpl(com.enonic.xp.portal.impl.script.PortalScriptServiceImpl) Application(com.enonic.xp.app.Application) URL(java.net.URL) BundleContext(org.osgi.framework.BundleContext) ApplicationService(com.enonic.xp.app.ApplicationService) ResourceKey(com.enonic.xp.resource.ResourceKey)

Example 5 with ResourceKey

use of com.enonic.xp.resource.ResourceKey in project xp by enonic.

the class MainExecutorTest method mainJsExecute.

@Test
public void mainJsExecute() {
    final ResourceKey key = ResourceKey.from("foo.bar:/main.js");
    when(this.scriptService.hasScript(key)).thenReturn(true);
    when(this.scriptService.executeAsync(key)).thenReturn(CompletableFuture.completedFuture(null));
    final Application app = mock(Application.class);
    when(app.getKey()).thenReturn(ApplicationKey.from("foo.bar"));
    this.executor.activated(app);
}
Also used : Application(com.enonic.xp.app.Application) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceKey (com.enonic.xp.resource.ResourceKey)76 Test (org.junit.jupiter.api.Test)49 Resource (com.enonic.xp.resource.Resource)21 ApplicationKey (com.enonic.xp.app.ApplicationKey)12 ResourceService (com.enonic.xp.resource.ResourceService)12 ScriptExports (com.enonic.xp.script.ScriptExports)11 Application (com.enonic.xp.app.Application)9 UrlResource (com.enonic.xp.resource.UrlResource)9 URL (java.net.URL)9 BeforeEach (org.junit.jupiter.api.BeforeEach)9 PortalRequest (com.enonic.xp.portal.PortalRequest)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 ApplicationService (com.enonic.xp.app.ApplicationService)7 AssetUrlParams (com.enonic.xp.portal.url.AssetUrlParams)7 ScriptAsyncService (com.enonic.xp.script.impl.async.ScriptAsyncService)7 ScriptRuntimeFactoryImpl (com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl)7 PortalResponse (com.enonic.xp.portal.PortalResponse)6 PortalScriptServiceImpl (com.enonic.xp.portal.impl.script.PortalScriptServiceImpl)6 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)6 PropertyTree (com.enonic.xp.data.PropertyTree)5