use of com.enonic.xp.page.DescriptorKey in project xp by enonic.
the class SubmitTaskHandler method submitTask.
public String submitTask() {
descriptor = descriptor == null ? "" : descriptor;
final DescriptorKey taskKey;
if (descriptor.contains(":")) {
taskKey = DescriptorKey.from(descriptor);
} else {
final ApplicationKey app = getApplication();
if (app == null) {
throw new RuntimeException("Could not resolve current application for descriptord task: '" + descriptor + "'");
}
taskKey = DescriptorKey.from(app, descriptor);
}
final TaskService taskService = taskServiceSupplier.get();
PropertyTree data = propertyTreeMarshallerServiceSupplier.get().marshal(Optional.ofNullable(config).map(ScriptValue::getMap).orElse(Map.of()));
final SubmitTaskParams params = SubmitTaskParams.create().descriptorKey(taskKey).data(data).build();
final TaskId taskId = taskService.submitTask(params);
return taskId.toString();
}
use of com.enonic.xp.page.DescriptorKey in project xp by enonic.
the class PageResolver method resolve.
public PageResolverResult resolve(final RenderMode mode, final Content content, final Site site) {
final Page page = content.getPage();
final PageTemplate pageTemplate;
final DescriptorKey controller;
final Page effectivePage;
if (content instanceof PageTemplate) {
pageTemplate = (PageTemplate) content;
controller = getControllerFromTemplate(pageTemplate, mode);
effectivePage = pageTemplate.getPage();
} else if (page != null) {
if (page.getFragment() != null) {
controller = null;
effectivePage = page;
} else if (page.getDescriptor() != null) {
controller = page.getDescriptor();
effectivePage = page;
} else if (page.getTemplate() != null) {
pageTemplate = getPageTemplateOrFindDefault(page.getTemplate(), content.getType(), site.getPath());
if (pageTemplate != null) {
controller = getControllerFromTemplate(pageTemplate, mode);
effectivePage = mergePageFromPageTemplate(pageTemplate, page);
} else {
controller = errorOrNull(null, mode, String.format("Template [%s] is missing and no default template found for content", page.getTemplate()));
effectivePage = page;
}
} else {
controller = errorOrNull(null, mode, "Content page has neither template nor descriptor");
effectivePage = page;
}
} else {
pageTemplate = this.pageTemplateService.getDefault(GetDefaultPageTemplateParams.create().sitePath(site.getPath()).contentType(content.getType()).build());
if (pageTemplate != null) {
controller = getControllerFromTemplate(pageTemplate, mode);
effectivePage = mergePageFromPageTemplate(pageTemplate, null);
} else {
controller = errorOrNull(null, mode, "No default template found for content");
effectivePage = null;
}
}
return new PageResolverResult(effectivePage, controller);
}
use of com.enonic.xp.page.DescriptorKey in project xp by enonic.
the class ComponentHandlerWorker method execute.
@Override
public PortalResponse execute() throws Exception {
final ContentResolverResult resolvedContent = contentResolver.resolve(this.request);
final Content content = resolvedContent.getContentOrElseThrow();
final Site site = resolvedContent.getNearestSiteOrElseThrow();
Page page = content.getPage();
final PageResolverResult resolvedPage = pageResolver.resolve(request.getMode(), content, site);
Component component = null;
if (content.getType().isFragment()) {
// fragment content, try resolving component path in Layout fragment
final Component fragmentComponent = page.getFragment();
if (this.componentPath.isEmpty()) {
component = fragmentComponent;
} else if (fragmentComponent instanceof LayoutComponent) {
component = ((LayoutComponent) fragmentComponent).getComponent(this.componentPath);
}
}
final Page effectivePage;
if (component == null) {
effectivePage = inlineFragments(resolvedPage.getEffectivePage(), this.componentPath);
component = effectivePage.getRegions().getComponent(this.componentPath);
} else {
effectivePage = resolvedPage.getEffectivePage();
}
if (component == null) {
throw WebException.notFound(String.format("Page component for [%s] not found", this.componentPath));
}
final Content effectiveContent = Content.create(content).page(effectivePage).build();
final DescriptorKey controller = resolvedPage.getController();
this.request.setSite(site);
this.request.setContent(effectiveContent);
this.request.setComponent(component);
this.request.setApplicationKey(controller != null ? controller.getApplicationKey() : null);
final Trace trace = Tracer.current();
if (trace != null) {
trace.put("componentPath", component.getPath());
trace.put("type", component.getType().toString());
}
final PortalResponse response = rendererDelegate.render(component, this.request);
return this.postProcessor.processResponseInstructions(this.request, response);
}
use of com.enonic.xp.page.DescriptorKey in project xp by enonic.
the class ServiceHandlerWorker method execute.
@Override
public PortalResponse execute() throws Exception {
// Retrieves the ServiceDescriptor
final DescriptorKey descriptorKey = DescriptorKey.from(applicationKey, name);
final ServiceDescriptor serviceDescriptor = serviceDescriptorService.getByKey(descriptorKey);
if (serviceDescriptor == null) {
throw WebException.notFound(String.format("Service [%s] not found", descriptorKey));
}
// Checks if the access to ServiceDescriptor is allowed
final PrincipalKeys principals = ContextAccessor.current().getAuthInfo().getPrincipals();
if (!serviceDescriptor.isAccessAllowed(principals)) {
throw WebException.forbidden(String.format("You don't have permission to access [%s]", descriptorKey));
}
final ContentResolverResult resolvedContent = contentResolver.resolve(request);
final Site site = resolvedContent.getNearestSite();
// Checks if the application is set on the current site
if (site != null) {
final PropertyTree siteConfig = site.getSiteConfig(applicationKey);
if (siteConfig == null) {
throw WebException.forbidden(String.format("Service [%s] forbidden for this site", descriptorKey));
}
}
// Checks if the application is set on the current application
final ApplicationKey baseApplicationKey = getBaseApplicationKey();
if (baseApplicationKey != null && !baseApplicationKey.equals(applicationKey)) {
throw WebException.forbidden(String.format("Service [%s] forbidden for this application", descriptorKey));
}
// Prepares the request
this.request.setApplicationKey(applicationKey);
this.request.setContent(resolvedContent.getContent());
this.request.setSite(site);
// Executes the service
final ControllerScript controllerScript = getScript();
final PortalResponse portalResponse = controllerScript.execute(this.request);
final WebSocketConfig webSocketConfig = portalResponse.getWebSocket();
final WebSocketContext webSocketContext = this.request.getWebSocketContext();
if ((webSocketContext != null) && (webSocketConfig != null)) {
final WebSocketEndpoint webSocketEndpoint = newWebSocketEndpoint(webSocketConfig);
webSocketContext.apply(webSocketEndpoint);
}
return portalResponse;
}
use of com.enonic.xp.page.DescriptorKey in project xp by enonic.
the class RenderBaseHandlerTest method createDescriptor.
private PageDescriptor createDescriptor() {
final ApplicationKey applicationKey = ApplicationKey.from("mainapplication");
final String name = "mypage";
final DescriptorKey key = DescriptorKey.from(applicationKey, name);
final String xml = "<?xml version=\"1.0\"?>\n" + "<page>\n" + " <display-name>Landing page</display-name>\n" + " <config/>\n" + "</page>";
final PageDescriptor.Builder builder = PageDescriptor.create();
parseXml(applicationKey, builder, xml);
return builder.key(key).displayName("Landing page").build();
}
Aggregations