Merged PR 798: [4回目実行][フルデータ]develop環境での移行実施後の修正作業
## 概要 [Task3821: [4回目実行][フルデータ]develop環境での移行実施後の修正作業](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3821) - 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず) - 移行ツールに対して以下の修正を実施しました。 - アカウントとユーザ間でAuthorIDが重複する際、通番を付与して重複を避けるようにしました - AADB2Cのエラー発生時、リトライ処理を行うように対応しました ## レビューポイント - 特にありません ## UIの変更 - 無し ## 動作確認状況 - ローカルで確認 ## 補足 - 相談、参考資料などがあれば
This commit is contained in:
parent
88ce6a2c9e
commit
a47ebaa9df
@ -194,6 +194,7 @@ export class TransferController {
|
||||
const transferDuplicateAuthorResultUsers =
|
||||
await this.transferService.transferDuplicateAuthor(
|
||||
context,
|
||||
resultDuplicateEmail.accountsFileLines,
|
||||
resultDuplicateEmail.usersFileLines
|
||||
);
|
||||
|
||||
|
||||
@ -627,11 +627,13 @@ export class TransferService {
|
||||
|
||||
/**
|
||||
* transferDuplicateAuthor
|
||||
* @param accountsFileLines: AccountsFile[]
|
||||
* @param usersFileLines: UsersFile[]
|
||||
* @returns UsersFile[]
|
||||
*/
|
||||
async transferDuplicateAuthor(
|
||||
context: Context,
|
||||
accountsFileLines: AccountsFile[],
|
||||
usersFileLines: UsersFile[]
|
||||
): Promise<UsersFile[]> {
|
||||
// パラメータ内容が長大なのでログには出さない
|
||||
@ -642,35 +644,40 @@ export class TransferService {
|
||||
try {
|
||||
const newUsersFileLines: UsersFile[] = [];
|
||||
|
||||
let processingAccountId: number = 0; //処理中のアカウントID
|
||||
for (const accountsFileLine of accountsFileLines) {
|
||||
let duplicateSequence: number = 2;
|
||||
let authorIdList: String[] = [];
|
||||
for (const user of usersFileLines) {
|
||||
if (user.accountId !== processingAccountId) {
|
||||
//アカウントIDが別になった場合、通番を初期化する
|
||||
duplicateSequence = 2;
|
||||
processingAccountId = user.accountId;
|
||||
authorIdList = [];
|
||||
|
||||
// メールアドレス重複時はアカウントにもAuthorIdが設定されるので重複チェック用のリストに追加しておく
|
||||
if (accountsFileLine.authorId) {
|
||||
authorIdList.push(accountsFileLine.authorId);
|
||||
}
|
||||
let assignAuthorId = user.authorId;
|
||||
if (authorIdList.includes(user.authorId)) {
|
||||
|
||||
const targetaccountUsers = usersFileLines.filter(
|
||||
(item) => item.accountId === accountsFileLine.accountId
|
||||
);
|
||||
|
||||
for (const targetaccountUser of targetaccountUsers) {
|
||||
let assignAuthorId = targetaccountUser.authorId;
|
||||
if (authorIdList.includes(targetaccountUser.authorId)) {
|
||||
// 同じauthorIdがいる場合、自分のauthorIdに連番を付与する
|
||||
assignAuthorId = assignAuthorId + duplicateSequence;
|
||||
duplicateSequence = duplicateSequence + 1;
|
||||
}
|
||||
authorIdList.push(user.authorId);
|
||||
authorIdList.push(targetaccountUser.authorId);
|
||||
|
||||
// 新しいAuthorIdのユーザに詰め替え
|
||||
const newUser: UsersFile = {
|
||||
accountId: user.accountId,
|
||||
userId: user.userId,
|
||||
name: user.name,
|
||||
role: user.role,
|
||||
accountId: targetaccountUser.accountId,
|
||||
userId: targetaccountUser.userId,
|
||||
name: targetaccountUser.name,
|
||||
role: targetaccountUser.role,
|
||||
authorId: assignAuthorId,
|
||||
email: user.email,
|
||||
email: targetaccountUser.email,
|
||||
};
|
||||
newUsersFileLines.push(newUser);
|
||||
}
|
||||
}
|
||||
|
||||
return newUsersFileLines;
|
||||
} catch (e) {
|
||||
|
||||
@ -64,6 +64,11 @@ export class AdB2cService {
|
||||
this.logger.log(
|
||||
`[IN] [${context.getTrackingId()}] ${this.createUser.name}`
|
||||
);
|
||||
|
||||
const retryCount: number = 3;
|
||||
let retry = 0;
|
||||
|
||||
while (retry < retryCount) {
|
||||
try {
|
||||
// ユーザをADB2Cに登録
|
||||
const newUser = await this.graphClient.api("users/").post({
|
||||
@ -88,6 +93,7 @@ export class AdB2cService {
|
||||
return { sub: newUser.id };
|
||||
} catch (e) {
|
||||
this.logger.error(`[${context.getTrackingId()}] error=${e}`);
|
||||
|
||||
if (e?.statusCode === 400 && e?.body) {
|
||||
const error = JSON.parse(e.body);
|
||||
|
||||
@ -97,13 +103,20 @@ export class AdB2cService {
|
||||
}
|
||||
}
|
||||
|
||||
if (++retry < retryCount) {
|
||||
this.logger.log(`ADB2Cエラー発生。5秒sleepしてリトライします (${retry}/${retryCount})...`);
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
} else {
|
||||
this.logger.log(`リトライ数が上限に達したのでエラーを返却します`);
|
||||
throw e;
|
||||
}
|
||||
} finally {
|
||||
this.logger.log(
|
||||
`[OUT] [${context.getTrackingId()}] ${this.createUser.name}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets users
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user