Skip to content

Commit 4aff69a

Browse files
authored
Add fieldMapMode to FieldToFieldMap and update related documentation (#2957)
This pull request adds a new `fieldMapMode` option to the FieldToFieldMap configuration, allowing users to specify how fields are mapped during migration—either from the source to the target system or between target fields. The update includes code changes, schema updates, documentation, and example configurations to support this new feature. **Field Mapping Mode Feature:** * Introduced the `FieldMapMode` enum with `SourceToTarget` and `TargetToTarget` options, and added the `fieldMapMode` property to `FieldToFieldMapOptions`, defaulting to `SourceToTarget`. This allows users to control the direction and context of field mapping. [[1]](diffhunk://#diff-81182bfd75331f6d5d0de7c559392ef9f61f2c0b7636cde99743276795186f21R3-R31) [[2]](diffhunk://#diff-81182bfd75331f6d5d0de7c559392ef9f61f2c0b7636cde99743276795186f21R53) * Updated the `InternalExecute` method in `FieldToFieldMap.cs` to use the new `fieldMapMode` property, determining whether to map from the source or target field, and improved logging to reflect the mapping mode used. **Schema and Documentation Updates:** * Added `fieldMapMode` to relevant JSON schema files (`configuration.schema.json`, `schema.fieldmaps.fieldtofieldmap.json`, `schema.tools.fieldmappingtool.json`) with descriptions and default values, ensuring configuration validation and discoverability. [[1]](diffhunk://#diff-52f03d9f526916598fa826728ae4633eae3ac279b3dd76548f1e6fdb93686ae4R1925-R1929) [[2]](diffhunk://#diff-08b834ba0de2813a02c071d1dfb9f98d0c6ac07c677008117f4d347c57fe42ffR20-R24) [[3]](diffhunk://#diff-8f718075f4ee2192874e43b363e8f395b1d9beb3f3024abd75a21fb64ed2f306R192-R196) * Updated documentation and YAML reference files to include the new `fieldMapMode` option in configuration samples and parameter lists, providing clear guidance and usage examples. [[1]](diffhunk://#diff-996da70e5724b7d991c1ad90fe0dc3d90658e67c22b3f787a8e5f3798ca2c507R57) [[2]](diffhunk://#diff-996da70e5724b7d991c1ad90fe0dc3d90658e67c22b3f787a8e5f3798ca2c507R89-R94) [[3]](diffhunk://#diff-d7cdd7597baae20026f0d5712a1fbba7d3daf959928a6001720f6d93e8d3c5f3R71) **Miscellaneous:** * Added a missing `using System.Windows.Forms;` directive in `FieldToFieldMap.cs`
2 parents 9626086 + 9056a47 commit 4aff69a

File tree

7 files changed

+60
-8
lines changed

7 files changed

+60
-8
lines changed

docs/content/docs/how-to/migrating-plans-and-suites/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ The important bits:
6868
"FieldMaps": [
6969
{
7070
"FieldMapType": "FieldToFieldMap",
71+
"fieldMapMode": "TargetToTarget",
7172
"sourceField": "Custom.ReflectedWorkItemId",
7273
"targetField": "Microsoft.VSTS.Build.IntegrationBuild",
7374
"defaultValue": "",

docs/data/classes/reference.fieldmaps.fieldtofieldmap.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ configurationSamples:
5454
code: >-
5555
{
5656
"$type": "FieldToFieldMapOptions",
57+
"fieldMapMode": "SourceToTarget",
5758
"sourceField": "Microsoft.VSTS.Common.BacklogPriority",
5859
"targetField": "Microsoft.VSTS.Common.StackRank",
5960
"defaultValue": "42",
@@ -85,6 +86,12 @@ options:
8586
defaultValue: missing XML code comments
8687
isRequired: false
8788
dotNetType: System.Boolean, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
89+
- parameterName: fieldMapMode
90+
type: FieldMapMode
91+
description: Gets or sets the mode of field mapping to be applied during migration. SourceToTarget will get data from the source system and apply it to the target. TargetToTarget will move data between the target fields.
92+
defaultValue: SourceToTarget
93+
isRequired: false
94+
dotNetType: MigrationTools.Tools.FieldMapMode, MigrationTools, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
8895
- parameterName: sourceField
8996
type: String
9097
description: Gets or sets the name of the source field to copy data from during migration.

docs/static/schema/configuration.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,11 @@
19221922
"description": "If set to `true` then the Fieldmap will run. Set to `false` and the processor will not run.",
19231923
"type": "boolean"
19241924
},
1925+
"fieldMapMode": {
1926+
"description": "Gets or sets the mode of field mapping to be applied during migration. SourceToTarget will get data from the source system and apply it to the target. TargetToTarget will move data between the target fields.",
1927+
"type": "string",
1928+
"default": "SourceToTarget"
1929+
},
19251930
"sourceField": {
19261931
"description": "Gets or sets the name of the source field to copy data from during migration.",
19271932
"type": "string"

docs/static/schema/schema.fieldmaps.fieldtofieldmap.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
"description": "If set to `true` then the Fieldmap will run. Set to `false` and the processor will not run.",
1818
"type": "boolean"
1919
},
20+
"fieldMapMode": {
21+
"description": "Gets or sets the mode of field mapping to be applied during migration. SourceToTarget will get data from the source system and apply it to the target. TargetToTarget will move data between the target fields.",
22+
"type": "string",
23+
"default": "SourceToTarget"
24+
},
2025
"sourceField": {
2126
"description": "Gets or sets the name of the source field to copy data from during migration.",
2227
"type": "string"

docs/static/schema/schema.tools.fieldmappingtool.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@
189189
"description": "If set to `true` then the Fieldmap will run. Set to `false` and the processor will not run.",
190190
"type": "boolean"
191191
},
192+
"fieldMapMode": {
193+
"description": "Gets or sets the mode of field mapping to be applied during migration. SourceToTarget will get data from the source system and apply it to the target. TargetToTarget will move data between the target fields.",
194+
"type": "string",
195+
"default": "SourceToTarget"
196+
},
192197
"sourceField": {
193198
"description": "Gets or sets the name of the source field to copy data from during migration.",
194199
"type": "string"

src/MigrationTools.Clients.TfsObjectModel/Tools/FieldMappingTool/FieldMaps/FieldToFieldMap.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Windows.Forms;
23
using Microsoft.Extensions.Logging;
34
using Microsoft.TeamFoundation.WorkItemTracking.Client;
45
using MigrationTools.Tools;
@@ -40,14 +41,23 @@ internal override void InternalExecute(WorkItem source, WorkItem target)
4041
{
4142
return;
4243
}
43-
44-
var value = Convert.ToString(source.Fields[Config.sourceField]?.Value);
44+
string value;
45+
switch (Config.fieldMapMode)
46+
{
47+
case FieldMapMode.SourceToTarget:
48+
value = Convert.ToString(source.Fields[Config.sourceField]?.Value);
49+
break;
50+
case FieldMapMode.TargetToTarget:
51+
value = Convert.ToString(target.Fields[Config.sourceField]?.Value);
52+
break;
53+
default:
54+
throw new ArgumentOutOfRangeException();
55+
}
4556
if (string.IsNullOrEmpty(value) && Config.defaultValue is not null)
4657
{
4758
value = Config.defaultValue;
4859
}
49-
5060
target.Fields[Config.targetField].Value = value;
51-
Log.LogDebug("FieldToFieldMap: [UPDATE] field mapped {0}:{1} to {2}:{3}", source.Id, Config.sourceField, target.Id, Config.targetField);
61+
Log.LogDebug("FieldToFieldMap: [UPDATE] field mapped {0}:{1} to {2}:{3} as {4}", source.Id, Config.sourceField, target.Id, Config.targetField, Config.fieldMapMode.ToString());
5262
}
53-
}
63+
}

src/MigrationTools/Tools/FieldMappingTool/FieldMaps/FieldtoFieldMapOptions.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,44 @@
11

22
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Converters;
35
using MigrationTools.Tools.Infrastructure;
46

57
namespace MigrationTools.Tools
68
{
9+
10+
[JsonConverter(typeof(StringEnumConverter))]
11+
public enum FieldMapMode
12+
{
13+
SourceToTarget = 0,
14+
TargetToTarget = 1
15+
}
16+
17+
718
/// <summary>
819
/// Just want to map one field to another? This is the one for you.
920
/// </summary>
1021
/// <status>ready</status>
1122
/// <processingtarget>Work Item Field</processingtarget>
1223
public class FieldToFieldMapOptions : FieldMapOptions
1324
{
25+
26+
/// <summary>
27+
/// Gets or sets the mode of field mapping to be applied during migration. SourceToTarget will get data from the source system and apply it to the target. TargetToTarget will move data between the target fields.
28+
/// </summary>
29+
/// <default>SourceToTarget</default>
30+
public FieldMapMode fieldMapMode { get; set; } = FieldMapMode.SourceToTarget;
31+
1432
/// <summary>
1533
/// Gets or sets the name of the source field to copy data from during migration.
1634
/// </summary>
1735
public string sourceField { get; set; }
18-
36+
1937
/// <summary>
2038
/// Gets or sets the name of the target field to copy data to during migration.
2139
/// </summary>
2240
public string targetField { get; set; }
23-
41+
2442
/// <summary>
2543
/// Gets or sets the default value to use when the source field is empty or null.
2644
/// </summary>
@@ -32,6 +50,7 @@ public void SetExampleConfigDefaults()
3250
sourceField = "System.StackRank";
3351
targetField = "System.Rank";
3452
defaultValue = "1000";
53+
fieldMapMode = FieldMapMode.SourceToTarget;
3554
}
3655
}
37-
}
56+
}

0 commit comments

Comments
 (0)