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