cloudcms-cli
Version:
Cloud CMS Command-Line client
92 lines (77 loc) • 2.53 kB
JavaScript
var helper = require("../../../helper");
var AbstractCommand = require("../../abstract");
class FindDuplicateQNamesCommand extends AbstractCommand
{
constructor()
{
super({
"group": "tools",
"name": "find-duplicate-qnames",
"description": "Finds any definition nodes that have duplicated QNames",
"schema": {
"properties": [{
"name": "repositoryId",
"type": "string",
"description": "Enter the repository ID",
"required": true,
"args": ["repository", "r"]
}, {
"name": "branchId",
"type": "string",
"description": "Enter the branch ID",
"required": true,
"args": ["branch", "b"]
}]
}
});
}
handle(options, callback)
{
var params = {
"limit": 1000,
"full": true,
"metadata": true
};
var query = {
"_type": {
"$in": ["d:type", "d:association", "d:feature"]
}
};
var repositoryId = options.repositoryId;
var branchId = options.branchId;
helper._handleGitanaPost("/repositories/" + repositoryId + "/branches/" + branchId + "/nodes/query", params, query, function(err, jsonResponse) {
var rows = jsonResponse.rows;
var map = {};
for (var i = 0; i < rows.length; i++)
{
var qname = rows[i]._qname;
if (qname)
{
var array = map[qname];
if (!array)
{
array = map[qname] = [];
}
array.push(rows[i]._doc);
}
}
var result = {};
result.ok = true;
for (var qname in map)
{
var array = map[qname];
if (array && array.length > 1)
{
if (!result.errors) {
result.errors = {};
}
result.errors[qname] = array;
result.ok = false;
}
}
helper._handleJsonResponse(err, result, callback);
callback();
});
}
}
module.exports = FindDuplicateQNamesCommand;