Skip to content

Commit

Permalink
Merge pull request #3 from nhsconnect/develop
Browse files Browse the repository at this point in the history
Improvements to the manual file import
  • Loading branch information
ChristopherJamesMorris authored Jun 4, 2024
2 parents 6d89031 + c964993 commit 50bfa6a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 7 deletions.
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>

0 comments on commit 50bfa6a

Please sign in to comment.