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 =
|
const transferDuplicateAuthorResultUsers =
|
||||||
await this.transferService.transferDuplicateAuthor(
|
await this.transferService.transferDuplicateAuthor(
|
||||||
context,
|
context,
|
||||||
|
resultDuplicateEmail.accountsFileLines,
|
||||||
resultDuplicateEmail.usersFileLines
|
resultDuplicateEmail.usersFileLines
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -627,11 +627,13 @@ export class TransferService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* transferDuplicateAuthor
|
* transferDuplicateAuthor
|
||||||
|
* @param accountsFileLines: AccountsFile[]
|
||||||
* @param usersFileLines: UsersFile[]
|
* @param usersFileLines: UsersFile[]
|
||||||
* @returns UsersFile[]
|
* @returns UsersFile[]
|
||||||
*/
|
*/
|
||||||
async transferDuplicateAuthor(
|
async transferDuplicateAuthor(
|
||||||
context: Context,
|
context: Context,
|
||||||
|
accountsFileLines: AccountsFile[],
|
||||||
usersFileLines: UsersFile[]
|
usersFileLines: UsersFile[]
|
||||||
): Promise<UsersFile[]> {
|
): Promise<UsersFile[]> {
|
||||||
// パラメータ内容が長大なのでログには出さない
|
// パラメータ内容が長大なのでログには出さない
|
||||||
@ -642,35 +644,40 @@ export class TransferService {
|
|||||||
try {
|
try {
|
||||||
const newUsersFileLines: UsersFile[] = [];
|
const newUsersFileLines: UsersFile[] = [];
|
||||||
|
|
||||||
let processingAccountId: number = 0; //処理中のアカウントID
|
for (const accountsFileLine of accountsFileLines) {
|
||||||
let duplicateSequence: number = 2;
|
let duplicateSequence: number = 2;
|
||||||
let authorIdList: String[] = [];
|
let authorIdList: String[] = [];
|
||||||
for (const user of usersFileLines) {
|
|
||||||
if (user.accountId !== processingAccountId) {
|
// メールアドレス重複時はアカウントにもAuthorIdが設定されるので重複チェック用のリストに追加しておく
|
||||||
//アカウントIDが別になった場合、通番を初期化する
|
if (accountsFileLine.authorId) {
|
||||||
duplicateSequence = 2;
|
authorIdList.push(accountsFileLine.authorId);
|
||||||
processingAccountId = user.accountId;
|
|
||||||
authorIdList = [];
|
|
||||||
}
|
}
|
||||||
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に連番を付与する
|
// 同じauthorIdがいる場合、自分のauthorIdに連番を付与する
|
||||||
assignAuthorId = assignAuthorId + duplicateSequence;
|
assignAuthorId = assignAuthorId + duplicateSequence;
|
||||||
duplicateSequence = duplicateSequence + 1;
|
duplicateSequence = duplicateSequence + 1;
|
||||||
}
|
}
|
||||||
authorIdList.push(user.authorId);
|
authorIdList.push(targetaccountUser.authorId);
|
||||||
|
|
||||||
// 新しいAuthorIdのユーザに詰め替え
|
// 新しいAuthorIdのユーザに詰め替え
|
||||||
const newUser: UsersFile = {
|
const newUser: UsersFile = {
|
||||||
accountId: user.accountId,
|
accountId: targetaccountUser.accountId,
|
||||||
userId: user.userId,
|
userId: targetaccountUser.userId,
|
||||||
name: user.name,
|
name: targetaccountUser.name,
|
||||||
role: user.role,
|
role: targetaccountUser.role,
|
||||||
authorId: assignAuthorId,
|
authorId: assignAuthorId,
|
||||||
email: user.email,
|
email: targetaccountUser.email,
|
||||||
};
|
};
|
||||||
newUsersFileLines.push(newUser);
|
newUsersFileLines.push(newUser);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return newUsersFileLines;
|
return newUsersFileLines;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@ -64,6 +64,11 @@ export class AdB2cService {
|
|||||||
this.logger.log(
|
this.logger.log(
|
||||||
`[IN] [${context.getTrackingId()}] ${this.createUser.name}`
|
`[IN] [${context.getTrackingId()}] ${this.createUser.name}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const retryCount: number = 3;
|
||||||
|
let retry = 0;
|
||||||
|
|
||||||
|
while (retry < retryCount) {
|
||||||
try {
|
try {
|
||||||
// ユーザをADB2Cに登録
|
// ユーザをADB2Cに登録
|
||||||
const newUser = await this.graphClient.api("users/").post({
|
const newUser = await this.graphClient.api("users/").post({
|
||||||
@ -88,6 +93,7 @@ export class AdB2cService {
|
|||||||
return { sub: newUser.id };
|
return { sub: newUser.id };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`[${context.getTrackingId()}] error=${e}`);
|
this.logger.error(`[${context.getTrackingId()}] error=${e}`);
|
||||||
|
|
||||||
if (e?.statusCode === 400 && e?.body) {
|
if (e?.statusCode === 400 && e?.body) {
|
||||||
const error = JSON.parse(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;
|
throw e;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
`[OUT] [${context.getTrackingId()}] ${this.createUser.name}`
|
`[OUT] [${context.getTrackingId()}] ${this.createUser.name}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets users
|
* Gets users
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user