Search in sources :

Example 11 with Content

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

the class ContentOutboundDependenciesIdsResolver method resolveOutboundDependenciesIds.

private ContentIds resolveOutboundDependenciesIds(final ContentId contentId) {
    final Content content = this.contentService.getById(contentId);
    final ContentIds.Builder contentIds = ContentIds.create();
    final PropertySet contentPageData = new PropertyTree().getRoot();
    if (content.getPage() != null) {
        contentDataSerializer.toPageData(content.getPage(), contentPageData);
    }
    final Stream<Property> extraDataDependencies = content.hasExtraData() ? content.getAllExtraData().stream().flatMap(extraData -> extraData.getData().getProperties(ValueTypes.REFERENCE).stream()) : Stream.empty();
    Stream.of(content.getData().getProperties(ValueTypes.REFERENCE).stream(), contentPageData.getProperties(ValueTypes.REFERENCE).stream(), extraDataDependencies).flatMap(s -> s).forEach(property -> {
        final String value = property.getValue().toString();
        if (!contentId.toString().equals(value) && !nullToEmpty(value).isBlank()) {
            contentIds.add(ContentId.from(value));
        }
    });
    if (content.getProcessedReferences() != null && content.getProcessedReferences().getSize() > 0) {
        contentIds.addAll(content.getProcessedReferences());
    }
    return contentIds.build();
}
Also used : ContentId(com.enonic.xp.content.ContentId) ContentService(com.enonic.xp.content.ContentService) Property(com.enonic.xp.data.Property) Stream(java.util.stream.Stream) ContentIds(com.enonic.xp.content.ContentIds) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) PropertySet(com.enonic.xp.data.PropertySet) Content(com.enonic.xp.content.Content) ContentDataSerializer(com.enonic.xp.core.impl.content.serializer.ContentDataSerializer) ValueTypes(com.enonic.xp.data.ValueTypes) PropertyTree(com.enonic.xp.data.PropertyTree) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentIds(com.enonic.xp.content.ContentIds) PropertySet(com.enonic.xp.data.PropertySet) Property(com.enonic.xp.data.Property)

Example 12 with Content

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

the class ContentServiceImplTest_versions method get_published_versions.

@Test
public void get_published_versions() throws Exception {
    final Content content = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("content").parent(ContentPath.ROOT).name("myContent").type(ContentTypeName.folder()).build());
    this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).build());
    this.contentService.unpublishContent(UnpublishContentParams.create().contentIds(ContentIds.from(content.getId())).unpublishBranch(WS_OTHER).build());
    final FindContentVersionsResult result = this.contentService.getVersions(FindContentVersionsParams.create().contentId(content.getId()).build());
    assertEquals(3, result.getHits());
    assertEquals(3, result.getTotalHits());
    final Iterator<ContentVersion> versions = result.getContentVersions().iterator();
    assertNotNull(versions.next().getPublishInfo());
    assertNotNull(versions.next().getPublishInfo());
    assertNull(versions.next().getPublishInfo());
}
Also used : Content(com.enonic.xp.content.Content) ContentVersion(com.enonic.xp.content.ContentVersion) PropertyTree(com.enonic.xp.data.PropertyTree) FindContentVersionsResult(com.enonic.xp.content.FindContentVersionsResult) Test(org.junit.jupiter.api.Test)

Example 13 with Content

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

the class ContentServiceImplTest_versions method version_workflow_info.

@Test
public void version_workflow_info() throws Exception {
    final Map<String, WorkflowCheckState> checks = Map.of("checkName1", WorkflowCheckState.APPROVED, "checkName2", WorkflowCheckState.PENDING);
    final WorkflowInfo workflowInfo = WorkflowInfo.create().state(WorkflowState.IN_PROGRESS).checks(checks).build();
    final Content content = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my test content").parent(ContentPath.ROOT).name("myContent").type(ContentTypeName.folder()).workflowInfo(workflowInfo).build());
    final FindContentVersionsResult versions = this.contentService.getVersions(FindContentVersionsParams.create().contentId(content.getId()).build());
    final ContentVersion contentVersion = versions.getContentVersions().iterator().next();
    final WorkflowInfo retrievedWorkflowInfo = contentVersion.getWorkflowInfo();
    assertEquals(WorkflowState.IN_PROGRESS, retrievedWorkflowInfo.getState());
    assertEquals(WorkflowCheckState.APPROVED, retrievedWorkflowInfo.getChecks().get("checkName1"));
    assertEquals(WorkflowCheckState.PENDING, retrievedWorkflowInfo.getChecks().get("checkName2"));
}
Also used : Content(com.enonic.xp.content.Content) ContentVersion(com.enonic.xp.content.ContentVersion) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) PropertyTree(com.enonic.xp.data.PropertyTree) FindContentVersionsResult(com.enonic.xp.content.FindContentVersionsResult) WorkflowCheckState(com.enonic.xp.content.WorkflowCheckState) Test(org.junit.jupiter.api.Test)

Example 14 with Content

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

the class ProjectEventListenerTest method testSingle.

@Test
public void testSingle() throws InterruptedException {
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "name"));
    handleEvents();
    final Content targetContent = targetContext.callWith(() -> contentService.getById(sourceContent.getId()));
    compareSynched(sourceContent, targetContent);
}
Also used : Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 15 with Content

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

the class ProjectEventListenerTest method testChildren.

@Test
public void testChildren() throws InterruptedException {
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "name"));
    final Content sourceChild1 = sourceContext.callWith(() -> createContent(sourceContent.getPath(), "name"));
    final Content sourceChild2 = sourceContext.callWith(() -> createContent(sourceChild1.getPath(), "name"));
    handleEvents();
    final Content targetChild1 = targetContext.callWith(() -> contentService.getById(sourceChild1.getId()));
    final Content targetChild2 = targetContext.callWith(() -> contentService.getById(sourceChild2.getId()));
    compareSynched(sourceChild1, targetChild1);
    compareSynched(sourceChild2, targetChild2);
}
Also used : Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Aggregations

Content (com.enonic.xp.content.Content)560 Test (org.junit.jupiter.api.Test)432 PropertyTree (com.enonic.xp.data.PropertyTree)130 CreateContentParams (com.enonic.xp.content.CreateContentParams)57 ContentId (com.enonic.xp.content.ContentId)50 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)48 ContentPath (com.enonic.xp.content.ContentPath)47 ValidationErrors (com.enonic.xp.content.ValidationErrors)47 Site (com.enonic.xp.site.Site)43 PropertySet (com.enonic.xp.data.PropertySet)30 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)27 Page (com.enonic.xp.page.Page)26 Contents (com.enonic.xp.content.Contents)25 Node (com.enonic.xp.node.Node)25 ContentIds (com.enonic.xp.content.ContentIds)24 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)24 ContentQuery (com.enonic.xp.content.ContentQuery)23 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)23 DataValidationError (com.enonic.xp.content.DataValidationError)21 ContentType (com.enonic.xp.schema.content.ContentType)20