Search in sources :

Example 16 with ContentPath

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());
}
Also used : Site(com.enonic.xp.site.Site) WebException(com.enonic.xp.web.WebException) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentPath(com.enonic.xp.content.ContentPath) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 17 with ContentPath

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());
}
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 18 with ContentPath

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);
}
Also used : Content(com.enonic.xp.content.Content) ArrayList(java.util.ArrayList) ContentPath(com.enonic.xp.content.ContentPath) ReprocessContentResultJson(com.enonic.xp.impl.server.rest.model.ReprocessContentResultJson) Path(javax.ws.rs.Path) ContentPath(com.enonic.xp.content.ContentPath) POST(javax.ws.rs.POST)

Example 19 with ContentPath

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);
}
Also used : Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath)

Example 20 with ContentPath

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;
}
Also used : Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath)

Aggregations

ContentPath (com.enonic.xp.content.ContentPath)56 Content (com.enonic.xp.content.Content)30 Test (org.junit.jupiter.api.Test)30 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)13 ContentId (com.enonic.xp.content.ContentId)11 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)10 WebException (com.enonic.xp.web.WebException)8 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)6 ArrayList (java.util.ArrayList)5 FindContentIdsByParentResult (com.enonic.xp.content.FindContentIdsByParentResult)4 Node (com.enonic.xp.node.Node)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4 ContentInheritType (com.enonic.xp.content.ContentInheritType)3 Context (com.enonic.xp.context.Context)3 Site (com.enonic.xp.site.Site)3 ContentAlreadyExistsException (com.enonic.xp.content.ContentAlreadyExistsException)2 CONTENT_ROOT_PATH_ATTRIBUTE (com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE)2 ContentVersionId (com.enonic.xp.content.ContentVersionId)2 List (java.util.List)2 Set (java.util.Set)2