Search in sources :

Example 1 with ArchiveContentParams

use of com.enonic.xp.archive.ArchiveContentParams in project xp by enonic.

the class ContentServiceImplTest_archive method archive_check_properties.

@Test
public void archive_check_properties() throws Exception {
    final Content parent = createContent(ContentPath.ROOT, "archive");
    final Content child = createContent(parent.getPath(), "content");
    final ArchiveContentParams params = ArchiveContentParams.create().contentId(parent.getId()).archiveContentListener(listener).build();
    this.contentService.archive(params);
    archiveContext().runWith(() -> {
        final Content archivedParent = contentService.getById(parent.getId());
        assertEquals("/", archivedParent.getOriginalParentPath().toString());
        assertEquals("archive", archivedParent.getOriginalName().toString());
        assertTrue(archivedParent.getArchivedTime().isBefore(Instant.now()));
        assertEquals("user:system:test-user", archivedParent.getArchivedBy().toString());
        final Content archivedChild = contentService.getById(child.getId());
        assertNull(archivedChild.getOriginalParentPath());
        assertNull(archivedChild.getOriginalName());
        assertTrue(archivedChild.getArchivedTime().isBefore(Instant.now()));
        assertEquals("user:system:test-user", archivedParent.getArchivedBy().toString());
    });
}
Also used : ArchiveContentParams(com.enonic.xp.archive.ArchiveContentParams) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 2 with ArchiveContentParams

use of com.enonic.xp.archive.ArchiveContentParams in project xp by enonic.

the class ContentServiceImplTest_archive method archive_tree.

@Test
public void archive_tree() throws Exception {
    final Content parent = createContent(ContentPath.ROOT, "archive");
    final Content child1 = createContent(parent.getPath(), "child1");
    final Content child1_1 = createContent(child1.getPath(), "child1_1");
    final Content child1_2 = createContent(child1.getPath(), "child2_1");
    final ArchiveContentParams params = ArchiveContentParams.create().contentId(parent.getId()).archiveContentListener(listener).build();
    final ArchiveContentsResult result = this.contentService.archive(params);
    assertEquals(1, result.getArchivedContents().getSize());
    assertEquals(4, listener.getArchived());
    assertFalse(this.contentService.contentExists(child1.getId()));
    assertFalse(this.contentService.contentExists(child1.getPath()));
    assertFalse(this.contentService.contentExists(child1_1.getId()));
    assertFalse(this.contentService.contentExists(child1_1.getPath()));
    assertFalse(this.contentService.contentExists(child1_2.getId()));
    assertFalse(this.contentService.contentExists(child1_2.getPath()));
    archiveContext().runWith(() -> {
        assertTrue(this.contentService.contentExists(child1.getId()));
        assertTrue(this.contentService.contentExists(child1.getPath()));
        assertTrue(this.contentService.contentExists(child1_1.getId()));
        assertTrue(this.contentService.contentExists(child1_1.getPath()));
        assertTrue(this.contentService.contentExists(child1_2.getId()));
        assertTrue(this.contentService.contentExists(child1_2.getPath()));
    });
}
Also used : ArchiveContentParams(com.enonic.xp.archive.ArchiveContentParams) Content(com.enonic.xp.content.Content) ArchiveContentsResult(com.enonic.xp.archive.ArchiveContentsResult) Test(org.junit.jupiter.api.Test)

Example 3 with ArchiveContentParams

use of com.enonic.xp.archive.ArchiveContentParams in project xp by enonic.

the class ContentServiceImplTest_archive method archive_child.

@Test
public void archive_child() throws Exception {
    final Content parent = createContent(ContentPath.ROOT, "parent");
    final Content child = createContent(parent.getPath(), "child");
    final ArchiveContentParams params = ArchiveContentParams.create().contentId(child.getId()).build();
    this.contentService.archive(params);
    assertTrue(this.contentService.contentExists(parent.getId()));
    assertFalse(this.contentService.contentExists(child.getPath()));
    assertFalse(this.contentService.contentExists(child.getId()));
    archiveContext().runWith(() -> {
        assertTrue(this.contentService.contentExists(child.getId()));
        assertTrue(this.contentService.contentExists(ContentPath.from("/child")));
        assertFalse(this.contentService.contentExists(parent.getId()));
    });
}
Also used : ArchiveContentParams(com.enonic.xp.archive.ArchiveContentParams) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 4 with ArchiveContentParams

use of com.enonic.xp.archive.ArchiveContentParams in project xp by enonic.

the class ArchiveContentHandler method archive.

private List<String> archive(final ContentId sourceId) {
    final ArchiveContentParams archiveParams = ArchiveContentParams.create().contentId(sourceId).build();
    final ArchiveContentsResult result = contentService.archive(archiveParams);
    return result.getArchivedContents().stream().map(ContentId::toString).collect(Collectors.toList());
}
Also used : ArchiveContentParams(com.enonic.xp.archive.ArchiveContentParams) ArchiveContentsResult(com.enonic.xp.archive.ArchiveContentsResult)

Example 5 with ArchiveContentParams

use of com.enonic.xp.archive.ArchiveContentParams in project xp by enonic.

the class ArchiveContentHandlerTest method testExample.

@Test
public void testExample() {
    final Content content = TestDataFixtures.newExampleContent();
    when(this.contentService.getByPath(ContentPath.from("/path/to/mycontent"))).thenReturn(content);
    when(this.contentService.archive(Mockito.isA(ArchiveContentParams.class))).thenAnswer(invocationOnMock -> invokeArchive((ArchiveContentParams) invocationOnMock.getArguments()[0]));
    runScript("/lib/xp/examples/content/archive.js");
}
Also used : ArchiveContentParams(com.enonic.xp.archive.ArchiveContentParams) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Aggregations

ArchiveContentParams (com.enonic.xp.archive.ArchiveContentParams)5 Content (com.enonic.xp.content.Content)4 Test (org.junit.jupiter.api.Test)4 ArchiveContentsResult (com.enonic.xp.archive.ArchiveContentsResult)2