Skip to content

Commit b031897

Browse files
authored
Merge pull request #2254 from BEXIS2/rc
Rc
2 parents 6bc4130 + a60528a commit b031897

File tree

4 files changed

+181
-130
lines changed

4 files changed

+181
-130
lines changed

Components/XML/BExIS.Xml.Helpers/BExIS.Xml.Helpers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
</ItemGroup>
7272
<ItemGroup>
7373
<Compile Include="DatasetStore.cs" />
74+
<Compile Include="Extensions\XmlExtensions.cs" />
7475
<Compile Include="Mapping\XmlMapperManager.cs" />
7576
<Compile Include="Mapping\XmlSchemaManager.cs" />
7677
<Compile Include="ExtensionStore.cs" />
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using System.Xml;
5+
6+
namespace BExIS.Xml.Helpers.Extensions
7+
{
8+
public static class XmlExtensions
9+
{
10+
public static void TransformXmlToMatchClassTypes(XmlNode node, Type classType)
11+
{
12+
foreach (XmlNode childNode in node.ChildNodes)
13+
{
14+
string propertyName = childNode.Name;
15+
PropertyInfo propertyInfo = classType.GetProperty(propertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
16+
17+
if (propertyInfo != null)
18+
{
19+
// If it's a list or array type, ensure the XML node appropriately reflects that
20+
if (propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(List<>))
21+
{
22+
Type itemType = propertyInfo.PropertyType.GetGenericArguments()[0];
23+
24+
foreach (XmlNode listItem in childNode.ChildNodes)
25+
{
26+
// Recursively transform the XML node to match the item type of the collection
27+
TransformXmlToMatchClassTypes(listItem, itemType);
28+
}
29+
}
30+
else if (childNode.HasChildNodes)
31+
{
32+
TransformXmlToMatchClassTypes(childNode, propertyInfo.PropertyType);
33+
}
34+
}
35+
else
36+
{
37+
// Handle cases where the property is not found in the class type
38+
Console.WriteLine($"Property '{propertyName}' not found in '{classType.Name}'.");
39+
}
40+
}
41+
}
42+
}
43+
}

Modules/DIM/BExIS.Dim.Helper/Export/GBIFDataRepoConverter.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System;
1616
using System.Collections.Generic;
1717
using System.Data;
18+
using System.Diagnostics;
1819
using System.IO;
1920
using System.IO.Compression;
2021
using System.Linq;
@@ -98,11 +99,11 @@ public string Convert(long datasetVersionId)
9899
{
99100
// generate metadata
100101
string metadataFilePath = helper.GenerateResourceMetadata(concept.Id, metadatastructureId, datasetversion.Metadata, folder, xsdPath);
101-
if (File.Exists(metadataFilePath)) archive.AddFileToArchive(metadataFilePath, "");
102+
if (File.Exists(metadataFilePath)) archive.AddFileToArchive(metadataFilePath, Path.GetFileName(metadataFilePath));
102103

103104
// get data
104105
string datapath = helper.GenerateData(id, versionId);
105-
if (File.Exists(datapath)) archive.AddFileToArchive(datapath, "");
106+
if (File.Exists(datapath)) archive.AddFileToArchive(datapath, Path.GetFileName(datapath));
106107

107108
// has links to extentions? (IsDwcEventOf,IsDwcHumboltExtensionOf, IsEwcEMofExtensionOf)
108109
// has links?
@@ -126,14 +127,14 @@ public string Convert(long datasetVersionId)
126127
var extention = helper.GetExtention(r.ReferenceType);
127128

128129
extentions.Add(new ExtentionEntity() { IdIndex = 0, Version = r.SourceVersion, StructureId = structureId, Extention = extention, dataPath = Path.GetFileName(rPath) });
129-
archive.AddFileToArchive(rPath, "");
130+
archive.AddFileToArchive(rPath, Path.GetFileName(rPath));
130131
}
131132
}
132133
}
133134

134135
// generate meta file
135136
string metaFilePath = helper.GenerateMeta(_type, dataset.DataStructure.Id, folder, Path.GetFileName(datapath), extentions);
136-
if (File.Exists(metaFilePath)) archive.AddFileToArchive(metaFilePath, "");
137+
if (File.Exists(metaFilePath)) archive.AddFileToArchive(metaFilePath, Path.GetFileName(metaFilePath));
137138
}
138139

139140
return zipfilepath;

0 commit comments

Comments
 (0)