Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to the manual file import #3

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions source/gpconnect-analytics.DAL/ImportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public ImportService(IConfigurationService configurationService, IDataService da

public async Task<IActionResult> AddDownloadedFileManually(HttpRequest req)
{
var fileTypes = (FileTypes?)Enum.Parse(typeof(FileTypes), req.Query["FileType"].ToString());
if (fileTypes != null)
var filePath = req.Query["FilePath"].ToString();
var fileTypeFromPath = filePath.GetFileType<FileTypes>();

if (fileTypeFromPath != null)
{
var fileType = await _configurationService.GetFileType((FileTypes)fileTypes);
var filePath = req.Query["FilePath"].ToString();
var fileType = await _configurationService.GetFileType((FileTypes)fileTypeFromPath);
await AddFileMessage(fileType, new ExtractResponse() { FilePath = filePath });
return new OkObjectResult($"Import of {filePath} complete");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public interface IConfigurationService
Task<BlobStorage> GetBlobStorageConfiguration();
Task<FilePathConstants> GetFilePathConstants();
Task<List<FileType>> GetFileTypes();
Task<FileType> GetFileType(FileTypes fileTypes);
Task<FileType> GetFileType(FileTypes fileType);
Task<SplunkClient> GetSplunkClientConfiguration();
Task<SplunkInstance> GetSplunkInstance(Helpers.SplunkInstances splunkInstance);
Task<SplunkInstance> GetSplunkInstance(SplunkInstances splunkInstance);
}
}
21 changes: 21 additions & 0 deletions source/gpconnect-analytics.Helpers/AttributeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Linq;

namespace gpconnect_analytics.Helpers
{
public static class AttributeExtensions
{
public static FileTypes? GetFileType<FilePath>(this string filePath)
{
return GetValueFromPath<FilePath>(filePath);
}

public static FileTypes? GetValueFromPath<FilePath>(string filePath)
{
var fileType = typeof(FilePath).GetFields()
.Where(x => Attribute.GetCustomAttribute(x, typeof(FilePathAttribute)) is FilePathAttribute filePathAttribute && filePath.Contains(filePathAttribute?.FilePath))
.FirstOrDefault();
return fileType != null ? (FileTypes)fileType.GetValue(filePath) : (FileTypes?)null;
}
}
}
14 changes: 14 additions & 0 deletions source/gpconnect-analytics.Helpers/FilePath.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace gpconnect_analytics.Helpers
{
public class FilePathAttribute : Attribute
{
public string FilePath { get; protected set; } = "";

public FilePathAttribute(string value)
{
FilePath = value;
}
}
}
5 changes: 4 additions & 1 deletion source/gpconnect-analytics.Helpers/FileTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
{
public enum FileTypes
{
[FilePath("asid-lookup-data")]
asidlookup,
[FilePath("ssp-transactions")]
ssptrans,
[FilePath("mesh-transactions")]
meshtrans
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.13" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
Loading