cloudcms-cli
Version:
Cloud CMS Command-Line client
280 lines (263 loc) • 12.2 kB
JavaScript
var helper = require("../../../helper");
var AbstractCommand = require("../../abstract");
class TransferExportCommand extends AbstractCommand
{
constructor()
{
super({
"group": "transfer",
"name": "export",
"description": "Export an archive from source object(s) or datastore(s)",
"schema": {
"properties": [{
"name": "source",
"type": "string",
"description": "Source Reference:",
"helper": "The reference for a source object or datastore that should be exported.",
"required": true,
"args": ["source", "s"]
}, {
"name": "group",
"type": "string",
"description": "Archive Group ID:",
"helper": "The group ID of the exported archive.",
"required": true,
"args": ["group", "g"]
}, {
"name": "artifact",
"type": "string",
"description": "Archive Artifact ID:",
"helper": "The artifact ID of the exported archive.",
"required": true,
"args": ["artifact", "a"]
}, {
"name": "version",
"type": "string",
"description": "Archive Version ID:",
"helper": "The version of the exported archive.",
"required": true,
"args": ["version", "v"]
}, {
"name": "vault",
"type": "boolean",
"description": "Vault ID:",
"helper": "The ID of the vault that will received the exported archive. If not specified, the \"primary\" vault will be used.",
"required": false,
"default": "primary",
"args": ["vault"]
}, {
"name": "includeACLs",
"type": "boolean",
"description": "Include ACLs:",
"helper": "Whether to include access control assignments for exported items",
"required": false,
"args": ["includeACLs", "includeAcls"]
}, {
"name": "includeTeams",
"type": "boolean",
"description": "Include Teams:",
"helper": "Whether to include teams (for any exported items that support them)",
"required": false,
"args": ["includeTeams"]
}, {
"name": "includeTeamMembers",
"type": "boolean",
"description": "Include Team Members:",
"helper": "Whether to include members (principals) for any exported teams",
"required": false,
"args": ["includeTeamMembers"]
}, {
"name": "includeRoles",
"type": "boolean",
"description": "Include Roles:",
"helper": "Whether to include any custom roles that are defined against an exported data store.",
"required": false,
"args": ["includeRoles"]
}, {
"name": "includeActivities",
"type": "boolean",
"description": "Include Activities:",
"helper": "Whether to include any activity reports for a given exported item.",
"required": false,
"args": ["includeActivities"]
}, {
"name": "includeBinaries",
"type": "boolean",
"description": "Include Binary Files:",
"helper": "Whether to include any binary files that are stored within an exported data store.",
"required": false,
"default": false,
"args": ["includeBinaries"]
}, {
"name": "includeAttachments",
"type": "boolean",
"description": "Include Attachments:",
"helper": "Whether to include any binary attachments that are stored on an attachable exported item.",
"required": false,
"default": false,
"args": ["includeAttachments"]
}, {
"name": "startDate",
"type": "string",
"description": "Starting Modification Date:",
"helper": "The lower bound modification date for any exported items - specified as a date string or epoch time format.",
"required": false,
"args": ["startDate"]
}, {
"name": "endDate",
"type": "string",
"description": "Ending Modification Date:",
"helper": "The upper bound modification date for any exported items - specified as a date string or epoch time format.",
"required": false,
"args": ["endDate"]
}, {
"name": "startChangeset",
"type": "string",
"description": "Starting Changeset ID:",
"helper": "Specifies a lower limit changeset ID for any exported repository changesets.",
"required": false,
"args": ["startChangeset"]
}, {
"name": "endChangeset",
"type": "string",
"description": "Ending Changeset ID:",
"helper": "Specifies an upper limit changeset ID for any exported repository changesets.",
"required": false,
"args": ["endChangeset"]
}, {
"name": "selectedBranchId",
"type": "string",
"description": "Selected Branch ID:",
"helper": "For project or repository exports, specifies a branch that should be exported. If not provided, all branches are exported.",
"required": false,
"args": ["selectedBranchId", "selectedBranch"]
}, {
"name": "tipChangesetOnly",
"type": "boolean",
"description": "Tip Changeset Only:",
"helper": "When exporting only a single branch, allows the branch contents to be compressed into a single changeset, resulting in a smaller archive.",
"required": false,
"args": ["tipChangesetOnly", "tipchangesetonly"]
}, {
"name": "contentIncludeFolders",
"type": "boolean",
"description": "Include Folders:",
"helper": "When exporting nodes, whether to walk those nodes to include any parental folder hierarchies.",
"required": false,
"args": ["contentIncludeFolders"]
}, {
"name": "contentIncludeRelators",
"type": "boolean",
"description": "Include Relators:",
"helper": "Forces the export of all relator property associations (and related content) even if those associations are linked.",
"required": false,
"args": ["contentIncludeRelators"]
}, {
"name": "branchIncludeRootChangeset",
"type": "boolean",
"description": "Include Root Changeset:",
"helper": "When exporting branches, forces the export of the root changeset of the branch. If not specified, the root is not included.",
"required": false,
"args": ["branchIncludeRootChangeset"]
}, {
"name": "optionalAssociationsIncludeTypes",
"type": "string",
"description": "Include Association Type:",
"helper": "Mark association type as non-optional so that its target will be traversed and included in the resulting archive",
"required": false,
"args": ["includeAssociationType"]
}, {
"name": "optionalAssociationsExcludeTypes",
"type": "string",
"description": "Exclude Association Type:",
"helper": "Mark association type as excluded so that its target won't be traversed or included in the resulting archive",
"required": false,
"args": ["excludeAssociationType"]
}, {
"name": "optionalAssociationsMaxDepth",
"type": "number",
"description": "Associations Max Depth:",
"helper": "Max traversal depth when evaluating content graph for nodes to include in the archive",
"required": false,
"args": ["associationMaxDepth"]
}]
}
});
}
handle(options, callback)
{
var config = JSON.parse(JSON.stringify(options));
var sourceRefs = config.source;
if (typeof(sourceRefs) === "string") {
sourceRefs = [sourceRefs];
}
delete config.source;
if (sourceRefs.length === 0)
{
return callback({
"message": "Missing source reference(s)"
});
}
var vaultId = config.vault;
delete config.vault;
var group = config.group;
delete config.group;
var artifact = config.artifact;
delete config.artifact;
var version = config.version;
delete config.version;
// ensure selectedBranchId is an array
if (typeof(config.selectedBranchId) === "string") {
// selectedBranchIds (plural) is the property on the API side
config.selectedBranchIds = [config.selectedBranchId];
}
delete config.selectedBranchId;
if ("startDate" in config)
{
var startDate = config.startDate;
if (typeof(startDate) === "string")
{
startDate = { "ms": Date.parse(startDate)};
}
else if (typeof(startDate) === "number")
{
startDate = { "ms": startDate };
}
config.startDate = startDate;
}
if ("endDate" in config)
{
var endDate = config.endDate;
if (typeof(endDate) === "string")
{
endDate = { "ms": Date.parse(endDate)};
}
else if (typeof(endDate) === "number")
{
endDate = { "ms": endDate };
}
config.endDate = endDate;
}
if ("optionalAssociationsIncludeTypes" in config)
{
var includeAssociationType = config.optionalAssociationsIncludeTypes;
if (typeof(includeAssociationType) === "string")
{
config.optionalAssociationsIncludeTypes = [includeAssociationType];
}
}
if ("optionalAssociationsExcludeTypes" in config)
{
var excludeAssociationType = config.optionalAssociationsExcludeTypes;
if (typeof(excludeAssociationType) === "string")
{
config.optionalAssociationsExcludeTypes = [excludeAssociationType];
}
}
// call workhorse function
helper.exportArchive(sourceRefs, group, artifact, version, vaultId, config, function(err) {
callback(err);
});
}
}
module.exports = TransferExportCommand;