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);
}
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;
}
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));
}
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());
}
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");
}
Aggregations