Search in sources :

Example 1 with NodeImportResult

use of com.enonic.xp.export.NodeImportResult in project xp by enonic.

the class ImportHandler method execute.

public NodeImportResultMapper execute() {
    final ImportNodesParams.Builder paramsBuilder = ImportNodesParams.create().targetNodePath(NodePath.create(targetNodePath).build()).nodeImportListener(new FunctionBasedNodeImportListener(nodeImported, nodeResolved));
    if (source instanceof ResourceKey) {
        paramsBuilder.source(toVirtualFile((ResourceKey) source));
    } else {
        paramsBuilder.exportName(source.toString());
    }
    if (xslt instanceof ResourceKey) {
        paramsBuilder.xslt(toVirtualFile((ResourceKey) xslt));
    } else {
        paramsBuilder.xsltFileName(xslt.toString());
    }
    if (xsltParams != null) {
        paramsBuilder.xsltParams(xsltParams.getMap());
    }
    if (includeNodeIds != null) {
        paramsBuilder.includeNodeIds(includeNodeIds);
    }
    if (includePermissions != null) {
        paramsBuilder.includePermissions(includePermissions);
    }
    final NodeImportResult nodeImportResult = this.context.getService(ExportService.class).get().importNodes(paramsBuilder.build());
    return new NodeImportResultMapper(nodeImportResult);
}
Also used : ImportNodesParams(com.enonic.xp.export.ImportNodesParams) NodeImportResult(com.enonic.xp.export.NodeImportResult) ResourceKey(com.enonic.xp.resource.ResourceKey)

Example 2 with NodeImportResult

use of com.enonic.xp.export.NodeImportResult in project xp by enonic.

the class NodeImportResultJson method from.

public static NodeImportResultJson from(final NodeImportResult result) {
    final NodeImportResultJson json = new NodeImportResultJson();
    json.dryRun = result.isDryRun();
    for (final NodePath nodePath : result.getAddedNodes()) {
        json.addedNodes.add(nodePath.toString());
    }
    for (final NodePath nodePath : result.getUpdateNodes()) {
        json.updateNodes.add(nodePath.toString());
    }
    for (final NodeImportResult.ImportError importError : result.getImportErrors()) {
        json.importErrors.add(importError.getMessage() + " - " + importError.getException());
    }
    json.importedBinaries.addAll(result.getImportedBinaries());
    return json;
}
Also used : NodePath(com.enonic.xp.node.NodePath) NodeImportResult(com.enonic.xp.export.NodeImportResult)

Example 3 with NodeImportResult

use of com.enonic.xp.export.NodeImportResult in project xp by enonic.

the class LoadRunnableTaskTest method load.

@Test
public void load() throws Exception {
    Path nameDir = Files.createDirectory(dumpDir.resolve("name"));
    final NodeImportResult importResult = NodeImportResult.create().added(NodePath.create("/path/to/node1").build()).updated(NodePath.create("/path/to/node2").build()).dryRun(true).build();
    final PropertyTree repoData = new PropertyTree();
    repoData.addString("key", "value");
    Mockito.when(this.exportService.importNodes(Mockito.isA(ImportNodesParams.class))).thenReturn(importResult);
    Mockito.when(this.repositoryService.list()).thenReturn(Repositories.from(Repository.create().branches(Branch.from("master")).id(RepositoryId.from("my-repo")).data(repoData).build()));
    Files.writeString(nameDir.resolve("export.properties"), "a=b");
    SystemLoadParams params = SystemLoadParams.create().dumpName("name").includeVersions(true).build();
    SystemLoadResult systemLoadResult = SystemLoadResult.create().add(RepoLoadResult.create(RepositoryId.from("my-repo")).add(BranchLoadResult.create(Branch.create().value("branch-value").build()).error(LoadError.error("error-message")).successful(2L).build()).versions(VersionsLoadResult.create().error(LoadError.error("version-load-error-message")).successful(1L).build()).build()).build();
    Mockito.when(this.dumpService.load(Mockito.isA(SystemLoadParams.class))).thenReturn(systemLoadResult);
    final LoadRunnableTask task = createAndRunTask(new SystemLoadRequestJson(params.getDumpName(), params.isUpgrade(), 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"));
    Mockito.verify(nodeRepositoryService, Mockito.times(1)).create(CreateRepositoryParams.create().repositoryId(RepositoryId.from("my-repo")).data(repoData).repositorySettings(RepositorySettings.create().build()).build());
    final String result = contentQueryArgumentCaptor.getAllValues().get(0);
    jsonTestHelper.assertJsonEquals(jsonTestHelper.loadTestJson("load_result.json"), jsonTestHelper.stringToJson(result));
}
Also used : Path(java.nio.file.Path) NodePath(com.enonic.xp.node.NodePath) ImportNodesParams(com.enonic.xp.export.ImportNodesParams) SystemLoadResult(com.enonic.xp.dump.SystemLoadResult) SystemLoadRequestJson(com.enonic.xp.impl.server.rest.model.SystemLoadRequestJson) PropertyTree(com.enonic.xp.data.PropertyTree) SystemLoadParams(com.enonic.xp.dump.SystemLoadParams) RunnableTask(com.enonic.xp.task.RunnableTask) NodeImportResult(com.enonic.xp.export.NodeImportResult) Test(org.junit.jupiter.api.Test) AbstractRunnableTaskTest(com.enonic.xp.task.AbstractRunnableTaskTest)

Example 4 with NodeImportResult

use of com.enonic.xp.export.NodeImportResult in project xp by enonic.

the class ImportRunnableTask method run.

@Override
public void run(final TaskId id, final ProgressReporter progressReporter) {
    final RepoPath targetRepoPath = params.getTargetRepoPath();
    final NodeImportResult result = getContext(params.getTargetRepoPath()).callWith(() -> {
        final ImportNodesParams.Builder builder = ImportNodesParams.create().exportName(params.getExportName()).targetNodePath(targetRepoPath.getNodePath()).dryRun(params.isDryRun()).includeNodeIds(params.isImportWithIds()).includePermissions(params.isImportWithPermissions()).xsltFileName(emptyToNull(params.getXslSource())).xsltParams(params.getXslParams()).nodeImportListener(new ImportListenerImpl(progressReporter));
        return this.exportService.importNodes(builder.build());
    });
    if (targetIsSystemRepo(targetRepoPath)) {
        initializeStoredRepositories();
    }
    progressReporter.info(NodeImportResultJson.from(result).toString());
}
Also used : RepoPath(com.enonic.xp.impl.server.rest.model.RepoPath) ImportNodesParams(com.enonic.xp.export.ImportNodesParams) ImportListenerImpl(com.enonic.xp.impl.server.rest.task.listener.ImportListenerImpl) NodeImportResult(com.enonic.xp.export.NodeImportResult)

Example 5 with NodeImportResult

use of com.enonic.xp.export.NodeImportResult in project xp by enonic.

the class ImportHandlerTest method testExample.

@Test
public void testExample() {
    when(applicationService.getInstalledApplication(ApplicationKey.from("myapplication"))).thenReturn(mock(Application.class));
    final NodeImportResult result = NodeImportResult.create().updated(NodePath.create("/updated").build()).added(NodePath.create("/added").build()).addBinary("binaryPath", BinaryReference.from("ref")).addError("error", new NoStacktraceException()).build();
    when(exportService.importNodes(any())).thenReturn(result);
    runScript("/lib/xp/examples/export/importNodes.js");
}
Also used : Application(com.enonic.xp.app.Application) NodeImportResult(com.enonic.xp.export.NodeImportResult) Test(org.junit.jupiter.api.Test)

Aggregations

NodeImportResult (com.enonic.xp.export.NodeImportResult)8 ImportNodesParams (com.enonic.xp.export.ImportNodesParams)4 Test (org.junit.jupiter.api.Test)3 PropertyTree (com.enonic.xp.data.PropertyTree)2 RepoLoadResult (com.enonic.xp.dump.RepoLoadResult)2 NodePath (com.enonic.xp.node.NodePath)2 AbstractRunnableTaskTest (com.enonic.xp.task.AbstractRunnableTaskTest)2 RunnableTask (com.enonic.xp.task.RunnableTask)2 Application (com.enonic.xp.app.Application)1 Branch (com.enonic.xp.branch.Branch)1 BranchLoadResult (com.enonic.xp.dump.BranchLoadResult)1 SystemLoadParams (com.enonic.xp.dump.SystemLoadParams)1 SystemLoadResult (com.enonic.xp.dump.SystemLoadResult)1 ImportNodesRequestJson (com.enonic.xp.impl.server.rest.model.ImportNodesRequestJson)1 RepoPath (com.enonic.xp.impl.server.rest.model.RepoPath)1 SystemLoadRequestJson (com.enonic.xp.impl.server.rest.model.SystemLoadRequestJson)1 ImportListenerImpl (com.enonic.xp.impl.server.rest.task.listener.ImportListenerImpl)1 ResourceKey (com.enonic.xp.resource.ResourceKey)1 Path (java.nio.file.Path)1