Search in sources :

Example 41 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class MappingHandler method handle.

@Override
public WebResponse handle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) throws Exception {
    if (!(webRequest instanceof PortalRequest) || webRequest.getEndpointPath() != null) {
        return webHandlerChain.handle(webRequest, webResponse);
    }
    final PortalRequest request = (PortalRequest) webRequest;
    if (request.getMode() == RenderMode.ADMIN || !request.isSiteBase()) {
        return webHandlerChain.handle(webRequest, webResponse);
    }
    WebHandlerHelper.checkAdminAccess(request);
    final HttpMethod method = webRequest.getMethod();
    if (!HttpMethod.standard().contains(method)) {
        throw new WebException(HttpStatus.METHOD_NOT_ALLOWED, String.format("Method %s not allowed", method));
    }
    final ContentResolverResult resolvedContent = contentResolver.resolve(request);
    final Site site = resolvedContent.getNearestSite();
    if (site == null) {
        return webHandlerChain.handle(request, webResponse);
    }
    final Content content = resolvedContent.getContent();
    final Optional<ControllerMappingDescriptor> resolve = controllerMappingsResolver.resolve(resolvedContent.getSiteRelativePath(), request.getParams(), content, site.getSiteConfigs());
    if (resolve.isPresent()) {
        final ControllerMappingDescriptor mapping = resolve.get();
        request.setContent(content);
        request.setSite(site);
        request.setContextPath(request.getBaseUri() + "/" + request.getBranch() + site.getPath());
        request.setApplicationKey(mapping.getApplication());
        if (mapping.isController()) {
            return handleController(request, mapping);
        } else {
            return handleFilter(request, webResponse, webHandlerChain, mapping);
        }
    } else {
        return webHandlerChain.handle(request, webResponse);
    }
}
Also used : ContentResolverResult(com.enonic.xp.portal.impl.ContentResolverResult) Site(com.enonic.xp.site.Site) WebException(com.enonic.xp.web.WebException) Content(com.enonic.xp.content.Content) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) HttpMethod(com.enonic.xp.web.HttpMethod) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 42 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class PageResolverTest method content_with_Page_but_template_was_deleted_fallback_to_default.

@Test
public void content_with_Page_but_template_was_deleted_fallback_to_default() {
    Site site = Site.create().id(ContentId.from("site-id")).path(ContentPath.from("/site")).displayName("My Site").type(ContentTypeName.from("portal:site")).build();
    Content content = Content.create().parentPath(site.getPath()).id(ContentId.from("content-id")).name("my-content").page(Page.create().template(PageTemplateKey.from("t-not-exists")).build()).type(ContentTypeName.templateFolder()).build();
    final Page page = Page.create().descriptor(DescriptorKey.from("myapp:my-descriptor")).build();
    PageTemplate template = PageTemplate.newPageTemplate().key(PageTemplateKey.from("t-1")).parentPath(site.getPath()).name("my-template").page(page).canRender(ContentTypeNames.from(ContentTypeName.templateFolder())).build();
    when(pageTemplateService.getByKey(PageTemplateKey.from("t-not-exists"))).thenThrow(new ContentNotFoundException(content.getId(), null));
    when(pageTemplateService.getDefault(notNull())).thenReturn(template);
    PageResolverResult result = pageResolver.resolve(RenderMode.LIVE, content, site);
    final Page effectivePage = result.getEffectivePage();
    assertEquals(template.getKey(), effectivePage.getTemplate());
    assertEquals(DescriptorKey.from("myapp:my-descriptor"), result.getController());
}
Also used : Site(com.enonic.xp.site.Site) PageTemplate(com.enonic.xp.page.PageTemplate) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) Content(com.enonic.xp.content.Content) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Example 43 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class PageResolverTest method content_is_PageTemplate.

@Test
public void content_is_PageTemplate() {
    Site site = Site.create().id(ContentId.from("site-id")).path(ContentPath.from("/site")).displayName("My Site").type(ContentTypeName.from("portal:site")).build();
    final Page page = Page.create().descriptor(DescriptorKey.from("myapp:my-descriptor")).config(configA).regions(regionsA).build();
    PageTemplate template = PageTemplate.newPageTemplate().key(PageTemplateKey.from("t-1")).parentPath(site.getPath()).name("my-template").page(page).canRender(ContentTypeNames.from(ContentTypeName.folder())).build();
    PageResolverResult result = pageResolver.resolve(RenderMode.LIVE, template, site);
    final Page effectivePage = result.getEffectivePage();
    assertSame(page, effectivePage);
    assertEquals(DescriptorKey.from("myapp:my-descriptor"), result.getController());
    verifyNoInteractions(pageTemplateService);
}
Also used : Site(com.enonic.xp.site.Site) PageTemplate(com.enonic.xp.page.PageTemplate) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Example 44 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class RenderBaseHandlerTest method setupContentWithoutPage.

protected final void setupContentWithoutPage() {
    when(this.contentService.getByPath(ContentPath.from("site/somepath/content").asAbsolute())).thenReturn(createPage("id", "site/somepath/content", "myapplication:ctype", false));
    final Site site = createSite("id", "site");
    when(this.contentService.findNearestSiteByPath(isA(ContentPath.class))).thenReturn(site);
}
Also used : Site(com.enonic.xp.site.Site) ContentPath(com.enonic.xp.content.ContentPath)

Example 45 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class ServiceHandlerTest method setupContentAndSite.

private void setupContentAndSite() throws Exception {
    final Content content = createPage("id", "site/somepath/content", "myapplication:ctype", true);
    Mockito.when(this.contentService.getByPath(ContentPath.from("site/somepath/content").asAbsolute())).thenReturn(content);
    final Site site = createSite("id", "site", "myapplication:contenttypename");
    Mockito.when(this.contentService.getNearestSite(Mockito.isA(ContentId.class))).thenReturn(site);
    Mockito.when(this.contentService.findNearestSiteByPath(Mockito.isA(ContentPath.class))).thenReturn(site);
    Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
}
Also used : Site(com.enonic.xp.site.Site) Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) ContentPath(com.enonic.xp.content.ContentPath)

Aggregations

Site (com.enonic.xp.site.Site)78 Test (org.junit.jupiter.api.Test)51 Content (com.enonic.xp.content.Content)41 PortalRequest (com.enonic.xp.portal.PortalRequest)17 PropertyTree (com.enonic.xp.data.PropertyTree)14 Page (com.enonic.xp.page.Page)12 ContentId (com.enonic.xp.content.ContentId)10 ContentPath (com.enonic.xp.content.ContentPath)10 SiteConfig (com.enonic.xp.site.SiteConfig)10 WebException (com.enonic.xp.web.WebException)10 ApplicationKey (com.enonic.xp.app.ApplicationKey)9 PageTemplate (com.enonic.xp.page.PageTemplate)8 PortalResponse (com.enonic.xp.portal.PortalResponse)7 ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)7 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 DescriptorKey (com.enonic.xp.page.DescriptorKey)5 SiteConfigs (com.enonic.xp.site.SiteConfigs)5 Branch (com.enonic.xp.branch.Branch)4 ContentService (com.enonic.xp.content.ContentService)4