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);
}
}
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());
}
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);
}
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);
}
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);
}
Aggregations