Skip to content

Commit

Permalink
Upload file action
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdanm-bb committed Mar 22, 2024
1 parent dfe2957 commit 2dd630d
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 37 deletions.
19 changes: 16 additions & 3 deletions Apps.BWX/Actions/ProjectActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Blackbird.Applications.Sdk.Utils.Extensions.Files;
using RestSharp;
using System.IO.Compression;
using Newtonsoft.Json;

namespace Apps.BWX.Actions;

Expand Down Expand Up @@ -81,7 +82,7 @@ public Task<ProjectDto> CreateProject([ActionParameter] CreateProjectRequest inp
}

[Action("Upload file to project", Description = "Upload file to project")]
public async Task<ProjectFileInfoDto> UploadFileToProject(
public async Task<WorkUnitDto> UploadFileToProject(
[ActionParameter] GetProjectRequest getProjectRequest,
[ActionParameter] UploadFileRequest uploadFileRequest)
{
Expand All @@ -94,10 +95,22 @@ public async Task<ProjectFileInfoDto> UploadFileToProject(
});
var projectFileInfoDto = await Client.ExecuteWithErrorHandling<ProjectFileInfoDto>(request);

var uploadRequest = new BWXRequest($"/api/v3/project/{getProjectRequest.ProjectId}/resource/{projectFileInfoDto.Uuid}/content", Method.Post, Creds);
var uploadRequest = new BWXRequest($"/api/v3/project/{getProjectRequest.ProjectId}/resource/{projectFileInfoDto.Uuid}/content", Method.Put, Creds);
var fileBytes = await (await _fileManagementClient.DownloadAsync(uploadFileRequest.File)).GetByteData();
uploadRequest.AlwaysMultipartFormData = true;
uploadRequest.AddFile("file", fileBytes, uploadFileRequest.File.Name);
await Client.ExecuteWithErrorHandling(uploadRequest);
return projectFileInfoDto;

var createWorkUnitRequest = new BWXRequest($"/api/v3/project/{getProjectRequest.ProjectId}/work-unit?bulk=true", Method.Post, Creds);
createWorkUnitRequest.AddJsonBody(JsonConvert.SerializeObject(
new List<WorkUnitCreateDto>() {
new WorkUnitCreateDto()
{
ProjectResourceUuid = projectFileInfoDto.Uuid,
Workflows = uploadFileRequest.Workflows,
TargetLocales = uploadFileRequest.TargetLocales,
}
}));
return (await Client.ExecuteWithErrorHandling<List<WorkUnitDto>>(createWorkUnitRequest)).First();
}
}
12 changes: 7 additions & 5 deletions Apps.BWX/DataSourceHandlers/ClientDataHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
using Blackbird.Applications.Sdk.Common.Dynamic;
using Blackbird.Applications.Sdk.Common.Invocation;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/** !!!Warning!!!
* Since BWX API is the same API their web platform uses
* and many endpoints are not described or irrelevant in BWX API documentation -
* some parts of code are based on the endpoints which are used by BWX web platform. (It could be both v3 or v2 endpoints)
* Next method is based on web platform calls
**/

namespace Apps.BWX.DataSourceHandlers
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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.BWX.DataSourceHandlers.EnumDataHandlers
{
public class WorkflowDataHandler : EnumDataHandler
{
protected override Dictionary<string, string> EnumValues => new()
{
{"TRANSCRIPTION","TRANSCRIPTION"},
{"TRANSLATION","TRANSLATION"},
{"PROOFREADING","PROOFREADING"},
{"REVIEW","REVIEW"},
{"REVIEW_2","REVIEW_2"},
{"REVIEW_3","REVIEW_3"},
{"ICR","ICR"},
{"REGIONAL_APPROVAL","REGIONAL_APPROVAL"},
{"ICR_2","ICR_2"},
{"WEB_QA","WEB_QA"},
{"FEEDBACK_IMPLEMENTATION","FEEDBACK_IMPLEMENTATION"},
{"DTP","DTP"},
{"QA","QA"},
{"SUBTITLING","SUBTITLING"},
{"VIDEO_EDITING","VIDEO_EDITING"},
{"VOICEOVER","VOICEOVER"},
{"SWORN","SWORN"},
{"INTERPRETATION","INTERPRETATION"},
{"DEVELOPMENT","DEVELOPMENT"}
};
}
}
5 changes: 0 additions & 5 deletions Apps.BWX/DataSourceHandlers/LanguageDataHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
using Blackbird.Applications.Sdk.Common.Dynamic;
using Blackbird.Applications.Sdk.Common.Invocation;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Apps.BWX.DataSourceHandlers
{
Expand Down
12 changes: 7 additions & 5 deletions Apps.BWX/DataSourceHandlers/OrganizationDataHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
using Blackbird.Applications.Sdk.Common.Dynamic;
using Blackbird.Applications.Sdk.Common.Invocation;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/** !!!Warning!!!
* Since BWX API is the same API their web platform uses
* and many endpoints are not described or irrelevant in BWX API documentation -
* some parts of code are based on the endpoints which are used by BWX web platform. (It could be both v3 or v2 endpoints)
* Next method is based on web platform calls
**/

namespace Apps.BWX.DataSourceHandlers
{
Expand Down
12 changes: 7 additions & 5 deletions Apps.BWX/DataSourceHandlers/ProjectManagerDataHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
using Blackbird.Applications.Sdk.Common.Dynamic;
using Blackbird.Applications.Sdk.Common.Invocation;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/** !!!Warning!!!
* Since BWX API is the same API their web platform uses
* and many endpoints are not described or irrelevant in BWX API documentation -
* some parts of code are based on the endpoints which are used by BWX web platform. (It could be both v3 or v2 endpoints)
* Next method is based on web platform calls
**/

namespace Apps.BWX.DataSourceHandlers
{
Expand Down
12 changes: 7 additions & 5 deletions Apps.BWX/DataSourceHandlers/UserDataHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
using Blackbird.Applications.Sdk.Common.Dynamic;
using Blackbird.Applications.Sdk.Common.Invocation;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/** !!!Warning!!!
* Since BWX API is the same API their web platform uses
* and many endpoints are not described or irrelevant in BWX API documentation -
* some parts of code are based on the endpoints which are used by BWX web platform. (It could be both v3 or v2 endpoints)
* Next method is based on web platform calls
**/

namespace Apps.BWX.DataSourceHandlers
{
Expand Down
23 changes: 15 additions & 8 deletions Apps.BWX/Dtos/ProjectFileInfoDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,30 @@ public class ProjectFileInfoDto
public string Type { get; set; }
public string Name { get; set; }
public string Path { get; set; }
public string Hash { get; set; }
public string Notes { get; set; }
public string SourceLocale { get; set; }
public long Creation { get; set; }
public string ProjectUuid { get; set; }
public Params Params { get; set; }
public List<string> Workflows { get; set; }
public List<string> TargetLocales { get; set; }
public bool DefaultFilterSettings { get; set; }
}

public class Params
{
public string ProjectResourceId { get; set; }
public string ApplySourceSegmentation { get; set; }
public string Parameters { get; set; }
public bool ApplySourceSegmentation { get; set; }
public bool ExtractTerms { get; set; }
public TermsParams TermsParams { get; set; }
public string ParserFilter { get; set; }
public string TagRegex { get; set; }
}

public class TermsParams
{
public bool KeepCase { get; set; }
public int MinWordsPerTerm { get; set; }
public bool SortByOccurrence { get; set; }
public bool RemoveSubTerms { get; set; }
public int MinOccurrences { get; set; }
public int MaxWordsPerTerm { get; set; }
public int TopTermsLimit { get; set; }
}

}
21 changes: 21 additions & 0 deletions Apps.BWX/Dtos/WorkUnitCreateDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Apps.BWX.Dtos
{
public class WorkUnitCreateDto
{
[JsonProperty("projectResourceUuid")]
public string ProjectResourceUuid { get; set; }

[JsonProperty("workflows")]
public List<string> Workflows { get; set; }

[JsonProperty("targetLocales")]
public List<string> TargetLocales { get; set; }
}
}
24 changes: 24 additions & 0 deletions Apps.BWX/Dtos/WorkUnitDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Apps.BWX.Dtos
{
public class WorkUnitDto
{
public string Uuid { get; set; }
public string WorkId { get; set; }
public string Name { get; set; }
public string SourceLanguage { get; set; }
public string TargetLanguage { get; set; }
public string Filename { get; set; }
public long CreationTimestamp { get; set; }
public long LastUpdate { get; set; }
public int Sequence { get; set; }
public string Workflow { get; set; }
public string ProjectUUID { get; set; }
public string ProjectResourceUuid { get; set; }
}
}
13 changes: 12 additions & 1 deletion Apps.BWX/Models/Requests/Project/UploadFileRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Blackbird.Applications.Sdk.Common;
using Apps.BWX.DataSourceHandlers;
using Apps.BWX.DataSourceHandlers.EnumDataHandlers;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Dynamic;
using Blackbird.Applications.Sdk.Common.Files;
using System;
using System.Collections.Generic;
Expand All @@ -12,6 +15,14 @@ public class UploadFileRequest
{
public FileReference File { get; set; }

[Display("Target locales")]
[DataSource(typeof(LanguageDataHandler))]
public List<string> TargetLocales { get; set; }

[Display("Workflows")]
[DataSource(typeof(WorkflowDataHandler))]
public List<string> Workflows { get; set; }

[Display("File name", Description = "Override file name")]
public string? FileName { get; set; }

Expand Down

0 comments on commit 2dd630d

Please sign in to comment.