PDSF (Process Data Standard Format) to use EAF for
pushing to OI
This commit is contained in:
@ -4,16 +4,13 @@ using OI.Metrology.Shared.Models;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Services;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace OI.Metrology.Server.Repository;
|
||||
|
||||
public class InboundRepository : IInboundRepository
|
||||
{
|
||||
|
||||
private readonly Serilog.ILogger _Log;
|
||||
|
||||
public InboundRepository() => _Log = Serilog.Log.ForContext<InboundRepository>();
|
||||
|
||||
bool IInboundRepository.IsIPAddressAllowed(string inboundApiAllowedIPList, IPAddress? remoteIP)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(inboundApiAllowedIPList))
|
||||
@ -38,29 +35,50 @@ public class InboundRepository : IInboundRepository
|
||||
// tooltype is the ToolTypeName column from the ToolType table
|
||||
// JToken is how you can accept a JSON message without deserialization.
|
||||
// Using "string" doesn't work because ASP.NET Core will expect a json encoded string, not give you the actual string.
|
||||
DataResponse IInboundRepository.Data(IMetrologyRepository metrologyRepository, IInboundDataService inboundDataService, string tooltype, JToken jsonbody)
|
||||
DataResponse IInboundRepository.Data(IMetrologyRepository metrologyRepository, IInboundDataService inboundDataService, string tooltype, string? json)
|
||||
{
|
||||
DataResponse result = new();
|
||||
ToolType? toolType = metrologyRepository.GetToolTypeByName(tooltype);
|
||||
if (toolType is null)
|
||||
result.Errors.Add("Invalid tool type: " + tooltype);
|
||||
result.Errors.Add($"Invalid tool type: {tooltype}");
|
||||
else
|
||||
{
|
||||
List<ToolTypeMetadata> metaData = metrologyRepository.GetToolTypeMetadataByToolTypeID(toolType.ID).ToList();
|
||||
if (metaData is null)
|
||||
result.Errors.Add("Invalid metadata for tool type: " + tooltype);
|
||||
else if (jsonbody is null)
|
||||
result.Errors.Add("Invalid json");
|
||||
InboundCommon? inboundCommon = string.IsNullOrEmpty(json) ? null : JsonSerializer.Deserialize<InboundCommon>(json);
|
||||
if (inboundCommon is null || string.IsNullOrEmpty(inboundCommon.ProcessDataStandardFormat))
|
||||
result.Errors.Add($"Invalid body: {json}");
|
||||
else
|
||||
inboundDataService.ValidateJSONFields(jsonbody, 0, metaData, result.Errors, result.Warnings);
|
||||
if (metaData is not null && jsonbody is not null && !result.Errors.Any())
|
||||
{
|
||||
try
|
||||
string? sourceDirectory = Path.GetDirectoryName(inboundCommon.ProcessDataStandardFormat);
|
||||
string? parentDirectory = Path.GetDirectoryName(sourceDirectory);
|
||||
if (string.IsNullOrEmpty(sourceDirectory) || string.IsNullOrEmpty(parentDirectory) || !Directory.Exists(parentDirectory))
|
||||
result.Errors.Add($"Invalid body:path: <{inboundCommon.ProcessDataStandardFormat}>");
|
||||
else
|
||||
{
|
||||
result.HeaderID = inboundDataService.DoSQLInsert(jsonbody, toolType, metaData);
|
||||
result.Success = result.HeaderID > 0;
|
||||
JToken jToken = string.IsNullOrEmpty(json) ? JToken.Parse("{}") : JToken.Parse(json);
|
||||
if (jToken is null)
|
||||
result.Errors.Add($"Invalid body: {json}");
|
||||
else
|
||||
{
|
||||
List<ToolTypeMetadata> metaData = metrologyRepository.GetToolTypeMetadataByToolTypeID(toolType.ID).ToList();
|
||||
if (metaData is null)
|
||||
result.Errors.Add($"Invalid metadata for tool type: {tooltype}");
|
||||
else
|
||||
{
|
||||
inboundDataService.ValidateJSONFields(jToken, 0, metaData, result.Errors, result.Warnings);
|
||||
if (!result.Errors.Any())
|
||||
{
|
||||
try
|
||||
{
|
||||
result.HeaderID = inboundDataService.DoSQLInsert(jToken, toolType, metaData);
|
||||
result.Success = result.HeaderID > 0;
|
||||
string? destinationDirectory = Path.Combine(parentDirectory, result.HeaderID.ToString());
|
||||
Directory.Move(sourceDirectory, destinationDirectory);
|
||||
}
|
||||
catch (Exception ex) { result.Errors.Add(ex.Message); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { result.Errors.Add(ex.Message); }
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
Reference in New Issue
Block a user