Skip to content

Commit ed41bc9

Browse files
committed
#2147 add download informations to general metadata
1 parent a00d89d commit ed41bc9

File tree

6 files changed

+77
-9
lines changed

6 files changed

+77
-9
lines changed

Components/IO/BExIS.Io/IoHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public static string GetFileName(FileType type, long datasetId, int versionNr, l
4444

4545
string downloadTitle = title.Replace(" ", "");
4646

47+
// tag vs version?
48+
4749
switch (type)
4850
{
4951
case FileType.Metadata:
@@ -71,7 +73,7 @@ public static string GetFileName(FileType type, long datasetId, int versionNr, l
7173
downloadName = string.Format("{0}_{1}_v{2}_{3}_{4}", appName, datasetId, versionNr, downloadTitle, downloadDate);
7274
break;
7375
case FileType.Manifest:
74-
downloadName = string.Format("{0}_{1}_v{2}_general-metadata", appName, datasetId, versionNr);
76+
downloadName = string.Format("{0}_{1}_v{2}_general_metadata", appName, datasetId, versionNr);
7577
break;
7678
default:
7779
downloadName = string.Format("{0}_{1}_v{2}_{3}", appName, datasetId, versionNr, title);

Console/BExIS.Web.Shell/Areas/DIM/BExIS.Modules.Dim.UI/BExIS.Modules.Dim.UI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@
515515
<Compile Include="Models\DataCiteDOIModels.cs" />
516516
<Compile Include="Models\DatasetModel.cs" />
517517
<Compile Include="Models\DatasetVersionModel.cs" />
518+
<Compile Include="Models\Download\GeneralMetadataModel.cs" />
518519
<Compile Include="Models\GbifModels.cs" />
519520
<Compile Include="Models\Export\SimpleDataStructureModel.cs" />
520521
<Compile Include="Models\Mapping\LinkElementModels.cs" />

Console/BExIS.Web.Shell/Areas/DIM/BExIS.Modules.Dim.UI/Controllers/ExportController.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using BExIS.IO.Transform.Output;
1515
using BExIS.Modules.Dim.UI.Helpers;
1616
using BExIS.Modules.Dim.UI.Models.Api;
17+
using BExIS.Modules.Dim.UI.Models.Download;
1718
using BExIS.Modules.Dim.UI.Models.Export;
1819
using BExIS.Security.Entities.Subjects;
1920
using BExIS.Security.Entities.Versions;
@@ -25,6 +26,7 @@
2526
using Newtonsoft.Json;
2627
using System;
2728
using System.Data;
29+
using System.Globalization;
2830
using System.IO;
2931
using System.IO.Compression;
3032
using System.Linq;
@@ -323,14 +325,22 @@ public ActionResult GenerateZip(long id, long versionid, string format)
323325
// manifest
324326
ApiDatasetHelper apiDatasetHelper = new ApiDatasetHelper();
325327
// get content
326-
ApiDatasetModel datasetModel = apiDatasetHelper.GetContent(datasetVersion, id, datasetVersionNumber, datasetVersion.Dataset.MetadataStructure.Id, dataStructureId);
328+
ApiDatasetModel apimodel = apiDatasetHelper.GetContent(datasetVersion, id, datasetVersionNumber, datasetVersion.Dataset.MetadataStructure.Id, dataStructureId);
329+
GeneralMetadataModel datasetModel = GeneralMetadataModel.Map(apimodel);
330+
331+
datasetModel.DownloadInformation.DownloadDate = DateTime.Now.ToString(new CultureInfo("en-US"));
332+
datasetModel.DownloadInformation.DownloadSource = Request.Url.Host;
333+
datasetModel.DownloadInformation.DownloadedBy = getPartyNameOrDefault();
334+
335+
if(datasetModel.DownloadInformation.DownloadedBy == "DEFAULT") datasetModel.DownloadInformation.DownloadedBy = "ANONYMOUS";
336+
327337
string manifest = JsonConvert.SerializeObject(datasetModel);
328338

329339
if (manifest != null)
330340
{
331341
string manifestFileName = IOHelper.GetFileName(FileType.Manifest, id, datasetVersionNumber, dataStructureId);
332342
string manifestPath = OutputDatasetManager.GetDynamicDatasetStorePath(id,
333-
datasetVersionNumber, manifestFileName, ".json");
343+
datasetVersionNumber, "general_metadata", ".json");
334344
string fullFilePath = Path.Combine(AppConfiguration.DataPath, manifestPath);
335345
string directory = Path.GetDirectoryName(fullFilePath);
336346
if (!Directory.Exists(directory))

Console/BExIS.Web.Shell/Areas/DIM/BExIS.Modules.Dim.UI/Helpers/ApiDatasetHelper.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ public ApiDatasetModel GetContent(DatasetVersion datasetVersion, long id, int ve
2929
Id = id,
3030
Version = versionNumber,
3131
VersionId = datasetVersion.Id,
32-
VersionName = datasetVersion.VersionName,
3332
VersionDate = datasetVersion.Timestamp.ToString(new CultureInfo("en-US")),
34-
VersionPublicAccess = datasetVersion.PublicAccess,
35-
VersionPublicAccessDate = datasetVersion.PublicAccessDate.ToString(new CultureInfo("en-US")),
3633
Title = datasetVersion.Title,
3734
Description = datasetVersion.Description,
3835
DataStructureId = dataStructureId,

Console/BExIS.Web.Shell/Areas/DIM/BExIS.Modules.Dim.UI/Models/API/ApiModels.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public class ApiDatasetModel
3737
public long MetadataStructureId { get; set; }
3838
public bool IsPublic { get; set; }
3939
public string PublicationDate { get; set; }
40-
public string VersionName { get; set; }
41-
public bool VersionPublicAccess { get; set; }
42-
public string VersionPublicAccessDate { get; set; }
40+
//public string VersionName { get; set; }
41+
//public bool VersionPublicAccess { get; set; }
42+
//public string VersionPublicAccessDate { get; set; }
4343
public Dictionary<string, string> AdditionalInformations { get; set; }
4444
public Dictionary<string, Dictionary<string, string>> Parties { get; set; }
4545
public string VersionDate { get; set; }
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using BExIS.Modules.Dim.UI.Models.Api;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Web;
7+
8+
namespace BExIS.Modules.Dim.UI.Models.Download
9+
{
10+
public class GeneralMetadataModel : ApiDatasetModel
11+
{
12+
//public ApiDatasetModel Dataset { get; set; }
13+
public DatasetDownloadInfoModel DownloadInformation { get; set; }
14+
15+
public GeneralMetadataModel() : base()
16+
{
17+
DownloadInformation = new DatasetDownloadInfoModel();
18+
}
19+
20+
public static GeneralMetadataModel Map(ApiDatasetModel source)
21+
{
22+
GeneralMetadataModel target = new GeneralMetadataModel();
23+
24+
// 1. Hole alle öffentlichen Instanz-Eigenschaften des Quell-Typs
25+
PropertyInfo[] sourceProperties = typeof(ApiDatasetModel).GetProperties(BindingFlags.Public | BindingFlags.Instance);
26+
27+
// 2. Durchlaufe die Eigenschaften in einer Schleife
28+
foreach (PropertyInfo sourceProperty in sourceProperties)
29+
{
30+
// 3. Suche die entsprechende Eigenschaft im Ziel-Typ
31+
PropertyInfo targetProperty = typeof(GeneralMetadataModel).GetProperty(sourceProperty.Name);
32+
33+
// 4. Überprüfe, ob die Eigenschaft existiert und gesetzt werden kann
34+
if (targetProperty != null && targetProperty.CanWrite)
35+
{
36+
// 5. Überprüfe, ob die Typen übereinstimmen (empfohlen)
37+
if (targetProperty.PropertyType == sourceProperty.PropertyType)
38+
{
39+
// 6. Lese den Wert aus der Quelle
40+
object value = sourceProperty.GetValue(source);
41+
42+
// 7. Setze den Wert im Ziel
43+
targetProperty.SetValue(target, value);
44+
}
45+
}
46+
}
47+
48+
return target;
49+
}
50+
}
51+
52+
public class DatasetDownloadInfoModel
53+
{
54+
public string DownloadSource { get; set; }
55+
public string DownloadDate { get; set; }
56+
public string DownloadedBy { get; set; }
57+
}
58+
}

0 commit comments

Comments
 (0)