All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lib.xp.examples.node.duplicate.js Maven / Gradle / Ivy

The newest version!
var nodeLib = require('/lib/xp/node');
var assert = require('/lib/xp/testing');

var repo = nodeLib.connect({
    repoId: 'com.enonic.cms.default',
    branch: 'draft'
});

var expectedJson = {
    "_id": "nodeid-copy",
    "_name": "duplicated-node",
    "_path": "/duplicated-node",
    "_childOrder": "_ts DESC",
    "_indexConfig": {
        "default": {
            "decideByType": true,
            "enabled": true,
            "nGram": false,
            "fulltext": false,
            "includeInAllText": false,
            "path": false,
            "indexValueProcessors": [],
            "languages": []
        }, "configs": []
    },
    "_inheritsPermissions": false,
    "_permissions": [{
        "principal": "role:system.admin",
        "allow": ["READ", "CREATE", "MODIFY", "DELETE", "PUBLISH", "READ_PERMISSIONS", "WRITE_PERMISSIONS"],
        "deny": []
    }],
    "_state": "DEFAULT",
    "_nodeType": "default",
    "data": {
        "prop1": "Value 1",
        "extraProp": "extraPropValue"
    }
};

// BEGIN
// Duplicates node
var result = repo.duplicate({
    nodeId: 'nodeId',
    name: 'duplicated-node',
    includeChildren: false,
    dataProcessor: function (data) {
        data.data.extraProp = 'extraPropValue';
        return data;
    },
    parent: '/',
    refresh: 'SEARCH'
});
// END

assert.assertJsonEquals(expectedJson, result);





© 2015 - 2024 Weber Informatics LLC | Privacy Policy