Search in sources :

Example 1 with UnpublishContentParams

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

Example 2 with UnpublishContentParams

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

the class UnpublishContentHandlerTest method unpublishById.

@Test
public void unpublishById() {
    ContentIds ids = ContentIds.from(PUB_ID_2, DEL_ID, FAIL_ID);
    UnpublishContentParams unpublishParams = UnpublishContentParams.create().contentIds(ids).unpublishBranch(ContentConstants.BRANCH_MASTER).includeChildren(true).build();
    Mockito.when(this.contentService.unpublishContent(unpublishParams)).thenReturn(exampleResult());
    runFunction("/test/UnpublishContentHandlerTest.js", "unpublishById");
}
Also used : UnpublishContentParams(com.enonic.xp.content.UnpublishContentParams) ContentIds(com.enonic.xp.content.ContentIds) Test(org.junit.jupiter.api.Test)

Example 3 with UnpublishContentParams

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

the class UnpublishContentHandlerTest method testExample.

@Test
public void testExample() {
    final Content content = exampleContent(PUB_ID_1, "mycontent", "My Content", "/mysite/somepage", "myfield", "Hello World");
    Mockito.when(this.contentService.getByPath(ContentPath.from("/mysite/somepage"))).thenReturn(content);
    ContentIds ids = ContentIds.from(PUB_ID_1, FAIL_ID);
    UnpublishContentParams unpublishParams = UnpublishContentParams.create().contentIds(ids).unpublishBranch(ContentConstants.BRANCH_MASTER).includeChildren(true).build();
    Mockito.when(this.contentService.unpublishContent(unpublishParams)).thenReturn(exampleResult());
    runScript("/lib/xp/examples/content/unpublish.js");
}
Also used : Content(com.enonic.xp.content.Content) UnpublishContentParams(com.enonic.xp.content.UnpublishContentParams) ContentIds(com.enonic.xp.content.ContentIds) Test(org.junit.jupiter.api.Test)

Example 4 with UnpublishContentParams

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

the class UnpublishContentHandlerTest method unpublishByPath.

@Test
public void unpublishByPath() {
    final Content myContent = exampleContent(PUB_ID_2, "mycontent", "My Content", "/myfolder/mycontent", "myfield", "Hello World");
    Mockito.when(this.contentService.getByPath(ContentPath.from("/myfolder/mycontent"))).thenReturn(myContent);
    final Content yourContent = exampleContent(PUB_ID_3, "yourcontent", "Your Content", "/yourfolder/yourcontent", "yourfield", "Hello Universe!");
    Mockito.when(this.contentService.getByPath(ContentPath.from("/yourfolder/yourcontent"))).thenReturn(yourContent);
    ContentIds ids = ContentIds.from(PUB_ID_2, PUB_ID_3);
    UnpublishContentParams unpublishParams = UnpublishContentParams.create().contentIds(ids).unpublishBranch(ContentConstants.BRANCH_MASTER).includeChildren(true).build();
    Mockito.when(this.contentService.unpublishContent(unpublishParams)).thenReturn(exampleResult());
    runFunction("/test/UnpublishContentHandlerTest.js", "unpublishByPath");
}
Also used : Content(com.enonic.xp.content.Content) UnpublishContentParams(com.enonic.xp.content.UnpublishContentParams) ContentIds(com.enonic.xp.content.ContentIds) Test(org.junit.jupiter.api.Test)

Aggregations

UnpublishContentParams (com.enonic.xp.content.UnpublishContentParams)4 ContentIds (com.enonic.xp.content.ContentIds)3 Test (org.junit.jupiter.api.Test)3 Content (com.enonic.xp.content.Content)2 Branch (com.enonic.xp.branch.Branch)1 ContentId (com.enonic.xp.content.ContentId)1 UnpublishContentsResult (com.enonic.xp.content.UnpublishContentsResult)1 Context (com.enonic.xp.context.Context)1 BeanContext (com.enonic.xp.script.bean.BeanContext)1