Search in sources :

Example 26 with ContentId

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

the class ContentAuditLogSupportImpl method doPublish.

private void doPublish(final PushContentParams params, final PublishContentResult result, final Context rootContext) {
    if (params.getContentIds() == null) {
        return;
    }
    final PropertyTree data = new PropertyTree();
    final PropertySet paramsSet = data.addSet("params");
    final PropertySet resultSet = data.addSet("result");
    if (params.getContentIds() != null) {
        paramsSet.addStrings("contentIds", params.getContentIds().stream().map(ContentId::toString).collect(Collectors.toList()));
    }
    if (params.getExcludedContentIds() != null) {
        paramsSet.addStrings("excludedContentIds", params.getExcludedContentIds().stream().map(ContentId::toString).collect(Collectors.toList()));
    }
    if (params.getExcludeChildrenIds() != null) {
        paramsSet.addStrings("excludeChildrenIds", params.getExcludeChildrenIds().stream().map(ContentId::toString).collect(Collectors.toList()));
    }
    if (params.getContentPublishInfo() != null) {
        final ContentPublishInfo contentPublishInfo = params.getContentPublishInfo();
        final PropertySet contentPublishInfoSet = paramsSet.addSet("contentPublishInfo");
        contentPublishInfoSet.addInstant("from", contentPublishInfo.getFrom());
        contentPublishInfoSet.addInstant("to", contentPublishInfo.getTo());
        contentPublishInfoSet.addInstant("first", contentPublishInfo.getFirst());
    }
    paramsSet.addString("target", params.getTarget().toString());
    paramsSet.addString("message", params.getMessage());
    paramsSet.addBoolean("includeDependencies", params.isIncludeDependencies());
    addContents(resultSet, result.getPushedContents(), "pushedContents");
    addContents(resultSet, result.getDeletedContents(), "deletedContents");
    addContents(resultSet, result.getFailedContents(), "failedContents");
    addContents(resultSet, result.getUnpublishedContents(), "unpublishedContents");
    log("system.content.publish", data, ContentIds.create().addAll(result.getPushedContents()).addAll(result.getDeletedContents()).addAll(result.getUnpublishedContents()).build(), rootContext);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) ContentId(com.enonic.xp.content.ContentId)

Example 27 with ContentId

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

the class ContentAuditLogSupportImpl method doCreateContent.

private void doCreateContent(final CreateContentParams params, final Content content, final Context rootContext) {
    final PropertyTree data = new PropertyTree();
    final PropertySet paramsSet = data.addSet("params");
    final PropertySet resultSet = data.addSet("result");
    paramsSet.addString("displayName", params.getDisplayName());
    paramsSet.addString("type", nullToNull(params.getType()));
    paramsSet.addString("name", nullToNull(params.getName()));
    paramsSet.addBoolean("requireValid", params.isRequireValid());
    paramsSet.addBoolean("inheritPermissions", params.isInheritPermissions());
    if (params.getProcessedIds() != null) {
        paramsSet.addStrings("processedIds", params.getProcessedIds().stream().map(ContentId::toString).collect(Collectors.toList()));
    }
    if (params.getPermissions() != null) {
        paramsSet.addStrings("permissions", params.getPermissions().getEntries().stream().map(AccessControlEntry::toString).collect(Collectors.toList()));
    }
    addContent(resultSet, content);
    log("system.content.create", data, content.getPath(), rootContext);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) ContentId(com.enonic.xp.content.ContentId)

Example 28 with ContentId

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

the class ContentServiceImplTest_delete method create_delete_published_content.

@Test
public void create_delete_published_content() throws Exception {
    final Content content = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").name("myContent").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build());
    refresh();
    final PublishContentResult result = this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).build());
    assertEquals(1, result.getPushedContents().getSize());
    // Deletes the content
    final DeleteContentParams deleteContentParams = DeleteContentParams.create().contentPath(content.getPath()).build();
    final DeleteContentsResult deletedContents = this.contentService.deleteWithoutFetch(deleteContentParams);
    assertNotNull(deletedContents);
    assertEquals(1, deletedContents.getPendingContents().getSize());
    for (ContentId deletedContent : deletedContents.getPendingContents()) {
        assertTrue(NodeState.PENDING_DELETE == this.nodeService.getById(NodeId.from(deletedContent)).getNodeState());
    }
    // Checks that the content is marked for deletion
    final Content foundContent = this.contentService.getById(content.getId());
    assertTrue(ContentState.PENDING_DELETE == foundContent.getContentState());
}
Also used : DeleteContentParams(com.enonic.xp.content.DeleteContentParams) PublishContentResult(com.enonic.xp.content.PublishContentResult) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentId(com.enonic.xp.content.ContentId) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) Test(org.junit.jupiter.api.Test)

Example 29 with ContentId

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

the class AbstractContentServiceTest method doAssertOrder.

private void doAssertOrder(final ContentIds contentIds, final Content[] expectedOrder) {
    assertEquals(expectedOrder.length, contentIds.getSize(), "Expected [" + expectedOrder.length + "] number of hits in result");
    final Iterator<ContentId> iterator = contentIds.iterator();
    for (final Content content : expectedOrder) {
        assertTrue(iterator.hasNext(), "Expected more content, iterator empty");
        final ContentId next = iterator.next();
        assertEquals(content.getId(), next, "Expected content with path [" + content.getPath() + "] in this position, found [" + this.contentService.getById(next).getPath() + "]");
    }
}
Also used : Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId)

Example 30 with ContentId

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

the class UnpublishContentHandler method execute.

public List<String> execute() {
    final Branch targetBranch = ContentConstants.BRANCH_MASTER;
    final Context context = ContextBuilder.from(ContextAccessor.current()).branch(targetBranch).build();
    final List<ContentId> contentIds = context.callWith(this::resolveContentIds);
    final UnpublishContentParams unpublishContentParams = UnpublishContentParams.create().contentIds(ContentIds.from(contentIds)).unpublishBranch(targetBranch).includeChildren(true).build();
    final UnpublishContentsResult result = this.contentService.unpublishContent(unpublishContentParams);
    return result.getUnpublishedContents().stream().map(ContentId::toString).collect(Collectors.toList());
}
Also used : BeanContext(com.enonic.xp.script.bean.BeanContext) Context(com.enonic.xp.context.Context) Branch(com.enonic.xp.branch.Branch) UnpublishContentParams(com.enonic.xp.content.UnpublishContentParams) UnpublishContentsResult(com.enonic.xp.content.UnpublishContentsResult) ContentId(com.enonic.xp.content.ContentId)

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