Search in sources :

Example 1 with ContentId

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

the class ProjectContentEventListenerTest method testSyncDuplicateWithExistedLocalName.

@Test
public void testSyncDuplicateWithExistedLocalName() throws InterruptedException {
    targetContext.callWith(() -> createContent(ContentPath.ROOT, "localName-copy"));
    targetContext.callWith(() -> createContent(ContentPath.ROOT, "localName-copy-1"));
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "localName"));
    handleEvents();
    final ContentId duplicatedContentId = sourceContext.callWith(() -> contentService.duplicate(DuplicateContentParams.create().contentId(sourceContent.getId()).build()).getDuplicatedContents().first());
    handleEvents();
    targetContext.runWith(() -> {
        final Content duplicatedTargetContent = contentService.getById(duplicatedContentId);
        assertEquals("localName-copy-1-1", duplicatedTargetContent.getName().toString());
        assertEquals(3, duplicatedTargetContent.getInherit().size());
        assertFalse(duplicatedTargetContent.getInherit().contains(ContentInheritType.NAME));
    });
}
Also used : Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 2 with ContentId

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

the class ProjectContentEventListenerTest method testDuplicateInherited.

@Test
public void testDuplicateInherited() throws InterruptedException {
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "localName"));
    handleEvents();
    final ContentId duplicatedContentId = targetContext.callWith(() -> contentService.duplicate(DuplicateContentParams.create().contentId(sourceContent.getId()).build()).getDuplicatedContents().first());
    targetContext.runWith(() -> {
        final Content duplicatedTargetContent = contentService.getById(duplicatedContentId);
        assertEquals("localName-copy", duplicatedTargetContent.getName().toString());
        assertTrue(duplicatedTargetContent.getInherit().isEmpty());
    });
}
Also used : Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 3 with ContentId

use of com.enonic.xp.content.ContentId 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 4 with ContentId

use of com.enonic.xp.content.ContentId 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 5 with ContentId

use of com.enonic.xp.content.ContentId 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)

Aggregations

ContentId (com.enonic.xp.content.ContentId)83 Content (com.enonic.xp.content.Content)34 Test (org.junit.jupiter.api.Test)33 PropertyTree (com.enonic.xp.data.PropertyTree)16 ContentPath (com.enonic.xp.content.ContentPath)14 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)13 ContentIds (com.enonic.xp.content.ContentIds)11 PropertySet (com.enonic.xp.data.PropertySet)10 NodeId (com.enonic.xp.node.NodeId)9 BeforeEach (org.junit.jupiter.api.BeforeEach)8 ContentInheritType (com.enonic.xp.content.ContentInheritType)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)7 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)6 Context (com.enonic.xp.context.Context)6 DeleteContentParams (com.enonic.xp.content.DeleteContentParams)5 Node (com.enonic.xp.node.Node)5 Branch (com.enonic.xp.branch.Branch)4 ContentConstants (com.enonic.xp.content.ContentConstants)4 ContextBuilder (com.enonic.xp.context.ContextBuilder)4