Search in sources :

Example 26 with ContentNotFoundException

use of com.enonic.xp.content.ContentNotFoundException in project xp by enonic.

the class ComponentHandlerWorker method getFragmentComponent.

private Component getFragmentComponent(final FragmentComponent component) {
    final ContentId contentId = component.getFragment();
    if (contentId == null) {
        return null;
    }
    try {
        final Content fragmentContent = contentService.getById(contentId);
        if (!fragmentContent.hasPage() || !fragmentContent.getType().isFragment()) {
            return null;
        }
        final Page page = fragmentContent.getPage();
        return page.getFragment();
    } catch (ContentNotFoundException e) {
        return null;
    }
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) Page(com.enonic.xp.page.Page)

Example 27 with ContentNotFoundException

use of com.enonic.xp.content.ContentNotFoundException 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 28 with ContentNotFoundException

use of com.enonic.xp.content.ContentNotFoundException in project xp by enonic.

the class PortalUrlServiceImpl_pageUrlTest method createUrl_withId_notFound.

@Test
public void createUrl_withId_notFound() {
    final Content content = ContentFixtures.newContent();
    Mockito.when(this.contentService.getById(content.getId())).thenThrow(new ContentNotFoundException(content.getId(), Branch.from("draft")));
    final PageUrlParams params = new PageUrlParams().portalRequest(this.portalRequest).id("123456");
    final String url = this.service.pageUrl(params);
    assertEquals("/site/default/draft/context/path/_/error/404?message=Content+with+id+%5B123456%5D+was+not+found+in+branch+%5Bdraft%5D", url);
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) Content(com.enonic.xp.content.Content) PageUrlParams(com.enonic.xp.portal.url.PageUrlParams) Test(org.junit.jupiter.api.Test)

Example 29 with ContentNotFoundException

use of com.enonic.xp.content.ContentNotFoundException in project xp by enonic.

the class FragmentRenderer method getFragmentComponent.

private Component getFragmentComponent(final FragmentComponent component) {
    final ContentId contentId = component.getFragment();
    try {
        final Content fragmentContent = contentService.getById(contentId);
        if (!fragmentContent.hasPage() || !fragmentContent.getType().isFragment()) {
            return null;
        }
        final Page page = fragmentContent.getPage();
        return page.getFragment();
    } catch (ContentNotFoundException e) {
        return null;
    }
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) Page(com.enonic.xp.page.Page)

Example 30 with ContentNotFoundException

use of com.enonic.xp.content.ContentNotFoundException in project xp by enonic.

the class ComponentHandlerTest method getContentNotFound.

@Test
public void getContentNotFound() {
    this.request.setEndpointPath("/_/component/main-region/666");
    final ContentPath path = ContentPath.from("/site/somepath/content");
    Mockito.when(this.contentService.getByPath(path)).thenThrow(new ContentNotFoundException(path, Branch.from("draft")));
    this.request.setContentPath(path);
    final WebException e = assertThrows(WebException.class, () -> this.handler.handle(this.request, PortalResponse.create().build(), null));
    assertEquals(HttpStatus.NOT_FOUND, e.getStatus());
    assertEquals("Page [/site/somepath/content] not found", e.getMessage());
}
Also used : WebException(com.enonic.xp.web.WebException) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentPath(com.enonic.xp.content.ContentPath) Test(org.junit.jupiter.api.Test)

Aggregations

ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)32 Test (org.junit.jupiter.api.Test)26 ContentPath (com.enonic.xp.content.ContentPath)13 ContentId (com.enonic.xp.content.ContentId)12 Content (com.enonic.xp.content.Content)8 WebException (com.enonic.xp.web.WebException)6 Page (com.enonic.xp.page.Page)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4 Site (com.enonic.xp.site.Site)4 ProcessHtmlParams (com.enonic.xp.portal.url.ProcessHtmlParams)3 ContentVersionId (com.enonic.xp.content.ContentVersionId)2 PrincipalKey (com.enonic.xp.security.PrincipalKey)2 SecurityService (com.enonic.xp.security.SecurityService)2 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)1 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)1 Context (com.enonic.xp.context.Context)1 Node (com.enonic.xp.node.Node)1 NodeIds (com.enonic.xp.node.NodeIds)1 NodePath (com.enonic.xp.node.NodePath)1 EditablePage (com.enonic.xp.page.EditablePage)1