-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReportMultipleParents.js
More file actions
executable file
·98 lines (85 loc) · 3.06 KB
/
Copy pathReportMultipleParents.js
File metadata and controls
executable file
·98 lines (85 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env node
/*jshint esversion: 8 */
/*jshint -W069 */
const BaseScript = require('./lib/BaseScript.js');
const objectPath = require("object-path");
const chalk = require('chalk');
const Logger = require('basic-logger');
const log = new Logger({
showMillis: false,
showTimestamp: true
});
module.exports =
class DetectMultipleParents extends BaseScript {
constructor() {
super(defaultOptions, defaultHelpMessage);
}
/** exec()
* entry point
*/
async exec() {
await this.connect();
this.gitanaConfig
log.info(chalk.yellow("Connected to project: \"" + this.project.title + "\" and branch: " + this.branch.title || this.branch._doc));
this.option_queryFilePath = this.options["query-file-path"] || null;
this.option_reportOnly = this.options["report-only"] || false;
let query = require(this.option_queryFilePath);
// query._fields = {};
let result = await this.session.queryNodes(this.repository, this.branch, query, { metadata: true, full: true, limit: 2000 });
let reportData = {};
result.rows.forEach(element => {
log.debug(`association: ${element._doc}, source: ${element.source} (${element.source_type}), target: ${element.target} (${element.target_type})`);
if (element.target && reportData[element.target] !== undefined) {
reportData[element.target].push(element.source);
} else {
reportData[element.target] = [element.source];
}
});
// filter out single parented nodes
// result.rows.forEach(element => {
// if (reportData[element.target].length == 1) {
// delete reportData[element.target];
// }
// });
console.log("Done");
if (this.option_reportOnly) {
console.log(JSON.stringify(reportData,null,2));
} else {
printHelp(getOptions());
}
}
async handle(nodes, op) {
log.debug("handle()");
}
};
const defaultOptions = [
{
name: 'report-only',
type: Boolean,
default: false,
description: 'Only report results. No node updates are made.'
},
{
name: 'query-file-path',
alias: 'y',
type: String,
required: true,
description: 'path to a json file defining the query'
}
];
const defaultHelpMessage = [
{
header: 'Cloud CMS - Report Nodes with Mulitple Parents (a:child)',
content: 'Update nodes in a branch by applying an HTTP PATCH method API call. The nodes to update are identified by a provided query.'
},
{
header: 'Examples',
content: [{
desc: '\n1. Report nodes found in a query:',
},
{
desc: 'npx cloudcms-util report-multiple-parents --report-only --query-file-path ./query-test1.json'
}
]
}
];