Skip to content

Commit

Permalink
fix(qseow): Implement missing --dry-run feature for `qseow user-activ…
Browse files Browse the repository at this point in the history
…ity-bucket-cp-create` command

Fixes #543
  • Loading branch information
mountaindude committed Nov 18, 2024
1 parent c61409e commit 473dde3
Showing 1 changed file with 61 additions and 31 deletions.
92 changes: 61 additions & 31 deletions src/lib/cmd/qseow/createuseractivitycp.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,23 @@ export async function createUserActivityBucketsCustomProperty(options) {
const customPropertyDefinition = JSON.parse(JSON.stringify(customPropertyExisting));
customPropertyDefinition.choiceValues = activityBucketsSorted;

const result = await updateCustomProperty(options, customPropertyDefinition);
if (result) {
logger.verbose(
` Updated existing custom property "${options.customPropertyName}" with new allowed values passed in via command line.`
// Is it a dry run?
if (options.dryRun) {
logger.info(
`(${importCount}/${importLimit}) Dry run: Would have updated custom property "${options.customPropertyName}" with activity info`
);
} else {
logger.error(
`Failed to update existing custom property "${options.customPropertyName}" with new allowed values.`
);
return false;
const result = await updateCustomProperty(options, customPropertyDefinition);
if (result) {
logger.verbose(
` Updated existing custom property "${options.customPropertyName}" with new allowed values passed in via command line.`
);
} else {
logger.error(
`Failed to update existing custom property "${options.customPropertyName}" with new allowed values.`
);
return false;
}
}
} else {
// Don't force overwrite the existing custom property.
Expand Down Expand Up @@ -163,14 +170,23 @@ export async function createUserActivityBucketsCustomProperty(options) {
const customPropertyDefinition = JSON.parse(JSON.stringify(customPropertyExisting));
customPropertyDefinition.choiceValues = activityBucketsSorted;

const result = await updateCustomProperty(options, customPropertyDefinition);
if (result) {
logger.verbose(
` Updated existing custom property "${options.customPropertyName}" with new allowed values passed in via command line.`
// Is it a dry run?
if (options.dryRun) {
logger.info(
`(${importCount}/${importLimit}) Dry run: Would have updated custom property "${options.customPropertyName}" to have new activity bucket values.`
);
} else {
logger.error(`Failed to update existing custom property "${options.customPropertyName}" with new allowed values.`);
return false;
const result = await updateCustomProperty(options, customPropertyDefinition);
if (result) {
logger.verbose(
` Updated existing custom property "${options.customPropertyName}" with new allowed values passed in via command line.`
);
} else {
logger.error(
`Failed to update existing custom property "${options.customPropertyName}" with new allowed values.`
);
return false;
}
}
}
}
Expand All @@ -187,12 +203,17 @@ export async function createUserActivityBucketsCustomProperty(options) {
choiceValues: activityBucketsSorted,
};

const result = await createCustomProperty(options, customPropertyDefinition);
if (result) {
logger.verbose(` Created custom property "${options.customPropertyName}"`);
// Is it a dry run?
if (options.dryRun) {
logger.info(`(${importCount}/${importLimit}) Dry run: Would have created custom property "${options.customPropertyName}"`);
} else {
logger.error(`Failed to create custom property "${options.customPropertyName}"`);
return false;
const result = await createCustomProperty(options, customPropertyDefinition);
if (result) {
logger.verbose(` Created custom property "${options.customPropertyName}"`);
} else {
logger.error(`Failed to create custom property "${options.customPropertyName}"`);
return false;
}
}
}

Expand Down Expand Up @@ -554,23 +575,32 @@ export async function createUserActivityBucketsCustomProperty(options) {

// Loop over the users in the batch, writing the user activity custom property to QRS
for (const user of usersBatch) {
// Payload: array of user objects
const axiosConfig = setupQrsConnection(options, {
method: 'put',
path: `qrs/user/${user.id}`,
body: user,
});

const result = await axios.request(axiosConfig);
if (result.status === 200) {
// Is it a dry run?
if (options.dryRun) {
logger.info(
` Updated user ${userCounter} of ${outputUserArray.length}, "${user.userDirectory}\\${user.userId}" in batch ${
`(${importCount}/${importLimit}) Dry run: Would have updated ${userCounter} of ${outputUserArray.length}, "${user.userDirectory}\\${user.userId}" in batch ${
i + 1
} of ${totalBatches}`
);
} else {
logger.error(`Error ${result.status} updating user activity custom property for batch ${i + 1} of ${totalBatches}`);
return false;
// Payload: array of user objects
const axiosConfig = setupQrsConnection(options, {
method: 'put',
path: `qrs/user/${user.id}`,
body: user,
});

const result = await axios.request(axiosConfig);
if (result.status === 200) {
logger.info(
` Updated user ${userCounter} of ${outputUserArray.length}, "${user.userDirectory}\\${user.userId}" in batch ${
i + 1
} of ${totalBatches}`
);
} else {
logger.error(`Error ${result.status} updating user activity custom property for batch ${i + 1} of ${totalBatches}`);
return false;
}
}
userCounter++;

Expand Down

0 comments on commit 473dde3

Please sign in to comment.