経緯・趣旨
あるコレクションのフィールド全体が英語名になっているため、全て日本語に変換したい。
変換マスタはコレクションとして用意できているが、各フィールド名をループで見回って、Utility - Collection Manipulation::Set Collection Fieldで変換していくのはちょっとスマートではない。
方法
変換マスタに従い、変換したフィールド名のリストをコレクションとして出力し、そのコレクションをUtility - Collection Manipulation::Rename Collection Fieldsを使って一気に入れ替える。
今回作成したアクションは前者の「変換マスタに従い、変換したフィールド名のリストをコレクションとして出力」までを行います。
アクション全体
Utility - Collection Manipulation を拡張し、フィールド名をマッチングして返却アクションを作成しました。
入力
名前 | 説明 | データ型 | 保管先 |
---|---|---|---|
Collection In | フィールド名を変換したいコレクション | コレクション | Collection In |
Master Collection | フィールド名の変換マッチングマスタ | コレクション | Master Collection |
Target Column Name | 変換対象のフィールド名 | テキスト | Target Column Name |
Master Key Column Name | マスタの検索キーとなるフィールド名 | テキスト | Master Key Column Name |
Master Convert Column Name | 変換後の名前が格納されているフィールド名 | テキスト | Master Convert Column Name |
出力
名前 | 説明 | データ型 | 保管先 |
---|---|---|---|
Collection Out | コレクション | Collection Out |
コード
入力
※オブジェクトの入力と同じ
出力
名前 | データ型 | 保管先 |
---|---|---|
Collection Out | コレクション | Collection Out |
Success | フラグ | Success |
Message | テキスト | Message |
コード
Try
Dim count As Integer = 1
Dim Convert_Header_Collection As New DataTable()
Convert_Header_Collection.Columns.Add("Name", GetType(String))
For Each InCol As DataColumn In Collection_In.Columns
Dim chRow = Convert_Header_Collection.NewRow
Dim columnExistFlg As Boolean = False
For Each m_row In Master_Collection.Rows
If m_row(Master_Key_Column_Name) = InCol.ColumnName Then
chRow("Name") = m_row(Master_Convert_Column_Name)
columnExistFlg = True
Exit For
End If
Next
If Not columnExistFlg Then
chRow("Name") = "Column" & count
count += 1
End If
Convert_Header_Collection.Rows.Add(chRow)
Next
Collection_Out = Convert_Header_Collection
Success = True
Catch e as Exception()
Message = e.ToString()
Success = False
End Try
結果
以下、各テスト用のコレクション、データアイテムの値をセットします。
Collection In Test
Master Collection Test
フィールドm1とm2にフィールド名の返還前後のパラメータを入れています。
アクションページの冒頭で各テスト用パラメータをセットしています。
今回の例は、コレクション:Collection In Testのフィールド:フィールドc1を、マスタのフィールド:フィールドm2に格納されている名前に変換する例です。
実行結果
Collection Out
フィールドc1, c2は変換マスタに従って、それぞれテスト1, テスト2に変換されていることが分かるかと思います。
フィールドc3については変換マスタにデータがなかったため、Column1という名前が自動的に命名されています。