Search in sources :

Example 1 with ContentPath

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

the class ArchiveContentHandler method executeArchive.

private List<String> executeArchive() {
    final ContentId sourceId;
    final ContentPath sourcePath;
    if (this.content.startsWith("/")) {
        // source is path
        sourcePath = ContentPath.from(this.content);
        final Content sourceContent = contentService.getByPath(sourcePath);
        sourceId = sourceContent.getId();
    } else {
        // source is key
        sourceId = ContentId.from(this.content);
    }
    return archive(sourceId);
}
Also used : Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) ContentPath(com.enonic.xp.content.ContentPath)

Example 2 with ContentPath

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

the class PublishContentHandler method publishContent.

private PublishContentResultMapper publishContent() {
    final List<ContentPath> contentNotFound = new ArrayList<>();
    final List<ContentId> contentIds = new ArrayList<>();
    for (final String key : this.keys) {
        if (key.startsWith("/")) {
            final ContentPath path = ContentPath.from(key);
            final Content content = getByPath(path);
            if (content != null) {
                contentIds.add(content.getId());
            } else {
                contentNotFound.add(path);
            }
        } else {
            contentIds.add(ContentId.from(key));
        }
    }
    final PushContentParams.Builder builder = PushContentParams.create();
    builder.contentIds(ContentIds.from(contentIds));
    builder.target(Branch.from(targetBranch));
    if (this.contentPublishInfo != null) {
        final Object from = this.contentPublishInfo.get("from");
        final Object to = this.contentPublishInfo.get("to");
        final ContentPublishInfo contentPublishInfo = ContentPublishInfo.create().from(from == null ? null : Instant.parse((String) from)).to(to == null ? null : Instant.parse((String) to)).build();
        builder.contentPublishInfo(contentPublishInfo);
    }
    if (this.excludeChildrenIds != null) {
        builder.excludeChildrenIds(ContentIds.from(this.excludeChildrenIds));
    }
    if (this.includeChildren != null) {
        builder.includeChildren(this.includeChildren);
    }
    if (this.includeDependencies != null) {
        builder.includeDependencies(includeDependencies);
    }
    builder.message(message);
    final PublishContentResult result = this.contentService.publish(builder.build());
    return result != null ? new PublishContentResultMapper(result, contentNotFound) : null;
}
Also used : ArrayList(java.util.ArrayList) ContentPath(com.enonic.xp.content.ContentPath) PublishContentResultMapper(com.enonic.xp.lib.content.mapper.PublishContentResultMapper) PushContentParams(com.enonic.xp.content.PushContentParams) PublishContentResult(com.enonic.xp.content.PublishContentResult) Content(com.enonic.xp.content.Content) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) ContentId(com.enonic.xp.content.ContentId)

Example 3 with ContentPath

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

the class RestoreContentHandler method executeRestore.

private List<String> executeRestore() {
    final ContentId sourceId;
    final ContentPath sourcePath;
    if (this.content.startsWith("/")) {
        // source is path
        sourcePath = ContentPath.from(this.content);
        final Content sourceContent = contentService.getByPath(sourcePath);
        sourceId = sourceContent.getId();
    } else {
        // source is key
        sourceId = ContentId.from(this.content);
    }
    final ContentPath pathToRestore = nullToEmpty(path).isBlank() ? null : ContentPath.from(path);
    return restore(sourceId, pathToRestore);
}
Also used : Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) ContentPath(com.enonic.xp.content.ContentPath)

Example 4 with ContentPath

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

the class DeleteContentHandlerTest method deleteByPath_notFound.

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

Example 5 with ContentPath

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

the class GetAttachmentsHandlerTest 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/GetAttachmentsHandlerTest.js", "getByPath_notFound");
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) 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