Skip to content

Commit

Permalink
#139: cli output improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Mar 22, 2023
1 parent 05e7d96 commit 2b17aea
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions lib/metadataTypes/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,12 @@ class User extends MetadataType {
operator: 'AND',
rightOperand: requestParams.filter,
};
} else {
// if we are not filtering by key the following requests will take long. Warn the user
Util.logger.info(` - Loading ${this.definition.type}s. This might take a while...`);
}

// get actual user details
Util.logger.info(` - Loading ${this.definition.type}. This might take a while...`);
return this.retrieveSOAP(retrieveDir, requestParams, key);
}

Expand Down Expand Up @@ -658,16 +660,19 @@ class User extends MetadataType {
const metadata = this.parseResponseBody(resultsBulk);
// get BUs that each users have access to
if (resultsBulk?.Results?.length > 0) {
if (!singleRetrieve) {
Util.logger.info(
Util.getGrayMsg(` - found ${resultsBulk?.Results.length} users`)
);
}
// split array resultsBulk?.Results into chunks to avoid not getting all roles
const chunkSize = 100;
this.userIdBuMap = {};
Util.logger.info(' - Caching dependent Metadata: Business Unit assignments');
Util.logger.info(` - Caching dependent Metadata: Business Unit assignments`);
for (let i = 0; i < resultsBulk?.Results?.length; i += chunkSize) {
if (i > 0) {
Util.logger.info(
Util.getGrayMsg(
` - Requesting next batch (already retrieved BUs for ${i} of ${resultsBulk.Results.length} users)`
)
Util.getGrayMsg(` - Requesting next batch (retrieved BUs for ${i} users)`)
);
}
const chunk = resultsBulk?.Results?.slice(i, i + chunkSize);
Expand Down Expand Up @@ -703,7 +708,31 @@ class User extends MetadataType {
`Downloaded: ${this.definition.type} (${Object.keys(savedMetadata).length})` +
Util.getKeysString(singleRetrieve)
);
if (!singleRetrieve) {
// print summary to cli
const counter = {
userActive: 0,
userInactive: 0,
installedPackage: 0,
};
for (const id in savedMetadata) {
const item = savedMetadata[id];
if (item.c__type === 'Installed Package') {
counter.installedPackage++;
} else if (item.ActiveFlag) {
counter.userActive++;
} else {
counter.userInactive++;
}
}
Util.logger.info(
Util.getGrayMsg(
`Found ${counter.userActive} active users / ${counter.userInactive} inactive users / ${counter.installedPackage} installed packages`
)
);
}
if (
!singleRetrieve &&
this.buObject &&
this.properties.metaDataTypes.documentOnRetrieve.includes(this.definition.type)
) {
Expand Down Expand Up @@ -863,28 +892,6 @@ class User extends MetadataType {
}
}

// print summary to cli
const counter = {
userActive: 0,
userInactive: 0,
installedPackage: 0,
};
for (const id in metadata) {
const item = metadata[id];
if (item.c__type === 'Installed Package') {
counter.installedPackage++;
} else if (item.ActiveFlag) {
counter.userActive++;
} else {
counter.userInactive++;
}
}
Util.logger.info(
Util.getGrayMsg(
`Found ${counter.userActive} active users / ${counter.userInactive} inactive users / ${counter.installedPackage} installed packages`
)
);

// init map of BU Ids > BU Name
this._getBuNames();

Expand Down

0 comments on commit 2b17aea

Please sign in to comment.