From dad2f361c6d8a97d138113fd18a408ff6343185b Mon Sep 17 00:00:00 2001 From: ce-nistal Date: Wed, 17 Jul 2024 17:04:45 -0300 Subject: [PATCH] Added Search LQA reports action --- Apps.XTM/Actions/LqaActions.cs | 69 +++++++ .../EnumHandlers/LqaTypeDataHandler.cs | 18 ++ Apps.XTM/Models/Request/LQARequest.cs | 25 +++ Apps.XTM/Models/Response/LqaResponse.cs | 182 ++++++++++++++++++ 4 files changed, 294 insertions(+) create mode 100644 Apps.XTM/Actions/LqaActions.cs create mode 100644 Apps.XTM/DataSourceHandlers/EnumHandlers/LqaTypeDataHandler.cs create mode 100644 Apps.XTM/Models/Request/LQARequest.cs create mode 100644 Apps.XTM/Models/Response/LqaResponse.cs diff --git a/Apps.XTM/Actions/LqaActions.cs b/Apps.XTM/Actions/LqaActions.cs new file mode 100644 index 0000000..01ac367 --- /dev/null +++ b/Apps.XTM/Actions/LqaActions.cs @@ -0,0 +1,69 @@ +using Apps.XTM.Constants; +using Apps.XTM.Invocables; +using Apps.XTM.Models.Request; +using Apps.XTM.Models.Response; +using Apps.XTM.Models.Response.Customers; +using Blackbird.Applications.Sdk.Common.Actions; +using Blackbird.Applications.Sdk.Common.Invocation; +using DocumentFormat.OpenXml.Bibliography; +using RestSharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Apps.XTM.Actions +{ + [ActionList] + public class LqaActions : XtmInvocable + { + public LqaActions(InvocationContext invocationContext) : base(invocationContext) + { + } + + [Action("Search LQA reports", Description = "Define criteria to search LQA reports")] + public async Task> SearchLqa(LQARequest input) + { + var Params = new List(); + if (input.DateFrom is not null) Params.Add($"completeDateFrom={input.DateFrom:yyyy-MM-dd}"); + if (input.DateTo is not null) Params.Add($"completeDateTo={input.DateTo:yyyy-MM-dd}"); + if (input.TargetLangs is not null) Params.Add($"targetLanguages={String.Join(",",input.TargetLangs)}"); + if (input.Type is not null) Params.Add($"type={input.Type}"); + + var endpoint = $"{ApiEndpoints.Projects}/lqa/download"; + if (Params is not null && Params.Count > 0) + { endpoint = endpoint + "?"+String.Join("&",Params); } + + var response = await Client.ExecuteXtmWithJson>(endpoint, + Method.Get, + null, + Creds); + + return FixDate(response); + } + + private List FixDate(List response) + { + var updated = new List(); + foreach (var item in response) + { + + updated.Add(new LqaResponse + { + id = item.id, + evaluator = item.evaluator, + project = item.project, + customer = item.customer, + language = item.language, + evaluee = item.evaluee, + files = item.files, + severityMultipliers = item.severityMultipliers, + completeDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(long.Parse(item.completeDate)).ToString("yyyy-MM-dd") + }); + } + + return updated; + } + } +} diff --git a/Apps.XTM/DataSourceHandlers/EnumHandlers/LqaTypeDataHandler.cs b/Apps.XTM/DataSourceHandlers/EnumHandlers/LqaTypeDataHandler.cs new file mode 100644 index 0000000..6a62148 --- /dev/null +++ b/Apps.XTM/DataSourceHandlers/EnumHandlers/LqaTypeDataHandler.cs @@ -0,0 +1,18 @@ +using Blackbird.Applications.Sdk.Utils.Sdk.DataSourceHandlers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Apps.XTM.DataSourceHandlers.EnumHandlers +{ + public class LqaTypeDataHandler : EnumDataHandler + { + protected override Dictionary EnumValues => new() + { + {"LANGUAGE", "Language"}, + {"FILE", "File"} + }; + } +} diff --git a/Apps.XTM/Models/Request/LQARequest.cs b/Apps.XTM/Models/Request/LQARequest.cs new file mode 100644 index 0000000..a8ca6f7 --- /dev/null +++ b/Apps.XTM/Models/Request/LQARequest.cs @@ -0,0 +1,25 @@ + + +using Apps.XTM.DataSourceHandlers.EnumHandlers; +using Blackbird.Applications.Sdk.Common; +using Blackbird.Applications.Sdk.Common.Dynamic; + +namespace Apps.XTM.Models.Request +{ + public class LQARequest + { + [Display("Date from")] + public DateTime? DateFrom { get; set; } + + [Display("Date to")] + public DateTime? DateTo { get; set; } + + [DataSource(typeof(LanguageDataHandler))] + [Display("Target languages")] + public List? TargetLangs { get; set; } + + [DataSource(typeof(LqaTypeDataHandler))] + [Display("LQA type")] + public string? Type { get; set; } + } +} diff --git a/Apps.XTM/Models/Response/LqaResponse.cs b/Apps.XTM/Models/Response/LqaResponse.cs new file mode 100644 index 0000000..2948349 --- /dev/null +++ b/Apps.XTM/Models/Response/LqaResponse.cs @@ -0,0 +1,182 @@ + + +using Blackbird.Applications.Sdk.Common; + +namespace Apps.XTM.Models.Response +{ + public class LqaResponse + { + [Display("LQA report ID")] + public string id { get; set; } + + [Display("Severity multipliers")] + public SeverityMultipliers severityMultipliers { get; set; } + + [Display("Completion date")] + public string completeDate { get; set; } + + [Display("Evaluee")] + public Evaluee evaluee { get; set; } + + [Display("Evaluator")] + public Evaluator evaluator { get; set; } + + [Display("Customer")] + public Customer customer { get; set; } + + [Display("Project")] + public Project project { get; set; } + + [Display("Language")] + public Language language { get; set; } + + [Display("Files")] + public List? files { get; set; } + } + public class Customer + { + [Display("Customer ID")] + public int id { get; set; } + + [Display("Customer name")] + public string name { get; set; } + } + + public class Error + { + [Display("Error ID")] + public string id { get; set; } + + [Display("Parent ID")] + public string parentId { get; set; } + + [Display("Parent Path")] + public string parentPath { get; set; } + + [Display("Key")] + public string key { get; set; } + + [Display("Weight")] + public string weight { get; set; } + + [Display("Issue count")] + public IssueCounts issueCounts { get; set; } + + [Display("Penalty")] + public Penalty penalty { get; set; } + + [Display("Target subscore")] + public string targetSubscore { get; set; } + } + + public class Evaluator + { + [Display("Evaluator ID")] + public int userId { get; set; } + + [Display("Evaluator Name")] + public string userName { get; set; } + } + + public class Evaluee + { + [Display("Evaluaee ID")] + public int userId { get; set; } + + [Display("Evaluaee name")] + public string userName { get; set; } + } + + public class File + { + public _File file { get; set; } + + [Display("Job ID")] + public int jobId { get; set; } + + [Display("Word count")] + public int wordCount { get; set; } + public Total total { get; set; } + public List errors { get; set; } + } + + public class _File + { + [Display("File ID")] + public int fileId { get; set; } + + [Display("File name")] + public string fileName { get; set; } + } + + public class IssueCounts + { + public int Neutral { get; set; } + public int Minor { get; set; } + public int Major { get; set; } + public int Critical { get; set; } + } + + public class Language + { + [Display("Language code")] + public string code { get; set; } + + [Display("Word count")] + public int wordCount { get; set; } + public Total Total { get; set; } + public List Errors { get; set; } + } + + public class Penalty + { + public string Raw { get; set; } + + [Display("Adjusted")] + public string adj { get; set; } + } + + public class Project + { + [Display("Project ID")] + public int id { get; set; } + + [Display("Project name")] + public string name { get; set; } + + [Display("Subject Matter")] + public SubjectMatter subjectMatter { get; set; } + + [Display("Word count")] + public int wordCount { get; set; } + public Total Total { get; set; } + public List Errors { get; set; } + } + + public class SeverityMultipliers + { + public string Neutral { get; set; } + public string Minor { get; set; } + public string Major { get; set; } + public string Critical { get; set; } + } + + public class SubjectMatter + { + [Display("Subject matter ID")] + public int id { get; set; } + public string Name { get; set; } + } + + public class Total + { + public string Weight { get; set; } + + [Display("Issue count")] + public IssueCounts issueCounts { get; set; } + public Penalty Penalty { get; set; } + + [Display("Target subscore")] + public string targetSubscore { get; set; } + } +}