Skip to content

Commit

Permalink
adjust handling of default value
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaeurle committed Oct 9, 2024
1 parent 1a70e4d commit 63b2f3e
Showing 1 changed file with 26 additions and 22 deletions.
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);
}
}

0 comments on commit 63b2f3e

Please sign in to comment.