Search in sources :

Example 16 with ContentNotFoundException

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

the class PageHandlerTest method getContentExistsButNeedsAuthentication.

@Test
public void getContentExistsButNeedsAuthentication() {
    final ContentPath path = ContentPath.from("/site/somepath/content");
    when(this.contentService.getByPath(path)).thenThrow(new ContentNotFoundException(path, Branch.from("draft")));
    when(this.contentService.contentExists(path)).thenReturn(true);
    this.request.setContentPath(path);
    final WebException e = assertThrows(WebException.class, () -> this.handler.handle(this.request, PortalResponse.create().build(), null));
    assertEquals(HttpStatus.UNAUTHORIZED, e.getStatus());
    assertEquals("You don't have permission to access [/site/somepath/content]", 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)

Example 17 with ContentNotFoundException

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

the class PortalUrlServiceImpl_processHtmlTest method process_unknown_image.

@Test
public void process_unknown_image() {
    when(contentService.getById(isA(ContentId.class))).thenAnswer((params) -> {
        final ContentId id = params.getArgument(0);
        throw new ContentNotFoundException(id, ContextAccessor.current().getBranch());
    });
    // Process an html text containing a link to an unknown media
    final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"image://123\">Image</a>");
    // Checks that the error 500 page is returned
    final String processedHtml = this.service.processHtml(params);
    assertEquals("<a href=\"/site/default/draft/context/path/_/error/500?message=Image+with+%5B123%5D+id+not+found\">Image</a>", processedHtml);
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 18 with ContentNotFoundException

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

the class CreateFragmentCommandTest method imageComponentName_contentNotFound.

@Test
public void imageComponentName_contentNotFound() {
    Mockito.when(contentService.getById(Mockito.isA(ContentId.class))).thenThrow(new ContentNotFoundException(ContentId.from("123"), ContextAccessor.current().getBranch()));
    assertEquals("Image", testImageComponentName(null, false));
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 19 with ContentNotFoundException

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

the class UpdatePageCommand method execute.

public Content execute() {
    final Content content = this.contentService.getById(this.params.getContent());
    if (content == null) {
        throw new ContentNotFoundException(this.params.getContent(), ContextAccessor.current().getBranch());
    }
    if (content.getPage() == null) {
        throw new PageNotFoundException(this.params.getContent());
    }
    final EditablePage editablePage = new EditablePage(content.getPage());
    this.params.getEditor().edit(editablePage);
    final Page editedPage = editablePage.build();
    if (editedPage.equals(content.getPage())) {
        return content;
    }
    defaultValuesProcessor.applyDefaultValues(editedPage, content.getPage());
    final UpdateContentParams params = new UpdateContentParams().contentId(this.params.getContent()).editor(edit -> edit.page = editedPage);
    this.contentService.update(params);
    return this.contentService.getById(this.params.getContent());
}
Also used : PageNotFoundException(com.enonic.xp.page.PageNotFoundException) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) EditablePage(com.enonic.xp.page.EditablePage) Page(com.enonic.xp.page.Page) EditablePage(com.enonic.xp.page.EditablePage)

Example 20 with ContentNotFoundException

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

the class ContentNodeTranslator method doTranslate.

private Content doTranslate(final Node node, final boolean hasChildren, final boolean allowAltRootPath) {
    final ContentId contentId = ContentId.from(node.id().toString());
    if (!allowAltRootPath && !(node.path().toString().startsWith(ContentNodeHelper.getContentRoot().toString() + "/") || node.path().equals(ContentNodeHelper.getContentRoot()))) {
        throw new ContentNotFoundException(contentId, ContextAccessor.current().getBranch(), ContentNodeHelper.getContentRoot());
    }
    final ContentPath parentContentPath = getParent(node.path());
    final Content.Builder<?> builder = contentDataSerializer.fromData(node.data().getRoot());
    builder.id(contentId).parentPath(parentContentPath).name(node.name().toString()).childOrder(node.getChildOrder()).permissions(node.getPermissions()).inheritPermissions(node.inheritsPermissions()).hasChildren(hasChildren).contentState(ContentState.from(node.getNodeState().value())).manualOrderValue(node.getManualOrderValue());
    final boolean isRoot = NodePath.ROOT.equals(node.parentPath());
    if (isRoot) {
        builder.root();
    }
    return builder.build();
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) ContentPath(com.enonic.xp.content.ContentPath)

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