1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import DomainAccountRequest from '../bean/request/DomainAccountRequest'; 16import DomainAccountResponse from '../bean/response/DomainAccountResponse'; 17import CommonUtil from '../common/CommonUtil'; 18import { HiLog } from '../common/HiLog'; 19 20const TAG = 'DomainAccountConvertor'; 21 22export default class DomainAccountConvertor { 23 24 private static readonly DOMAIN_ACCOUNT_TYPE_IDAAS = 2; 25 26 public static convertBatchToDomainAccountReq(searchArray: string[], accountName: string, accountId: string): 27 DomainAccountRequest { 28 let result: DomainAccountRequest = new DomainAccountRequest(); 29 result.setAccountName(CommonUtil.encodeByBase64(accountName)); 30 result.setAccountId(CommonUtil.encodeByBase64(accountId)); 31 result.setAccountType(this.DOMAIN_ACCOUNT_TYPE_IDAAS); 32 result.setKeywordsList(searchArray); 33 return result; 34 } 35 36 public static convertToDomainAccountResp(origin: string): DomainAccountResponse { 37 let result: DomainAccountResponse = new DomainAccountResponse(); 38 if (CommonUtil.isEmptyStr(origin)) { 39 return result; 40 } 41 try { 42 let obj = JSON.parse(origin); 43 result.setErrorCode(obj.errorCode); 44 result.setErrorMsg(obj.errorMsg); 45 result.setData(obj.result); 46 } catch (error) { 47 HiLog.error(TAG, `convertToDomainAccountResp result: ${error}`); 48 } 49 return result; 50 } 51 52 53 54}