Skip to content

Commit 62222cf

Browse files
authored
adjust handling of default value (#2439)
Improve `FieldToFieldMap` according to #2437.
2 parents 857d378 + 68969de commit 62222cf

File tree

1 file changed

+26
-22
lines changed
  • src/MigrationTools.Clients.TfsObjectModel/Tools/FieldMappingTool/FieldMaps

1 file changed

+26
-22
lines changed
Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
1-
using Microsoft.Extensions.Logging;
1+
using System;
2+
using Microsoft.Extensions.Logging;
23
using Microsoft.TeamFoundation.WorkItemTracking.Client;
3-
using MigrationTools._EngineV1.Configuration;
44
using MigrationTools.Tools;
55
using MigrationTools.Tools.Infrastructure;
66

7-
namespace MigrationTools.FieldMaps.AzureDevops.ObjectModel
7+
namespace MigrationTools.FieldMaps.AzureDevops.ObjectModel;
8+
9+
#nullable enable
10+
11+
public class FieldToFieldMap : FieldMapBase
812
{
9-
public class FieldToFieldMap : FieldMapBase
13+
public override string MappingDisplayName => $"{Config.sourceField} {Config.targetField}";
14+
private FieldToFieldMapOptions Config => (FieldToFieldMapOptions)_Config;
15+
16+
public FieldToFieldMap(ILogger<FieldToFieldMap> logger, ITelemetryLogger telemetryLogger) : base(logger, telemetryLogger)
1017
{
11-
public FieldToFieldMap(ILogger<FieldToFieldMap> logger, ITelemetryLogger telemetryLogger) : base(logger, telemetryLogger)
12-
{
13-
}
18+
}
1419

15-
public override string MappingDisplayName => $"{Config.sourceField} {Config.targetField}";
16-
private FieldToFieldMapOptions Config { get { return (FieldToFieldMapOptions)_Config; } }
20+
public override void Configure(IFieldMapOptions config)
21+
{
22+
base.Configure(config);
23+
}
1724

18-
public override void Configure(IFieldMapOptions config)
25+
internal override void InternalExecute(WorkItem source, WorkItem target)
26+
{
27+
if (!source.Fields.Contains(Config.sourceField) || !target.Fields.Contains(Config.targetField))
1928
{
20-
base.Configure(config);
29+
return;
2130
}
2231

23-
internal override void InternalExecute(WorkItem source, WorkItem target)
32+
var value = Convert.ToString(source.Fields[Config.sourceField]?.Value);
33+
if (string.IsNullOrEmpty(value) && Config.defaultValue is not null)
2434
{
25-
if (source.Fields.Contains(Config.sourceField) && target.Fields.Contains(Config.targetField))
26-
{
27-
var value = source.Fields[Config.sourceField].Value;
28-
if ((value as string is null || value as string == "") && Config.defaultValue != null)
29-
{
30-
value = Config.defaultValue;
31-
}
32-
target.Fields[Config.targetField].Value = value;
33-
Log.LogDebug("FieldToFieldMap: [UPDATE] field mapped {0}:{1} to {2}:{3}", source.Id, Config.sourceField, target.Id, Config.targetField);
34-
}
35+
value = Config.defaultValue;
3536
}
37+
38+
target.Fields[Config.targetField].Value = value;
39+
Log.LogDebug("FieldToFieldMap: [UPDATE] field mapped {0}:{1} to {2}:{3}", source.Id, Config.sourceField, target.Id, Config.targetField);
3640
}
3741
}

0 commit comments

Comments
 (0)