Import from internal git
This commit is contained in:
20
Generator/Services/AnalyzeService.cs
Normal file
20
Generator/Services/AnalyzeService.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Core;
|
||||
using Generator.Repo;
|
||||
|
||||
namespace Generator.Services;
|
||||
|
||||
public class AnalyzeService
|
||||
{
|
||||
private readonly ApiAnalyzer _analyzer;
|
||||
|
||||
public AnalyzeService(ApiAnalyzer analyzer)
|
||||
{
|
||||
_analyzer = analyzer;
|
||||
}
|
||||
|
||||
public IEnumerable<Location> ListSpecs() => _analyzer.ListSpecifications();
|
||||
|
||||
public bool CanBeGenerated(string folder, string spec) => _analyzer.CanBeGenerated(folder, spec);
|
||||
|
||||
public string GetSpecText(string folder, string spec) => _analyzer.GetText(folder, spec);
|
||||
}
|
||||
19
Generator/Services/ExportService.cs
Normal file
19
Generator/Services/ExportService.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Core;
|
||||
using Generator.Repo;
|
||||
|
||||
namespace Generator.Services;
|
||||
|
||||
public class ExportService
|
||||
{
|
||||
private readonly ExportRepo _repo;
|
||||
|
||||
public ExportService(ExportRepo repo)
|
||||
{
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
public void ExportAsPuml(ISpecFile file)
|
||||
{
|
||||
_repo.PlantUml(file);
|
||||
}
|
||||
}
|
||||
68
Generator/Services/GenerationService.cs
Normal file
68
Generator/Services/GenerationService.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using Core.Exceptions;
|
||||
using Core.SpecConfig;
|
||||
using Generator.Repo;
|
||||
|
||||
namespace Generator.Services;
|
||||
|
||||
public class GenerationService
|
||||
{
|
||||
private readonly GenerateRepo _repo;
|
||||
private readonly PublicationService _pubService;
|
||||
|
||||
public GenerationService(PublicationService publicationService, GenerateRepo repo)
|
||||
{
|
||||
_repo = repo;
|
||||
_pubService = publicationService;
|
||||
}
|
||||
|
||||
public async Task Launch(ProcessTask task)
|
||||
{
|
||||
switch (task.Language)
|
||||
{
|
||||
case Language.Dotnet:
|
||||
await LaunchDotnet(task);
|
||||
break;
|
||||
case Language.Java:
|
||||
await LaunchJava(task);
|
||||
break;
|
||||
case Language.Javascript:
|
||||
await LaunchJavascript(task);
|
||||
break;
|
||||
default:
|
||||
throw new WeirdException("You broke me :(");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LaunchDotnet(ProcessTask task)
|
||||
{
|
||||
while (task.Tasks.TryDequeue(out var file))
|
||||
{
|
||||
await _repo.GenerateDotnet(task.GenerationType, file);
|
||||
|
||||
if (task.PublishType == PublishType.No) continue;
|
||||
await _pubService.PublishDotnet(file, task.GenerationType, task.PublishType);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LaunchJava(ProcessTask task)
|
||||
{
|
||||
while (task.Tasks.TryDequeue(out var file))
|
||||
{
|
||||
await _repo.GenerateJava(file);
|
||||
|
||||
if (task.PublishType == PublishType.No) continue;
|
||||
await _pubService.PublishJava(file, task.GenerationType, task.PublishType);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LaunchJavascript(ProcessTask task)
|
||||
{
|
||||
while (task.Tasks.TryDequeue(out var file))
|
||||
{
|
||||
await _repo.GenerateJavascript(file);
|
||||
|
||||
if (task.PublishType == PublishType.No) continue;
|
||||
await _pubService.PublishJavascript(file, task.GenerationType, task.PublishType);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Generator/Services/PreGenerationService.cs
Normal file
22
Generator/Services/PreGenerationService.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Core.Process;
|
||||
using Core.SpecConfig;
|
||||
using Generator.Repo;
|
||||
|
||||
namespace Generator.Services;
|
||||
|
||||
public class PreGenerationService
|
||||
{
|
||||
|
||||
private readonly PreGenerationRepo _repo;
|
||||
|
||||
public PreGenerationService(PreGenerationRepo repo)
|
||||
{
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
public GenerationProcess ComputeGeneration(string specPath, GenerationType? generationType, PublishType publishType)
|
||||
{
|
||||
return _repo.GetProcess(specPath, generationType, publishType);
|
||||
}
|
||||
|
||||
}
|
||||
123
Generator/Services/PublicationService.cs
Normal file
123
Generator/Services/PublicationService.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using Core;
|
||||
using Core.Process;
|
||||
using Core.SpecConfig;
|
||||
using Generator.Repo;
|
||||
|
||||
namespace Generator.Services;
|
||||
|
||||
public class PublicationService
|
||||
{
|
||||
|
||||
private readonly PublisherRepo _publisherRepo;
|
||||
private readonly RepositoryService _repoService;
|
||||
public PublicationService(
|
||||
PublisherRepo pubRepo,
|
||||
RepositoryService repoService)
|
||||
{
|
||||
_publisherRepo = pubRepo;
|
||||
_repoService = repoService;
|
||||
}
|
||||
|
||||
public async Task Publish(GenerationProcess process)
|
||||
{
|
||||
foreach (var task in process)
|
||||
{
|
||||
switch (task.Language)
|
||||
{
|
||||
case Language.Dotnet:
|
||||
await PublishDotnet(task);
|
||||
break;
|
||||
case Language.Java:
|
||||
await PublishJava(task);
|
||||
break;
|
||||
case Language.Javascript:
|
||||
await PublishJavascript(task);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PublishDotnet(ProcessTask task)
|
||||
{
|
||||
while (task.Tasks.TryDequeue(out var file))
|
||||
{
|
||||
await PublishDotnet(file, task.GenerationType, task.PublishType);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PublishJava(ProcessTask task)
|
||||
{
|
||||
while (task.Tasks.TryDequeue(out var file))
|
||||
{
|
||||
await PublishJava(file, task.GenerationType, task.PublishType);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PublishJavascript(ProcessTask task)
|
||||
{
|
||||
while (task.Tasks.TryDequeue(out var file))
|
||||
{
|
||||
await PublishJavascript(file, task.GenerationType, task.PublishType);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PublishDotnet(ISpecFile file, GenerationType genType, PublishType pubType)
|
||||
{
|
||||
var data = await _repoService.GetVersions(Language.Dotnet, file.NugetPackage);
|
||||
var package = data.FirstOrDefault(pd => pd.Version == file.Version);
|
||||
|
||||
if(pubType == PublishType.Force)
|
||||
{
|
||||
if (package != null) await _repoService.DeletePackage(package.Id);
|
||||
await _publisherRepo.PublishDotnet(genType, file);
|
||||
return;
|
||||
}
|
||||
|
||||
if(pubType == PublishType.Safe)
|
||||
{
|
||||
if (package == null) await _publisherRepo.PublishDotnet(genType, file);
|
||||
else Console.WriteLine($"The version {file.Version} of package {file.NugetPackage} already exists on the repository");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PublishJava(ISpecFile file, GenerationType genType, PublishType pubType)
|
||||
{
|
||||
var artifact = $"{file.Name}-api";
|
||||
var data = await _repoService.GetVersions(Language.Java, artifact);
|
||||
var package = data.FirstOrDefault(pd => pd.Version == file.Version);
|
||||
|
||||
if(pubType == PublishType.Force)
|
||||
{
|
||||
if (package != null) await _repoService.DeletePackage(package.Id);
|
||||
await _publisherRepo.PublishJava(genType, file);
|
||||
return;
|
||||
}
|
||||
|
||||
if(pubType == PublishType.Safe)
|
||||
{
|
||||
if (package == null) await _publisherRepo.PublishJava(genType, file);
|
||||
else Console.WriteLine($"The version {file.Version} of package {artifact} already exists on the repository");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PublishJavascript(ISpecFile file, GenerationType genType, PublishType pubType)
|
||||
{
|
||||
var data = await _repoService.GetVersions(Language.Javascript, file.NpmPackage);
|
||||
var package = data.FirstOrDefault(pd => pd.Version == file.Version);
|
||||
|
||||
if(pubType == PublishType.Force)
|
||||
{
|
||||
if (package != null) await _repoService.DeletePackage(package.Id);
|
||||
await _publisherRepo.PublishJavascript(genType, file);
|
||||
return;
|
||||
}
|
||||
|
||||
if(pubType == PublishType.Safe)
|
||||
{
|
||||
if (package == null) await _publisherRepo.PublishJavascript(genType, file);
|
||||
else Console.WriteLine($"The version {file.Version} of package {file.NpmPackage} already exists on the repository");
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Generator/Services/RepositoryService.cs
Normal file
25
Generator/Services/RepositoryService.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Core;
|
||||
using Core.SpecConfig;
|
||||
using Generator.Repo;
|
||||
|
||||
namespace Generator.Services;
|
||||
|
||||
public class RepositoryService
|
||||
{
|
||||
private readonly RepositoryActions _actions;
|
||||
|
||||
public RepositoryService(RepositoryActions actions)
|
||||
{
|
||||
_actions = actions;
|
||||
}
|
||||
|
||||
public async Task<List<PackageData>> GetVersions(Language language, string package)
|
||||
{
|
||||
return await _actions.GetVersions(language, package);
|
||||
}
|
||||
|
||||
public async Task DeletePackage(string packageId)
|
||||
{
|
||||
await _actions.DeleteVersion(packageId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user