From 7d4b0383e9d311ac1a441e1ff7327648ba65a797 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Sun, 23 Apr 2023 11:03:48 -0700 Subject: [PATCH] Update API --- Adaptation/FileHandlers/json/ProcessData.cs | 121 +++++++++++++----- Adaptation/MESAFIBACKLOG.yml | 3 +- .../Development/v2.49.0/MESAFIBACKLOG.cs | 18 +++ 3 files changed, 111 insertions(+), 31 deletions(-) diff --git a/Adaptation/FileHandlers/json/ProcessData.cs b/Adaptation/FileHandlers/json/ProcessData.cs index 865667f..f6814ad 100644 --- a/Adaptation/FileHandlers/json/ProcessData.cs +++ b/Adaptation/FileHandlers/json/ProcessData.cs @@ -126,6 +126,58 @@ public class ProcessData : IProcessData private static string GetDescription(FIBacklogMesa fiBacklogMesa, DateTime dateTime) => $"Req:{fiBacklogMesa.Req}; Submitted:{(dateTime == DateTime.MinValue ? fiBacklogMesa.Submitted : dateTime.ToString("d-MMM-yy"))}; Requestor:{fiBacklogMesa.Requestor}; AssignedTo:{fiBacklogMesa.AssignedTo}; SecondResource:{fiBacklogMesa.SecondResource}; Systems:{fiBacklogMesa.SystemS}; "; + private static void Update(HttpClient httpClient, string basePage, string api, string query, HttpContent httpContent) + { + Task httpResponseMessageTask = httpClient.PatchAsync(string.Concat(basePage, api, query), httpContent); + httpResponseMessageTask.Wait(); + if (!httpResponseMessageTask.Result.IsSuccessStatusCode) + throw new Exception(httpResponseMessageTask.Result.StatusCode.ToString()); + Task stringTask = httpResponseMessageTask.Result.Content.ReadAsStringAsync(); + stringTask.Wait(); + } + + private static void UpdateIds(HttpClient httpClient, string basePage, string api, string[] checkFiles) + { + int? idIndex; + string[] lines; + string[] segments; + string stringPayload; + HttpContent httpContent; + foreach (string checkFile in checkFiles) + { + idIndex = null; + lines = File.ReadAllLines(checkFile); + if (lines.Length < 1) + continue; + segments = lines.First().Split(','); + for (int i = 0; i < segments.Length; i++) + { + if (segments[i] == "ID") + { + idIndex = i; + break; + } + } + if (idIndex is null) + continue; + for (int i = 1; i < lines.Length; i++) + { + segments = lines[i].Split(','); + if (segments.Length < idIndex.Value) + continue; + var payload = new + { + op = "replace", + path = "/fields/System.IterationPath", + value = "Mesa_FI" + }; + stringPayload = JsonSerializer.Serialize(payload); + httpContent = new StringContent($"[{stringPayload}]", Encoding.UTF8, "application/json-patch+json"); + Update(httpClient, basePage, api, $"/workitems/{segments[idIndex.Value].Replace("\"", string.Empty)}?api-version=1.0", httpContent); + } + } + } + private void Parse(IFileRead fileRead, Logistics logistics, List fileInfoCollection, HttpClient httpClient, string basePage, string api, string query, WorkItemTrackingHttpClient workItemTrackingHttpClient, string project, string json) { if (fileRead is null) @@ -138,37 +190,46 @@ public class ProcessData : IProcessData DateTime dateTime; string description; string keySection = " UAT for "; - string ids = GetIds(httpClient, basePage, api, query); - Value[] workItems = GetWorkItems(httpClient, basePage, api, ids); - Task workItemTask; - Dictionary keyToFIBacklogMesa = GetFIBacklogMesaCollection(json, keySection); - int count = keyToFIBacklogMesa.Count; - Value[] extra = GetExtra(keySection, workItems, keyToFIBacklogMesa); - if (count != extra.Length) - { } - if (count != keyToFIBacklogMesa.Count) - { } - _Details.AddRange(workItems); - foreach (KeyValuePair keyValuePair in keyToFIBacklogMesa) + string? directory = Path.GetDirectoryName(fileRead.ReportFullPath); + if (directory is null) + throw new Exception(); + string[] checkFiles = Directory.GetFiles(directory, "*.csv", SearchOption.TopDirectoryOnly); + if (checkFiles.Any()) + UpdateIds(httpClient, basePage, api, checkFiles); + else { - if (counter > 5) - break; - JsonPatchDocument document = new(); - if (!DateTime.TryParse(keyValuePair.Value.Submitted, out dateTime)) - dateTime = DateTime.MinValue; - AddPatch(document, "/fields/System.AreaPath", project); - description = GetDescription(keyValuePair.Value, dateTime); - AddPatch(document, "/fields/System.Title", keyValuePair.Key); - AddPatch(document, "/fields/System.Description", description); - AddPatch(document, "/fields/System.IterationPath", $"{project}\\(Default)"); - // AddPatch(document, "/fields/System.AssignedTo", "Mike.Phares@infineon.com"); - if (!fileRead.IsEAFHosted) - continue; - workItemTask = workItemTrackingHttpClient.CreateWorkItemAsync(document, project, "Task"); - workItemTask.Wait(); - counter++; - if (workItemTask.Result is null) - continue; + string ids = GetIds(httpClient, basePage, api, query); + Value[] workItems = GetWorkItems(httpClient, basePage, api, ids); + Task workItemTask; + Dictionary keyToFIBacklogMesa = GetFIBacklogMesaCollection(json, keySection); + int count = keyToFIBacklogMesa.Count; + Value[] extra = GetExtra(keySection, workItems, keyToFIBacklogMesa); + if (count != extra.Length) + { } + if (count != keyToFIBacklogMesa.Count) + { } + _Details.AddRange(workItems); + foreach (KeyValuePair keyValuePair in keyToFIBacklogMesa) + { + if (counter > 5) + break; + JsonPatchDocument document = new(); + if (!DateTime.TryParse(keyValuePair.Value.Submitted, out dateTime)) + dateTime = DateTime.MinValue; + AddPatch(document, "/fields/System.AreaPath", project); + description = GetDescription(keyValuePair.Value, dateTime); + AddPatch(document, "/fields/System.IterationPath", project); + AddPatch(document, "/fields/System.Title", keyValuePair.Key); + AddPatch(document, "/fields/System.Description", description); + // AddPatch(document, "/fields/System.AssignedTo", "Mike.Phares@infineon.com"); + if (!fileRead.IsEAFHosted) + continue; + workItemTask = workItemTrackingHttpClient.CreateWorkItemAsync(document, project, "Task"); + workItemTask.Wait(); + counter++; + if (workItemTask.Result is null) + continue; + } } } diff --git a/Adaptation/MESAFIBACKLOG.yml b/Adaptation/MESAFIBACKLOG.yml index 273f495..3f65e0a 100644 --- a/Adaptation/MESAFIBACKLOG.yml +++ b/Adaptation/MESAFIBACKLOG.yml @@ -151,12 +151,13 @@ steps: "C:\program files\dotnet\dotnet.exe" clean --configuration $(Configuration) workingDirectory: Adaptation displayName: "Core Clean - Tests" - enabled: false + continueOnError: true - script: | "C:\program files\dotnet\dotnet.exe" clean --configuration $(Configuration) workingDirectory: Adaptation displayName: "Core Clean - Adaptation" + continueOnError: true - script: 'echo $(Build.SourceVersion)-$(Build.BuildId)>bin_x_x_\$(Configuration)\$(CoreVersion)\win-x64\$(Build.Repository.Name).txt' displayName: "Force Fail" diff --git a/Adaptation/_Tests/Extract/Development/v2.49.0/MESAFIBACKLOG.cs b/Adaptation/_Tests/Extract/Development/v2.49.0/MESAFIBACKLOG.cs index 4dce0d4..516bee3 100644 --- a/Adaptation/_Tests/Extract/Development/v2.49.0/MESAFIBACKLOG.cs +++ b/Adaptation/_Tests/Extract/Development/v2.49.0/MESAFIBACKLOG.cs @@ -59,4 +59,22 @@ public class MESAFIBACKLOG NonThrowTryCatch(); } + [Ignore] + [TestMethod] + public void Development__v2_49_0__MESAFIBACKLOG__json637961251829737449__Normal() + { + string check = "*.json"; + bool validatePDSF = false; + _MESAFIBACKLOG.Development__v2_49_0__MESAFIBACKLOG__json(); + MethodBase methodBase = new StackFrame().GetMethod(); + Assert.IsFalse(string.IsNullOrEmpty(_MESAFIBACKLOG.AdaptationTesting.TestContext.FullyQualifiedTestClassName)); + string[] variables = _MESAFIBACKLOG.AdaptationTesting.GetVariables(methodBase, check, validatePDSF); + IFileRead fileRead = _MESAFIBACKLOG.AdaptationTesting.Get(methodBase, sourceFileLocation: variables[2], sourceFileFilter: variables[3], useCyclicalForDescription: false); + Tuple> extractResult = fileRead.ReExtract(); + Assert.IsFalse(string.IsNullOrEmpty(extractResult?.Item1)); + Assert.IsNotNull(extractResult.Item3); + Assert.IsNotNull(extractResult.Item4); + NonThrowTryCatch(); + } + } \ No newline at end of file