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