Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/bb-io/XTM into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalii-bezuhlyi committed Sep 2, 2024
2 parents 835fc12 + 98a3068 commit 0433760
Show file tree
Hide file tree
Showing 19 changed files with 592 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,4 @@ healthchecksdb
*.DS_Store
*.dmg
*.env
/ConsoleApp1
24 changes: 21 additions & 3 deletions Apps.XTM/Actions/FileActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,29 @@ public FileActions(InvocationContext invocationContext, IFileManagementClient fi
[Action("Generate files", Description = "Generate project files")]
public async Task<ListGeneratedFilesResponse> GenerateFiles(
[ActionParameter] ProjectRequest project,
[ActionParameter] GenerateFileRequest query)
[ActionParameter] GenerateFileRequest input)
{
var endpoint = $"{ApiEndpoints.Projects}/{project.ProjectId}/files/generate";

if (input.jobIds == null)
{
var projectActions = new ProjectActions(InvocationContext, _fileManagementClient);
var projectCompletion = await projectActions.GetProjectCompletion(project);
input.jobIds = projectCompletion.JobIds;
}

var queryParameters = new Dictionary<string, string>
{
{ "jobIds", string.Join(",", input.jobIds) },
{ "fileType", input.FileType }
};

if (input.TargetLanguage != null)
queryParameters.Add("targetLanguage", input.TargetLanguage);

var request = new XTMRequest(new()
{
Url = Creds.Get(CredsNames.Url) + endpoint.WithQuery(query),
Url = Creds.Get(CredsNames.Url) + endpoint.WithQuery(queryParameters),
Method = Method.Post
}, await Client.GetToken(Creds));

Expand Down Expand Up @@ -161,10 +177,12 @@ public async Task<DownloadFilesResponse<XtmProjectFileDescription>> DownloadProj
foreach (var file in files)
{
var uploadedFile = await _fileManagementClient.UploadAsync(file.FileStream, MediaTypeNames.Application.Octet, file.UploadName);
var language = file.Path.Split('/').FirstOrDefault();
var name = file.Path.Split('/').LastOrDefault();
result.Add(new()
{
Content = uploadedFile,
FileDescription = xtmFileDescriptions.First(description => description.FileName == file.UploadName)
FileDescription = xtmFileDescriptions.FirstOrDefault(description => description.TargetLanguage == language && description.FileName == name)
});
}

Expand Down
81 changes: 81 additions & 0 deletions Apps.XTM/Actions/LqaActions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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;
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<List<LqaResponse>> SearchLqa([ActionParameter] LQARequest input)
{
var Params = new List<string>();
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<List<LqaDto>>(endpoint,
Method.Get,
null,
Creds);

return FixDate(response);
}

private List<LqaResponse> FixDate(List<LqaDto> response)
{
var updated = new List<LqaResponse>();
foreach (var item in response)
{

updated.Add(new LqaResponse
{
id = item.id,
completeDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(long.Parse(item.completeDate)).ToString("yyyy-MM-dd"),
severityMultiplierNeutral = item.severityMultipliers.Neutral,
severityMultiplierCritical = item.severityMultipliers.Critical,
severityMultiplierMajor = item.severityMultipliers.Major,
severityMultiplierMinor = item.severityMultipliers.Minor,
evaluee = item.evaluee.userName,
evaluator = item.evaluator.userName,
customer = item.customer.name,
projectId = item.project.id.ToString(),
projectName = item.project.name,
projectWordcount = item.project.wordCount,
projectTotal = item.project.Total,
projectErrors = item.project.Errors,
SubjectMatter = item.project.subjectMatter.Name,
languageCode = item.language.code,
languageWordcount = item.language.wordCount,
languageTotal = item.language.Total,
languageErrors = item.language.Errors,
files = item.files,
});
}

return updated;
}
}
}
5 changes: 2 additions & 3 deletions Apps.XTM/Apps.XTM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Product>XTM</Product>
<Version>3.1.5</Version>
<Version>3.2.3</Version>
<Description>Translation management system that centralizes localization assets and enables fast, accurate translation and deployment of content tailored to any audience in any territory</Description>
<AssemblyName>Apps.XTM</AssemblyName>
<LangVersion>12</LangVersion>
Expand All @@ -18,8 +18,7 @@
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.10.*"/>
<PackageReference Include="System.ServiceModel.Primitives" Version="8.0.0"/>
<PackageReference Include="System.ServiceModel.Security" Version="4.10.*"/>
<PackageReference Include="Blackbird.Applications.Sdk.Common" Version="2.6.0"/>
<PackageReference Include="Blackbird.Applications.Sdk.Utils" Version="1.0.17"/>
<PackageReference Include="Blackbird.Applications.Sdk.Common" Version="2.8.0"/>
</ItemGroup>
<ItemGroup>
<EmbeddedResource CopyToOutputDirectory="Always" Include="image\icon.png"/>
Expand Down
18 changes: 18 additions & 0 deletions Apps.XTM/DataSourceHandlers/EnumHandlers/LqaTypeDataHandler.cs
Original file line number Diff line number Diff line change
@@ -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<string, string> EnumValues => new()
{
{"LANGUAGE", "Language"},
{"FILE", "File"}
};
}
}
16 changes: 16 additions & 0 deletions Apps.XTM/DataSourceHandlers/EnumHandlers/ProjectStatusHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Blackbird.Applications.Sdk.Common.Dictionaries;

namespace Apps.XTM.DataSourceHandlers.EnumHandlers;

public class ProjectStatusHandler : IStaticDataSourceHandler
{
public Dictionary<string, string> GetData()
{
return new()
{
["NOT_STARTED"] = "Not started",
["STARTED"] = "Started",
["FINISHED"] = "Finished"
};
}
}
3 changes: 3 additions & 0 deletions Apps.XTM/Models/Request/Files/GenerateFileRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public class GenerateFileRequest
[JsonProperty("targetLanguage")]
[DataSource(typeof(ProjectTargetLanguageDataSourceHandler))]
public string? TargetLanguage { get; set; }

[Display("Job IDs")]
public IEnumerable<string>? jobIds { get; set; }
}
25 changes: 25 additions & 0 deletions Apps.XTM/Models/Request/LQARequest.cs
Original file line number Diff line number Diff line change
@@ -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<string>? TargetLangs { get; set; }

[DataSource(typeof(LqaTypeDataHandler))]
[Display("LQA type")]
public string? Type { get; set; }
}
}
6 changes: 6 additions & 0 deletions Apps.XTM/Models/Response/Files/GeneratedFileResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ public class GeneratedFileResponse
{
[Display("File ID")]
public string FileId { get; set; }

[Display("Job ID")]
public string JobId { get; set; }

[Display("File type")]
public string FileType { get; set; }
}
Loading

0 comments on commit 0433760

Please sign in to comment.