Search in sources :

Example 46 with ContentPath

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

the class PublishContentResultMapper method serializeFailedContent.

private void serializeFailedContent(final MapGenerator gen, final String name, final ContentIds contents) {
    gen.array(name);
    for (ContentId id : contents) {
        gen.value(id.toString());
    }
    for (ContentPath path : this.contentNotFound) {
        gen.value(path.toString());
    }
    gen.end();
}
Also used : ContentId(com.enonic.xp.content.ContentId) ContentPath(com.enonic.xp.content.ContentPath)

Example 47 with ContentPath

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

the class GetContentHandlerTest method getByPath_notFound.

@Test
public void getByPath_notFound() throws Exception {
    final ContentPath path = ContentPath.from("/a/b/mycontent");
    Mockito.when(this.contentService.getByPath(path)).thenThrow(new ContentNotFoundException(path, null));
    runFunction("/test/GetContentHandlerTest.js", "getByPath_notFound");
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentPath(com.enonic.xp.content.ContentPath) Test(org.junit.jupiter.api.Test)

Example 48 with ContentPath

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

the class ReprocessRunnableTask method run.

@Override
public void run(final TaskId id, final ProgressReporter progressReporter) {
    final List<ContentPath> updated = new ArrayList<>();
    final List<String> errors = new ArrayList<>();
    final Content content = this.contentService.getByPath(params.getSourceBranchPath().getContentPath());
    try {
        if (!params.isSkipChildren()) {
            String nodePath = CONTENT_ROOT_PATH.asAbsolute().toString();
            final ContentPath contentPath = params.getSourceBranchPath().getContentPath();
            if (!ContentPath.ROOT.equals(contentPath)) {
                nodePath += content.getPath().asAbsolute().toString();
            }
            final ConstraintExpr pathExpr = CompareExpr.like(FieldExpr.from("_path"), ValueExpr.string(nodePath + "/*"));
            final ContentQuery countChildren = ContentQuery.create().queryExpr(QueryExpr.from(pathExpr)).size(0).build();
            total = (int) contentService.find(countChildren).getTotalHits() + 1;
        }
        reprocessContent(content, params.isSkipChildren(), updated, errors, progressReporter);
    } 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);
    }
    progressReporter.info(new ReprocessContentResultJson(ContentPaths.from(updated), errors).toString());
}
Also used : ConstraintExpr(com.enonic.xp.query.expr.ConstraintExpr) ContentQuery(com.enonic.xp.content.ContentQuery) 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)

Example 49 with ContentPath

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

the class MappingHandlerTest method setupContentAndSite.

private void setupContentAndSite(final ControllerMappingDescriptor mapping) {
    final Content content = createPage("id", "site/somesite/content", "myapplication:ctype", true);
    final Site site = createSite("id", "site", "myapplication:contenttypename");
    final ContentPath path = ContentPath.from("site/somesite/content").asAbsolute();
    when(this.contentService.getByPath(path)).thenReturn(content);
    when(this.contentService.findNearestSiteByPath(eq(path))).thenReturn(site);
    when(this.contentService.getById(content.getId())).thenReturn(content);
    final ControllerMappingDescriptors mappings = ControllerMappingDescriptors.from(mapping);
    final SiteDescriptor siteDescriptor = SiteDescriptor.create().mappingDescriptors(mappings).build();
    when(this.siteService.getDescriptor(any(ApplicationKey.class))).thenReturn(siteDescriptor);
}
Also used : Site(com.enonic.xp.site.Site) SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath) ControllerMappingDescriptors(com.enonic.xp.site.mapping.ControllerMappingDescriptors)

Example 50 with ContentPath

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

the class ComponentHandlerTest method getSiteNotFound.

@Test
public void getSiteNotFound() {
    setupContent();
    this.request.setEndpointPath("/_/component/main-region/666");
    final ContentPath path = ContentPath.from("/site/somepath/content");
    Mockito.when(this.contentService.findNearestSiteByPath(path)).thenReturn(null);
    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("Site for [/site/somepath/content] not found", e.getMessage());
}
Also used : WebException(com.enonic.xp.web.WebException) ContentPath(com.enonic.xp.content.ContentPath) Test(org.junit.jupiter.api.Test)

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