From 69cdca6357b68632a6f345fa275fc4716f4cba05 Mon Sep 17 00:00:00 2001 From: Darko Date: Mon, 9 Dec 2024 11:30:30 -0400 Subject: [PATCH] I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls Refactor other commands --- ...AssetWsApiHelper.java => AssetClient.java} | 12 +- .../cli/apiclient/AuthenticatedApiClient.java | 17 +-- .../AuthenticatedApiInterceptor.java | 12 +- ...WsApiHelper.java => RepositoryClient.java} | 14 +- .../mojito/cli/apiclient/WsApiConfig.java | 70 --------- .../mappers/GitBlameWithUsageMapper.java | 142 ++++++++++++++++++ .../AIRepositoryLocaleOverrideCommand.java | 6 +- .../command/AddPromptToRepositoryCommand.java | 7 +- .../cli/command/BranchDeleteCommand.java | 16 +- .../mojito/cli/command/BranchViewCommand.java | 12 +- .../cli/command/CommitCreateCommand.java | 14 +- .../cli/command/CommitToPullRunCommand.java | 12 +- .../cli/command/CreateAIPromptCommand.java | 7 +- .../CreateAIPromptContextMessageCommand.java | 8 +- .../cli/command/DeleteAIPromptCommand.java | 7 +- .../DeleteAIPromptContextMessageCommand.java | 7 +- .../mojito/cli/command/EvolveCommand.java | 51 ++++--- .../mojito/cli/command/GitBlameCommand.java | 82 ++++++---- .../mojito/cli/command/GitRepository.java | 6 +- .../l10n/mojito/cli/command/MainCommand.java | 5 +- .../cli/command/QuartzJobsDeleteCommand.java | 5 +- .../cli/command/QuartzJobsViewCommand.java | 5 +- .../mojito/cli/command/RepoViewCommand.java | 9 +- .../RepositoryMachineTranslationCommand.java | 19 ++- .../mojito/cli/command/ScreenshotCommand.java | 5 +- .../mojito/cli/command/TMExportCommand.java | 10 +- .../mojito/cli/command/TMImportCommand.java | 12 +- .../cli/command/ThirdPartySyncCommand.java | 11 +- .../l10n/mojito/cli/command/UserCommand.java | 15 +- .../command/VirtualAssetCreateCommand.java | 11 +- .../mojito/cli/command/checks/AIChecker.java | 11 +- .../com/box/l10n/mojito/cli/CLITestBase.java | 3 + .../cli/command/BranchDeleteCommandTest.java | 10 +- .../cli/command/GitBlameCommandTest.java | 58 ++++--- .../cli/command/TMExportCommandTest.java | 17 ++- .../box/l10n/mojito/entity/ScreenshotRun.java | 2 + 36 files changed, 429 insertions(+), 281 deletions(-) rename cli/src/main/java/com/box/l10n/mojito/cli/apiclient/{AssetWsApiHelper.java => AssetClient.java} (74%) rename cli/src/main/java/com/box/l10n/mojito/cli/apiclient/{RepositoryWsApiHelper.java => RepositoryClient.java} (83%) delete mode 100644 cli/src/main/java/com/box/l10n/mojito/cli/apiclient/WsApiConfig.java create mode 100644 cli/src/main/java/com/box/l10n/mojito/cli/apiclient/mappers/GitBlameWithUsageMapper.java 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/AuthenticatedApiClient.java b/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AuthenticatedApiClient.java index 4845311732..9685fff1ec 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AuthenticatedApiClient.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AuthenticatedApiClient.java @@ -2,34 +2,19 @@ import com.squareup.okhttp.OkHttpClient; import jakarta.annotation.PostConstruct; -import java.net.CookieHandler; -import java.net.CookieManager; -import java.net.CookiePolicy; import org.springframework.stereotype.Component; @Component public class AuthenticatedApiClient extends ApiClient { - private CookieManager cookieManager; - @PostConstruct public void init() { - this.cookieManager = this.getCookieManager(); this.setHttpClient(this.getOkHttpClient()); } - private CookieManager getCookieManager() { - CookieManager cookieManager = new CookieManager(); - cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER); - CookieHandler.setDefault(cookieManager); - return cookieManager; - } - private OkHttpClient getOkHttpClient() { OkHttpClient httpClient = new OkHttpClient(); - httpClient - .interceptors() - .add(new AuthenticatedApiInterceptor(this.cookieManager, this.getBasePath())); + httpClient.interceptors().add(new AuthenticatedApiInterceptor(this.getBasePath())); return httpClient; } } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AuthenticatedApiInterceptor.java b/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AuthenticatedApiInterceptor.java index 03cc7c1bcf..bb1247ac78 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AuthenticatedApiInterceptor.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AuthenticatedApiInterceptor.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.net.CookieHandler; import java.net.CookieManager; +import java.net.CookiePolicy; import java.net.CookieStore; import java.net.HttpCookie; import java.util.Optional; @@ -37,11 +38,18 @@ public class AuthenticatedApiInterceptor implements Interceptor { private final String basePath; - public AuthenticatedApiInterceptor(CookieManager cookieManager, String basePath) { - this.cookieManager = cookieManager; + public AuthenticatedApiInterceptor(String basePath) { + this.cookieManager = getCookieManager(); this.basePath = basePath; } + private CookieManager getCookieManager() { + CookieManager cookieManager = new CookieManager(); + cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER); + CookieHandler.setDefault(cookieManager); + return cookieManager; + } + private Optional getCookie() { CookieStore cookieStore = this.cookieManager.getCookieStore(); return cookieStore.getCookies().stream() 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 deleted file mode 100644 index 030aadb548..0000000000 --- a/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/WsApiConfig.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.box.l10n.mojito.cli.apiclient; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class WsApiConfig { - @Autowired private ApiClient apiClient; - - @Bean - public ThirdPartyWsApi thirdPartyWsApi() { - return new ThirdPartyWsApi(this.apiClient); - } - - @Bean - public UserWsApi userWsApi() { - return new UserWsApi(this.apiClient); - } - - @Bean - public QuartzWsApi quartzWsApi() { - return new QuartzWsApi(this.apiClient); - } - - @Bean - public VirtualAssetWsApi virtualAssetWsApi() { - return new VirtualAssetWsApi(this.apiClient); - } - - @Bean - 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); - } - - @Bean - 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); - } -} diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/mappers/GitBlameWithUsageMapper.java b/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/mappers/GitBlameWithUsageMapper.java new file mode 100644 index 0000000000..f24f30062b --- /dev/null +++ b/cli/src/main/java/com/box/l10n/mojito/cli/apiclient/mappers/GitBlameWithUsageMapper.java @@ -0,0 +1,142 @@ +package com.box.l10n.mojito.cli.apiclient.mappers; + +import static java.util.Optional.ofNullable; + +import com.box.l10n.mojito.cli.model.Branch; +import com.box.l10n.mojito.cli.model.BranchGitBlameWithUsage; +import com.box.l10n.mojito.cli.model.GitBlame; +import com.box.l10n.mojito.cli.model.GitBlameGitBlameWithUsage; +import com.box.l10n.mojito.cli.model.GitBlameWithUsage; +import com.box.l10n.mojito.cli.model.GitBlameWithUsageGitBlameWithUsage; +import com.box.l10n.mojito.cli.model.Repository; +import com.box.l10n.mojito.cli.model.RepositoryGitBlameWithUsage; +import com.box.l10n.mojito.cli.model.Screenshot; +import com.box.l10n.mojito.cli.model.ScreenshotGitBlameWithUsage; +import com.box.l10n.mojito.cli.model.ScreenshotTextUnit; +import com.box.l10n.mojito.cli.model.ScreenshotTextUnitGitBlameWithUsage; +import com.box.l10n.mojito.cli.model.TMTextUnit; +import com.box.l10n.mojito.cli.model.TMTextUnitGitBlameWithUsage; +import com.box.l10n.mojito.cli.model.User; +import com.box.l10n.mojito.cli.model.UserGitBlameWithUsage; + +public class GitBlameWithUsageMapper { + public static GitBlame mapToGitBlame(GitBlameGitBlameWithUsage gitBlameWithUsage) { + GitBlame gitBlame = new GitBlame(); + gitBlame.setId(gitBlameWithUsage.getId()); + gitBlame.setCreatedDate(gitBlameWithUsage.getCreatedDate()); + gitBlame.setAuthorEmail(gitBlameWithUsage.getAuthorEmail()); + gitBlame.setAuthorName(gitBlameWithUsage.getAuthorName()); + gitBlame.setCommitTime(gitBlameWithUsage.getCommitTime()); + gitBlame.setCommitName(gitBlameWithUsage.getCommitName()); + return gitBlame; + } + + public static Repository mapToRepository( + RepositoryGitBlameWithUsage repositoryGitBlameWithUsage) { + Repository repository = new Repository(); + repository.setId(repositoryGitBlameWithUsage.getId()); + repository.setCreatedDate(repositoryGitBlameWithUsage.getCreatedDate()); + repository.setName(repositoryGitBlameWithUsage.getName()); + return repository; + } + + public static User mapToUser(UserGitBlameWithUsage userGitBlameWithUsage) { + User user = new User(); + user.setId(userGitBlameWithUsage.getId()); + user.setCreatedDate(userGitBlameWithUsage.getCreatedDate()); + user.setUsername(userGitBlameWithUsage.getUsername()); + user.setCommonName(userGitBlameWithUsage.getCommonName()); + return user; + } + + public static TMTextUnit mapToTmTextUnit( + TMTextUnitGitBlameWithUsage tmTextUnitGitBlameWithUsage) { + TMTextUnit tmTextUnit = new TMTextUnit(); + tmTextUnit.setId(tmTextUnitGitBlameWithUsage.getId()); + tmTextUnit.setCreatedDate(tmTextUnitGitBlameWithUsage.getCreatedDate()); + tmTextUnit.setName(tmTextUnitGitBlameWithUsage.getName()); + return tmTextUnit; + } + + public static ScreenshotTextUnit mapToScreenshotTextUnit( + ScreenshotTextUnitGitBlameWithUsage screenshotTextUnitGitBlameWithUsage) { + ScreenshotTextUnit screenshotTextUnit = new ScreenshotTextUnit(); + screenshotTextUnit.setId(screenshotTextUnitGitBlameWithUsage.getId()); + screenshotTextUnit.setTmTextUnit( + ofNullable(screenshotTextUnitGitBlameWithUsage.getTmTextUnit()) + .map(GitBlameWithUsageMapper::mapToTmTextUnit) + .orElse(null)); + return screenshotTextUnit; + } + + public static Screenshot mapToScreenshot( + ScreenshotGitBlameWithUsage screenshotGitBlameWithUsage) { + Screenshot screenshot = new Screenshot(); + screenshot.setId(screenshotGitBlameWithUsage.getId()); + screenshot.setCreatedDate(screenshotGitBlameWithUsage.getCreatedDate()); + screenshot.setSrc(screenshotGitBlameWithUsage.getSrc()); + screenshot.setTextUnits( + ofNullable(screenshotGitBlameWithUsage.getTextUnits()) + .map( + textUnits -> + textUnits.stream() + .map(GitBlameWithUsageMapper::mapToScreenshotTextUnit) + .toList()) + .orElse(null)); + return screenshot; + } + + public static Branch mapToBranch(BranchGitBlameWithUsage branchGitBlameWithUsage) { + Branch branch = new Branch(); + branch.setId(branchGitBlameWithUsage.getId()); + branch.setCreatedDate(branchGitBlameWithUsage.getCreatedDate()); + branch.setRepository( + ofNullable(branchGitBlameWithUsage.getRepository()) + .map(GitBlameWithUsageMapper::mapToRepository) + .orElse(null)); + branch.setName(branchGitBlameWithUsage.getName()); + branch.setCreatedByUser( + ofNullable(branchGitBlameWithUsage.getCreatedByUser()) + .map(GitBlameWithUsageMapper::mapToUser) + .orElse(null)); + branch.setDeleted(branchGitBlameWithUsage.isDeleted()); + branch.setScreenshots( + ofNullable(branchGitBlameWithUsage.getScreenshots()) + .map( + screenshots -> + screenshots.stream().map(GitBlameWithUsageMapper::mapToScreenshot).toList()) + .orElse(null)); + return branch; + } + + public static GitBlameWithUsage mapToGitBlameWithUsage( + GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage) { + GitBlameWithUsage newGitBlameWithUsage = new GitBlameWithUsage(); + newGitBlameWithUsage.setUsages(gitBlameWithUsage.getUsages()); + newGitBlameWithUsage.setTextUnitName(gitBlameWithUsage.getTextUnitName()); + newGitBlameWithUsage.setPluralForm(gitBlameWithUsage.getPluralForm()); + newGitBlameWithUsage.setTmTextUnitId(gitBlameWithUsage.getTmTextUnitId()); + newGitBlameWithUsage.setAssetId(gitBlameWithUsage.getAssetId()); + newGitBlameWithUsage.setAssetTextUnitId(gitBlameWithUsage.getAssetTextUnitId()); + newGitBlameWithUsage.setThirdPartyTextUnitId(gitBlameWithUsage.getThirdPartyTextUnitId()); + newGitBlameWithUsage.setContent(gitBlameWithUsage.getContent()); + newGitBlameWithUsage.setComment(gitBlameWithUsage.getComment()); + newGitBlameWithUsage.setGitBlame( + ofNullable(gitBlameWithUsage.getGitBlame()) + .map(GitBlameWithUsageMapper::mapToGitBlame) + .orElse(null)); + newGitBlameWithUsage.setBranch( + ofNullable(gitBlameWithUsage.getBranch()) + .map(GitBlameWithUsageMapper::mapToBranch) + .orElse(null)); + newGitBlameWithUsage.setScreenshots( + ofNullable(gitBlameWithUsage.getScreenshots()) + .map( + screenshots -> + screenshots.stream().map(GitBlameWithUsageMapper::mapToScreenshot).toList()) + .orElse(null)); + newGitBlameWithUsage.setIntroducedBy(gitBlameWithUsage.getIntroducedBy()); + newGitBlameWithUsage.setIsVirtual(gitBlameWithUsage.isIsVirtual()); + return newGitBlameWithUsage; + } +} diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/AIRepositoryLocaleOverrideCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/AIRepositoryLocaleOverrideCommand.java index 6e70c0be74..c72b23d622 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/AIRepositoryLocaleOverrideCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/AIRepositoryLocaleOverrideCommand.java @@ -3,6 +3,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.box.l10n.mojito.cli.apiclient.AiPromptWsApi; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; import com.box.l10n.mojito.cli.model.AITranslationLocalePromptOverridesRequest; import org.slf4j.Logger; @@ -22,8 +23,6 @@ public class AIRepositoryLocaleOverrideCommand extends Command { static Logger logger = LoggerFactory.getLogger(CreateAIPromptCommand.class); - @Autowired AiPromptWsApi aiServiceClient; - @Parameter( names = {"--repository-name", "-r"}, required = true, @@ -55,6 +54,8 @@ public class AIRepositoryLocaleOverrideCommand extends Command { description = "Delete the AI prompt overrides for the given locales") boolean isDelete = false; + @Autowired private ApiClient apiClient; + @Override protected void execute() throws CommandException { AITranslationLocalePromptOverridesRequest aiTranslationLocalePromptOverridesRequest = @@ -64,6 +65,7 @@ protected void execute() throws CommandException { StringUtils.commaDelimitedListToSet(locales).stream().toList()); aiTranslationLocalePromptOverridesRequest.setAiPromptId(aiPromptId); aiTranslationLocalePromptOverridesRequest.setDisabled(disabled); + AiPromptWsApi aiServiceClient = new AiPromptWsApi(this.apiClient); try { if (isDelete) { aiServiceClient.deleteRepositoryLocalePromptOverrides( diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/AddPromptToRepositoryCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/AddPromptToRepositoryCommand.java index c93ad67854..fbbddfb58e 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/AddPromptToRepositoryCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/AddPromptToRepositoryCommand.java @@ -3,6 +3,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.box.l10n.mojito.cli.apiclient.AiPromptWsApi; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; import com.box.l10n.mojito.cli.console.ConsoleWriter; import org.slf4j.Logger; @@ -20,8 +21,6 @@ public class AddPromptToRepositoryCommand extends Command { static Logger logger = LoggerFactory.getLogger(AddPromptToRepositoryCommand.class); - @Autowired AiPromptWsApi aiServiceClient; - @Parameter( names = {"--repository-name", "-r"}, required = true, @@ -42,10 +41,12 @@ public class AddPromptToRepositoryCommand extends Command { @Autowired ConsoleWriter consoleWriter; + @Autowired ApiClient apiClient; + public void execute() { logger.debug("Add prompt to {} repository with id: {}", repository, promptId); try { - this.aiServiceClient.addPromptToRepository(promptId, repository, promptType); + new AiPromptWsApi(this.apiClient).addPromptToRepository(promptId, repository, promptType); } catch (ApiException e) { throw new CommandException(e.getMessage(), e); } 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/CreateAIPromptCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/CreateAIPromptCommand.java index ce9bca9bbb..05e23c45b7 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/CreateAIPromptCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/CreateAIPromptCommand.java @@ -3,6 +3,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.box.l10n.mojito.cli.apiclient.AiPromptWsApi; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; import com.box.l10n.mojito.cli.console.ConsoleWriter; import com.box.l10n.mojito.cli.model.AIPromptCreateRequest; @@ -21,8 +22,6 @@ public class CreateAIPromptCommand extends Command { static Logger logger = LoggerFactory.getLogger(CreateAIPromptCommand.class); - @Autowired AiPromptWsApi aiServiceClient; - @Parameter( names = {"--repository-name", "-r"}, required = false, @@ -73,6 +72,8 @@ public class CreateAIPromptCommand extends Command { @Autowired private ConsoleWriter consoleWriter; + @Autowired ApiClient apiClient; + @Override protected void execute() throws CommandException { createPrompt(); @@ -94,7 +95,7 @@ private void createPrompt() { aiPromptCreateRequest.setJsonResponseKey(jsonResponseKey); long promptId; try { - promptId = aiServiceClient.createPrompt(aiPromptCreateRequest); + promptId = new AiPromptWsApi(this.apiClient).createPrompt(aiPromptCreateRequest); } catch (ApiException e) { throw new CommandException(e.getMessage(), e); } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/CreateAIPromptContextMessageCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/CreateAIPromptContextMessageCommand.java index 8288866e9d..b100202b26 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/CreateAIPromptContextMessageCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/CreateAIPromptContextMessageCommand.java @@ -3,6 +3,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.box.l10n.mojito.cli.apiclient.AiPromptWsApi; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; import com.box.l10n.mojito.cli.console.ConsoleWriter; import com.box.l10n.mojito.cli.model.AIPromptContextMessageCreateRequest; @@ -21,8 +22,6 @@ public class CreateAIPromptContextMessageCommand extends Command { static Logger logger = LoggerFactory.getLogger(CreateAIPromptContextMessageCommand.class); - @Autowired AiPromptWsApi aiServiceClient; - @Parameter( names = {"--content", "-c"}, required = true, @@ -49,6 +48,8 @@ public class CreateAIPromptContextMessageCommand extends Command { @Autowired private ConsoleWriter consoleWriter; + @Autowired private ApiClient apiClient; + @Override protected void execute() throws CommandException { createPromptContextMessage(); @@ -65,7 +66,8 @@ private void createPromptContextMessage() { long contextMessageId; try { contextMessageId = - this.aiServiceClient.createPromptMessage(AIPromptContextMessageCreateRequest); + new AiPromptWsApi(this.apiClient) + .createPromptMessage(AIPromptContextMessageCreateRequest); } catch (ApiException e) { throw new CommandException(e.getMessage(), e); } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/DeleteAIPromptCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/DeleteAIPromptCommand.java index 143eb3953f..6be038d9df 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/DeleteAIPromptCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/DeleteAIPromptCommand.java @@ -3,6 +3,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.box.l10n.mojito.cli.apiclient.AiPromptWsApi; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; import com.box.l10n.mojito.cli.console.ConsoleWriter; import org.fusesource.jansi.Ansi; @@ -21,8 +22,6 @@ public class DeleteAIPromptCommand extends Command { static Logger logger = LoggerFactory.getLogger(DeleteAIPromptCommand.class); - @Autowired AiPromptWsApi aiServiceClient; - @Parameter( names = {"--prompt-id", "-pi"}, required = true, @@ -31,6 +30,8 @@ public class DeleteAIPromptCommand extends Command { @Autowired private ConsoleWriter consoleWriter; + @Autowired private ApiClient apiClient; + @Override protected void execute() throws CommandException { consoleWriter @@ -44,7 +45,7 @@ protected void execute() throws CommandException { private void deletePrompt() { logger.debug("Received request to delete prompt {}", promptId); try { - aiServiceClient.deletePrompt(promptId); + new AiPromptWsApi(this.apiClient).deletePrompt(promptId); } catch (ApiException e) { throw new CommandException(e.getMessage(), e); } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/DeleteAIPromptContextMessageCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/DeleteAIPromptContextMessageCommand.java index 20860148a4..6f18f9b0ba 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/DeleteAIPromptContextMessageCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/DeleteAIPromptContextMessageCommand.java @@ -3,6 +3,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.box.l10n.mojito.cli.apiclient.AiPromptWsApi; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; import com.box.l10n.mojito.cli.console.ConsoleWriter; import org.slf4j.Logger; @@ -20,8 +21,6 @@ public class DeleteAIPromptContextMessageCommand extends Command { static Logger logger = LoggerFactory.getLogger(DeleteAIPromptContextMessageCommand.class); - @Autowired AiPromptWsApi aiServiceClient; - @Parameter( names = {"--id", "-i"}, required = true, @@ -30,6 +29,8 @@ public class DeleteAIPromptContextMessageCommand extends Command { @Autowired private ConsoleWriter consoleWriter; + @Autowired private ApiClient apiClient; + @Override protected void execute() throws CommandException { deletePromptContextMessage(); @@ -38,7 +39,7 @@ protected void execute() throws CommandException { private void deletePromptContextMessage() { logger.debug("Received request to create prompt content message"); try { - aiServiceClient.deletePromptMessage(id); + new AiPromptWsApi(this.apiClient).deletePromptMessage(id); } 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/GitBlameCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/GitBlameCommand.java index 9cc63dc5db..e8bb1be3b0 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/GitBlameCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/GitBlameCommand.java @@ -5,18 +5,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.TextUnitWsApi; +import com.box.l10n.mojito.cli.apiclient.mappers.GitBlameWithUsageMapper; 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; import com.box.l10n.mojito.cli.filefinder.file.FileType; import com.box.l10n.mojito.cli.filefinder.file.GitBlameType; -import com.box.l10n.mojito.rest.client.AssetClient; -import com.box.l10n.mojito.rest.client.GitBlameWithUsageClient; -import com.box.l10n.mojito.rest.client.RepositoryClient; +import com.box.l10n.mojito.cli.model.GitBlameGitBlameWithUsage; +import com.box.l10n.mojito.cli.model.GitBlameWithUsage; +import com.box.l10n.mojito.cli.model.GitBlameWithUsageGitBlameWithUsage; +import com.box.l10n.mojito.cli.model.PollableTask; import com.box.l10n.mojito.rest.client.exception.PollableTaskException; -import com.box.l10n.mojito.rest.entity.GitBlame; -import com.box.l10n.mojito.rest.entity.GitBlameWithUsage; -import com.box.l10n.mojito.rest.entity.PollableTask; import com.box.l10n.mojito.rest.entity.Repository; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; @@ -123,11 +125,7 @@ public class GitBlameCommand extends Command { converter = GitBlameOverrideConverter.class) OverrideType overrideType = OverrideType.NONE; - @Autowired AssetClient assetClient; - - @Autowired RepositoryClient repositoryClient; - - @Autowired GitBlameWithUsageClient gitBlameWithUsageClient; + @Autowired ApiClient apiClient; @Autowired CommandHelper commandHelper; @@ -173,11 +171,18 @@ public void execute() throws CommandException { .a("-") .a(offset + BATCH_SIZE) .println(); - List gitBlameWithUsages = - gitBlameWithUsageClient.getGitBlameWithUsages(repository.getId(), offset, BATCH_SIZE); + TextUnitWsApi gitBlameWithUsageClient = new TextUnitWsApi(this.apiClient); + List gitBlameWithUsages; + try { + gitBlameWithUsages = + gitBlameWithUsageClient.getGitBlameWithUsages( + List.of(repository.getId()), null, null, null, null, null, BATCH_SIZE, offset); + } catch (ApiException e) { + throw new CommandException(e.getMessage(), e); + } numGitBlameWithUsages = gitBlameWithUsages.size(); - List getGitBlameWithUsagesToProcess = + List getGitBlameWithUsagesToProcess = getGitBlameWithUsagesToProcess(gitBlameWithUsages); logger.debug( @@ -190,8 +195,15 @@ public void execute() throws CommandException { blameWithTextUnitUsages(getGitBlameWithUsagesToProcess); blameSourceFiles(getGitBlameWithUsagesToProcess); - pollableTasks.add( - gitBlameWithUsageClient.saveGitBlameWithUsages(getGitBlameWithUsagesToProcess)); + try { + pollableTasks.add( + gitBlameWithUsageClient.saveGitBlameWithUsages( + getGitBlameWithUsagesToProcess.stream() + .map(GitBlameWithUsageMapper::mapToGitBlameWithUsage) + .toList())); + } catch (ApiException e) { + throw new RuntimeException(e); + } } while (numGitBlameWithUsages == BATCH_SIZE); try { @@ -219,11 +231,11 @@ void initGitRepository() throws CommandException { * @param gitBlameWithUsages * @return the entries to be processed */ - public List getGitBlameWithUsagesToProcess( - List gitBlameWithUsages) { - List filteredGitBlameWithUsages = new ArrayList<>(); + public List getGitBlameWithUsagesToProcess( + List gitBlameWithUsages) { + List filteredGitBlameWithUsages = new ArrayList<>(); - for (GitBlameWithUsage gitBlameWithUsage : gitBlameWithUsages) { + for (GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage : gitBlameWithUsages) { if (gitBlameWithUsage.getGitBlame() == null || OverrideType.ALL.equals(overrideType) || (OverrideType.NO_INFO.equals(overrideType) @@ -242,7 +254,8 @@ public List getGitBlameWithUsagesToProcess( * @param gitBlameWithUsages * @throws CommandException */ - void blameSourceFiles(List gitBlameWithUsages) throws CommandException { + void blameSourceFiles(List gitBlameWithUsages) + throws CommandException { logger.debug("blameSourceFiles"); ArrayList sourceFileMatches = @@ -273,10 +286,10 @@ void blameSourceFiles(List gitBlameWithUsages) throws Command for (int i = 0; i < blameResultForFile.getResultContents().size(); i++) { String lineText = blameResultForFile.getResultContents().getString(i); - List gitBlameWithUsageList = + List gitBlameWithUsageList = getGitBlameWithUsagesFromLine( lineText, gitBlameWithUsages, sourceFileMatch.getFileType()); - for (GitBlameWithUsage gitBlameWithUsage : gitBlameWithUsageList) { + for (GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage : gitBlameWithUsageList) { try { updateBlameResultsInGitBlameWithUsage(i, blameResultForFile, gitBlameWithUsage); } catch (LineMissingException lme) { @@ -301,10 +314,11 @@ void blameSourceFiles(List gitBlameWithUsages) throws Command * @param gitBlameWithUsages * @throws CommandException */ - void blameWithTextUnitUsages(List gitBlameWithUsages) throws CommandException { + void blameWithTextUnitUsages(List gitBlameWithUsages) + throws CommandException { logger.debug("blameWithTextUnitUsages"); - for (GitBlameWithUsage gitBlameWithUsage : gitBlameWithUsages) { + for (GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage : gitBlameWithUsages) { if (gitBlameWithUsage.getUsages() != null && gitBlameWithUsage.getUsages().size() > 0) { @@ -338,9 +352,12 @@ void blameWithTextUnitUsages(List gitBlameWithUsages) throws } void updateBlameResultsInGitBlameWithUsage( - int lineNumber, BlameResult blameResultForFile, GitBlameWithUsage gitBlameWithUsage) + int lineNumber, + BlameResult blameResultForFile, + GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage) throws LineMissingException { - GitBlame gitBlame = gitRepository.getBlameResults(lineNumber, blameResultForFile); + GitBlameGitBlameWithUsage gitBlame = + gitRepository.getBlameResults(lineNumber, blameResultForFile); gitBlameWithUsage.setGitBlame(gitBlame); } @@ -386,13 +403,13 @@ public BlameResult call() throws Exception { * @param fileType * @return list of GitBlameWithUsage objects that match current line */ - List getGitBlameWithUsagesFromLine( - String line, List gitBlameWithUsages, FileType fileType) { + List getGitBlameWithUsagesFromLine( + String line, List gitBlameWithUsages, FileType fileType) { - List gitBlameWithUsagesWithLine = new ArrayList<>(); + List gitBlameWithUsagesWithLine = new ArrayList<>(); if (line != null) { - for (GitBlameWithUsage gitBlameWithUsage : gitBlameWithUsages) { + for (GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage : gitBlameWithUsages) { String textUnitNameInSource = textUnitNameToTextUnitNameInSource( gitBlameWithUsage.getTextUnitName(), @@ -411,8 +428,9 @@ List getGitBlameWithUsagesFromLine( /** * Converts text unit name to the text unit name in the source code * - * @param textUnitNameToStringInFilePattern * @param textUnitName + * @param fileType + * @param isPluralForm * @return text unit name as string in source file */ String textUnitNameToTextUnitNameInSource( diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/GitRepository.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/GitRepository.java index 2227009a4e..a5b3c196da 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/GitRepository.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/GitRepository.java @@ -1,6 +1,6 @@ package com.box.l10n.mojito.cli.command; -import com.box.l10n.mojito.rest.entity.GitBlame; +import com.box.l10n.mojito.cli.model.GitBlameGitBlameWithUsage; import java.io.File; import java.io.IOException; import java.text.MessageFormat; @@ -45,10 +45,10 @@ public void init(String gitDir) throws CommandException { * @param blameResultForFile * @return */ - public GitBlame getBlameResults(int lineNumber, BlameResult blameResultForFile) + public GitBlameGitBlameWithUsage getBlameResults(int lineNumber, BlameResult blameResultForFile) throws LineMissingException { - GitBlame gitBlame = new GitBlame(); + GitBlameGitBlameWithUsage gitBlame = new GitBlameGitBlameWithUsage(); try { gitBlame.setAuthorName(blameResultForFile.getSourceAuthor(lineNumber).getName()); 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/QuartzJobsDeleteCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/QuartzJobsDeleteCommand.java index f2de2f7b16..362c142588 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/QuartzJobsDeleteCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/QuartzJobsDeleteCommand.java @@ -1,6 +1,7 @@ package com.box.l10n.mojito.cli.command; 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.QuartzWsApi; import com.box.l10n.mojito.cli.console.ConsoleWriter; @@ -22,7 +23,7 @@ public class QuartzJobsDeleteCommand extends Command { @Autowired ConsoleWriter consoleWriter; - @Autowired QuartzWsApi quartzJobsClient; + @Autowired ApiClient apiClient; @Override public boolean shouldShowInCommandList() { @@ -33,7 +34,7 @@ public boolean shouldShowInCommandList() { protected void execute() throws CommandException { consoleWriter.a("Delete quartz jobs").println(); try { - quartzJobsClient.deleteAllDynamicJobs(); + new QuartzWsApi(this.apiClient).deleteAllDynamicJobs(); } catch (ApiException e) { throw new RuntimeException(e); } diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/QuartzJobsViewCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/QuartzJobsViewCommand.java index 0a42672c5b..0e7191996c 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/QuartzJobsViewCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/QuartzJobsViewCommand.java @@ -1,6 +1,7 @@ package com.box.l10n.mojito.cli.command; 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.QuartzWsApi; import com.box.l10n.mojito.cli.console.ConsoleWriter; @@ -24,7 +25,7 @@ public class QuartzJobsViewCommand extends Command { @Autowired ConsoleWriter consoleWriter; - @Autowired QuartzWsApi quartzJobsClient; + @Autowired ApiClient apiClient; @Override public boolean shouldShowInCommandList() { @@ -36,7 +37,7 @@ protected void execute() throws CommandException { consoleWriter.a("Dynamic quartz jobs:").println(); List allDynamicJobs; try { - allDynamicJobs = quartzJobsClient.getAllDynamicJobs(); + allDynamicJobs = new QuartzWsApi(this.apiClient).getAllDynamicJobs(); } 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..6b0d615339 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; @@ -70,11 +71,9 @@ public class TMImportCommand extends Command { description = "Skip the source file import") Boolean skipSourceImportParam = false; - @Autowired RepositoryWsApi repositoryClient; - @Autowired CommandHelper commandHelper; - @Autowired RepositoryWsApiHelper repositoryWsApiHelper; + @Autowired private ApiClient apiClient; RepositoryRepository repository; @@ -90,7 +89,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(); @@ -131,7 +130,8 @@ protected void doImportFileMatch(FileMatch fileMatch) throws CommandException { ImportRepositoryBody importRepositoryBody = new ImportRepositoryBody(); importRepositoryBody.setUpdateTM(updateTMParam); importRepositoryBody.setXliffContent(getFileContent(fileMatch)); - repositoryClient.importRepository(importRepositoryBody, repository.getId()); + new RepositoryWsApi(this.apiClient) + .importRepository(importRepositoryBody, repository.getId()); consoleWriter.erasePreviouslyPrintedLines(); consoleWriter 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..30cf6acc7c 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; @@ -119,11 +120,9 @@ public class ThirdPartySyncCommand extends Command { description = "Options to synchronize") List options; - @Autowired ThirdPartyWsApi thirdPartyClient; - @Autowired CommandHelper commandHelper; - @Autowired RepositoryWsApiHelper repositoryWsApiHelper; + @Autowired ApiClient apiClient; private ThirdPartySync getThirdPartySync(RepositoryRepository repository) { ThirdPartySync thirdPartySyncBody = new ThirdPartySync(); @@ -190,12 +189,12 @@ public void execute() throws CommandException { .println(2); RepositoryRepository repository = - this.repositoryWsApiHelper.findRepositoryByName(repositoryParam); + new RepositoryClient(this.apiClient).findRepositoryByName(repositoryParam); ThirdPartySync thirdPartySyncBody = getThirdPartySync(repository); try { - PollableTask pollableTask = thirdPartyClient.sync(thirdPartySyncBody); + PollableTask pollableTask = new ThirdPartyWsApi(this.apiClient).sync(thirdPartySyncBody); commandHelper.waitForPollableTask(pollableTask.getId()); consoleWriter.fg(Ansi.Color.GREEN).newLine().a("Finished").println(2); 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..ac2a9f21e2 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; @@ -48,9 +49,7 @@ public class VirtualAssetCreateCommand extends Command { description = Param.REPOSITORY_DESCRIPTION) String pathParam; - @Autowired VirtualAssetWsApi virtualAssetClient; - - @Autowired RepositoryWsApiHelper repositoryWsApiHelper; + @Autowired private ApiClient apiClient; private HttpClientErrorJson toHttpClientErrorJson(ApiException ae) { try { @@ -75,7 +74,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); @@ -84,7 +83,7 @@ public void execute() throws CommandException { try { consoleWriter.a(" - Create virtual asset: ").fg(Ansi.Color.CYAN).a(pathParam).println(); - virtualAsset = virtualAssetClient.createOrUpdateVirtualAsset(virtualAsset); + virtualAsset = new VirtualAssetWsApi(this.apiClient).createOrUpdateVirtualAsset(virtualAsset); consoleWriter.a(" --> asset id: ").fg(Ansi.Color.MAGENTA).a(virtualAsset.getId()).println(); consoleWriter.fg(Ansi.Color.GREEN).newLine().a("Finished").println(2); } catch (ApiException ae) { diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/checks/AIChecker.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/checks/AIChecker.java index 65fde9e8a2..e3ccb0728c 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/checks/AIChecker.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/checks/AIChecker.java @@ -4,6 +4,7 @@ import static java.util.stream.Collectors.toList; import com.box.l10n.mojito.cli.apiclient.AiChecksWsApi; +import com.box.l10n.mojito.cli.apiclient.ApiClient; import com.box.l10n.mojito.cli.apiclient.ApiException; import com.box.l10n.mojito.cli.command.CommandException; import com.box.l10n.mojito.cli.command.extraction.AssetExtractionDiff; @@ -16,6 +17,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.annotation.PostConstruct; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -39,7 +41,14 @@ public class AIChecker extends AbstractCliChecker { Retry.backoff(RETRY_MAX_ATTEMPTS, Duration.ofSeconds(RETRY_MIN_DURATION_SECONDS)) .maxBackoff(Duration.ofSeconds(RETRY_MAX_BACKOFF_DURATION_SECONDS)); - @Autowired AiChecksWsApi aiServiceClient; + @Autowired ApiClient apiClient; + + AiChecksWsApi aiServiceClient; + + @PostConstruct + public void init() { + this.aiServiceClient = new AiChecksWsApi(apiClient); + } @Override public CliCheckResult run(List assetExtractionDiffs) { 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/GitBlameCommandTest.java b/cli/src/test/java/com/box/l10n/mojito/cli/command/GitBlameCommandTest.java index 3137d70594..b60ecd02be 100644 --- a/cli/src/test/java/com/box/l10n/mojito/cli/command/GitBlameCommandTest.java +++ b/cli/src/test/java/com/box/l10n/mojito/cli/command/GitBlameCommandTest.java @@ -14,9 +14,9 @@ import com.box.l10n.mojito.cli.filefinder.file.ChromeExtensionJSONFileType; import com.box.l10n.mojito.cli.filefinder.file.FileType; import com.box.l10n.mojito.cli.filefinder.file.POFileType; +import com.box.l10n.mojito.cli.model.GitBlameGitBlameWithUsage; +import com.box.l10n.mojito.cli.model.GitBlameWithUsageGitBlameWithUsage; import com.box.l10n.mojito.entity.Repository; -import com.box.l10n.mojito.rest.entity.GitBlame; -import com.box.l10n.mojito.rest.entity.GitBlameWithUsage; import com.box.l10n.mojito.service.gitblame.GitBlameService; import com.box.l10n.mojito.service.tm.search.TextUnitSearcherParameters; import java.io.File; @@ -69,7 +69,7 @@ public void android() throws Exception { assertNull(gitBlameWithUsage.getGitBlame()); } - GitBlame gitBlame = new GitBlame(); + GitBlameGitBlameWithUsage gitBlame = new GitBlameGitBlameWithUsage(); gitBlame.setCommitName("37801193683d2e852a8a2b81e6dd05ca9ed13598"); gitBlame.setCommitTime("1537568049"); gitBlame.setAuthorName("Jean Aurambault"); @@ -104,7 +104,7 @@ public void poFile() throws Exception { assertNull(gitBlameWithUsage.getGitBlame()); } - GitBlame gitBlame = new GitBlame(); + GitBlameGitBlameWithUsage gitBlame = new GitBlameGitBlameWithUsage(); gitBlame.setCommitName("1a86b8a2003f4d20858bfb53770119f039520f79"); gitBlame.setCommitTime("1537572147"); gitBlame.setAuthorName("Liz Magalindan"); @@ -213,19 +213,20 @@ public void getTextUnitName() { new String[] { "Test 0\n", " Test 1" }; - GitBlameWithUsage gitBlameWithUsage = new GitBlameWithUsage(); + GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage = new GitBlameWithUsageGitBlameWithUsage(); gitBlameWithUsage.setTextUnitName("test_0"); - GitBlameWithUsage gitBlameWithUsage1 = new GitBlameWithUsage(); + GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage1 = + new GitBlameWithUsageGitBlameWithUsage(); gitBlameWithUsage1.setTextUnitName("test_1"); - List textUnitWithUsages = new ArrayList<>(); + List textUnitWithUsages = new ArrayList<>(); textUnitWithUsages.add(gitBlameWithUsage); textUnitWithUsages.add(gitBlameWithUsage1); GitBlameCommand gitBlameCommand = new GitBlameCommand(); for (int i = 0; i < lines.length; i++) { - List gitBlameWithUsages = + List gitBlameWithUsages = gitBlameCommand.getGitBlameWithUsagesFromLine( lines[i], textUnitWithUsages, new AndroidStringsFileType()); assertEquals(textUnitWithUsages.get(i), gitBlameWithUsages.get(i)); @@ -236,20 +237,26 @@ public void getTextUnitName() { @Test public void getTextUnitNamePlural() { String line = "\n"; - GitBlameWithUsage gitBlameWithUsage_zero = new GitBlameWithUsage(); + GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage_zero = + new GitBlameWithUsageGitBlameWithUsage(); gitBlameWithUsage_zero.setTextUnitName("plural_tests_zero"); - GitBlameWithUsage gitBlameWithUsage_one = new GitBlameWithUsage(); + GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage_one = + new GitBlameWithUsageGitBlameWithUsage(); gitBlameWithUsage_one.setTextUnitName("plural_tests_one"); - GitBlameWithUsage gitBlameWithUsage_two = new GitBlameWithUsage(); + GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage_two = + new GitBlameWithUsageGitBlameWithUsage(); gitBlameWithUsage_two.setTextUnitName("plural_tests_two"); - GitBlameWithUsage gitBlameWithUsage_few = new GitBlameWithUsage(); + GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage_few = + new GitBlameWithUsageGitBlameWithUsage(); gitBlameWithUsage_few.setTextUnitName("plural_tests_few"); - GitBlameWithUsage gitBlameWithUsage_many = new GitBlameWithUsage(); + GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage_many = + new GitBlameWithUsageGitBlameWithUsage(); gitBlameWithUsage_many.setTextUnitName("plural_tests_many"); - GitBlameWithUsage gitBlameWithUsage_other = new GitBlameWithUsage(); + GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage_other = + new GitBlameWithUsageGitBlameWithUsage(); gitBlameWithUsage_other.setTextUnitName("plural_tests_other"); - List gitBlameWithUsagesExpected = new ArrayList<>(); + List gitBlameWithUsagesExpected = new ArrayList<>(); gitBlameWithUsagesExpected.add(gitBlameWithUsage_zero); gitBlameWithUsagesExpected.add(gitBlameWithUsage_one); gitBlameWithUsagesExpected.add(gitBlameWithUsage_two); @@ -258,7 +265,7 @@ public void getTextUnitNamePlural() { gitBlameWithUsagesExpected.add(gitBlameWithUsage_other); GitBlameCommand gitBlameCommand = new GitBlameCommand(); - List gitBlameWithUsagesActual = + List gitBlameWithUsagesActual = gitBlameCommand.getGitBlameWithUsagesFromLine( line, gitBlameWithUsagesExpected, new AndroidStringsFileType()); @@ -352,7 +359,7 @@ public void updateGitBlameOutOfBousnd() gitBlameCommand.commandDirectories = new CommandDirectories(getBaseDir().getAbsolutePath()); gitBlameCommand.initGitRepository(); BlameResult blameResult = gitBlameCommand.getBlameResultForFileCached("pom.xml"); - GitBlameWithUsage gitBlameWithUsage = new GitBlameWithUsage(); + GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage = new GitBlameWithUsageGitBlameWithUsage(); gitBlameCommand.updateBlameResultsInGitBlameWithUsage(100000, blameResult, gitBlameWithUsage); assertNull(gitBlameWithUsage.getGitBlame().getAuthorName()); } @@ -364,7 +371,7 @@ public void updateGitBlameOMissingFile() gitBlameCommand.commandDirectories = new CommandDirectories(getBaseDir().getAbsolutePath()); gitBlameCommand.initGitRepository(); BlameResult blameResult = gitBlameCommand.getBlameResultForFileCached("somemissginfile"); - GitBlameWithUsage gitBlameWithUsage = new GitBlameWithUsage(); + GitBlameWithUsageGitBlameWithUsage gitBlameWithUsage = new GitBlameWithUsageGitBlameWithUsage(); gitBlameCommand.updateBlameResultsInGitBlameWithUsage(10, blameResult, gitBlameWithUsage); assertNull(gitBlameWithUsage.getGitBlame().getAuthorName()); } @@ -384,13 +391,13 @@ public void getSourceCommitsAccessOutOfBound() throws CommandException, NoSuchFi public void getGitBlameWithUsagesToProcess() { GitBlameCommand gitBlameCommand = new GitBlameCommand(); - ArrayList gitBlameWithUsages = new ArrayList<>(); - GitBlameWithUsage toSkip = new GitBlameWithUsage(); - toSkip.setGitBlame(new GitBlame()); + ArrayList gitBlameWithUsages = new ArrayList<>(); + GitBlameWithUsageGitBlameWithUsage toSkip = new GitBlameWithUsageGitBlameWithUsage(); + toSkip.setGitBlame(new GitBlameGitBlameWithUsage()); gitBlameWithUsages.add(toSkip); - gitBlameWithUsages.add(new GitBlameWithUsage()); + gitBlameWithUsages.add(new GitBlameWithUsageGitBlameWithUsage()); - List gitBlameWithUsagesToProcess = + List gitBlameWithUsagesToProcess = gitBlameCommand.getGitBlameWithUsagesToProcess(gitBlameWithUsages); assertEquals(1, gitBlameWithUsagesToProcess.size()); @@ -399,7 +406,7 @@ public void getGitBlameWithUsagesToProcess() { void verifyGitBlame( List gitBlameWithUsages, - GitBlame gitBlame) { + GitBlameGitBlameWithUsage gitBlame) { assertFalse(gitBlameWithUsages.isEmpty()); gitBlameWithUsages.stream() @@ -421,7 +428,8 @@ void verifyGitBlame( } } - L10nJCommander getL10nJCommanderWithSpiedIfShallow(GitBlame gitBlame) throws Exception { + L10nJCommander getL10nJCommanderWithSpiedIfShallow(GitBlameGitBlameWithUsage gitBlame) + throws Exception { L10nJCommander l10nJCommander = getL10nJCommander(); if (shallowClone) { 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")