use of com.enonic.xp.content.ContentPath in project xp by enonic.
the class ContentResolverTest method resolve_existing_but_needs_authentication_in_live_mode.
@Test
void resolve_existing_but_needs_authentication_in_live_mode() {
final Site site = newSite();
final PortalRequest request = new PortalRequest();
final ContentPath contentPath = ContentPath.from("/mysite/landing-page/non-existing");
request.setContentPath(contentPath);
when(this.contentService.getByPath(contentPath)).thenThrow(new ContentNotFoundException(contentPath, null));
when(this.contentService.contentExists(contentPath)).thenReturn(true);
when(this.contentService.findNearestSiteByPath(contentPath)).thenReturn(site);
final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
assertNull(result.getContent());
assertSame(site, result.getNearestSite());
assertEquals("/landing-page/non-existing", result.getSiteRelativePath());
final WebException e = assertThrows(WebException.class, result::getContentOrElseThrow);
assertEquals(HttpStatus.UNAUTHORIZED, e.getStatus());
}
use of com.enonic.xp.content.ContentPath 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.ContentPath in project xp by enonic.
the class ContentResource method reprocess.
@POST
@Path("reprocess")
@Deprecated
public ReprocessContentResultJson reprocess(final ReprocessContentRequestJson request) {
final List<ContentPath> updated = new ArrayList<>();
final List<String> errors = new ArrayList<>();
final Content content = this.contentService.getByPath(request.getSourceBranchPath().getContentPath());
try {
reprocessContent(content, request.isSkipChildren(), updated, errors);
} catch (Exception e) {
errors.add(String.format("Content '%s' - %s: %s", content.getPath().toString(), e.getClass().getCanonicalName(), e.getMessage()));
LOG.warn("Error reprocessing content [" + content.getPath() + "]", e);
}
return new ReprocessContentResultJson(ContentPaths.from(updated), errors);
}
use of com.enonic.xp.content.ContentPath in project xp by enonic.
the class WidgetHandlerTest method setupContentAndSite.
private void setupContentAndSite() {
final Content content = createPage("id", "site/somepath/content", "myapplication:ctype", true);
final ContentPath path = ContentPath.from("site/somepath/content").asAbsolute();
Mockito.when(this.contentService.getByPath(path)).thenReturn(content);
Mockito.when(this.contentService.findNearestSiteByPath(path)).thenReturn(createSite("id", "site", "myapplication:contenttypename"));
Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
}
use of com.enonic.xp.content.ContentPath in project xp by enonic.
the class ContentServiceImpl method doFindNearestByPath.
private Content doFindNearestByPath(final ContentPath contentPath, final Predicate<Content> predicate) {
final Content content = executeGetByPath(contentPath);
if (content != null && predicate.test(content)) {
return content;
}
// Resolves the closest content, starting from the root.
Content foundContent = null;
ContentPath nextContentPath = ContentPath.ROOT;
for (int contentPathIndex = 0; contentPathIndex < contentPath.elementCount(); contentPathIndex++) {
final ContentPath currentContentPath = ContentPath.from(nextContentPath, contentPath.getElement(contentPathIndex));
final Content childContent = executeGetByPath(currentContentPath);
if (childContent == null) {
break;
}
if (predicate.test(childContent)) {
foundContent = childContent;
}
nextContentPath = currentContentPath;
}
return foundContent;
}
Aggregations