use of com.enonic.xp.node.ImportNodeResult in project xp by enonic.
the class ImportContentCommand method doExecute.
private ImportContentResult doExecute() {
final Node importNode = ImportContentFactory.create().params(params).contentDataSerializer(contentDataSerializer).build().execute();
final ImportNodeParams importNodeParams = ImportNodeParams.create().importNode(importNode).binaryAttachments(params.getBinaryAttachments()).insertManualStrategy(params.getInsertManualStrategy()).dryRun(params.isDryRun()).importPermissions(params.isImportPermissions()).importPermissionsOnCreate(params.isImportPermissionsOnCreate()).build();
final ImportNodeResult result = nodeService.importNode(importNodeParams);
return ImportContentResult.create().content(translator.fromNode(result.getNode(), false)).build();
}
use of com.enonic.xp.node.ImportNodeResult in project xp by enonic.
the class NodeImporter method processNodeSource.
private Node processNodeSource(final VirtualFile nodeFolder, final ProcessNodeSettings.Builder processNodeSettings) {
final VirtualFile nodeSource = this.exportReader.getNodeSource(nodeFolder);
final CharSource nodeCharSource;
try {
nodeCharSource = transformer == null ? nodeSource.getCharSource() : CharSource.wrap(this.transformer.transform(nodeSource.getCharSource()));
} catch (Exception e) {
throw new ImportNodeException("Error during XSLT pre-processing for node in '" + nodeSource.getUrl() + "'", e);
}
final Node.Builder newNodeBuilder = Node.create();
try {
final XmlNodeParser parser = new XmlNodeParser();
parser.builder(newNodeBuilder);
parser.source(nodeCharSource);
parser.parse();
} catch (final Exception e) {
throw new XmlException(e, "Could not load source node [" + nodeSource.getUrl() + "]: ", e);
}
final Node newNode = newNodeBuilder.build();
final NodePath importNodePath = NodeImportPathResolver.resolveNodeImportPath(nodeFolder, this.exportRoot, this.importRoot);
final ImportNodeResult importNodeResult = importNode(nodeFolder, processNodeSettings, newNode, importNodePath);
if (nodeImportListener != null) {
nodeImportListener.nodeImported(1L);
}
if (importNodeResult.isPreExisting()) {
result.updated(importNodeResult.getNode().path());
} else {
result.added(importNodeResult.getNode().path());
}
return importNodeResult.getNode();
}
use of com.enonic.xp.node.ImportNodeResult in project xp by enonic.
the class NodeServiceImpl method importNode.
@Override
public ImportNodeResult importNode(final ImportNodeParams params) {
verifyContext();
final ImportNodeResult importNodeResult = ImportNodeCommand.create().binaryAttachments(params.getBinaryAttachments()).importNode(params.getNode()).insertManualStrategy(params.getInsertManualStrategy()).dryRun(params.isDryRun()).importPermissions(params.isImportPermissions()).importPermissionsOnCreate(params.isImportPermissionsOnCreate()).binaryBlobStore(this.binaryService).indexServiceInternal(this.indexServiceInternal).storageService(this.nodeStorageService).searchService(this.nodeSearchService).build().execute();
if (importNodeResult.isPreExisting()) {
this.eventPublisher.publish(NodeEvents.updated(importNodeResult.getNode()));
} else {
this.eventPublisher.publish(NodeEvents.created(importNodeResult.getNode()));
}
return importNodeResult;
}
use of com.enonic.xp.node.ImportNodeResult in project xp by enonic.
the class ImportNodeCommandTest method no_timestamp.
@Test
public void no_timestamp() throws Exception {
final Node importNode = Node.create().name("myNode").parentPath(NodePath.ROOT).data(new PropertyTree()).build();
final ImportNodeResult importNodeResult = importNode(importNode);
assertNotNull(importNodeResult.getNode().getTimestamp());
}
use of com.enonic.xp.node.ImportNodeResult in project xp by enonic.
the class ImportNodeCommandTest method import_existing_node.
@Test
public void import_existing_node() {
PropertyTree data = new PropertyTree();
data.addString("name", "value");
final Node importNode = Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(data).build();
importNode(importNode);
final Node abc = getNodeById(NodeId.from("abc"));
assertNotNull(abc);
assertEquals(data, abc.data());
PropertyTree data2 = new PropertyTree();
data2.addString("name", "valueUpdated");
final Node importNode2 = Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(data2).build();
final ImportNodeResult importNodeResult = importNode(importNode2);
final Node abc2 = getNodeById(NodeId.from("abc"));
assertNotNull(abc2);
assertEquals(data2, abc2.data());
assertEquals(importNodeResult.getNode().data(), abc2.data());
assertTrue(importNodeResult.isPreExisting());
}
Aggregations