Skip to content

Commit

Permalink
Merge pull request #344 from mountaindude/167
Browse files Browse the repository at this point in the history
167
  • Loading branch information
mountaindude authored Nov 16, 2023
2 parents fd4e6f5 + d9db29f commit d6bf1d9
Show file tree
Hide file tree
Showing 9 changed files with 582 additions and 181 deletions.
125 changes: 67 additions & 58 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/src/ctrl-q.js",
"runtimeVersion": "19",
"runtimeVersion": "20",
"cwd": "${workspaceFolder}",

// ------------------------------------
Expand Down Expand Up @@ -79,7 +79,7 @@
// "--file-name",
// "testdata/tasks.xlsx",
// "--sheet-name",
// "4"
// "7"

// // "--import-app",
// // "--import-app-sheet-name",
Expand All @@ -100,37 +100,45 @@
// ------------------------------------
// Import tasks from CSV file
// ------------------------------------
// "args": [
// "task-import",
// "--auth-type",
// "cert",
// "--host",
// "192.168.100.109",
// // "--auth-cert-file",
// // "./cert/client.pem",
// // "--auth-cert-key-file",
// // "./cert/client_key.pem",
// "--auth-user-dir",
// "LAB",
// "--auth-user-id",
// "goran",
"args": [
"task-import",
"--auth-type",
"cert",
"--host",
// "192.168.100.109",
"10.211.55.15",

"--auth-cert-file",
"../../code/secret/winsrv.local/client.pem",
"--auth-cert-key-file",
"../../code/secret/winsrv.local/client_key.pem",
// "--auth-cert-file",
// "./cert/client.pem",
// "--auth-cert-key-file",
// "./cert/client_key.pem",
"--auth-user-dir",
"winsrv1",
// "LAB",
"--auth-user-id",
"goran",

// "--file-type",
// "csv",
"--file-type",
"csv",

// "--file-name",
// // "tasks2source.csv",
// // "task-chain.csv",
// "testdata/reload-tasks.csv",
"--file-name",
// "tasks2source.csv",
// "task-chain.csv",
// "testdata/reload-tasks.csv",
"./tasks_all.csv",

// // "--qvf-overwrite",
// // "no",
// "--qvf-overwrite",
// "no",

// // "--limit-import-count",
// // "2",
"--limit-import-count",
"2",

// // "--dry-run"
// ]
// "--dry-run"
]

// ------------------------------------
// Export apps to QVF files
Expand Down Expand Up @@ -350,36 +358,37 @@
// "file",
// "--output-file-name",
// // "tasks.xlsx",
// "tasks.csv",
// // "tasks.csv",
// "tasks_all.csv",
// // "tasks2.json",
// // "tasks2.xlsx",
// "--output-file-format",
// // "excel",
// // "json",
// "csv",

// "--output-file-name",
// // "reload-tasks.xlsx",
// "reload-tasks.csv",
// // "--output-file-name",
// // // "reload-tasks.xlsx",
// // "reload-tasks.csv",

// // "--text-color",
// // "no",
// // // "--text-color",
// // // "no",

// // "--output-file-overwrite",
// // // "--output-file-overwrite",

// "--table-details",
// // "common",
// // "lastexecution",
// // "tag",
// // "customproperty",
// // "schematrigger",
// // "compositetrigger",
// // "comptimeconstraint",
// // "comprule",
// // "--table-details",
// // // "common",
// // // "lastexecution",
// // // "tag",
// // // "customproperty",
// // // "schematrigger",
// // // "compositetrigger",
// // // "comptimeconstraint",
// // // "comprule",

// // "--log-level",
// // "debug"
// ]
// // // "--log-level",
// // // "debug"
// // ]

// ------------------------------------
// Create custom property with user activity buckets
Expand Down Expand Up @@ -771,17 +780,17 @@
// ------------------------------------
// Connection test
// ------------------------------------
"args": [
"connection-test",
"--host",
"192.168.100.109",
"--auth-user-dir",
"LAB",
"--auth-user-id",
"goran",
"--log-level",
"info"
]
// "args": [
// "connection-test",
// "--host",
// "192.168.100.109",
// "--auth-user-dir",
// "LAB",
// "--auth-user-id",
// "goran",
// "--log-level",
// "info"
// ]

}
]
Expand Down
2 changes: 1 addition & 1 deletion src/ctrl-q.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ const program = new Command();
taskImportAssertOptions(options);
importTaskFromFile(options);
} catch (err) {
logger.error(`IMPORT TASK: ${err}`);
logger.error(`IMPORT TASK 1: ${err}`);
}
})
.addOption(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/app/class_allapps.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class QlikSenseApps {
logger.error(
`IMPORT APP TO QSEOW: Custom property "${tmpCustomProperties[0]}" for app "${
appRow[0][appFileColumnHeaders.appName.pos]
}" not found or not valid for object type "Reload task". Exiting.`
}" not found or not valid for task type "Reload task". Exiting.`
);
process.exit(1);
}
Expand Down
25 changes: 20 additions & 5 deletions src/lib/cmd/gettask.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,25 @@ const getTask = async (options) => {
taskTable = taskTable.concat([row]);

// Find all triggers for this task
const schemaEventsForThisTask = schemaEventList.filter((item) => item.schemaEvent?.reloadTask?.id === task.taskId);
const compositeEventsForThisTask = compositeEventList.filter(
(item) => item.compositeEvent?.reloadTask?.id === task.taskId
);
const schemaEventsForThisTask = schemaEventList.filter((item) => {
if (item.schemaEvent?.reloadTask?.id === task.taskId) {
return true;
}
if (item.schemaEvent?.externalProgramTask?.id === task.taskId) {
return true;
}
return false;
});

const compositeEventsForThisTask = compositeEventList.filter((item) => {
if (item.compositeEvent?.reloadTask?.id === task.taskId) {
return true;
}
if (item.compositeEvent?.externalProgramTask?.id === task.taskId) {
return true;
}
return false;
});

// Write schema events to table
if (columnBlockShow.schematrigger) {
Expand Down Expand Up @@ -690,7 +705,7 @@ const getTask = async (options) => {
}

if (columnBlockShow.extprogram) {
headerRow = headerRow.concat(['Path', 'Parameters']);
headerRow = headerRow.concat(['Ext program path', 'Ext program parameters']);
}

if (columnBlockShow.lastexecution) {
Expand Down
55 changes: 15 additions & 40 deletions src/lib/cmd/importtask.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,40 @@ const { getCustomPropertiesFromQseow } = require('../util/customproperties');

const getHeaders = async (options) => {
const records = [];

const parser = fs.createReadStream(options.fileName).pipe(
parse({
info: true,
to_line: 1,
skip_empty_lines: true,
})
);
parser.on('readable', () => {
let record;
while ((record = parser.read()) !== null) {
// Work with each record
records.push(record);

// Get the header row
// eslint-disable-next-line no-restricted-syntax
for await (const record of parser) {
if (record.info.lines === 1) {
// Header row
records.push(record.record);
}
});
await finished(parser);
}

return records;
};

const processCsvFile = async (options) => {
// First get header row

// const parser = parse({
// delimiter: ',',
// info: true,
// // to_line: 1,
// });

// const parser = fs.createReadStream(options.fileName).pipe(
// parse({
// info: true,
// to_line: 1,
// }).pipe(process.stdout)
// );

const headers = await getHeaders(options);

// const headers = fs.createReadStream(options.fileName).pipe(parser).pipe(process.stdout);

// const content = await fsp.readFile(options.fileName);

// Parse the CSV content
// const headers = parse(content, { bom: true, to_line: 1 });

const headerRow = [];

// Push all column headers to array
// eslint-disable-next-line no-restricted-syntax
for (const record of headers) {
for (const record of headers[0]) {
// Get each column header text
headerRow.push(record.record);
headerRow.push(record);
}
// // eslint-disable-next-line no-restricted-syntax
// for await (const record of headers) {
// // for await (const record of parser) {
// // Get each column header text
// headerRow.push(record.record);
// }

// Get positions of column headers
const colHeaders = getTaskColumnPosFromHeaderRow(headerRow[0]);
const colHeaders = getTaskColumnPosFromHeaderRow(headerRow);

const records = [];
const parser = fs.createReadStream(options.fileName).pipe(
Expand Down Expand Up @@ -439,7 +414,7 @@ const importTaskFromFile = async (options) => {
await qlikSenseTasks.init(options, importedApps);
const taskList = await qlikSenseTasks.getTaskModelFromFile(tasksFromFile, tagsExisting, cpExisting);
} catch (err) {
logger.error(`IMPORT TASK: ${err.stack}`);
logger.error(`IMPORT TASK 2: ${err.stack}`);
}
};

Expand Down
Loading

0 comments on commit d6bf1d9

Please sign in to comment.