diff --git a/CHANGELOG.md b/CHANGELOG.md
index efbec15..a82f15a 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## v2.0.0-beta.34 - 2024-12-18
+
+- The OriginalName property was not set properly
+
## v2.0.0-beta.33 - 2024-12-17
- Follow Nexus changes
diff --git a/src/Nexus.Sources.StructuredFile/StructureFileDataModelExtensions.cs b/src/Nexus.Sources.StructuredFile/StructureFileDataModelExtensions.cs
index ad1fe9a..5d4f53f 100644
--- a/src/Nexus.Sources.StructuredFile/StructureFileDataModelExtensions.cs
+++ b/src/Nexus.Sources.StructuredFile/StructureFileDataModelExtensions.cs
@@ -12,11 +12,6 @@ public static class StructuredFileDataModelExtensions
///
public const string FileSourceIdKey = "file-source-id";
- ///
- /// A constant with the key for a original name property.
- ///
- public const string OriginalNameKey = "original-name";
-
///
/// Adds a file source id property.
///
@@ -28,16 +23,5 @@ public static ResourceBuilder WithFileSourceId(this ResourceBuilder resourceBuil
return resourceBuilder.WithProperty(FileSourceIdKey, fileSourceId);
}
- ///
- /// Adds an original name property.
- ///
- /// The resource builder.
- /// The original name to add.
- /// A resource catalog builder.
- public static ResourceBuilder WithOriginalName(this ResourceBuilder resourceBuilder, string originalName)
- {
- return resourceBuilder.WithProperty(OriginalNameKey, originalName);
- }
-
#endregion
}
diff --git a/src/Nexus.Sources.StructuredFile/StructuredFileDataSource.cs b/src/Nexus.Sources.StructuredFile/StructuredFileDataSource.cs
index e7a0b3d..183c9e4 100644
--- a/src/Nexus.Sources.StructuredFile/StructuredFileDataSource.cs
+++ b/src/Nexus.Sources.StructuredFile/StructuredFileDataSource.cs
@@ -1,5 +1,6 @@
using System.Buffers;
using System.Diagnostics.CodeAnalysis;
+using System.Text.Json;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging;
using Nexus.DataModel;
@@ -501,7 +502,7 @@ protected virtual async Task ReadAsync(
);
var originalName = catalogItem.Resource.Properties?
- .GetStringValue(StructuredFileDataModelExtensions.OriginalNameKey)!;
+ .GetStringValue(DataModelExtensions.OriginalNameKey) ?? throw new Exception("The OriginalName property is not set.");
return new ReadRequest(
OriginalResourceName: originalName,
@@ -744,13 +745,45 @@ async Task IDataSource.EnrichCatalogAsync(
if (catalog.Resources is not null)
{
+ // TODO: code duplication (DataModelExtensions.cs)
+ var isModified = false;
+ var newResources = new List();
+
foreach (var resource in catalog.Resources)
{
- // ensure file source id
- var fileSourceId = resource.Properties?.GetStringValue(StructuredFileDataModelExtensions.FileSourceIdKey);
+ var resourceProperties = resource.Properties;
+ var newResource = resource;
+
+ var originalName = resourceProperties?
+ .GetStringValue(DataModelExtensions.OriginalNameKey);
+
+ if (originalName is null)
+ {
+ var newResourceProperties = resourceProperties is null
+ ? []
+ : resourceProperties!.ToDictionary(entry => entry.Key, entry => entry.Value);
+
+ // Original name
+ if (originalName is null)
+ newResourceProperties[DataModelExtensions.OriginalNameKey] = JsonSerializer.SerializeToElement(resource.Id);
+
+ newResource = resource with
+ {
+ Properties = newResourceProperties
+ };
- if (string.IsNullOrWhiteSpace(fileSourceId))
- throw new Exception($"The resource {resource.Id} is missing the file source property.");
+ isModified = true;
+ }
+
+ newResources.Add(newResource);
+ }
+
+ if (isModified)
+ {
+ catalog = catalog with
+ {
+ Resources = newResources
+ };
}
}
diff --git a/tests/Nexus.Sources.StructuredFile.Tests/StructuredFileDataSourceTests.cs b/tests/Nexus.Sources.StructuredFile.Tests/StructuredFileDataSourceTests.cs
index 0cf3044..526ae14 100644
--- a/tests/Nexus.Sources.StructuredFile.Tests/StructuredFileDataSourceTests.cs
+++ b/tests/Nexus.Sources.StructuredFile.Tests/StructuredFileDataSourceTests.cs
@@ -3,7 +3,6 @@
using Nexus.Extensibility;
using System.Globalization;
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.Json;
using Xunit;
diff --git a/version.json b/version.json
index eef8daf..e3027e8 100755
--- a/version.json
+++ b/version.json
@@ -1,4 +1,4 @@
{
"version": "2.0.0",
- "suffix": "beta.33"
+ "suffix": "beta.34"
}
\ No newline at end of file