Search in sources :

Example 1 with SystemDumpResult

use of com.enonic.xp.dump.SystemDumpResult in project xp by enonic.

the class DumpRunnableTask method run.

@Override
public void run(final TaskId id, final ProgressReporter progressReporter) {
    final SystemDumpParams systemDumpParams = SystemDumpParams.create().dumpName(params.getName()).includeBinaries(true).includeVersions(params.isIncludeVersions()).maxAge(params.getMaxAge()).archive(params.isArchive()).maxVersions(params.getMaxVersions()).listener(new SystemDumpListenerImpl(progressReporter)).build();
    final SystemDumpResult result = this.dumpService.dump(systemDumpParams);
    progressReporter.info(SystemDumpResultJson.from(result).toString());
}
Also used : SystemDumpParams(com.enonic.xp.dump.SystemDumpParams) SystemDumpResult(com.enonic.xp.dump.SystemDumpResult) SystemDumpListenerImpl(com.enonic.xp.impl.server.rest.task.listener.SystemDumpListenerImpl)

Example 2 with SystemDumpResult

use of com.enonic.xp.dump.SystemDumpResult in project xp by enonic.

the class DumpRunnableTaskTest method dump.

@Test
public void dump() {
    final SystemDumpResult systemDumpResult = SystemDumpResult.create().add(RepoDumpResult.create(RepositoryId.from("my-repo")).versions(3L).add(BranchDumpResult.create(Branch.create().value("branch-value").build()).addedNodes(3).error(DumpError.error("error-message")).build()).build()).build();
    final SystemDumpParams params = SystemDumpParams.create().dumpName("dump").includeBinaries(true).includeVersions(true).maxAge(10).maxVersions(20).listener(new SystemDumpListenerImpl(progressReporter)).build();
    Mockito.when(this.dumpService.dump(Mockito.isA(SystemDumpParams.class))).thenReturn(systemDumpResult);
    final DumpRunnableTask task = createAndRunTask(new SystemDumpRequestJson(params.getDumpName(), params.isIncludeVersions(), params.getMaxAge(), params.getMaxVersions(), params.isArchive()));
    task.createTaskResult();
    Mockito.verify(progressReporter, Mockito.times(1)).info(contentQueryArgumentCaptor.capture());
    Mockito.verify(taskService, Mockito.times(1)).submitTask(Mockito.isA(RunnableTask.class), Mockito.eq("dump"));
    final String result = contentQueryArgumentCaptor.getAllValues().get(0);
    jsonTestHelper.assertJsonEquals(jsonTestHelper.loadTestJson("dump_result.json"), jsonTestHelper.stringToJson(result));
}
Also used : SystemDumpParams(com.enonic.xp.dump.SystemDumpParams) SystemDumpRequestJson(com.enonic.xp.impl.server.rest.model.SystemDumpRequestJson) RunnableTask(com.enonic.xp.task.RunnableTask) SystemDumpResult(com.enonic.xp.dump.SystemDumpResult) SystemDumpListenerImpl(com.enonic.xp.impl.server.rest.task.listener.SystemDumpListenerImpl) Test(org.junit.jupiter.api.Test) AbstractRunnableTaskTest(com.enonic.xp.task.AbstractRunnableTaskTest)

Example 3 with SystemDumpResult

use of com.enonic.xp.dump.SystemDumpResult in project xp by enonic.

the class SystemRepoDumpResultJsonTest method create.

@Test
public void create() throws Exception {
    final SystemDumpResult systemDumpResult = SystemDumpResult.create().add(RepoDumpResult.create(RepositoryId.from("repo1")).add(BranchDumpResult.create(Branch.from("branch1")).addedNodes(5).build()).add(BranchDumpResult.create(Branch.from("branch2")).addedNodes(23).build()).addedVersion().build()).add(RepoDumpResult.create(RepositoryId.from("repo2")).add(BranchDumpResult.create(Branch.from("branch3")).addedNodes(5).build()).add(BranchDumpResult.create(Branch.from("branch4")).addedNodes(23).error(DumpError.error("cannot find binary with version 123")).error(DumpError.error("cannot find version with id 123")).build()).addedVersion().build()).build();
    final SystemDumpResultJson json = SystemDumpResultJson.from(systemDumpResult);
    assertEquals(2, json.getRepositories().size());
    assertEquals(2, json.getRepositories().get(0).getBranches().size());
}
Also used : SystemDumpResult(com.enonic.xp.dump.SystemDumpResult) Test(org.junit.jupiter.api.Test)

Example 4 with SystemDumpResult

use of com.enonic.xp.dump.SystemDumpResult in project xp by enonic.

the class DumpServiceImplTest method dumpAndLoad.

@Test
public void dumpAndLoad() throws Exception {
    final Node node = createNode(NodePath.ROOT, "myNode");
    final SystemDumpResult systemDumpResult = NodeHelper.runAsAdmin(() -> this.dumpService.dump(SystemDumpParams.create().dumpName("testDump").build()));
    final BranchDumpResult result = systemDumpResult.get(TEST_REPO_ID).get(WS_DEFAULT);
    assertNotNull(result);
    assertEquals(2, result.getSuccessful());
    NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
    final Node currentStoredNode = this.nodeService.getById(node.id());
    assertEquals(node.getTimestamp(), currentStoredNode.getTimestamp());
    assertEquals(node.id(), currentStoredNode.id());
    assertEquals(node.path(), currentStoredNode.path());
    assertEquals(node.getManualOrderValue(), currentStoredNode.getManualOrderValue());
    assertEquals(node.getAttachedBinaries(), currentStoredNode.getAttachedBinaries());
    assertEquals(node.getIndexConfigDocument(), currentStoredNode.getIndexConfigDocument());
    assertEquals(node.getChildOrder(), currentStoredNode.getChildOrder());
    assertEquals(node.getNodeState(), currentStoredNode.getNodeState());
    assertEquals(node.getNodeType(), currentStoredNode.getNodeType());
    assertEquals(node.data(), currentStoredNode.data());
}
Also used : BranchDumpResult(com.enonic.xp.dump.BranchDumpResult) Node(com.enonic.xp.node.Node) SystemDumpResult(com.enonic.xp.dump.SystemDumpResult) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 5 with SystemDumpResult

use of com.enonic.xp.dump.SystemDumpResult in project xp by enonic.

the class DumpMetaJson method fromJson.

public static DumpMeta fromJson(final DumpMetaJson dumpMetaJson) {
    final DumpMeta.Builder dumpMeta = DumpMeta.create().xpVersion(dumpMetaJson.getXpVersion()).timestamp(Instant.parse(dumpMetaJson.getTimestamp()));
    if (dumpMetaJson.getResult() != null) {
        SystemDumpResult.Builder systemDumpResult = SystemDumpResult.create();
        dumpMetaJson.getResult().forEach((key, value) -> systemDumpResult.add(RepoDumpResultJson.fromJson(key, value)));
        dumpMeta.systemDumpResult(systemDumpResult.build());
    }
    if (!isNullOrEmpty(dumpMetaJson.getModelVersion())) {
        final Version modelVersion = Version.valueOf(dumpMetaJson.getModelVersion());
        dumpMeta.modelVersion(modelVersion);
    }
    return dumpMeta.build();
}
Also used : DumpMeta(com.enonic.xp.repo.impl.dump.model.DumpMeta) Version(com.enonic.xp.util.Version) SystemDumpResult(com.enonic.xp.dump.SystemDumpResult)

Aggregations

SystemDumpResult (com.enonic.xp.dump.SystemDumpResult)8 Test (org.junit.jupiter.api.Test)6 BranchDumpResult (com.enonic.xp.dump.BranchDumpResult)4 Node (com.enonic.xp.node.Node)4 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)4 SystemDumpParams (com.enonic.xp.dump.SystemDumpParams)2 SystemDumpListenerImpl (com.enonic.xp.impl.server.rest.task.listener.SystemDumpListenerImpl)2 SystemDumpRequestJson (com.enonic.xp.impl.server.rest.model.SystemDumpRequestJson)1 DumpMeta (com.enonic.xp.repo.impl.dump.model.DumpMeta)1 Repositories (com.enonic.xp.repository.Repositories)1 AbstractRunnableTaskTest (com.enonic.xp.task.AbstractRunnableTaskTest)1 RunnableTask (com.enonic.xp.task.RunnableTask)1 Version (com.enonic.xp.util.Version)1