61c6278bd0
Decision 2.8: preserve-if-null on the server. UpdateSiteCommand, UpdateDataConnectionCommand and UpdateApiMethodCommand fields (except the id) are now nullable; the ManagementActor handlers apply only non-null values and treat an empty string as 'clear this optional field'. The CLI update commands no longer require --name/--protocol/--script and drop the --failover-retry-count (3) and --timeout (30) defaults, so an omitted option travels as null instead of overwriting the stored value (site update --name used to null both gRPC addresses). The site gRPC-address validation now runs on the merged values. Additive/compatible: the fields only became nullable, so an older CLI that always sends every field still deserializes (pinned by a test) and now simply updates every field as before. The Central UI full-entity forms send "" for a field the operator cleared (description/addresses, removed backup endpoint, cleared parameter/return definitions) so clearing keeps working.
20 lines
1.1 KiB
C#
20 lines
1.1 KiB
C#
namespace ZB.MOM.WW.ScadaBridge.ManagementService;
|
|
|
|
/// <summary>
|
|
/// Preserve-if-null merge rules for the partial update commands (CLI-2):
|
|
/// <c>UpdateSiteCommand</c>, <c>UpdateDataConnectionCommand</c> and
|
|
/// <c>UpdateApiMethodCommand</c>. A <c>null</c> field means "not supplied — keep the
|
|
/// stored value"; an empty (or whitespace-only) string means "clear this optional
|
|
/// field". The CLI sends only the options that were actually passed, and the Central
|
|
/// UI's full-entity forms send an empty string for a field the operator cleared.
|
|
/// </summary>
|
|
internal static class PartialUpdate
|
|
{
|
|
/// <summary>Merges an optional (nullable) string field.</summary>
|
|
/// <param name="incoming">The value carried by the command, or <c>null</c> when not supplied.</param>
|
|
/// <param name="stored">The value currently stored.</param>
|
|
/// <returns><paramref name="stored"/> when <paramref name="incoming"/> is null; null when it is blank; otherwise <paramref name="incoming"/>.</returns>
|
|
public static string? Optional(string? incoming, string? stored) =>
|
|
incoming is null ? stored : string.IsNullOrWhiteSpace(incoming) ? null : incoming;
|
|
}
|