diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AssetWsApiHelper.java b/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AssetClient.java similarity index 74% rename from cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AssetWsApiHelper.java rename to cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AssetClient.java index 1b997debfe..7d848cf7b0 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AssetWsApiHelper.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AssetClient.java @@ -3,13 +3,13 @@ import com.box.l10n.mojito.cli.command.CommandException; import com.box.l10n.mojito.cli.model.AssetAssetSummary; import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import org.springframework.util.Assert; -@Component -public class AssetWsApiHelper { - @Autowired AssetWsApi assetClient; +public class AssetClient extends AssetWsApi { + + public AssetClient(ApiClient apiClient) { + super(apiClient); + } public AssetAssetSummary getAssetByPathAndRepositoryId(String path, Long repositoryId) throws CommandException { @@ -18,7 +18,7 @@ public AssetAssetSummary getAssetByPathAndRepositoryId(String path, Long reposit List assets; try { - assets = this.assetClient.getAssets(repositoryId, path, null, null, null); + assets = this.getAssets(repositoryId, path, null, null, null); } catch (ApiException e) { throw new RuntimeException(e); } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/RepositoryWsApiHelper.java b/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/RepositoryClient.java similarity index 83% rename from cli/src/main/java/com/box/l10n/mojito/cli/apiclient/RepositoryWsApiHelper.java rename to cli/src/main/java/com/box/l10n/mojito/cli/apiclient/RepositoryClient.java index e3522ecbf1..ce170d0e5b 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/RepositoryWsApiHelper.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/RepositoryClient.java @@ -7,12 +7,12 @@ import java.time.OffsetDateTime; import java.util.List; import java.util.regex.Pattern; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -@Component -public class RepositoryWsApiHelper { - @Autowired RepositoryWsApi repositoryClient; +public class RepositoryClient extends RepositoryWsApi { + + public RepositoryClient(ApiClient apiClient) { + super(apiClient); + } public List getBranchesOfRepository( Long repositoryId, @@ -26,7 +26,7 @@ public List getBranchesOfRepository( List branches; try { branches = - this.repositoryClient.getBranchesOfRepository( + this.getBranchesOfRepository( repositoryId, branchName, deleted, translated, createdBefore); } catch (ApiException e) { throw new CommandException(e.getMessage(), e); @@ -51,7 +51,7 @@ public List getBranchesOfRepository( public RepositoryRepository findRepositoryByName(String repositoryName) throws CommandException { try { Preconditions.checkNotNull(repositoryName, "Repository name can't be null"); - List repositories = repositoryClient.getRepositories(repositoryName); + List repositories = this.getRepositories(repositoryName); if (repositories.size() != 1) { throw new CommandException("Repository with name [" + repositoryName + "] is not found"); } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/WsApiConfig.java b/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/WsApiConfig.java index 030aadb548..fb70ec5252 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/WsApiConfig.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/WsApiConfig.java @@ -33,16 +33,6 @@ public RepositoryWsApi repositoryWsApi() { return new RepositoryWsApi(this.apiClient); } - @Bean - public CommitWsApi commitWsApi() { - return new CommitWsApi(this.apiClient); - } - - @Bean - public ImageWsApi imageWsApi() { - return new ImageWsApi(this.apiClient); - } - @Bean public AiPromptWsApi aiPromptWsApi() { return new AiPromptWsApi(this.apiClient); @@ -53,18 +43,13 @@ public AiChecksWsApi aiChecksWsApi() { return new AiChecksWsApi(this.apiClient); } - @Bean - public AssetWsApi assetWsApi() { - return new AssetWsApi(this.apiClient); - } - @Bean public DropWsApi dropWsApi() { return new DropWsApi(this.apiClient); } @Bean - public CliWsApi cliWsApi() { - return new CliWsApi(this.apiClient); + public ScreenshotWsApi screenshotWsApi() { + return new ScreenshotWsApi(this.apiClient); } } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/BranchDeleteCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/BranchDeleteCommand.java index b1e429dac3..c910cb9e96 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/BranchDeleteCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/BranchDeleteCommand.java @@ -16,9 +16,9 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; -import com.box.l10n.mojito.cli.apiclient.RepositoryWsApi; -import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiHelper; +import com.box.l10n.mojito.cli.apiclient.RepositoryClient; import com.box.l10n.mojito.cli.command.param.Param; import com.box.l10n.mojito.cli.console.ConsoleWriter; import com.box.l10n.mojito.cli.model.BranchBranchSummary; @@ -44,10 +44,6 @@ public class BranchDeleteCommand extends Command { @Autowired ConsoleWriter consoleWriter; - @Autowired RepositoryWsApi repositoryClient; - - @Autowired RepositoryWsApiHelper repositoryWsApiHelper; - @Autowired CommandHelper commandHelper; @Parameter( @@ -93,6 +89,8 @@ public class BranchDeleteCommand extends Command { description = BRANCH_CREATED_BEFORE_DESCRIPTION) String createdBefore = null; + @Autowired private ApiClient apiClient; + @Override public void execute() throws CommandException { consoleWriter @@ -101,8 +99,8 @@ public void execute() throws CommandException { .fg(Ansi.Color.CYAN) .a(repositoryParam) .println(); - RepositoryRepository repository = - this.repositoryWsApiHelper.findRepositoryByName(this.repositoryParam); + RepositoryClient repositoryClient = new RepositoryClient(this.apiClient); + RepositoryRepository repository = repositoryClient.findRepositoryByName(this.repositoryParam); ZonedDateTime createdBeforeDateTime = this.commandHelper.getLastWeekDateIfTrue(this.beforeLastWeek); @@ -118,7 +116,7 @@ public void execute() throws CommandException { } List branches = - this.repositoryWsApiHelper.getBranchesOfRepository( + repositoryClient.getBranchesOfRepository( repository.getId(), branchName, branchNameRegex, diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/BranchViewCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/BranchViewCommand.java index 6466031d2f..5919ddb558 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/BranchViewCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/BranchViewCommand.java @@ -13,7 +13,8 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; -import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiHelper; +import com.box.l10n.mojito.cli.apiclient.ApiClient; +import com.box.l10n.mojito.cli.apiclient.RepositoryClient; import com.box.l10n.mojito.cli.command.param.Param; import com.box.l10n.mojito.cli.console.ConsoleWriter; import com.box.l10n.mojito.cli.model.BranchBranchSummary; @@ -38,8 +39,6 @@ public class BranchViewCommand extends Command { @Autowired ConsoleWriter consoleWriter; - @Autowired RepositoryWsApiHelper repositoryWsApiHelper; - @Autowired CommandHelper commandHelper; @Parameter( @@ -79,6 +78,8 @@ public class BranchViewCommand extends Command { description = BRANCH_CREATED_BEFORE_LAST_WEEK_DESCRIPTION) boolean beforeLastWeek; + @Autowired private ApiClient apiClient; + @Override public void execute() throws CommandException { consoleWriter @@ -87,10 +88,11 @@ public void execute() throws CommandException { .fg(Ansi.Color.CYAN) .a(repositoryParam) .println(); - RepositoryRepository repository = repositoryWsApiHelper.findRepositoryByName(repositoryParam); + RepositoryClient repositoryClient = new RepositoryClient(this.apiClient); + RepositoryRepository repository = repositoryClient.findRepositoryByName(repositoryParam); List branches = - this.repositoryWsApiHelper.getBranchesOfRepository( + repositoryClient.getBranchesOfRepository( repository.getId(), null, branchNameRegex, diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/CommitCreateCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/CommitCreateCommand.java index da234262d7..b9868db719 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/CommitCreateCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/CommitCreateCommand.java @@ -5,9 +5,10 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.box.l10n.mojito.JSR310Migration; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; import com.box.l10n.mojito.cli.apiclient.CommitWsApi; -import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiHelper; +import com.box.l10n.mojito.cli.apiclient.RepositoryClient; import com.box.l10n.mojito.cli.command.param.Param; import com.box.l10n.mojito.cli.console.ConsoleWriter; import com.box.l10n.mojito.cli.model.CommitBody; @@ -46,10 +47,6 @@ public class CommitCreateCommand extends Command { @Autowired CommandHelper commandHelper; - @Autowired CommitWsApi commitClient; - - @Autowired RepositoryWsApiHelper repositoryWsApiHelper; - @Parameter( names = {Param.COMMIT_HASH_LONG, Param.COMMIT_HASH_SHORT}, arity = 1, @@ -90,6 +87,8 @@ public class CommitCreateCommand extends Command { + " the first commit from 'git log' is used.") boolean readInfoFromGit = false; + @Autowired private ApiClient apiClient; + @Override protected void execute() throws CommandException { consoleWriter @@ -98,9 +97,8 @@ protected void execute() throws CommandException { .fg(Ansi.Color.CYAN) .a(repositoryParam) .println(2); - RepositoryRepository repository = - this.repositoryWsApiHelper.findRepositoryByName(repositoryParam); + new RepositoryClient(this.apiClient).findRepositoryByName(repositoryParam); final CommitInfo commitInfo; @@ -122,7 +120,7 @@ protected void execute() throws CommandException { commitBody.setSourceCreationDate(creationDateMilliSeconds); CommitCommit commit; try { - commit = commitClient.createCommit(commitBody); + commit = new CommitWsApi(this.apiClient).createCommit(commitBody); } catch (ApiException e) { throw new CommandException(e.getMessage(), e); } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/CommitToPullRunCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/CommitToPullRunCommand.java index 76f0ba43d9..446c344f74 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/CommitToPullRunCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/CommitToPullRunCommand.java @@ -2,9 +2,10 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; import com.box.l10n.mojito.cli.apiclient.CommitWsApi; -import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiHelper; +import com.box.l10n.mojito.cli.apiclient.RepositoryClient; import com.box.l10n.mojito.cli.command.param.Param; import com.box.l10n.mojito.cli.console.ConsoleWriter; import com.box.l10n.mojito.cli.model.CommitToPullRunBody; @@ -60,9 +61,7 @@ public class CommitToPullRunCommand extends Command { @Autowired ObjectMapper objectMapper; - @Autowired CommitWsApi commitClient; - - @Autowired RepositoryWsApiHelper repositoryWsApiHelper; + @Autowired ApiClient apiClient; RepositoryRepository repository; @@ -70,8 +69,7 @@ public class CommitToPullRunCommand extends Command { public void execute() throws CommandException { consoleWriter.newLine().a("Mapping commit: ").fg(Color.CYAN).a(commitHash).println(2); - - repository = this.repositoryWsApiHelper.findRepositoryByName(repositoryParam); + repository = new RepositoryClient(this.apiClient).findRepositoryByName(repositoryParam); String pullRunName = readPullRunNameFromFile(); @@ -96,7 +94,7 @@ void associateCommitToPullRun( commitToPullRunBody.setRepositoryId(repository.getId()); commitToPullRunBody.setPullRunName(pullRunName); try { - commitClient.associateCommitToPullRun(commitToPullRunBody); + new CommitWsApi(this.apiClient).associateCommitToPullRun(commitToPullRunBody); } catch (ApiException e) { throw new CommandException(e.getMessage(), e); } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/EvolveCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/EvolveCommand.java index 680529e5a3..153bae6663 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/EvolveCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/EvolveCommand.java @@ -2,19 +2,20 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; +import com.box.l10n.mojito.cli.apiclient.ApiClient; +import com.box.l10n.mojito.cli.apiclient.ApiException; +import com.box.l10n.mojito.cli.apiclient.AssetWsApi; import com.box.l10n.mojito.cli.command.param.Param; import com.box.l10n.mojito.cli.console.ConsoleWriter; +import com.box.l10n.mojito.cli.model.LocalizedAssetBody; +import com.box.l10n.mojito.cli.model.SourceAsset; import com.box.l10n.mojito.evolve.Course; import com.box.l10n.mojito.evolve.Evolve; import com.box.l10n.mojito.io.Files; -import com.box.l10n.mojito.rest.client.AssetClient; import com.box.l10n.mojito.rest.client.PollableTaskClient; -import com.box.l10n.mojito.rest.client.RepositoryClient; import com.box.l10n.mojito.rest.entity.Locale; -import com.box.l10n.mojito.rest.entity.LocalizedAssetBody; import com.box.l10n.mojito.rest.entity.Repository; import com.box.l10n.mojito.rest.entity.RepositoryLocale; -import com.box.l10n.mojito.rest.entity.SourceAsset; import com.google.common.base.Preconditions; import com.ibm.icu.util.ULocale; import java.nio.file.Path; @@ -79,14 +80,14 @@ public class EvolveCommand extends Command { @Autowired(required = false) Evolve evolve; - @Autowired RepositoryClient repositoryClient; - - @Autowired AssetClient assetClient; + @Autowired ApiClient apiClient; @Autowired PollableTaskClient pollableTaskClient; @Autowired CommandHelper commandHelper; + private AssetWsApi assetClient; + @Override public boolean shouldShowInCommandList() { return false; @@ -94,6 +95,7 @@ public boolean shouldShowInCommandList() { @Override public void execute() throws CommandException { + this.assetClient = new AssetWsApi(apiClient); checkEvolveConfiguration(); consoleWriter @@ -173,24 +175,33 @@ SourceAsset sendSource(Repository repository, String courseId, String translatio sourceAsset.setPath(courseId + ".json"); sourceAsset.setContent(translationsByCourseId); sourceAsset.setFilterOptions(FILTER_OPTIONS); - sourceAsset = assetClient.sendSourceAsset(sourceAsset); + try { + sourceAsset = assetClient.importSourceAsset(sourceAsset); + } catch (ApiException e) { + throw new CommandException(e.getMessage(), e); + } pollableTaskClient.waitForPollableTask(sourceAsset.getPollableTask().getId()); return sourceAsset; } String getLocalizedCourse(Long assetId, long localeId, String translationsByCourseId) { - - LocalizedAssetBody localizedAssetForContent = - assetClient.getLocalizedAssetForContent( - assetId, - localeId, - translationsByCourseId, - null, - null, - FILTER_OPTIONS, - LocalizedAssetBody.Status.ALL, - LocalizedAssetBody.InheritanceMode.USE_PARENT, - null); + LocalizedAssetBody localizedAssetBody = new LocalizedAssetBody(); + localizedAssetBody.setAssetId(assetId); + localizedAssetBody.setLocaleId(localeId); + localizedAssetBody.setContent(translationsByCourseId); + localizedAssetBody.setOutputBcp47tag(null); + localizedAssetBody.setFilterConfigIdOverride(null); + localizedAssetBody.setFilterOptions(FILTER_OPTIONS); + localizedAssetBody.setStatus(LocalizedAssetBody.StatusEnum.ALL); + localizedAssetBody.setInheritanceMode(LocalizedAssetBody.InheritanceModeEnum.USE_PARENT); + localizedAssetBody.setPullRunName(null); + LocalizedAssetBody localizedAssetForContent; + try { + localizedAssetForContent = + assetClient.getLocalizedAssetForContent(localizedAssetBody, assetId, localeId); + } catch (ApiException e) { + throw new CommandException(e.getMessage(), e); + } return localizedAssetForContent.getContent(); } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/MainCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/MainCommand.java index 4953aafc56..bc2b13049a 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/MainCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/MainCommand.java @@ -3,6 +3,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.box.l10n.mojito.cli.GitInfo; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; import com.box.l10n.mojito.cli.apiclient.CliWsApi; import com.box.l10n.mojito.cli.console.ConsoleWriter; @@ -38,7 +39,7 @@ public class MainCommand extends Command { @Autowired GitInfo gitInfo; - @Autowired CliWsApi cliClient; + @Autowired ApiClient apiClient; @Override void showUsage() { @@ -59,7 +60,7 @@ protected void execute() throws CommandException { void checkServerVersion() throws CommandException { String serverVersion; try { - serverVersion = cliClient.getVersion(); + serverVersion = new CliWsApi(this.apiClient).getVersion(); } catch (ApiException e) { throw new CommandException(e.getMessage(), e); } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoViewCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoViewCommand.java index 84b1ff5944..3fb26092cf 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoViewCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoViewCommand.java @@ -2,7 +2,8 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; -import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiHelper; +import com.box.l10n.mojito.cli.apiclient.ApiClient; +import com.box.l10n.mojito.cli.apiclient.RepositoryClient; import com.box.l10n.mojito.cli.command.param.Param; import com.box.l10n.mojito.cli.model.AssetIntegrityCheckerRepository; import com.box.l10n.mojito.cli.model.RepositoryLocaleRepository; @@ -39,13 +40,13 @@ public class RepoViewCommand extends RepoCommand { description = Param.REPOSITORY_NAME_DESCRIPTION) String nameParam; - @Autowired RepositoryWsApiHelper repositoryWsApiHelper; + @Autowired private ApiClient apiClient; @Override public void execute() throws CommandException { consoleWriter.a("View repository: ").fg(Ansi.Color.CYAN).a(nameParam).println(); - - RepositoryRepository repository = this.repositoryWsApiHelper.findRepositoryByName(nameParam); + RepositoryRepository repository = + new RepositoryClient(this.apiClient).findRepositoryByName(nameParam); consoleWriter .newLine() .a("Repository id --> ") diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/RepositoryMachineTranslationCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/RepositoryMachineTranslationCommand.java index 57a98f3510..d81049f5ae 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/RepositoryMachineTranslationCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/RepositoryMachineTranslationCommand.java @@ -2,11 +2,13 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; +import com.box.l10n.mojito.cli.apiclient.ApiClient; +import com.box.l10n.mojito.cli.apiclient.ApiException; +import com.box.l10n.mojito.cli.apiclient.MachineTranslationWsApi; import com.box.l10n.mojito.cli.command.param.Param; import com.box.l10n.mojito.cli.console.ConsoleWriter; -import com.box.l10n.mojito.rest.client.RepositoryMachineTranslationClient; -import com.box.l10n.mojito.rest.entity.PollableTask; -import com.box.l10n.mojito.rest.entity.RepositoryMachineTranslationBody; +import com.box.l10n.mojito.cli.model.PollableTask; +import com.box.l10n.mojito.cli.model.RepositoryMachineTranslationBody; import java.util.List; import java.util.stream.Collectors; import org.fusesource.jansi.Ansi.Color; @@ -57,7 +59,7 @@ public class RepositoryMachineTranslationCommand extends Command { @Autowired CommandHelper commandHelper; - @Autowired RepositoryMachineTranslationClient repositoryMachineTranslationClient; + @Autowired ApiClient apiClient; @Override public boolean shouldShowInCommandList() { @@ -84,8 +86,13 @@ public void execute() throws CommandException { repositoryMachineTranslationBody.setTargetBcp47tags(locales); repositoryMachineTranslationBody.setSourceTextMaxCountPerLocale(sourceTextMaxCount); - repositoryMachineTranslationBody = - repositoryMachineTranslationClient.translateRepository(repositoryMachineTranslationBody); + try { + repositoryMachineTranslationBody = + new MachineTranslationWsApi(this.apiClient) + .translateRepository(repositoryMachineTranslationBody); + } catch (ApiException e) { + throw new CommandException(e.getMessage(), e); + } PollableTask pollableTask = repositoryMachineTranslationBody.getPollableTask(); commandHelper.waitForPollableTask(pollableTask.getId()); diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/ScreenshotCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/ScreenshotCommand.java index 52130f0da4..35b574d4d8 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/ScreenshotCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/ScreenshotCommand.java @@ -3,6 +3,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.box.l10n.mojito.LocaleMappingHelper; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; import com.box.l10n.mojito.cli.apiclient.ImageWsApi; import com.box.l10n.mojito.cli.command.param.Param; @@ -90,7 +91,7 @@ public class ScreenshotCommand extends Command { CommandDirectories commandDirectories; - @Autowired ImageWsApi imageClient; + @Autowired ApiClient apiClient; @Autowired ScreenshotClient screenshotClient; @@ -206,7 +207,7 @@ void uploadImage(Path image, String uploadPath) throws CommandException { logger.debug("Upload image: {} to path: {}", image.toString(), uploadPath); try { byte[] content = Files.readAllBytes(image); - imageClient.uploadImage(content, uploadPath); + new ImageWsApi(this.apiClient).uploadImage(content, uploadPath); } catch (IOException | ApiException ex) { throw new CommandException("Failed to upload image: " + image.toString(), ex); } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/TMExportCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/TMExportCommand.java index 3951d68d0f..840a6d590d 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/TMExportCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/TMExportCommand.java @@ -2,9 +2,10 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; import com.box.l10n.mojito.cli.apiclient.AssetWsApi; -import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiHelper; +import com.box.l10n.mojito.cli.apiclient.RepositoryClient; import com.box.l10n.mojito.cli.command.param.Param; import com.box.l10n.mojito.cli.console.ConsoleWriter; import com.box.l10n.mojito.cli.model.AssetAssetSummary; @@ -70,9 +71,7 @@ public class TMExportCommand extends Command { @Autowired CommandHelper commandHelper; - @Autowired RepositoryWsApiHelper repositoryWsApiHelper; - - @Autowired AssetWsApi assetClient; + @Autowired private ApiClient apiClient; CommandDirectories commandDirectories; @@ -92,8 +91,9 @@ public void execute() throws CommandException { targetBasenameParam = MoreObjects.firstNonNull(targetBasenameParam, repositoryParam); RepositoryRepository repository = - this.repositoryWsApiHelper.findRepositoryByName(repositoryParam); + new RepositoryClient(this.apiClient).findRepositoryByName(repositoryParam); + AssetWsApi assetClient = new AssetWsApi(this.apiClient); List assets; try { assets = assetClient.getAssets(repository.getId(), null, null, null, null); diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/TMImportCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/TMImportCommand.java index d5533b5cb4..b8ad8df483 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/TMImportCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/TMImportCommand.java @@ -2,9 +2,10 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; +import com.box.l10n.mojito.cli.apiclient.RepositoryClient; import com.box.l10n.mojito.cli.apiclient.RepositoryWsApi; -import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiHelper; import com.box.l10n.mojito.cli.command.param.Param; import com.box.l10n.mojito.cli.console.ConsoleWriter; import com.box.l10n.mojito.cli.filefinder.FileMatch; @@ -74,7 +75,7 @@ public class TMImportCommand extends Command { @Autowired CommandHelper commandHelper; - @Autowired RepositoryWsApiHelper repositoryWsApiHelper; + @Autowired private ApiClient apiClient; RepositoryRepository repository; @@ -90,7 +91,7 @@ public void execute() throws CommandException { .a(repositoryParam) .println(2); - repository = this.repositoryWsApiHelper.findRepositoryByName(repositoryParam); + repository = new RepositoryClient(this.apiClient).findRepositoryByName(repositoryParam); commandDirectories = new CommandDirectories(sourceDirectoryParam); FileType xliffFileType = new XliffFileType(); diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/ThirdPartySyncCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/ThirdPartySyncCommand.java index 8e7d898e1f..c22f01fa68 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/ThirdPartySyncCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/ThirdPartySyncCommand.java @@ -4,8 +4,9 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; -import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiHelper; +import com.box.l10n.mojito.cli.apiclient.RepositoryClient; import com.box.l10n.mojito.cli.apiclient.ThirdPartyWsApi; import com.box.l10n.mojito.cli.command.param.Param; import com.box.l10n.mojito.cli.console.ConsoleWriter; @@ -123,7 +124,7 @@ public class ThirdPartySyncCommand extends Command { @Autowired CommandHelper commandHelper; - @Autowired RepositoryWsApiHelper repositoryWsApiHelper; + @Autowired ApiClient apiClient; private ThirdPartySync getThirdPartySync(RepositoryRepository repository) { ThirdPartySync thirdPartySyncBody = new ThirdPartySync(); @@ -190,7 +191,7 @@ public void execute() throws CommandException { .println(2); RepositoryRepository repository = - this.repositoryWsApiHelper.findRepositoryByName(repositoryParam); + new RepositoryClient(this.apiClient).findRepositoryByName(repositoryParam); ThirdPartySync thirdPartySyncBody = getThirdPartySync(repository); diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/UserCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/UserCommand.java index ac347adc36..84ef6dece0 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/UserCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/UserCommand.java @@ -1,5 +1,6 @@ package com.box.l10n.mojito.cli.command; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; import com.box.l10n.mojito.cli.apiclient.UserWsApi; import com.box.l10n.mojito.cli.console.ConsoleWriter; @@ -9,19 +10,27 @@ import com.box.l10n.mojito.cli.model.User; import com.box.l10n.mojito.rest.entity.Role; import java.util.List; +import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; public abstract class UserCommand extends Command { - @Autowired UserWsApi userClient; + @Autowired protected ApiClient apiClient; - @Autowired ConsoleWriter consoleWriter; + @Autowired protected ConsoleWriter consoleWriter; + + protected UserWsApi userClient; + + @PostConstruct + protected void init() { + this.userClient = new UserWsApi(this.apiClient); + } protected PageUser getPageUser(String username) throws ApiException { Pageable pageable = new Pageable(); pageable.setPage(0); pageable.setSize(Integer.MAX_VALUE); pageable.setSort(List.of()); - PageUser pageUser = this.userClient.getUsers(pageable, username, null); + PageUser pageUser = new UserWsApi(this.apiClient).getUsers(pageable, username, null); if (pageUser.getContent().isEmpty()) { throw new CommandException("User with username [" + username + "] is not found"); } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/VirtualAssetCreateCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/VirtualAssetCreateCommand.java index 9e0ecb6639..1c3504c029 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/VirtualAssetCreateCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/VirtualAssetCreateCommand.java @@ -2,8 +2,9 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; -import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiHelper; +import com.box.l10n.mojito.cli.apiclient.RepositoryClient; import com.box.l10n.mojito.cli.apiclient.VirtualAssetWsApi; import com.box.l10n.mojito.cli.command.param.Param; import com.box.l10n.mojito.cli.console.ConsoleWriter; @@ -50,7 +51,7 @@ public class VirtualAssetCreateCommand extends Command { @Autowired VirtualAssetWsApi virtualAssetClient; - @Autowired RepositoryWsApiHelper repositoryWsApiHelper; + @Autowired private ApiClient apiClient; private HttpClientErrorJson toHttpClientErrorJson(ApiException ae) { try { @@ -75,7 +76,7 @@ public void execute() throws CommandException { .println(2); RepositoryRepository repository = - this.repositoryWsApiHelper.findRepositoryByName(repositoryParam); + new RepositoryClient(this.apiClient).findRepositoryByName(repositoryParam); VirtualAsset virtualAsset = new VirtualAsset(); virtualAsset.setPath(pathParam); diff --git a/cli/src/test/java/com/box/l10n/mojito/cli/CLITestBase.java b/cli/src/test/java/com/box/l10n/mojito/cli/CLITestBase.java index 6d788742de..8a8cb1c5a1 100644 --- a/cli/src/test/java/com/box/l10n/mojito/cli/CLITestBase.java +++ b/cli/src/test/java/com/box/l10n/mojito/cli/CLITestBase.java @@ -1,6 +1,7 @@ package com.box.l10n.mojito.cli; import com.box.l10n.mojito.Application; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.command.L10nJCommander; import com.box.l10n.mojito.entity.Locale; import com.box.l10n.mojito.entity.Repository; @@ -74,6 +75,8 @@ public class CLITestBase extends IOTestBase { @LocalServerPort int port; + @Autowired protected ApiClient apiClient; + @PostConstruct public void setPort() { logger.debug("Saving port number = {}", port); diff --git a/cli/src/test/java/com/box/l10n/mojito/cli/command/BranchDeleteCommandTest.java b/cli/src/test/java/com/box/l10n/mojito/cli/command/BranchDeleteCommandTest.java index 46e0304c64..03805e8f8b 100644 --- a/cli/src/test/java/com/box/l10n/mojito/cli/command/BranchDeleteCommandTest.java +++ b/cli/src/test/java/com/box/l10n/mojito/cli/command/BranchDeleteCommandTest.java @@ -9,7 +9,7 @@ import static org.junit.Assert.assertEquals; import com.box.l10n.mojito.cli.CLITestBase; -import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiHelper; +import com.box.l10n.mojito.cli.apiclient.RepositoryClient; import com.box.l10n.mojito.cli.model.BranchBranchSummary; import com.box.l10n.mojito.entity.Repository; import com.box.l10n.mojito.service.branch.BranchRepository; @@ -19,16 +19,22 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; public class BranchDeleteCommandTest extends CLITestBase { - @Autowired RepositoryWsApiHelper repositoryClient; + RepositoryClient repositoryClient; @Autowired BranchRepository branchRepository; + @Before + public void before() { + this.repositoryClient = new RepositoryClient(this.apiClient); + } + @Test public void delete() throws Exception { Repository repository = createTestRepoUsingRepoService(); diff --git a/cli/src/test/java/com/box/l10n/mojito/cli/command/TMExportCommandTest.java b/cli/src/test/java/com/box/l10n/mojito/cli/command/TMExportCommandTest.java index 9abe48285d..186d00d999 100644 --- a/cli/src/test/java/com/box/l10n/mojito/cli/command/TMExportCommandTest.java +++ b/cli/src/test/java/com/box/l10n/mojito/cli/command/TMExportCommandTest.java @@ -1,19 +1,24 @@ package com.box.l10n.mojito.cli.command; import com.box.l10n.mojito.cli.CLITestBase; -import com.box.l10n.mojito.cli.apiclient.AssetWsApiHelper; +import com.box.l10n.mojito.cli.apiclient.AssetClient; import com.box.l10n.mojito.cli.model.AssetAssetSummary; import com.box.l10n.mojito.entity.Repository; import com.box.l10n.mojito.test.XliffUtils; +import org.junit.Before; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; /** * @author jaurambault */ public class TMExportCommandTest extends CLITestBase { - @Autowired AssetWsApiHelper assetWsApiHelper; + AssetClient assetClient; + + @Before + public void before() { + this.assetClient = new AssetClient(this.apiClient); + } @Test public void export() throws Exception { @@ -29,14 +34,12 @@ public void export() throws Exception { getInputResourcesTestDir("source").getAbsolutePath()); AssetAssetSummary asset = - this.assetWsApiHelper.getAssetByPathAndRepositoryId( - "source-xliff.xliff", repository.getId()); + this.assetClient.getAssetByPathAndRepositoryId("source-xliff.xliff", repository.getId()); importTranslations(asset.getId(), "source-xliff_", "fr-FR"); importTranslations(asset.getId(), "source-xliff_", "ja-JP"); AssetAssetSummary asset2 = - this.assetWsApiHelper.getAssetByPathAndRepositoryId( - "source2-xliff.xliff", repository.getId()); + this.assetClient.getAssetByPathAndRepositoryId("source2-xliff.xliff", repository.getId()); importTranslations(asset2.getId(), "source2-xliff_", "fr-FR"); importTranslations(asset2.getId(), "source2-xliff_", "ja-JP"); diff --git a/webapp/src/main/java/com/box/l10n/mojito/entity/ScreenshotRun.java b/webapp/src/main/java/com/box/l10n/mojito/entity/ScreenshotRun.java index f00fe7d257..a7517587fe 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/entity/ScreenshotRun.java +++ b/webapp/src/main/java/com/box/l10n/mojito/entity/ScreenshotRun.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -38,6 +39,7 @@ public class ScreenshotRun extends SettableAuditableEntity { foreignKey = @ForeignKey(name = "FK__SCREENSHOT_RUN__REPOSITORY__ID"), nullable = false) @JsonBackReference + @Schema(accessMode = Schema.AccessMode.WRITE_ONLY) private Repository repository; @Column(name = "name")