-
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adjust handling of default value (#2439)
Improve `FieldToFieldMap` according to #2437.
- Loading branch information
Showing
1 changed file
with
26 additions
and
22 deletions.
There are no files selected for viewing
48 changes: 26 additions & 22 deletions
48
...MigrationTools.Clients.TfsObjectModel/Tools/FieldMappingTool/FieldMaps/FieldToFieldMap.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,41 @@ | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.TeamFoundation.WorkItemTracking.Client; | ||
using MigrationTools._EngineV1.Configuration; | ||
using MigrationTools.Tools; | ||
using MigrationTools.Tools.Infrastructure; | ||
|
||
namespace MigrationTools.FieldMaps.AzureDevops.ObjectModel | ||
namespace MigrationTools.FieldMaps.AzureDevops.ObjectModel; | ||
|
||
#nullable enable | ||
|
||
public class FieldToFieldMap : FieldMapBase | ||
{ | ||
public class FieldToFieldMap : FieldMapBase | ||
public override string MappingDisplayName => $"{Config.sourceField} {Config.targetField}"; | ||
private FieldToFieldMapOptions Config => (FieldToFieldMapOptions)_Config; | ||
|
||
public FieldToFieldMap(ILogger<FieldToFieldMap> logger, ITelemetryLogger telemetryLogger) : base(logger, telemetryLogger) | ||
{ | ||
public FieldToFieldMap(ILogger<FieldToFieldMap> logger, ITelemetryLogger telemetryLogger) : base(logger, telemetryLogger) | ||
{ | ||
} | ||
} | ||
|
||
public override string MappingDisplayName => $"{Config.sourceField} {Config.targetField}"; | ||
private FieldToFieldMapOptions Config { get { return (FieldToFieldMapOptions)_Config; } } | ||
public override void Configure(IFieldMapOptions config) | ||
{ | ||
base.Configure(config); | ||
} | ||
|
||
public override void Configure(IFieldMapOptions config) | ||
internal override void InternalExecute(WorkItem source, WorkItem target) | ||
{ | ||
if (!source.Fields.Contains(Config.sourceField) || !target.Fields.Contains(Config.targetField)) | ||
{ | ||
base.Configure(config); | ||
return; | ||
} | ||
|
||
internal override void InternalExecute(WorkItem source, WorkItem target) | ||
var value = Convert.ToString(source.Fields[Config.sourceField]?.Value); | ||
if (string.IsNullOrEmpty(value) && Config.defaultValue is not null) | ||
{ | ||
if (source.Fields.Contains(Config.sourceField) && target.Fields.Contains(Config.targetField)) | ||
{ | ||
var value = source.Fields[Config.sourceField].Value; | ||
if ((value as string is null || value as string == "") && Config.defaultValue != null) | ||
{ | ||
value = Config.defaultValue; | ||
} | ||
target.Fields[Config.targetField].Value = value; | ||
Log.LogDebug("FieldToFieldMap: [UPDATE] field mapped {0}:{1} to {2}:{3}", source.Id, Config.sourceField, target.Id, Config.targetField); | ||
} | ||
value = Config.defaultValue; | ||
} | ||
|
||
target.Fields[Config.targetField].Value = value; | ||
Log.LogDebug("FieldToFieldMap: [UPDATE] field mapped {0}:{1} to {2}:{3}", source.Id, Config.sourceField, target.Id, Config.targetField); | ||
} | ||
} |