dropIds = new HashMap<>();
long i = 1;
- for (Drop availableDrop :
- dropClient
- .getDrops(repositoryId, getImportedFilter(), 0L, numberOfDropsToFetchParam)
- .getContent()) {
- dropIds.put(i++, availableDrop);
+ Pageable pageable = new Pageable();
+ pageable.setPage(0);
+ pageable.setSize(this.numberOfDropsToFetchParam.intValue());
+ try {
+ for (DropDropSummary availableDrop :
+ dropClient.getDrops(pageable, repositoryId, getImportedFilter(), null).getContent()) {
+ dropIds.put(i++, availableDrop);
+ }
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
}
return dropIds;
}
/**
- * Returns the "imported" filter to be passed to {@link DropClient#getDrops(java.lang.Long,
- * java.lang.Boolean, java.lang.Long, java.lang.Long) } based on the CLI parameter {@link
- * #alsoShowImportedParam}.
+ * Returns the "imported" filter to be passed to {@link
+ * com.box.l10n.mojito.cli.apiclient.DropWsApi#getDrops(com.box.l10n.mojito.cli.model.Pageable,
+ * Long, Boolean, Boolean)} based on the CLI parameter {@link #alsoShowImportedParam}.
*
* @return the imported filter to get drops
*/
@@ -181,17 +211,19 @@ private Boolean getImportedFilter() {
}
/**
- * Gets the list of selected {@link Drop#id}.
+ * Gets the list of selected {@link com.box.l10n.mojito.cli.model.DropDropSummary#getId()}.
*
- * First, reads a drop number from the console and then gets the {@link Drop} from the map of
- * available {@link Drop}s.
+ *
First, reads a drop number from the console and then gets the {@link
+ * com.box.l10n.mojito.cli.model.DropDropSummary} from the map of available {@link
+ * com.box.l10n.mojito.cli.model.DropDropSummary}s.
*
- * @param numberedAvailableDrops candidate {@link Drop}s for selection
- * @return selected {@link Drop#id}
+ * @param numberedAvailableDrops candidate {@link com.box.l10n.mojito.cli.model.DropDropSummary}s
+ * for selection
+ * @return selected {@link com.box.l10n.mojito.cli.model.DropDropSummary#getId()}
* @throws CommandException if the input doesn't match a number from the map of available {@link
- * Drop}s
+ * com.box.l10n.mojito.cli.model.DropDropSummary}s
*/
- private List getSelectedDropIds(Map numberedAvailableDrops)
+ private List getSelectedDropIds(Map numberedAvailableDrops)
throws CommandException {
List selectedDropIds;
@@ -204,7 +236,7 @@ private List getSelectedDropIds(Map numberedAvailableDrops)
return selectedDropIds;
}
- private List getFromConsoleDropIds(Map numberedAvailableDrops)
+ private List getFromConsoleDropIds(Map numberedAvailableDrops)
throws CommandException {
consoleWriter.newLine().a("Enter Drop number to import").println();
Long dropNumber = console.readLine(Long.class);
@@ -219,9 +251,10 @@ private List getFromConsoleDropIds(Map numberedAvailableDrops)
return Arrays.asList(selectId);
}
- private List getWithImportFetchedDropIds(Map numberedAvailableDrops) {
+ private List getWithImportFetchedDropIds(
+ Map numberedAvailableDrops) {
return numberedAvailableDrops.entrySet().stream()
- .filter(x -> !Boolean.TRUE.equals(x.getValue().getCanceled()))
+ .filter(x -> !Boolean.TRUE.equals(x.getValue().isCanceled()))
.map(x -> x.getValue().getId())
.collect(Collectors.toList());
}
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/DropXliffImportCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/DropXliffImportCommand.java
index b6938f2754..cffe90a071 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/DropXliffImportCommand.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/DropXliffImportCommand.java
@@ -1,13 +1,20 @@
package com.box.l10n.mojito.cli.command;
+import static java.util.Optional.ofNullable;
+
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.DropWsApi;
import com.box.l10n.mojito.cli.command.param.Param;
import com.box.l10n.mojito.cli.console.Console;
import com.box.l10n.mojito.cli.console.ConsoleWriter;
-import com.box.l10n.mojito.rest.client.DropClient;
-import com.box.l10n.mojito.rest.entity.ImportDropConfig;
-import com.box.l10n.mojito.rest.entity.Repository;
+import com.box.l10n.mojito.cli.model.ImportDropConfig;
+import com.box.l10n.mojito.cli.model.ImportXliffBody;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
+import com.google.common.base.Preconditions;
+import jakarta.annotation.PostConstruct;
import java.nio.file.Path;
import java.util.List;
import org.fusesource.jansi.Ansi;
@@ -63,7 +70,7 @@ public class DropXliffImportCommand extends Command {
required = false,
description = Param.DROP_IMPORT_STATUS_DESCRIPTION,
converter = ImportDropConfigStatusConverter.class)
- ImportDropConfig.Status importStatusParam = null;
+ ImportDropConfig.StatusEnum importStatusParam = null;
@Parameter(
names = {"--import-by-md5"},
@@ -75,12 +82,19 @@ public class DropXliffImportCommand extends Command {
@Autowired Console console;
- @Autowired DropClient dropClient;
+ @Autowired ApiClient apiClient;
- Repository repository;
+ RepositoryRepository repository;
CommandDirectories commandDirectories;
+ DropWsApi dropClient;
+
+ @PostConstruct
+ public void init() {
+ this.dropClient = new DropWsApi(this.apiClient);
+ }
+
@Override
public void execute() throws CommandException {
@@ -91,7 +105,11 @@ public void execute() throws CommandException {
.a(repositoryParam)
.println(2);
- repository = commandHelper.findRepositoryByName(repositoryParam);
+ try {
+ repository = this.commandHelper.findRepositoryByName(repositoryParam);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
commandDirectories = new CommandDirectories(sourceDirectoryParam, targetDirectoryParam);
@@ -109,6 +127,20 @@ void importXliffs() throws CommandException {
}
}
+ private ImportXliffBody getImportXliffBody(String xliffContent) {
+ ImportXliffBody importXliffBody = new ImportXliffBody();
+ importXliffBody.setRepositoryId(Preconditions.checkNotNull(this.repository.getId()));
+ importXliffBody.setTranslationKit(!this.importByMD5);
+ importXliffBody.setImportStatus(
+ ofNullable(this.importStatusParam)
+ .map(
+ importStatusParam ->
+ ImportXliffBody.ImportStatusEnum.fromValue(importStatusParam.name()))
+ .orElse(null));
+ importXliffBody.setXliffContent(xliffContent);
+ return importXliffBody;
+ }
+
void importXliff(Path xliffPath) throws CommandException {
consoleWriter
@@ -119,8 +151,13 @@ void importXliff(Path xliffPath) throws CommandException {
String xliffContent = commandHelper.getFileContent(xliffPath);
- String importedXliff =
- dropClient.importXiff(xliffContent, repository.getId(), !importByMD5, importStatusParam);
+ String importedXliff;
+ try {
+ importedXliff =
+ this.dropClient.importXliff(getImportXliffBody(xliffContent)).getXliffContent();
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
Path outputPath =
commandDirectories.resolveWithTargetDirectoryAndCreateParentDirectories(xliffPath);
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..a49542294d 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,21 +2,23 @@
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.AssetWsApiProxy;
+import com.box.l10n.mojito.cli.apiclient.PollableTaskWsApiProxy;
import com.box.l10n.mojito.cli.command.param.Param;
import com.box.l10n.mojito.cli.console.ConsoleWriter;
+import com.box.l10n.mojito.cli.model.LocaleRepository;
+import com.box.l10n.mojito.cli.model.LocalizedAssetBody;
+import com.box.l10n.mojito.cli.model.RepositoryLocaleRepository;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
+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 jakarta.annotation.PostConstruct;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
@@ -79,14 +81,19 @@ public class EvolveCommand extends Command {
@Autowired(required = false)
Evolve evolve;
- @Autowired RepositoryClient repositoryClient;
+ @Autowired ApiClient apiClient;
- @Autowired AssetClient assetClient;
-
- @Autowired PollableTaskClient pollableTaskClient;
+ @Autowired PollableTaskWsApiProxy pollableTaskClient;
@Autowired CommandHelper commandHelper;
+ private AssetWsApiProxy assetClient;
+
+ @PostConstruct
+ public void init() {
+ this.assetClient = new AssetWsApiProxy(this.apiClient);
+ }
+
@Override
public boolean shouldShowInCommandList() {
return false;
@@ -107,7 +114,12 @@ public void execute() throws CommandException {
.a(repositoryParam)
.println(2);
- Repository repository = commandHelper.findRepositoryByName(repositoryParam);
+ RepositoryRepository repository;
+ try {
+ repository = this.commandHelper.findRepositoryByName(repositoryParam);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
evolve
.getCourses()
@@ -118,7 +130,7 @@ public void execute() throws CommandException {
});
}
- void translateCourse(Repository repository, Course course) {
+ void translateCourse(RepositoryRepository repository, Course course) {
consoleWriter
.a("Get translations for course: ")
@@ -131,7 +143,7 @@ void translateCourse(Repository repository, Course course) {
repository.getRepositoryLocales().stream()
.filter(repositoryLocale -> repositoryLocale.getParentLocale() != null)
- .map(RepositoryLocale::getLocale)
+ .map(RepositoryLocaleRepository::getLocale)
.forEach(
locale -> {
consoleWriter
@@ -157,7 +169,10 @@ void translateCourse(Repository repository, Course course) {
}
void writeJsonToFile(
- Repository repository, Course course, Locale locale, String localizedCourse) {
+ RepositoryRepository repository,
+ Course course,
+ LocaleRepository locale,
+ String localizedCourse) {
Preconditions.checkNotNull(writeJsonTo);
Path path =
Paths.get(
@@ -166,31 +181,41 @@ void writeJsonToFile(
Files.write(path, localizedCourse);
}
- SourceAsset sendSource(Repository repository, String courseId, String translationsByCourseId) {
+ SourceAsset sendSource(
+ RepositoryRepository repository, String courseId, String translationsByCourseId) {
consoleWriter.a("Sending source course to Mojito").println();
SourceAsset sourceAsset = new SourceAsset();
sourceAsset.setRepositoryId(repository.getId());
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/ExportDropConfigTypeConverter.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/ExportDropConfigTypeConverter.java
index ad06f39dc0..0d2686235e 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/ExportDropConfigTypeConverter.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/ExportDropConfigTypeConverter.java
@@ -1,14 +1,14 @@
package com.box.l10n.mojito.cli.command;
-import com.box.l10n.mojito.rest.entity.ExportDropConfig;
+import com.box.l10n.mojito.cli.model.ExportDropConfig;
/**
* @author jaurambault
*/
-public class ExportDropConfigTypeConverter extends EnumConverter {
+public class ExportDropConfigTypeConverter extends EnumConverter {
@Override
- protected Class getGenericClass() {
- return ExportDropConfig.Type.class;
+ protected Class getGenericClass() {
+ return ExportDropConfig.TypeEnum.class;
}
}
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/ExtractionCheckCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/ExtractionCheckCommand.java
index 0c301778a2..cd35f57f3b 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/ExtractionCheckCommand.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/ExtractionCheckCommand.java
@@ -2,6 +2,8 @@
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.command.checks.AbstractCliChecker;
import com.box.l10n.mojito.cli.command.checks.CheckerOptionsMapEntry;
import com.box.l10n.mojito.cli.command.checks.CheckerOptionsMapEntryConverter;
@@ -28,12 +30,13 @@
import com.box.l10n.mojito.github.GithubException;
import com.box.l10n.mojito.okapi.extractor.AssetExtractorTextUnit;
import com.box.l10n.mojito.regex.PlaceholderRegularExpressions;
-import com.box.l10n.mojito.rest.resttemplate.AuthenticatedRestTemplate;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import com.ibm.icu.text.MessageFormat;
+import com.squareup.okhttp.Call;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -273,7 +276,7 @@ public class ExtractionCheckCommand extends Command {
description = "Full git commit sha, used for setting a status on a commit in Github.")
String commitSha;
- @Autowired AuthenticatedRestTemplate restTemplate;
+ @Autowired ApiClient apiClient;
List extractionCheckNotificationSenders = new ArrayList<>();
@@ -393,7 +396,23 @@ private void reportStatistic(CliCheckResult result) {
.put("outcome", result.isSuccessful() ? "success" : "failure")
.build();
String url = urlMessageFormat.format(paramMap);
- restTemplate.put(url, null);
+
+ try {
+ Call call =
+ this.apiClient.buildCall(
+ url,
+ "PUT",
+ new ArrayList<>(),
+ new ArrayList<>(),
+ null,
+ new HashMap<>(),
+ new HashMap<>(),
+ new String[] {},
+ null);
+ this.apiClient.execute(call);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
} catch (RestClientException e) {
logger.error("Error reporting statistics to http endpoint " + e.getMessage(), e);
consoleWriter
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/ExtractionDiffCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/ExtractionDiffCommand.java
index b9e97c1420..3f2da3ee9b 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/ExtractionDiffCommand.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/ExtractionDiffCommand.java
@@ -2,9 +2,13 @@
import static java.util.Optional.empty;
import static java.util.Optional.of;
+import static java.util.Optional.ofNullable;
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.RepositoryWsApiProxy;
import com.box.l10n.mojito.cli.command.extraction.AssetExtractionDiff;
import com.box.l10n.mojito.cli.command.extraction.ExtractionDiffPaths;
import com.box.l10n.mojito.cli.command.extraction.ExtractionDiffService;
@@ -14,19 +18,19 @@
import com.box.l10n.mojito.cli.command.param.Param;
import com.box.l10n.mojito.cli.command.utils.SlackNotificationSender;
import com.box.l10n.mojito.cli.console.ConsoleWriter;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
+import com.box.l10n.mojito.cli.model.SourceAsset;
import com.box.l10n.mojito.json.ObjectMapper;
-import com.box.l10n.mojito.rest.entity.Repository;
-import com.box.l10n.mojito.rest.entity.SourceAsset;
import com.box.l10n.mojito.shell.Shell;
import com.box.l10n.mojito.slack.SlackClient;
import com.google.common.base.Strings;
+import jakarta.annotation.PostConstruct;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
-import java.util.Set;
import java.util.stream.Stream;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.fusesource.jansi.Ansi;
@@ -169,7 +173,7 @@ public class ExtractionDiffCommand extends Command {
required = false,
description =
"Optional list of notifiers when pusing to a repository, (notification will be sent eg. when new strings are processed or when translations are ready")
- Set pushToBranchNotifiers = Collections.emptySet();
+ List pushToBranchNotifiers = Collections.emptyList();
@Parameter(
names = Param.PUSH_TYPE_LONG,
@@ -241,8 +245,17 @@ public class ExtractionDiffCommand extends Command {
@Autowired(required = false)
private SlackClient slackClient;
+ @Autowired private ApiClient apiClient;
+
+ RepositoryWsApiProxy repositoryClient;
+
private Optional notificationSender;
+ @PostConstruct
+ public void init() {
+ this.repositoryClient = new RepositoryWsApiProxy(this.apiClient);
+ }
+
// Method for testing purposes
protected Optional getNotificationSender() {
if (!Strings.isNullOrEmpty(this.slackNotificationChannel)) {
@@ -361,7 +374,12 @@ void executeUnsafe() {
}
private String getValidRepositoryName() {
- List repositories = commandHelper.getAllRepositories();
+ List repositories = null;
+ try {
+ repositories = this.repositoryClient.getRepositories(null);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
if (repositories.stream()
.anyMatch(repository -> repository.getName().equals(pushToRepository))) {
@@ -382,7 +400,12 @@ private String getValidRepositoryName() {
void pushToRepository(ExtractionDiffPaths extractionDiffPaths) throws CommandException {
- Repository repository = commandHelper.findRepositoryByName(pushToRepository);
+ RepositoryRepository repository;
+ try {
+ repository = this.commandHelper.findRepositoryByName(pushToRepository);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
Stream allAssetExtractionDiffPaths =
extractionDiffPaths.findAllAssetExtractionDiffPaths();
@@ -414,7 +437,12 @@ void pushToRepository(ExtractionDiffPaths extractionDiffPaths) throws CommandExc
sourceAsset.setExtractedContent(true);
sourceAsset.setRepositoryId(repository.getId());
sourceAsset.setFilterConfigIdOverride(
- assetExtractionDiff.getCurrentFilterConfigIdOverride());
+ ofNullable(assetExtractionDiff.getCurrentFilterConfigIdOverride())
+ .map(
+ filterConfigIdOverride ->
+ SourceAsset.FilterConfigIdOverrideEnum.fromValue(
+ filterConfigIdOverride.name()))
+ .orElse(null));
sourceAsset.setFilterOptions(assetExtractionDiff.getCurrentFilterOptions());
}
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..663ccacde2 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,21 +5,24 @@
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.exceptions.PollableTaskException;
+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.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.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.cli.model.RepositoryRepository;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
+import jakarta.annotation.PostConstruct;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.text.MessageFormat;
@@ -123,14 +126,12 @@ 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;
+ TextUnitWsApi gitBlameWithUsageClient;
+
CommandDirectories commandDirectories;
GitRepository gitRepository = new GitRepository();
@@ -146,6 +147,11 @@ public class GitBlameCommand extends Command {
Cache getBlameResultForFileCache =
CacheBuilder.newBuilder().softValues().build();
+ @PostConstruct
+ public void init() {
+ this.gitBlameWithUsageClient = new TextUnitWsApi(this.apiClient);
+ }
+
@Override
public void execute() throws CommandException {
@@ -153,7 +159,12 @@ public void execute() throws CommandException {
consoleWriter.newLine().a("Git blame for repository: ").fg(CYAN).a(repositoryParam).println(2);
- Repository repository = commandHelper.findRepositoryByName(repositoryParam);
+ RepositoryRepository repository;
+ try {
+ repository = this.commandHelper.findRepositoryByName(repositoryParam);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
List pollableTasks = new ArrayList<>();
initGitRepository();
@@ -173,11 +184,17 @@ public void execute() throws CommandException {
.a("-")
.a(offset + BATCH_SIZE)
.println();
- List gitBlameWithUsages =
- gitBlameWithUsageClient.getGitBlameWithUsages(repository.getId(), offset, BATCH_SIZE);
+ 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 +207,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.getMessage(), e);
+ }
} while (numGitBlameWithUsages == BATCH_SIZE);
try {
@@ -219,11 +243,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 +266,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 +298,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 +326,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 +364,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 +415,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 +440,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/ImportDropConfigStatusConverter.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/ImportDropConfigStatusConverter.java
index acbd018605..f983f0fc18 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/ImportDropConfigStatusConverter.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/ImportDropConfigStatusConverter.java
@@ -1,14 +1,14 @@
package com.box.l10n.mojito.cli.command;
-import com.box.l10n.mojito.rest.entity.ImportDropConfig;
+import com.box.l10n.mojito.cli.model.ImportDropConfig;
/**
* @author jaurambault
*/
-public class ImportDropConfigStatusConverter extends EnumConverter {
+public class ImportDropConfigStatusConverter extends EnumConverter {
@Override
- protected Class getGenericClass() {
- return ImportDropConfig.Status.class;
+ protected Class getGenericClass() {
+ return ImportDropConfig.StatusEnum.class;
}
}
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/ImportLocalizedAssetBodyStatusForEqualTargetConverter.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/ImportLocalizedAssetBodyStatusForEqualTargetConverter.java
index 41a093dc29..7c10b01c5e 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/ImportLocalizedAssetBodyStatusForEqualTargetConverter.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/ImportLocalizedAssetBodyStatusForEqualTargetConverter.java
@@ -1,15 +1,15 @@
package com.box.l10n.mojito.cli.command;
-import com.box.l10n.mojito.rest.entity.ImportLocalizedAssetBody;
+import com.box.l10n.mojito.cli.model.ImportLocalizedAssetBody;
/**
* @author jaurambault
*/
public class ImportLocalizedAssetBodyStatusForEqualTargetConverter
- extends EnumConverter {
+ extends EnumConverter {
@Override
- protected Class getGenericClass() {
- return ImportLocalizedAssetBody.StatusForEqualTarget.class;
+ protected Class getGenericClass() {
+ return ImportLocalizedAssetBody.StatusForEqualTargetEnum.class;
}
}
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/ImportLocalizedAssetCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/ImportLocalizedAssetCommand.java
index 896b2f59be..939f9e5021 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/ImportLocalizedAssetCommand.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/ImportLocalizedAssetCommand.java
@@ -1,22 +1,23 @@
package com.box.l10n.mojito.cli.command;
+import static java.util.Optional.ofNullable;
+
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.AssetWsApiProxy;
+import com.box.l10n.mojito.cli.apiclient.exceptions.PollableTaskException;
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.rest.client.AssetClient;
-import com.box.l10n.mojito.rest.client.LocaleClient;
-import com.box.l10n.mojito.rest.client.RepositoryClient;
-import com.box.l10n.mojito.rest.client.exception.AssetNotFoundException;
-import com.box.l10n.mojito.rest.client.exception.PollableTaskException;
-import com.box.l10n.mojito.rest.entity.Asset;
-import com.box.l10n.mojito.rest.entity.ImportLocalizedAssetBody;
-import com.box.l10n.mojito.rest.entity.ImportLocalizedAssetBody.StatusForEqualTarget;
-import com.box.l10n.mojito.rest.entity.Locale;
-import com.box.l10n.mojito.rest.entity.Repository;
+import com.box.l10n.mojito.cli.model.AssetAssetSummary;
+import com.box.l10n.mojito.cli.model.ImportLocalizedAssetBody;
+import com.box.l10n.mojito.cli.model.LocaleRepository;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
+import jakarta.annotation.PostConstruct;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Iterator;
@@ -122,25 +123,29 @@ public class ImportLocalizedAssetCommand extends Command {
"Status of the imported translation when the target is the same as "
+ "the parent (SKIPPED for no import). Applies only to fully translated locales",
converter = ImportLocalizedAssetBodyStatusForEqualTargetConverter.class)
- StatusForEqualTarget statusForEqualTarget = StatusForEqualTarget.APPROVED;
-
- @Autowired AssetClient assetClient;
+ ImportLocalizedAssetBody.StatusForEqualTargetEnum statusForEqualTarget =
+ ImportLocalizedAssetBody.StatusForEqualTargetEnum.APPROVED;
- @Autowired LocaleClient localeClient;
-
- @Autowired RepositoryClient repositoryClient;
+ @Autowired ApiClient apiClient;
@Autowired CommandHelper commandHelper;
@Autowired LocaleMappingHelper localeMappingHelper;
- Repository repository;
+ AssetWsApiProxy assetClient;
+
+ RepositoryRepository repository;
CommandDirectories commandDirectories;
/** Contains a map of locale for generating localized file a locales defined in the repository. */
Map inverseLocaleMapping;
+ @PostConstruct
+ public void init() {
+ this.assetClient = new AssetWsApiProxy(this.apiClient);
+ }
+
@Override
public void execute() throws CommandException {
@@ -151,7 +156,11 @@ public void execute() throws CommandException {
.a(repositoryParam)
.println(2);
- repository = commandHelper.findRepositoryByName(repositoryParam);
+ try {
+ repository = this.commandHelper.findRepositoryByName(repositoryParam);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
commandDirectories = new CommandDirectories(sourceDirectoryParam, targetDirectoryParam);
inverseLocaleMapping = localeMappingHelper.getInverseLocaleMapping(localeMappingParam);
@@ -163,7 +172,7 @@ public void execute() throws CommandException {
sourcePathFilterRegex,
directoriesIncludePatterns,
directoriesExcludePatterns)) {
- for (Locale locale : getLocalesForImport()) {
+ for (LocaleRepository locale : getLocalesForImport()) {
doImportFileMatch(sourceFileMatch, locale);
}
}
@@ -171,7 +180,8 @@ public void execute() throws CommandException {
consoleWriter.fg(Ansi.Color.GREEN).newLine().a("Finished").println(2);
}
- protected void doImportFileMatch(FileMatch fileMatch, Locale locale) throws CommandException {
+ protected void doImportFileMatch(FileMatch fileMatch, LocaleRepository locale)
+ throws CommandException {
try {
logger.info("Importing for locale: {}", locale.getBcp47Tag());
Path targetPath = getTargetPath(fileMatch, locale);
@@ -182,44 +192,50 @@ protected void doImportFileMatch(FileMatch fileMatch, Locale locale) throws Comm
.a(targetPath.toString())
.println();
- Asset assetByPathAndRepositoryId =
+ AssetAssetSummary assetByPathAndRepositoryId =
assetClient.getAssetByPathAndRepositoryId(fileMatch.getSourcePath(), repository.getId());
- ImportLocalizedAssetBody importLocalizedAssetForContent =
- assetClient.importLocalizedAssetForContent(
- assetByPathAndRepositoryId.getId(),
- locale.getId(),
- commandHelper.getFileContent(targetPath),
- statusForEqualTarget,
- fileMatch.getFileType().getFilterConfigIdOverride(),
- commandHelper.getFilterOptionsOrDefaults(
- fileMatch.getFileType(), filterOptionsParam));
+ ImportLocalizedAssetBody importLocalizedAssetBody = new ImportLocalizedAssetBody();
+ importLocalizedAssetBody.setContent(commandHelper.getFileContent(targetPath));
+ importLocalizedAssetBody.setStatusForEqualTarget(statusForEqualTarget);
+ importLocalizedAssetBody.setFilterConfigIdOverride(
+ ofNullable(fileMatch.getFileType().getFilterConfigIdOverride())
+ .map(
+ filterConfigIdOverride ->
+ ImportLocalizedAssetBody.FilterConfigIdOverrideEnum.fromValue(
+ filterConfigIdOverride.name()))
+ .orElse(null));
+ importLocalizedAssetBody.setFilterOptions(
+ commandHelper.getFilterOptionsOrDefaults(fileMatch.getFileType(), filterOptionsParam));
try {
+ ImportLocalizedAssetBody importLocalizedAssetForContent =
+ assetClient.importLocalizedAsset(
+ importLocalizedAssetBody, assetByPathAndRepositoryId.getId(), locale.getId());
commandHelper.waitForPollableTask(importLocalizedAssetForContent.getPollableTask().getId());
} catch (PollableTaskException e) {
throw new CommandException(e.getMessage(), e.getCause());
}
- } catch (AssetNotFoundException ex) {
+ } catch (ApiException ex) {
throw new CommandException(
"No asset for file [" + fileMatch.getPath() + "] into repo [" + repositoryParam + "]",
ex);
}
}
- public Collection getLocalesForImport() {
- Collection sortedRepositoryLocales =
+ public Collection getLocalesForImport() {
+ Collection sortedRepositoryLocales =
commandHelper.getSortedRepositoryLocales(repository).values();
filterLocalesWithMapping(sortedRepositoryLocales);
return sortedRepositoryLocales;
}
- private void filterLocalesWithMapping(Collection locales) {
+ private void filterLocalesWithMapping(Collection locales) {
if (inverseLocaleMapping != null) {
- Iterator iterator = locales.iterator();
+ Iterator iterator = locales.iterator();
while (iterator.hasNext()) {
- Locale l = iterator.next();
+ LocaleRepository l = iterator.next();
if (!inverseLocaleMapping.containsKey(l.getBcp47Tag())) {
iterator.remove();
}
@@ -227,7 +243,7 @@ private void filterLocalesWithMapping(Collection locales) {
}
}
- private Path getTargetPath(FileMatch fileMatch, Locale locale) throws CommandException {
+ private Path getTargetPath(FileMatch fileMatch, LocaleRepository locale) throws CommandException {
String targetLocale;
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/L10nJCommander.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/L10nJCommander.java
index 2eda4fdcfd..f19eb84b90 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/L10nJCommander.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/L10nJCommander.java
@@ -1,9 +1,9 @@
package com.box.l10n.mojito.cli.command;
import com.beust.jcommander.JCommander;
+import com.box.l10n.mojito.cli.apiclient.ApiClient;
import com.box.l10n.mojito.cli.command.utils.SlackNotificationSender;
import com.box.l10n.mojito.cli.console.ConsoleWriter;
-import com.box.l10n.mojito.rest.resttemplate.AuthenticatedRestTemplate;
import com.box.l10n.mojito.slack.SlackClient;
import com.google.common.base.Strings;
import jakarta.annotation.PostConstruct;
@@ -44,8 +44,6 @@ public class L10nJCommander {
@Autowired MainCommand mainCommand;
- @Autowired AuthenticatedRestTemplate authenticatedRestTemplate;
-
@Autowired(required = false)
SlackClient slackClient;
@@ -55,6 +53,8 @@ public class L10nJCommander {
@Value("${FAILURE_URL:#{null}}")
String failureUrl;
+ @Autowired private ApiClient apiClient;
+
static final String PROGRAM_NAME = "mojito";
boolean systemExitEnabled = true;
@@ -182,8 +182,7 @@ public void run(String... args) {
}
exitWithError();
} catch (ResourceAccessException rae) {
- String msg =
- "Is a server running on: " + authenticatedRestTemplate.getURIForResource("") + "?";
+ String msg = "Is a server running on: " + this.apiClient.getBasePath() + "?";
printErrorMessage(msg);
logger.error(msg, rae);
this.notifyFailure(command, args, msg);
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/LeveragingCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/LeveragingCommand.java
index 06159647f1..a0a327e2ca 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/LeveragingCommand.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/LeveragingCommand.java
@@ -1,17 +1,22 @@
package com.box.l10n.mojito.cli.command;
+import static java.util.Optional.ofNullable;
+
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.AssetWsApiProxy;
+import com.box.l10n.mojito.cli.apiclient.LeveragingWsApi;
import com.box.l10n.mojito.cli.command.param.Param;
import com.box.l10n.mojito.cli.console.ConsoleWriter;
-import com.box.l10n.mojito.rest.client.AssetClient;
-import com.box.l10n.mojito.rest.client.LeveragingClient;
-import com.box.l10n.mojito.rest.client.exception.AssetNotFoundException;
-import com.box.l10n.mojito.rest.entity.Asset;
-import com.box.l10n.mojito.rest.entity.CopyTmConfig;
-import com.box.l10n.mojito.rest.entity.PollableTask;
-import com.box.l10n.mojito.rest.entity.Repository;
+import com.box.l10n.mojito.cli.model.AssetAssetSummary;
+import com.box.l10n.mojito.cli.model.CopyTmConfig;
+import com.box.l10n.mojito.cli.model.PollableTask;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
+import jakarta.annotation.PostConstruct;
import java.util.Map;
+import java.util.stream.Collectors;
import org.fusesource.jansi.Ansi.Color;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -88,7 +93,7 @@ public class LeveragingCommand extends Command {
+ "MD5 will perform matching based on the ID, content and comment. "
+ "EXACT match is only using the content.",
converter = CopyTmConfigModeConverter.class)
- CopyTmConfig.Mode mode = CopyTmConfig.Mode.MD5;
+ CopyTmConfig.ModeEnum mode = CopyTmConfig.ModeEnum.MD5;
@Parameter(
names = {"--tuids-mapping"},
@@ -102,14 +107,22 @@ public class LeveragingCommand extends Command {
@Autowired CommandHelper commandHelper;
- @Autowired LeveragingClient leveragingClient;
+ LeveragingWsApi leveragingClient;
+
+ @Autowired ApiClient apiClient;
+
+ AssetWsApiProxy assetClient;
- @Autowired AssetClient assetClient;
+ @PostConstruct
+ public void init() {
+ this.assetClient = new AssetWsApiProxy(this.apiClient);
+ this.leveragingClient = new LeveragingWsApi(this.apiClient);
+ }
@Override
public void execute() throws CommandException {
- if (CopyTmConfig.Mode.TUIDS.equals(mode)) {
+ if (CopyTmConfig.ModeEnum.TUIDS.equals(mode)) {
copyTranslationBetweenTextUnits();
} else {
copyTmBetweenRepositories();
@@ -135,42 +148,57 @@ void copyTmBetweenRepositories() throws CommandException {
.a(targetRepositoryParam)
.println(2);
- Repository sourceRepository = commandHelper.findRepositoryByName(sourceRepositoryParam);
- Repository targetRepository = commandHelper.findRepositoryByName(targetRepositoryParam);
-
+ RepositoryRepository sourceRepository;
+ RepositoryRepository targetRepository;
try {
- CopyTmConfig copyTmConfig = new CopyTmConfig();
- copyTmConfig.setSourceRepositoryId(sourceRepository.getId());
- copyTmConfig.setTargetRepositoryId(targetRepository.getId());
- copyTmConfig.setNameRegex(nameRegexParam);
- copyTmConfig.setTargetBranchName(targetBranchNameParam);
-
- if (mode != null) {
- copyTmConfig.setMode(mode);
- }
+ sourceRepository = commandHelper.findRepositoryByName(sourceRepositoryParam);
+ targetRepository = commandHelper.findRepositoryByName(targetRepositoryParam);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
+
+ CopyTmConfig copyTmConfig = new CopyTmConfig();
+ copyTmConfig.setSourceRepositoryId(sourceRepository.getId());
+ copyTmConfig.setTargetRepositoryId(targetRepository.getId());
+ copyTmConfig.setNameRegex(nameRegexParam);
+ copyTmConfig.setTargetBranchName(targetBranchNameParam);
+
+ if (mode != null) {
+ copyTmConfig.setMode(mode);
+ }
- if (targetAssetPathParam != null) {
- Asset asset =
+ if (targetAssetPathParam != null) {
+ AssetAssetSummary asset;
+ try {
+ asset =
assetClient.getAssetByPathAndRepositoryId(
targetAssetPathParam, targetRepository.getId());
- copyTmConfig.setTargetAssetId(asset.getId());
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
}
+ copyTmConfig.setTargetAssetId(asset.getId());
+ }
- if (sourceAssetPathParam != null) {
- Asset asset =
+ if (sourceAssetPathParam != null) {
+ AssetAssetSummary asset;
+ try {
+ asset =
assetClient.getAssetByPathAndRepositoryId(
sourceAssetPathParam, sourceRepository.getId());
- copyTmConfig.setSourceAssetId(asset.getId());
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
}
+ copyTmConfig.setSourceAssetId(asset.getId());
+ }
+ try {
copyTmConfig = leveragingClient.copyTM(copyTmConfig);
-
- PollableTask pollableTask = copyTmConfig.getPollableTask();
- commandHelper.waitForPollableTask(pollableTask.getId());
-
- } catch (AssetNotFoundException assetNotFoundException) {
- throw new CommandException(assetNotFoundException);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
}
+
+ PollableTask pollableTask = copyTmConfig.getPollableTask();
+ commandHelper.waitForPollableTask(pollableTask.getId());
}
void copyTranslationBetweenTextUnits() throws CommandException {
@@ -189,10 +217,22 @@ void copyTranslationBetweenTextUnits() throws CommandException {
CopyTmConfig copyTmConfig = new CopyTmConfig();
copyTmConfig.setNameRegex(nameRegexParam);
- copyTmConfig.setMode(CopyTmConfig.Mode.TUIDS);
- copyTmConfig.setSourceToTargetTmTextUnitIds(sourceToTargetTmTextUnitMapping);
+ copyTmConfig.setMode(CopyTmConfig.ModeEnum.TUIDS);
+ copyTmConfig.setSourceToTargetTmTextUnitIds(
+ ofNullable(sourceToTargetTmTextUnitMapping)
+ .map(
+ sourceToTargetTmTextUnitMapping ->
+ sourceToTargetTmTextUnitMapping.entrySet().stream()
+ .collect(
+ Collectors.toMap(
+ entry -> String.valueOf(entry.getKey()), Map.Entry::getValue)))
+ .orElse(null));
- copyTmConfig = leveragingClient.copyTM(copyTmConfig);
+ try {
+ copyTmConfig = leveragingClient.copyTM(copyTmConfig);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
PollableTask pollableTask = copyTmConfig.getPollableTask();
commandHelper.waitForPollableTask(pollableTask.getId());
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/LocaleHelper.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/LocaleHelper.java
index 6db2d9f4a0..c6a154757e 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/LocaleHelper.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/LocaleHelper.java
@@ -1,16 +1,17 @@
package com.box.l10n.mojito.cli.command;
import com.beust.jcommander.internal.Lists;
+import com.box.l10n.mojito.cli.apiclient.ApiClient;
+import com.box.l10n.mojito.cli.apiclient.ApiException;
+import com.box.l10n.mojito.cli.apiclient.LocaleWsApiProxy;
import com.box.l10n.mojito.cli.console.ConsoleWriter;
-import com.box.l10n.mojito.rest.client.LocaleClient;
-import com.box.l10n.mojito.rest.entity.Locale;
-import com.box.l10n.mojito.rest.entity.Repository;
-import com.box.l10n.mojito.rest.entity.RepositoryLocale;
+import com.box.l10n.mojito.cli.model.Locale;
+import com.box.l10n.mojito.cli.model.RepositoryLocale;
+import jakarta.annotation.PostConstruct;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.fusesource.jansi.Ansi;
@@ -35,21 +36,33 @@ public class LocaleHelper {
@Autowired ConsoleWriter consoleWriter;
- @Autowired LocaleClient localeClient;
+ @Autowired ApiClient apiClient;
+
+ LocaleWsApiProxy localeClient;
+
+ @PostConstruct
+ public void init() {
+ this.localeClient = new LocaleWsApiProxy(this.apiClient);
+ }
/**
* Extract {@link RepositoryLocale} set from {@link RepoCreateCommand#encodedBcp47Tags} to prep
- * for {@link Repository} creation
+ * for {@link com.box.l10n.mojito.cli.model.Repository} creation
*
* @return
* @throws CommandException
*/
- protected Set extractRepositoryLocalesFromInput(
+ protected List extractRepositoryLocalesFromInput(
List encodedBcp47Tags, boolean doPrint) throws CommandException {
- Set repositoryLocales = new LinkedHashSet<>();
+ List repositoryLocales = new ArrayList<>();
if (encodedBcp47Tags != null) {
- List locales = localeClient.getLocales();
+ List locales;
+ try {
+ locales = this.localeClient.getLocales(null);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
Map localeMapByBcp47Tag = getLocaleMapByBcp47Tag(locales);
for (String encodedBcp47Tag : encodedBcp47Tags) {
@@ -63,7 +76,7 @@ protected Set extractRepositoryLocalesFromInput(
/**
* Convert encoded Bcp47 Tag into {@link RepositoryLocale} with all the parent relationships and
- * {@link RepositoryLocale#toBeFullyTranslated} set
+ * {@link RepositoryLocale#isToBeFullyTranslated()} set
*
* @param encodedBcp47Tag
* @return
@@ -109,8 +122,8 @@ protected RepositoryLocale getRepositoryLocaleFromEncodedBcp47Tag(
}
/**
- * Add locale to the end (last) of the parent hierarchy ({@link RepositoryLocale#parentLocale}) in
- * this {@link RepositoryLocale}
+ * Add locale to the end (last) of the parent hierarchy ({@link
+ * RepositoryLocale#getParentLocale()}) in this {@link RepositoryLocale}
*
* @param repositoryLocale
* @param parentLocale
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/LocalizedAssetBodyInheritanceModeConverter.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/LocalizedAssetBodyInheritanceModeConverter.java
index 9206be63ec..cc03deac1b 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/LocalizedAssetBodyInheritanceModeConverter.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/LocalizedAssetBodyInheritanceModeConverter.java
@@ -1,15 +1,15 @@
package com.box.l10n.mojito.cli.command;
-import com.box.l10n.mojito.rest.entity.LocalizedAssetBody;
+import com.box.l10n.mojito.cli.model.LocalizedAssetBody;
/**
* @author dragosv
*/
public class LocalizedAssetBodyInheritanceModeConverter
- extends EnumConverter {
+ extends EnumConverter {
@Override
- protected Class getGenericClass() {
- return LocalizedAssetBody.InheritanceMode.class;
+ protected Class getGenericClass() {
+ return LocalizedAssetBody.InheritanceModeEnum.class;
}
}
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/LocalizedAssetBodyStatusConverter.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/LocalizedAssetBodyStatusConverter.java
index 9183b3f963..45c2db5f4a 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/LocalizedAssetBodyStatusConverter.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/LocalizedAssetBodyStatusConverter.java
@@ -1,14 +1,15 @@
package com.box.l10n.mojito.cli.command;
-import com.box.l10n.mojito.rest.entity.LocalizedAssetBody;
+import com.box.l10n.mojito.cli.model.LocalizedAssetBody;
/**
* @author dragosv
*/
-public class LocalizedAssetBodyStatusConverter extends EnumConverter {
+public class LocalizedAssetBodyStatusConverter
+ extends EnumConverter {
@Override
- protected Class getGenericClass() {
- return LocalizedAssetBody.Status.class;
+ protected Class getGenericClass() {
+ return LocalizedAssetBody.StatusEnum.class;
}
}
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..d0e83c15d4 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,9 +3,11 @@
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;
+import jakarta.annotation.PostConstruct;
import org.fusesource.jansi.Ansi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -38,7 +40,14 @@ public class MainCommand extends Command {
@Autowired GitInfo gitInfo;
- @Autowired CliWsApi cliClient;
+ @Autowired ApiClient apiClient;
+
+ CliWsApi cliClient;
+
+ @PostConstruct
+ public void init() {
+ this.cliClient = new CliWsApi(this.apiClient);
+ }
@Override
void showUsage() {
@@ -59,7 +68,7 @@ protected void execute() throws CommandException {
void checkServerVersion() throws CommandException {
String serverVersion;
try {
- serverVersion = cliClient.getVersion();
+ serverVersion = this.cliClient.getVersion();
} catch (ApiException e) {
throw new CommandException(e.getMessage(), e);
}
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/PseudoLocCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/PseudoLocCommand.java
index 6a554c5948..1306a4bad0 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/PseudoLocCommand.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/PseudoLocCommand.java
@@ -1,16 +1,20 @@
package com.box.l10n.mojito.cli.command;
+import static java.util.Optional.ofNullable;
+
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.AssetWsApiProxy;
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.rest.client.AssetClient;
-import com.box.l10n.mojito.rest.client.exception.AssetNotFoundException;
-import com.box.l10n.mojito.rest.entity.Asset;
-import com.box.l10n.mojito.rest.entity.LocalizedAssetBody;
-import com.box.l10n.mojito.rest.entity.Repository;
+import com.box.l10n.mojito.cli.model.AssetAssetSummary;
+import com.box.l10n.mojito.cli.model.LocalizedAssetBody;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
+import jakarta.annotation.PostConstruct;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
@@ -99,17 +103,24 @@ public class PseudoLocCommand extends Command {
description = Param.DIR_PATH_EXCLUDE_PATTERNS_DESCRIPTION)
List directoriesExcludePatterns = null;
- @Autowired AssetClient assetClient;
+ @Autowired ApiClient apiClient;
@Autowired CommandHelper commandHelper;
- Repository repository;
+ AssetWsApiProxy assetClient;
+
+ RepositoryRepository repository;
CommandDirectories commandDirectories;
/** Contains a map of locale for generating localized file a locales defined in the repository. */
Map localeMappings;
+ @PostConstruct
+ public void init() {
+ this.assetClient = new AssetWsApiProxy(this.apiClient);
+ }
+
@Override
public void execute() throws CommandException {
consoleWriter
@@ -119,7 +130,11 @@ public void execute() throws CommandException {
.a(repositoryParam)
.println(2);
- repository = commandHelper.findRepositoryByName(repositoryParam);
+ try {
+ repository = this.commandHelper.findRepositoryByName(repositoryParam);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
commandDirectories = new CommandDirectories(sourceDirectoryParam, targetDirectoryParam);
@@ -150,7 +165,7 @@ public void execute() throws CommandException {
* @throws CommandException
*/
void generatePseudoLocalizedFile(
- Repository repository, FileMatch sourceFileMatch, List filterOptions)
+ RepositoryRepository repository, FileMatch sourceFileMatch, List filterOptions)
throws CommandException {
logger.debug("Generate pseudo localzied files");
@@ -176,27 +191,35 @@ void writePseudoLocalizedAssetToTargetDirectory(
}
LocalizedAssetBody getPseudoLocalizedAsset(
- Repository repository, FileMatch sourceFileMatch, List filterOptions)
+ RepositoryRepository repository, FileMatch sourceFileMatch, List filterOptions)
throws CommandException {
consoleWriter.a(" - Processing locale: ").fg(Color.CYAN).a(OUTPUT_BCP47_TAG).print();
try {
- Asset assetByPathAndRepositoryId =
+ AssetAssetSummary assetByPathAndRepositoryId =
assetClient.getAssetByPathAndRepositoryId(
sourceFileMatch.getSourcePath(), repository.getId());
String assetContent = commandHelper.getFileContentWithXcodePatch(sourceFileMatch);
+ LocalizedAssetBody localizedAssetBody = new LocalizedAssetBody();
+ localizedAssetBody.setContent(assetContent);
+ localizedAssetBody.setOutputBcp47tag(AssetWsApiProxy.OUTPUT_BCP47_TAG);
+ localizedAssetBody.setFilterConfigIdOverride(
+ ofNullable(sourceFileMatch.getFileType().getFilterConfigIdOverride())
+ .map(
+ filterConfigIdOverride ->
+ LocalizedAssetBody.FilterConfigIdOverrideEnum.fromValue(
+ filterConfigIdOverride.name()))
+ .orElse(null));
+ localizedAssetBody.setFilterOptions(filterOptions);
LocalizedAssetBody pseudoLocalizedAsset =
assetClient.getPseudoLocalizedAssetForContent(
- assetByPathAndRepositoryId.getId(),
- assetContent,
- sourceFileMatch.getFileType().getFilterConfigIdOverride(),
- filterOptions);
+ localizedAssetBody, assetByPathAndRepositoryId.getId());
logger.trace("PseudoLocalizedAsset content = {}", pseudoLocalizedAsset.getContent());
return pseudoLocalizedAsset;
- } catch (AssetNotFoundException e) {
+ } catch (ApiException e) {
throw new CommandException(
"Asset with path ["
+ sourceFileMatch.getSourcePath()
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/PullCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/PullCommand.java
index 87a016d2eb..7b44368528 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/PullCommand.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/PullCommand.java
@@ -1,27 +1,35 @@
package com.box.l10n.mojito.cli.command;
+import static java.util.Optional.ofNullable;
+
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.AssetWsApiProxy;
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.model.AssetAssetSummary;
+import com.box.l10n.mojito.cli.model.LocaleInfo;
+import com.box.l10n.mojito.cli.model.LocalizedAssetBody;
+import com.box.l10n.mojito.cli.model.MultiLocalizedAssetBody;
+import com.box.l10n.mojito.cli.model.PollableTask;
+import com.box.l10n.mojito.cli.model.RepositoryLocaleRepository;
+import com.box.l10n.mojito.cli.model.RepositoryLocaleStatisticRepository;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
+import com.box.l10n.mojito.cli.model.RepositoryStatisticRepository;
import com.box.l10n.mojito.json.ObjectMapper;
-import com.box.l10n.mojito.rest.client.AssetClient;
-import com.box.l10n.mojito.rest.client.exception.AssetNotFoundException;
-import com.box.l10n.mojito.rest.entity.Asset;
-import com.box.l10n.mojito.rest.entity.LocalizedAssetBody;
-import com.box.l10n.mojito.rest.entity.PollableTask;
-import com.box.l10n.mojito.rest.entity.Repository;
-import com.box.l10n.mojito.rest.entity.RepositoryLocale;
-import com.box.l10n.mojito.rest.entity.RepositoryLocaleStatistic;
-import com.box.l10n.mojito.rest.entity.RepositoryStatistic;
+import jakarta.annotation.PostConstruct;
import java.nio.file.Path;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import java.util.stream.Collectors;
import org.fusesource.jansi.Ansi.Color;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -121,8 +129,8 @@ public class PullCommand extends Command {
description =
"Inheritance Mode. Used when there is no translations in the target locale for a text unit. (USE_PARENT to fallback to parent locale translation, REMOVE_UNTRANSLATED to remove the text unit from the file ",
converter = LocalizedAssetBodyInheritanceModeConverter.class)
- LocalizedAssetBody.InheritanceMode inheritanceMode =
- LocalizedAssetBody.InheritanceMode.USE_PARENT;
+ LocalizedAssetBody.InheritanceModeEnum inheritanceMode =
+ LocalizedAssetBody.InheritanceModeEnum.USE_PARENT;
@Parameter(
names = {"--status"},
@@ -130,7 +138,7 @@ public class PullCommand extends Command {
description =
"To choose the translations used to generate the file based on their status. ACCEPTED: only includes translations that are accepted. ACCEPTED_OR_NEEDS_REVIEW: includes translations that are accepted or that need review. ALL: includes all translations available even if they need re-translation (\"rejected\" translations are always excluded as they are considered harmful).",
converter = LocalizedAssetBodyStatusConverter.class)
- LocalizedAssetBody.Status status = LocalizedAssetBody.Status.ALL;
+ LocalizedAssetBody.StatusEnum status = LocalizedAssetBody.StatusEnum.ALL;
@Parameter(
names = {"--asset-mapping", "-am"},
@@ -167,7 +175,9 @@ public class PullCommand extends Command {
"Indicates that the pull should use parallel execution. This is run as an asynchronous request, if --async-ws is also specified it will be ignored.")
Boolean isParallel = false;
- @Autowired AssetClient assetClient;
+ @Autowired ApiClient apiClient;
+
+ protected AssetWsApiProxy assetClient;
@Autowired CommandHelper commandHelper;
@@ -175,11 +185,11 @@ public class PullCommand extends Command {
@Autowired LocaleMappingHelper localeMappingHelper;
- Map repositoryLocalesWithoutRootLocale;
+ Map repositoryLocalesWithoutRootLocale;
- RepositoryLocale rootRepositoryLocale;
+ RepositoryLocaleRepository rootRepositoryLocale;
- Repository repository;
+ RepositoryRepository repository;
CommandDirectories commandDirectories;
@@ -191,6 +201,11 @@ public class PullCommand extends Command {
String pullRunName;
+ @PostConstruct
+ public void init() {
+ this.assetClient = new AssetWsApiProxy(this.apiClient);
+ }
+
@Override
public void execute() throws CommandException {
@@ -201,7 +216,11 @@ public void execute() throws CommandException {
.a(repositoryParam)
.println(2);
- repository = commandHelper.findRepositoryByName(repositoryParam);
+ try {
+ repository = commandHelper.findRepositoryByName(repositoryParam);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
if (onlyIfFullyTranslated) {
initLocaleFullyTranslatedMap(repository);
@@ -277,12 +296,13 @@ void writePullRunFileIfNeeded() {
* @throws CommandException
*/
void generateLocalizedFilesWithoutLocaleMapping(
- Repository repository, FileMatch sourceFileMatch, List filterOptions)
+ RepositoryRepository repository, FileMatch sourceFileMatch, List filterOptions)
throws CommandException {
logger.debug("Generate localized files (without locale mapping)");
- for (RepositoryLocale repositoryLocale : repositoryLocalesWithoutRootLocale.values()) {
+ for (RepositoryLocaleRepository repositoryLocale :
+ repositoryLocalesWithoutRootLocale.values()) {
generateLocalizedFile(repository, sourceFileMatch, filterOptions, null, repositoryLocale);
}
}
@@ -297,25 +317,32 @@ void generateLocalizedFilesWithoutLocaleMapping(
* @throws CommandException
*/
void generateLocalizedFilesWithLocaleMaping(
- Repository repository, FileMatch sourceFileMatch, List filterOptions)
+ RepositoryRepository repository, FileMatch sourceFileMatch, List filterOptions)
throws CommandException {
logger.debug("Generate localized files with locale mapping");
+ List repositoryLocales =
+ localeMappings.entrySet().stream()
+ .map(entry -> getRepositoryLocaleForOutputBcp47Tag(entry.getKey()))
+ .distinct()
+ .collect(Collectors.toList());
+
for (Map.Entry localeMapping : localeMappings.entrySet()) {
String outputBcp47tag = localeMapping.getKey();
- RepositoryLocale repositoryLocale = getRepositoryLocaleForOutputBcp47Tag(outputBcp47tag);
+ RepositoryLocaleRepository repositoryLocale =
+ getRepositoryLocaleForOutputBcp47Tag(outputBcp47tag);
generateLocalizedFile(
repository, sourceFileMatch, filterOptions, outputBcp47tag, repositoryLocale);
}
}
void generateLocalizedFile(
- Repository repository,
+ RepositoryRepository repository,
FileMatch sourceFileMatch,
List filterOptions,
String outputBcp47tag,
- RepositoryLocale repositoryLocale)
+ RepositoryLocaleRepository repositoryLocale)
throws CommandException {
if (shouldGenerateLocalizedFile(repositoryLocale)) {
LocalizedAssetBody localizedAsset =
@@ -333,19 +360,19 @@ void generateLocalizedFile(
}
/**
- * Gets the {@link RepositoryLocale} that correspond to the output BCP47 tag
+ * Gets the {@link com.box.l10n.mojito.cli.model.RepositoryLocaleRepository} that correspond to the output BCP47 tag
* based on the {@link #localeMappings
*
* @param outputBcp47tag
* @return the repository locale to be used for the output BCP47 tag
* @throws CommandException if the mapping is invalid
*/
- RepositoryLocale getRepositoryLocaleForOutputBcp47Tag(String outputBcp47tag)
+ RepositoryLocaleRepository getRepositoryLocaleForOutputBcp47Tag(String outputBcp47tag)
throws CommandException {
String repositoryLocaleBcp47Tag = localeMappings.get(outputBcp47tag);
- RepositoryLocale repositoryLocale;
+ RepositoryLocaleRepository repositoryLocale;
if (rootRepositoryLocale.getLocale().getBcp47Tag().equals(outputBcp47tag)) {
repositoryLocale = rootRepositoryLocale;
@@ -366,18 +393,20 @@ RepositoryLocale getRepositoryLocaleForOutputBcp47Tag(String outputBcp47tag)
}
/**
- * Gets the list of {@link RepositoryLocale}s of a {@link Repository} excluding the root locale
- * (the only locale that has no parent locale).
+ * Gets the list of {@link com.box.l10n.mojito.cli.model.RepositoryLocaleRepository}s of a {@link
+ * com.box.l10n.mojito.cli.model.RepositoryRepository} excluding the root locale (the only locale
+ * that has no parent locale).
*
* @param repository the repository
- * @return the list of {@link RepositoryLocale}s excluding the root locale.
+ * @return the list of {@link com.box.l10n.mojito.cli.model.RepositoryLocaleRepository}s excluding
+ * the root locale.
*/
- private Map initRepositoryLocalesMapAndRootRepositoryLocale(
- Repository repository) {
+ private Map initRepositoryLocalesMapAndRootRepositoryLocale(
+ RepositoryRepository repository) {
repositoryLocalesWithoutRootLocale = new HashMap<>();
- for (RepositoryLocale repositoryLocale : repository.getRepositoryLocales()) {
+ for (RepositoryLocaleRepository repositoryLocale : repository.getRepositoryLocales()) {
if (repositoryLocale.getParentLocale() != null) {
repositoryLocalesWithoutRootLocale.put(
repositoryLocale.getLocale().getBcp47Tag(), repositoryLocale);
@@ -404,9 +433,9 @@ void writeLocalizedAssetToTargetDirectory(
}
LocalizedAssetBody getLocalizedAsset(
- Repository repository,
+ RepositoryRepository repository,
FileMatch sourceFileMatch,
- RepositoryLocale repositoryLocale,
+ RepositoryLocaleRepository repositoryLocale,
String outputBcp47tag,
List filterOptions)
throws CommandException {
@@ -419,7 +448,7 @@ LocalizedAssetBody getLocalizedAsset(
String sourcePath =
commandHelper.getMappedSourcePath(assetMapping, sourceFileMatch.getSourcePath());
- Asset assetByPathAndRepositoryId;
+ AssetAssetSummary assetByPathAndRepositoryId;
try {
logger.debug(
@@ -428,7 +457,7 @@ LocalizedAssetBody getLocalizedAsset(
repositoryLocale.getLocale().getBcp47Tag());
assetByPathAndRepositoryId =
assetClient.getAssetByPathAndRepositoryId(sourcePath, repository.getId());
- } catch (AssetNotFoundException e) {
+ } catch (CommandException | ApiException e) {
throw new CommandException(
"Asset with path [" + sourcePath + "] was not found in repo [" + repositoryParam + "]",
e);
@@ -466,10 +495,10 @@ LocalizedAssetBody getLocalizedAsset(
LocalizedAssetBody getLocalizedAssetBodySync(
FileMatch sourceFileMatch,
- RepositoryLocale repositoryLocale,
+ RepositoryLocaleRepository repositoryLocale,
String outputBcp47tag,
List filterOptions,
- Asset assetByPathAndRepositoryId,
+ AssetAssetSummary assetByPathAndRepositoryId,
String assetContent,
LocalizedAssetBody localizedAsset)
throws CommandException {
@@ -479,17 +508,27 @@ LocalizedAssetBody getLocalizedAssetBodySync(
int maxCount = 5;
while (localizedAsset == null && count < maxCount) {
try {
+ LocalizedAssetBody localizedAssetBody = new LocalizedAssetBody();
+ localizedAssetBody.setAssetId(assetByPathAndRepositoryId.getId());
+ localizedAssetBody.setLocaleId(repositoryLocale.getLocale().getId());
+ localizedAssetBody.setContent(assetContent);
+ localizedAssetBody.setOutputBcp47tag(outputBcp47tag);
+ localizedAssetBody.setFilterConfigIdOverride(
+ ofNullable(sourceFileMatch.getFileType().getFilterConfigIdOverride())
+ .map(
+ filterConfigIdOverride ->
+ LocalizedAssetBody.FilterConfigIdOverrideEnum.fromValue(
+ filterConfigIdOverride.name()))
+ .orElse(null));
+ localizedAssetBody.setFilterOptions(filterOptions);
+ localizedAssetBody.setInheritanceMode(inheritanceMode);
+ localizedAssetBody.setStatus(status);
+ localizedAssetBody.setPullRunName(pullRunName);
localizedAsset =
assetClient.getLocalizedAssetForContent(
+ localizedAssetBody,
assetByPathAndRepositoryId.getId(),
- repositoryLocale.getLocale().getId(),
- assetContent,
- outputBcp47tag,
- sourceFileMatch.getFileType().getFilterConfigIdOverride(),
- filterOptions,
- status,
- inheritanceMode,
- pullRunName);
+ repositoryLocale.getLocale().getId());
} catch (Exception e) {
count++;
consoleWriter
@@ -513,59 +552,118 @@ LocalizedAssetBody getLocalizedAssetBodySync(
return localizedAsset;
}
+ private static List mapRepoLocaleToLocaleInfos(
+ RepositoryLocaleRepository locale,
+ Map> repoLocaleToOutputTagsMap) {
+ List localeInfos = new ArrayList<>();
+ if (repoLocaleToOutputTagsMap.containsKey(locale)) {
+ for (String outputTag : repoLocaleToOutputTagsMap.get(locale)) {
+ LocaleInfo localeInfo = new LocaleInfo();
+ localeInfo.setLocaleId(locale.getLocale().getId());
+ localeInfo.setOutputBcp47tag(outputTag);
+ localeInfos.add(localeInfo);
+ }
+ } else {
+ LocaleInfo localeInfo = new LocaleInfo();
+ localeInfo.setLocaleId(locale.getLocale().getId());
+ localeInfos.add(localeInfo);
+ }
+ return localeInfos;
+ }
+
PollableTask getLocalizedAssetBodyParallel(
FileMatch sourceFileMatch,
- List repositoryLocales,
- Map> localeIdToOutputTagsMap,
+ List repositoryLocales,
+ Map> localeIdToOutputTagsMap,
List filterOptions,
- Asset assetByPathAndRepositoryId,
+ AssetAssetSummary assetByPathAndRepositoryId,
String assetContent)
throws CommandException {
-
- return assetClient.getLocalizedAssetForContentParallel(
- assetByPathAndRepositoryId.getId(),
- assetContent,
- repositoryLocales,
- localeIdToOutputTagsMap,
- sourceFileMatch.getFileType().getFilterConfigIdOverride(),
- filterOptions,
- status,
- inheritanceMode,
- pullRunName);
+ List localeInfos =
+ repositoryLocales.stream()
+ .map(locale -> mapRepoLocaleToLocaleInfos(locale, localeIdToOutputTagsMap))
+ .flatMap(List::stream)
+ .toList();
+ MultiLocalizedAssetBody multiLocalizedAssetBody = new MultiLocalizedAssetBody();
+ multiLocalizedAssetBody.setAssetId(assetByPathAndRepositoryId.getId());
+ multiLocalizedAssetBody.setSourceContent(assetContent);
+ multiLocalizedAssetBody.setLocaleInfos(localeInfos);
+ multiLocalizedAssetBody.setGenerateLocalizedAssetJobIds(new HashMap<>());
+ multiLocalizedAssetBody.setFilterConfigIdOverride(
+ ofNullable(sourceFileMatch.getFileType().getFilterConfigIdOverride())
+ .map(
+ filterConfigIdOverride ->
+ MultiLocalizedAssetBody.FilterConfigIdOverrideEnum.fromValue(
+ filterConfigIdOverride.name()))
+ .orElse(null));
+ multiLocalizedAssetBody.setFilterOptions(filterOptions);
+ multiLocalizedAssetBody.setInheritanceMode(
+ ofNullable(inheritanceMode)
+ .map(
+ inheritanceModeEnum ->
+ MultiLocalizedAssetBody.InheritanceModeEnum.fromValue(
+ inheritanceModeEnum.name()))
+ .orElse(null));
+ multiLocalizedAssetBody.setStatus(
+ ofNullable(status)
+ .map(statusEnum -> MultiLocalizedAssetBody.StatusEnum.fromValue(statusEnum.name()))
+ .orElse(null));
+ multiLocalizedAssetBody.setPullRunName(pullRunName);
+ try {
+ return assetClient.getLocalizedAssetForContentParallel(
+ multiLocalizedAssetBody, assetByPathAndRepositoryId.getId());
+ } catch (ApiException e) {
+ throw new RuntimeException(e);
+ }
}
LocalizedAssetBody getLocalizedAssetBodyAsync(
FileMatch sourceFileMatch,
- RepositoryLocale repositoryLocale,
+ RepositoryLocaleRepository repositoryLocale,
String outputBcp47tag,
List filterOptions,
- Asset assetByPathAndRepositoryId,
+ AssetAssetSummary assetByPathAndRepositoryId,
String assetContent)
throws CommandException {
LocalizedAssetBody localizedAsset;
- PollableTask localizedAssetForContentAsync =
- assetClient.getLocalizedAssetForContentAsync(
- assetByPathAndRepositoryId.getId(),
- repositoryLocale.getLocale().getId(),
- assetContent,
- outputBcp47tag,
- sourceFileMatch.getFileType().getFilterConfigIdOverride(),
- filterOptions,
- status,
- inheritanceMode,
- pullRunName);
- commandHelper.waitForPollableTask(localizedAssetForContentAsync.getId());
- String jsonOutput =
- commandHelper.pollableTaskClient.getPollableTaskOutput(
- localizedAssetForContentAsync.getId());
+ LocalizedAssetBody localizedAssetBody = new LocalizedAssetBody();
+ localizedAssetBody.setAssetId(assetByPathAndRepositoryId.getId());
+ localizedAssetBody.setLocaleId(repositoryLocale.getLocale().getId());
+ localizedAssetBody.setContent(assetContent);
+ localizedAssetBody.setOutputBcp47tag(outputBcp47tag);
+ localizedAssetBody.setFilterConfigIdOverride(
+ ofNullable(sourceFileMatch.getFileType().getFilterConfigIdOverride())
+ .map(
+ filterConfigIdOverride ->
+ LocalizedAssetBody.FilterConfigIdOverrideEnum.fromValue(
+ filterConfigIdOverride.name()))
+ .orElse(null));
+ localizedAssetBody.setFilterOptions(filterOptions);
+ localizedAssetBody.setInheritanceMode(inheritanceMode);
+ localizedAssetBody.setStatus(status);
+ localizedAssetBody.setPullRunName(pullRunName);
+ String jsonOutput;
+ try {
+ PollableTask localizedAssetForContentAsync =
+ assetClient.getLocalizedAssetForContentAsync(
+ localizedAssetBody, assetByPathAndRepositoryId.getId());
+ commandHelper.waitForPollableTask(localizedAssetForContentAsync.getId());
+
+ jsonOutput =
+ commandHelper.pollableTaskClient.getPollableTaskOutput(
+ localizedAssetForContentAsync.getId());
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
localizedAsset = objectMapper.readValueUnchecked(jsonOutput, LocalizedAssetBody.class);
return localizedAsset;
}
- private void initLocaleFullyTranslatedMap(Repository repository) {
- RepositoryStatistic repoStat = repository.getRepositoryStatistic();
+ private void initLocaleFullyTranslatedMap(RepositoryRepository repository) {
+ RepositoryStatisticRepository repoStat = repository.getRepositoryStatistic();
if (repoStat != null) {
- for (RepositoryLocaleStatistic repoLocaleStat : repoStat.getRepositoryLocaleStatistics()) {
+ for (RepositoryLocaleStatisticRepository repoLocaleStat :
+ repoStat.getRepositoryLocaleStatistics()) {
localeFullyTranslated.put(
repoLocaleStat.getLocale().getBcp47Tag(),
repoLocaleStat.getForTranslationCount() == 0L);
@@ -573,7 +671,7 @@ private void initLocaleFullyTranslatedMap(Repository repository) {
}
}
- protected boolean shouldGenerateLocalizedFile(RepositoryLocale repositoryLocale) {
+ protected boolean shouldGenerateLocalizedFile(RepositoryLocaleRepository repositoryLocale) {
boolean localize = true;
if (onlyIfFullyTranslated) {
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/PullCommandParallel.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/PullCommandParallel.java
index a8452ce6e0..f1600f9aa8 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/PullCommandParallel.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/PullCommandParallel.java
@@ -1,13 +1,13 @@
package com.box.l10n.mojito.cli.command;
+import com.box.l10n.mojito.cli.apiclient.ApiException;
import com.box.l10n.mojito.cli.filefinder.FileMatch;
-import com.box.l10n.mojito.rest.client.exception.AssetNotFoundException;
-import com.box.l10n.mojito.rest.entity.Asset;
-import com.box.l10n.mojito.rest.entity.LocalizedAssetBody;
-import com.box.l10n.mojito.rest.entity.MultiLocalizedAssetBody;
-import com.box.l10n.mojito.rest.entity.PollableTask;
-import com.box.l10n.mojito.rest.entity.Repository;
-import com.box.l10n.mojito.rest.entity.RepositoryLocale;
+import com.box.l10n.mojito.cli.model.AssetAssetSummary;
+import com.box.l10n.mojito.cli.model.LocalizedAssetBody;
+import com.box.l10n.mojito.cli.model.MultiLocalizedAssetBody;
+import com.box.l10n.mojito.cli.model.PollableTask;
+import com.box.l10n.mojito.cli.model.RepositoryLocaleRepository;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
import com.google.common.collect.Lists;
import java.nio.file.Path;
import java.util.HashMap;
@@ -102,27 +102,31 @@ private void pollForLocalizedFiles() {
.forEach(
entry -> {
commandHelper.waitForPollableTaskSilencedOutput(entry.getKey());
- String jsonOutput =
- commandHelper.pollableTaskClient.getPollableTaskOutput(entry.getKey());
- MultiLocalizedAssetBody multiLocalizedAsset =
- objectMapper.readValueUnchecked(jsonOutput, MultiLocalizedAssetBody.class);
- for (String outputTag :
- multiLocalizedAsset.getGenerateLocalizedAssetJobIds().keySet()) {
- jsonOutput =
- commandHelper.pollableTaskClient.getPollableTaskOutput(
- multiLocalizedAsset.getGenerateLocalizedAssetJobIds().get(outputTag));
- writeLocalizedAssetToTargetDirectory(
- objectMapper.readValueUnchecked(jsonOutput, LocalizedAssetBody.class),
- entry.getValue());
+ String jsonOutput;
+ try {
+ jsonOutput = commandHelper.pollableTaskClient.getPollableTaskOutput(entry.getKey());
+ MultiLocalizedAssetBody multiLocalizedAsset =
+ objectMapper.readValueUnchecked(jsonOutput, MultiLocalizedAssetBody.class);
+ for (String outputTag :
+ multiLocalizedAsset.getGenerateLocalizedAssetJobIds().keySet()) {
+ jsonOutput =
+ commandHelper.pollableTaskClient.getPollableTaskOutput(
+ multiLocalizedAsset.getGenerateLocalizedAssetJobIds().get(outputTag));
+ writeLocalizedAssetToTargetDirectory(
+ objectMapper.readValueUnchecked(jsonOutput, LocalizedAssetBody.class),
+ entry.getValue());
+ }
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
}
});
}
private PollableTask generateLocalizedFilesWithLocaleMappingParallel(
- Repository repository, FileMatch sourceFileMatch, List filterOptions)
+ RepositoryRepository repository, FileMatch sourceFileMatch, List filterOptions)
throws CommandException {
- List repositoryLocales =
+ List repositoryLocales =
localeMappings.entrySet().stream()
.map(entry -> getRepositoryLocaleForOutputBcp47Tag(entry.getKey()))
.distinct()
@@ -131,7 +135,7 @@ private PollableTask generateLocalizedFilesWithLocaleMappingParallel(
}
private PollableTask generateLocalizedFilesWithoutLocaleMappingParallel(
- Repository repository, FileMatch sourceFileMatch, List filterOptions)
+ RepositoryRepository repository, FileMatch sourceFileMatch, List filterOptions)
throws CommandException {
logger.debug("Generate localized files (without locale mapping)");
@@ -174,7 +178,7 @@ private synchronized void printFileGeneratedToConsole(
}
void generateLocalizedFilesWithoutLocaleMapping(
- Repository repository, FileMatch sourceFileMatch, List filterOptions)
+ RepositoryRepository repository, FileMatch sourceFileMatch, List filterOptions)
throws CommandException {
logger.debug("Generate localized files (without locale mapping)");
@@ -187,11 +191,11 @@ void generateLocalizedFilesWithoutLocaleMapping(
}
private PollableTask generateLocalizedFiles(
- Repository repository,
+ RepositoryRepository repository,
FileMatch sourceFileMatch,
List filterOptions,
- List repositoryLocales) {
- Asset assetByPathAndRepositoryId;
+ List repositoryLocales) {
+ AssetAssetSummary assetByPathAndRepositoryId;
String sourcePath =
commandHelper.getMappedSourcePath(assetMapping, sourceFileMatch.getSourcePath());
@@ -200,7 +204,7 @@ private PollableTask generateLocalizedFiles(
logger.debug("Getting the asset for path: {}", sourceFileMatch.getSourcePath());
assetByPathAndRepositoryId =
assetClient.getAssetByPathAndRepositoryId(sourcePath, repository.getId());
- } catch (AssetNotFoundException e) {
+ } catch (CommandException | ApiException e) {
throw new CommandException(
String.format(
"Asset with path [%s] was not found in repo [%s]", sourcePath, repositoryParam),
@@ -219,13 +223,13 @@ private PollableTask generateLocalizedFiles(
commandHelper.getFileContentWithXcodePatch(sourceFileMatch));
}
- private Map> getRepoLocaleToOutputTagsMap() {
- Map> localeIdToOutputTagsMap = new HashMap<>();
+ private Map> getRepoLocaleToOutputTagsMap() {
+ Map> localeIdToOutputTagsMap = new HashMap<>();
if (localeMappings != null) {
for (Map.Entry mapping : localeMappings.entrySet()) {
String outputBcp47tag = mapping.getKey();
- RepositoryLocale locale = getRepositoryLocaleForOutputBcp47Tag(outputBcp47tag);
+ RepositoryLocaleRepository locale = getRepositoryLocaleForOutputBcp47Tag(outputBcp47tag);
if (localeIdToOutputTagsMap.containsKey(locale)) {
localeIdToOutputTagsMap.get(locale).add(outputBcp47tag);
} else {
@@ -238,7 +242,7 @@ private Map> getRepoLocaleToOutputTagsMap() {
}
private boolean shouldGenerateLocalizedFileWithCliOutput(
- FileMatch sourceFileMatch, RepositoryLocale repositoryLocale) {
+ FileMatch sourceFileMatch, RepositoryLocaleRepository repositoryLocale) {
boolean localize = shouldGenerateLocalizedFile(repositoryLocale);
if (!localize) {
printLocaleSkippedToConsole(sourceFileMatch, repositoryLocale);
@@ -247,7 +251,7 @@ private boolean shouldGenerateLocalizedFileWithCliOutput(
}
private synchronized void printLocaleSkippedToConsole(
- FileMatch sourceFileMatch, RepositoryLocale repositoryLocale) {
+ FileMatch sourceFileMatch, RepositoryLocaleRepository repositoryLocale) {
consoleWriter
.a("Skipping locale: ")
.fg(Ansi.Color.CYAN)
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/PushCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/PushCommand.java
index 272a30e84b..63c005f865 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/PushCommand.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/PushCommand.java
@@ -1,21 +1,23 @@
package com.box.l10n.mojito.cli.command;
+import static java.util.Optional.ofNullable;
+
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.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.rest.client.RepositoryClient;
-import com.box.l10n.mojito.rest.entity.Repository;
-import com.box.l10n.mojito.rest.entity.SourceAsset;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
+import com.box.l10n.mojito.cli.model.SourceAsset;
import com.ibm.icu.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.UUID;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
@@ -118,7 +120,7 @@ public class PushCommand extends Command {
required = false,
description =
"Optional list of notifiers when pusing to a repository (notification will be sent eg. when new strings are processed or when translations are ready)")
- Set pushToBranchNotifiers = Collections.emptySet();
+ List pushToBranchNotifiers = Collections.emptyList();
@Parameter(
names = Param.PUSH_TYPE_LONG,
@@ -147,12 +149,12 @@ public class PushCommand extends Command {
converter = AssetMappingConverter.class)
Map assetMapping;
- @Autowired RepositoryClient repositoryClient;
-
@Autowired CommandHelper commandHelper;
@Autowired PushService pushService;
+ @Autowired ApiClient apiClient;
+
CommandDirectories commandDirectories;
@Override
@@ -167,7 +169,12 @@ public void execute() throws CommandException {
.a(repositoryParam)
.println(2);
- Repository repository = commandHelper.findRepositoryByName(repositoryParam);
+ RepositoryRepository repository;
+ try {
+ repository = this.commandHelper.findRepositoryByName(repositoryParam);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
if (commitHash != null && StringUtils.isBlank(commitHash)) {
throw new CommandException(
@@ -225,7 +232,12 @@ public void execute() throws CommandException {
sourceAsset.setRepositoryId(repository.getId());
sourceAsset.setPushRunName(recordPushRun ? pushRunName : null);
sourceAsset.setFilterConfigIdOverride(
- sourceFileMatch.getFileType().getFilterConfigIdOverride());
+ ofNullable(sourceFileMatch.getFileType().getFilterConfigIdOverride())
+ .map(
+ filterConfigIdOverride ->
+ SourceAsset.FilterConfigIdOverrideEnum.fromValue(
+ filterConfigIdOverride.name()))
+ .orElse(null));
sourceAsset.setFilterOptions(
commandHelper.getFilterOptionsOrDefaults(
sourceFileMatch.getFileType(), filterOptionsParam));
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/PushService.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/PushService.java
index faaca978e2..864345c5f4 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/PushService.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/PushService.java
@@ -1,15 +1,18 @@
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.AssetWsApiProxy;
+import com.box.l10n.mojito.cli.apiclient.CommitWsApi;
+import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiProxy;
+import com.box.l10n.mojito.cli.apiclient.exceptions.PollableTaskException;
import com.box.l10n.mojito.cli.console.ConsoleWriter;
-import com.box.l10n.mojito.rest.client.AssetClient;
-import com.box.l10n.mojito.rest.client.CommitClient;
-import com.box.l10n.mojito.rest.client.RepositoryClient;
-import com.box.l10n.mojito.rest.client.exception.PollableTaskException;
-import com.box.l10n.mojito.rest.entity.Branch;
-import com.box.l10n.mojito.rest.entity.PollableTask;
-import com.box.l10n.mojito.rest.entity.Repository;
-import com.box.l10n.mojito.rest.entity.SourceAsset;
-import com.google.common.collect.Sets;
+import com.box.l10n.mojito.cli.model.BranchBranchSummary;
+import com.box.l10n.mojito.cli.model.CommitToPushRunBody;
+import com.box.l10n.mojito.cli.model.PollableTask;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
+import com.box.l10n.mojito.cli.model.SourceAsset;
+import jakarta.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -33,16 +36,25 @@ public class PushService {
@Autowired ConsoleWriter consoleWriter;
- @Autowired AssetClient assetClient;
+ private AssetWsApiProxy assetClient;
- @Autowired CommitClient commitClient;
+ @Autowired CommandHelper commandHelper;
- @Autowired RepositoryClient repositoryClient;
+ @Autowired ApiClient apiClient;
- @Autowired CommandHelper commandHelper;
+ RepositoryWsApiProxy repositoryClient;
+
+ CommitWsApi commitClient;
+
+ @PostConstruct
+ public void init() {
+ this.assetClient = new AssetWsApiProxy(this.apiClient);
+ this.repositoryClient = new RepositoryWsApiProxy(this.apiClient);
+ this.commitClient = new CommitWsApi(this.apiClient);
+ }
public void push(
- Repository repository,
+ RepositoryRepository repository,
Stream sourceAssetStream,
String branchName,
PushType pushType)
@@ -55,7 +67,12 @@ public void push(
sourceAsset -> {
consoleWriter.a(" - Uploading: ").fg(Ansi.Color.CYAN).a(sourceAsset.getPath()).println();
- SourceAsset assetAfterSend = assetClient.sendSourceAsset(sourceAsset);
+ SourceAsset assetAfterSend = null;
+ try {
+ assetAfterSend = assetClient.importSourceAsset(sourceAsset);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
pollableTasks.add(assetAfterSend.getPollableTask());
consoleWriter
@@ -84,9 +101,9 @@ public void push(
}
void optionalDeleteUnusedAssets(
- Repository repository, String branchName, PushType pushType, Set usedAssetIds)
+ RepositoryRepository repository, String branchName, PushType pushType, Set usedAssetIds)
throws CommandException {
- Branch branch = repositoryClient.getBranch(repository.getId(), branchName);
+ BranchBranchSummary branch = this.repositoryClient.getBranch(repository.getId(), branchName);
if (PushType.NO_DELETE.equals(pushType)) {
logger.debug("Don't delete unused asset");
@@ -95,26 +112,30 @@ void optionalDeleteUnusedAssets(
logger.debug(
"No branch in the repository, no asset must have been pushed yet, no need to delete");
} else {
- logger.debug("process deleted assets here");
- Set assetIds =
- Sets.newHashSet(
- assetClient.getAssetIds(repository.getId(), false, false, branch.getId()));
-
- assetIds.removeAll(usedAssetIds);
- if (!assetIds.isEmpty()) {
- consoleWriter
- .newLine()
- .a("Delete assets from repository, ids: ")
- .fg(Ansi.Color.CYAN)
- .a(assetIds.toString())
- .println();
- PollableTask pollableTask = assetClient.deleteAssetsInBranch(assetIds, branch.getId());
- consoleWriter
- .a(" --> task id: ")
- .fg(Ansi.Color.MAGENTA)
- .a(pollableTask.getId())
- .println();
- commandHelper.waitForPollableTask(pollableTask.getId());
+ try {
+ logger.debug("process deleted assets here");
+ List assetIds =
+ assetClient.getAssetIds(repository.getId(), false, false, branch.getId());
+
+ assetIds.removeAll(usedAssetIds);
+ if (!assetIds.isEmpty()) {
+ consoleWriter
+ .newLine()
+ .a("Delete assets from repository, ids: ")
+ .fg(Ansi.Color.CYAN)
+ .a(assetIds.toString())
+ .println();
+ PollableTask pollableTask =
+ assetClient.deleteAssetsOfBranches(assetIds, branch.getId());
+ consoleWriter
+ .a(" --> task id: ")
+ .fg(Ansi.Color.MAGENTA)
+ .a(pollableTask.getId())
+ .println();
+ commandHelper.waitForPollableTask(pollableTask.getId());
+ }
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
}
}
}
@@ -131,11 +152,20 @@ void waitForPollableTasks(List pollableTasks) throws CommandExcept
}
}
- public void associatePushRun(Repository repository, String pushRunName, String commitHash) {
+ public void associatePushRun(
+ RepositoryRepository repository, String pushRunName, String commitHash) {
if (!StringUtils.isBlank(pushRunName) && !StringUtils.isBlank(commitHash)) {
logger.debug(
"Associating commit with hash: {} to push run with name: {}.", commitHash, pushRunName);
- commitClient.associateCommitToPushRun(commitHash, repository.getId(), pushRunName);
+ CommitToPushRunBody commitToPushRunBody = new CommitToPushRunBody();
+ commitToPushRunBody.setCommitName(commitHash);
+ commitToPushRunBody.setRepositoryId(repository.getId());
+ commitToPushRunBody.setPushRunName(pushRunName);
+ try {
+ this.commitClient.associateCommitToPushRun(commitToPushRunBody);
+ } 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..476a891b3b 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,9 +1,11 @@
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;
+import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -22,7 +24,14 @@ public class QuartzJobsDeleteCommand extends Command {
@Autowired ConsoleWriter consoleWriter;
- @Autowired QuartzWsApi quartzJobsClient;
+ @Autowired ApiClient apiClient;
+
+ QuartzWsApi quartzJobsClient;
+
+ @PostConstruct
+ public void init() {
+ this.quartzJobsClient = new QuartzWsApi(this.apiClient);
+ }
@Override
public boolean shouldShowInCommandList() {
@@ -33,9 +42,9 @@ public boolean shouldShowInCommandList() {
protected void execute() throws CommandException {
consoleWriter.a("Delete quartz jobs").println();
try {
- quartzJobsClient.deleteAllDynamicJobs();
+ this.quartzJobsClient.deleteAllDynamicJobs();
} catch (ApiException e) {
- throw new RuntimeException(e);
+ throw new CommandException(e.getMessage(), 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..d7e41fa216 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,9 +1,11 @@
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;
+import jakarta.annotation.PostConstruct;
import java.util.List;
import org.fusesource.jansi.Ansi;
import org.slf4j.Logger;
@@ -24,7 +26,14 @@ public class QuartzJobsViewCommand extends Command {
@Autowired ConsoleWriter consoleWriter;
- @Autowired QuartzWsApi quartzJobsClient;
+ @Autowired ApiClient apiClient;
+
+ QuartzWsApi quartzJobsClient;
+
+ @PostConstruct
+ public void init() {
+ this.quartzJobsClient = new QuartzWsApi(this.apiClient);
+ }
@Override
public boolean shouldShowInCommandList() {
@@ -36,7 +45,7 @@ protected void execute() throws CommandException {
consoleWriter.a("Dynamic quartz jobs:").println();
List allDynamicJobs;
try {
- allDynamicJobs = quartzJobsClient.getAllDynamicJobs();
+ allDynamicJobs = this.quartzJobsClient.getAllDynamicJobs();
} catch (ApiException e) {
throw new CommandException(e.getMessage(), e);
}
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoCommand.java
index 344a8a2a7a..dd6c06b8b2 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoCommand.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoCommand.java
@@ -1,11 +1,13 @@
package com.box.l10n.mojito.cli.command;
import com.beust.jcommander.ParameterException;
+import com.box.l10n.mojito.cli.apiclient.ApiClient;
+import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiProxy;
import com.box.l10n.mojito.cli.console.ConsoleWriter;
-import com.box.l10n.mojito.rest.client.RepositoryClient;
-import com.box.l10n.mojito.rest.entity.IntegrityChecker;
-import com.box.l10n.mojito.rest.entity.IntegrityCheckerType;
-import java.util.HashSet;
+import com.box.l10n.mojito.cli.model.AssetIntegrityChecker;
+import jakarta.annotation.PostConstruct;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
import org.fusesource.jansi.Ansi;
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,23 +27,31 @@ public abstract class RepoCommand extends Command {
@Autowired protected ConsoleWriter consoleWriter;
- @Autowired protected RepositoryClient repositoryClient;
-
@Autowired protected LocaleHelper localeHelper;
+ @Autowired private ApiClient apiClient;
+
+ protected RepositoryWsApiProxy repositoryClient;
+
+ @PostConstruct
+ protected void init() {
+ this.repositoryClient = new RepositoryWsApiProxy(this.apiClient);
+ }
+
/**
- * Extract {@link IntegrityChecker} Set from {@link RepoCreateCommand#integrityCheckParam} to prep
- * for {@link Repository} creation
+ * Extract {@link com.box.l10n.mojito.cli.model.AssetIntegrityChecker} Set from {@link
+ * RepoCreateCommand#integrityCheckParam} to prep for {@link
+ * com.box.l10n.mojito.cli.model.Repository} creation
*
* @param integrityCheckParam
* @param doPrint
* @return
*/
- protected Set extractIntegrityCheckersFromInput(
+ protected List extractIntegrityCheckersFromInput(
String integrityCheckParam, boolean doPrint) throws CommandException {
- Set integrityCheckers = null;
+ List integrityCheckers = null;
if (integrityCheckParam != null) {
- integrityCheckers = new HashSet<>();
+ integrityCheckers = new ArrayList<>();
Set integrityCheckerParams = StringUtils.commaDelimitedListToSet(integrityCheckParam);
if (doPrint) {
consoleWriter.a("Extracted Integrity Checkers").println();
@@ -55,10 +65,11 @@ protected Set extractIntegrityCheckersFromInput(
}
String fileExtension = param[0];
String checkerType = param[1];
- IntegrityChecker integrityChecker = new IntegrityChecker();
+ AssetIntegrityChecker integrityChecker = new AssetIntegrityChecker();
integrityChecker.setAssetExtension(fileExtension);
try {
- integrityChecker.setIntegrityCheckerType(IntegrityCheckerType.valueOf(checkerType));
+ integrityChecker.setIntegrityCheckerType(
+ AssetIntegrityChecker.IntegrityCheckerTypeEnum.valueOf(checkerType));
} catch (IllegalArgumentException ex) {
throw new ParameterException("Invalid integrity checker type [" + checkerType + "]");
}
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoCreateCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoCreateCommand.java
index 14e8699219..e9f3876db8 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoCreateCommand.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoCreateCommand.java
@@ -3,16 +3,17 @@
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
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.LocaleWsApiProxy;
import com.box.l10n.mojito.cli.command.param.Param;
-import com.box.l10n.mojito.rest.client.LocaleClient;
-import com.box.l10n.mojito.rest.client.exception.LocaleNotFoundException;
-import com.box.l10n.mojito.rest.client.exception.ResourceNotCreatedException;
-import com.box.l10n.mojito.rest.entity.IntegrityChecker;
-import com.box.l10n.mojito.rest.entity.Locale;
-import com.box.l10n.mojito.rest.entity.Repository;
-import com.box.l10n.mojito.rest.entity.RepositoryLocale;
+import com.box.l10n.mojito.cli.model.AssetIntegrityChecker;
+import com.box.l10n.mojito.cli.model.Locale;
+import com.box.l10n.mojito.cli.model.Repository;
+import com.box.l10n.mojito.cli.model.RepositoryLocale;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
+import jakarta.annotation.PostConstruct;
import java.util.List;
-import java.util.Set;
import org.fusesource.jansi.Ansi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -92,39 +93,47 @@ public class RepoCreateCommand extends RepoCommand {
description = INTEGRITY_CHECK_DESCRIPTION)
String integrityCheckParam;
- @Autowired LocaleClient localeClient;
+ @Autowired ApiClient apiClient;
+
+ LocaleWsApiProxy localeClient;
+
+ @PostConstruct
+ public void init() {
+ super.init();
+ this.localeClient = new LocaleWsApiProxy(this.apiClient);
+ }
@Override
public void execute() throws CommandException {
consoleWriter.a("Create repository: ").fg(Ansi.Color.CYAN).a(nameParam).println();
try {
- Set repositoryLocales =
+ List repositoryLocales =
localeHelper.extractRepositoryLocalesFromInput(encodedBcp47Tags, true);
- Set integrityCheckers =
+ List integrityCheckers =
extractIntegrityCheckersFromInput(integrityCheckParam, true);
Locale sourceLocale = null;
if (sourceLocaleBcp47Tags != null) {
- sourceLocale = localeClient.getLocaleByBcp47Tag(sourceLocaleBcp47Tags);
+ sourceLocale = this.localeClient.getLocaleByBcp47Tag(sourceLocaleBcp47Tags);
}
- Repository repository =
- repositoryClient.createRepository(
- nameParam,
- descriptionParam,
- sourceLocale,
- repositoryLocales,
- integrityCheckers,
- checkSLA);
+ Repository repositoryBody = new Repository();
+ repositoryBody.setName(nameParam);
+ repositoryBody.setDescription(descriptionParam);
+ repositoryBody.setSourceLocale(sourceLocale);
+ repositoryBody.setRepositoryLocales(repositoryLocales);
+ repositoryBody.setAssetIntegrityCheckers(integrityCheckers);
+ repositoryBody.setCheckSLA(checkSLA);
+ RepositoryRepository repository = this.repositoryClient.createRepository(repositoryBody);
consoleWriter
.newLine()
.a("created --> repository id: ")
.fg(Ansi.Color.MAGENTA)
.a(repository.getId())
.println();
- } catch (ParameterException | ResourceNotCreatedException | LocaleNotFoundException ex) {
+ } catch (ParameterException | ApiException ex) {
throw new CommandException(ex.getMessage(), ex);
}
}
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoDeleteCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoDeleteCommand.java
index 830384c23b..89956d5342 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoDeleteCommand.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoDeleteCommand.java
@@ -2,10 +2,12 @@
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.RepositoryWsApiProxy;
import com.box.l10n.mojito.cli.command.param.Param;
import com.box.l10n.mojito.cli.console.ConsoleWriter;
-import com.box.l10n.mojito.rest.client.RepositoryClient;
-import com.box.l10n.mojito.rest.client.exception.RepositoryNotFoundException;
+import jakarta.annotation.PostConstruct;
import org.fusesource.jansi.Ansi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,21 +39,28 @@ public class RepoDeleteCommand extends Command {
description = Param.REPOSITORY_NAME_DESCRIPTION)
String nameParam;
- @Autowired RepositoryClient repositoryClient;
+ @Autowired private ApiClient apiClient;
+
+ RepositoryWsApiProxy repositoryClient;
+
+ @PostConstruct
+ public void init() {
+ this.repositoryClient = new RepositoryWsApiProxy(this.apiClient);
+ }
@Override
protected void execute() throws CommandException {
consoleWriter.a("Delete repository: ").fg(Ansi.Color.CYAN).a(nameParam).println();
try {
- repositoryClient.deleteRepositoryByName(nameParam);
+ this.repositoryClient.deleteRepositoryByName(nameParam);
consoleWriter
.newLine()
.a("deleted --> repository name: ")
.fg(Ansi.Color.MAGENTA)
.a(nameParam)
.println();
- } catch (RepositoryNotFoundException ex) {
+ } catch (ApiException ex) {
throw new CommandException(ex.getMessage(), ex);
}
}
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoUpdateCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoUpdateCommand.java
index 0500daf5a3..2beafe33a4 100644
--- a/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoUpdateCommand.java
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/RepoUpdateCommand.java
@@ -1,21 +1,18 @@
package com.box.l10n.mojito.cli.command;
-import static com.box.l10n.mojito.cli.command.RepoCommand.INTEGRITY_CHECK_LONG_PARAM;
-
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.Parameters;
+import com.box.l10n.mojito.cli.apiclient.ApiException;
import com.box.l10n.mojito.cli.command.param.Param;
-import com.box.l10n.mojito.rest.client.exception.RepositoryNotFoundException;
-import com.box.l10n.mojito.rest.client.exception.ResourceNotUpdatedException;
-import com.box.l10n.mojito.rest.entity.IntegrityChecker;
-import com.box.l10n.mojito.rest.entity.Repository;
-import com.box.l10n.mojito.rest.entity.RepositoryLocale;
+import com.box.l10n.mojito.cli.model.AssetIntegrityChecker;
+import com.box.l10n.mojito.cli.model.Repository;
+import com.box.l10n.mojito.cli.model.RepositoryLocale;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import org.fusesource.jansi.Ansi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -127,22 +124,24 @@ public void execute() throws CommandException {
public void updateRepositoriesForRepositoryNames() throws CommandException {
try {
- List repositoriesForUpdate = getRepositoriesToUpdateFromParams();
+ List repositoriesForUpdate = getRepositoriesToUpdateFromParams();
- Set repositoryLocales =
+ List repositoryLocales =
localeHelper.extractRepositoryLocalesFromInput(encodedBcp47Tags, true);
- Set integrityCheckers =
+ List integrityCheckers =
extractIntegrityCheckersFromInput(integrityCheckParam, true);
consoleWriter.a("Update repositories").println();
- for (Repository repository : repositoriesForUpdate) {
- repositoryClient.updateRepository(
- repository.getName(),
- newNameParam,
- descriptionParam,
- checkSLA,
- repositoryLocales,
- integrityCheckers);
+ for (RepositoryRepository repository : repositoriesForUpdate) {
+ Repository repositoryBody = new Repository();
+ repositoryBody.setDescription(descriptionParam);
+ repositoryBody.setName(newNameParam);
+ repositoryBody.setRepositoryLocales(repositoryLocales);
+ repositoryBody.setCheckSLA(checkSLA);
+ if (integrityCheckers != null) {
+ repositoryBody.setAssetIntegrityCheckers(integrityCheckers);
+ }
+ repositoryClient.updateRepository(repository.getName(), repositoryBody);
consoleWriter
.newLine()
.a("updated --> repository name: ")
@@ -151,19 +150,24 @@ public void updateRepositoriesForRepositoryNames() throws CommandException {
.println();
}
- } catch (ParameterException | RepositoryNotFoundException | ResourceNotUpdatedException ex) {
+ } catch (ParameterException | ApiException ex) {
throw new CommandException(ex.getMessage(), ex);
}
}
- List getRepositoriesToUpdateFromParams() throws CommandException {
- List repositoriesForUpdate = new ArrayList<>();
+ List getRepositoriesToUpdateFromParams() throws CommandException {
+ List repositoriesForUpdate = new ArrayList<>();
- List allRepositories = repositoryClient.getRepositories(null);
+ List allRepositories;
+ try {
+ allRepositories = repositoryClient.getRepositories(null);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
if (repositoryNames != null) {
HashSet repositoryNamesAsSet = new HashSet<>(repositoryNames);
- for (Repository allRepository : allRepositories) {
+ for (RepositoryRepository allRepository : allRepositories) {
if (repositoryNamesAsSet.contains(allRepository.getName())) {
repositoriesForUpdate.add(allRepository);
}
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..dba309177d 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.ApiException;
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,17 @@ 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;
+ try {
+ repository = this.repositoryClient.getRepositoryByName(nameParam);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
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..1a9e0d87b0 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,14 @@
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 jakarta.annotation.PostConstruct;
import java.util.List;
import java.util.stream.Collectors;
import org.fusesource.jansi.Ansi.Color;
@@ -57,7 +60,14 @@ public class RepositoryMachineTranslationCommand extends Command {
@Autowired CommandHelper commandHelper;
- @Autowired RepositoryMachineTranslationClient repositoryMachineTranslationClient;
+ @Autowired ApiClient apiClient;
+
+ MachineTranslationWsApi repositoryMachineTranslationClient;
+
+ @PostConstruct
+ public void init() {
+ this.repositoryMachineTranslationClient = new MachineTranslationWsApi(this.apiClient);
+ }
@Override
public boolean shouldShowInCommandList() {
@@ -84,8 +94,13 @@ public void execute() throws CommandException {
repositoryMachineTranslationBody.setTargetBcp47tags(locales);
repositoryMachineTranslationBody.setSourceTextMaxCountPerLocale(sourceTextMaxCount);
- repositoryMachineTranslationBody =
- repositoryMachineTranslationClient.translateRepository(repositoryMachineTranslationBody);
+ try {
+ repositoryMachineTranslationBody =
+ this.repositoryMachineTranslationClient.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..26e96da44f 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
@@ -1,18 +1,24 @@
package com.box.l10n.mojito.cli.command;
+import static java.util.Optional.ofNullable;
+
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.apiclient.ScreenshotWsApi;
+import com.box.l10n.mojito.cli.apiclient.mappers.RepositoryMapper;
import com.box.l10n.mojito.cli.command.param.Param;
import com.box.l10n.mojito.cli.console.ConsoleWriter;
-import com.box.l10n.mojito.rest.client.ScreenshotClient;
-import com.box.l10n.mojito.rest.entity.Locale;
-import com.box.l10n.mojito.rest.entity.Repository;
-import com.box.l10n.mojito.rest.entity.Screenshot;
-import com.box.l10n.mojito.rest.entity.ScreenshotRun;
+import com.box.l10n.mojito.cli.model.Locale;
+import com.box.l10n.mojito.cli.model.LocaleRepository;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
+import com.box.l10n.mojito.cli.model.Screenshot;
+import com.box.l10n.mojito.cli.model.ScreenshotRun;
import com.fasterxml.jackson.databind.ObjectMapper;
+import jakarta.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
@@ -90,16 +96,24 @@ public class ScreenshotCommand extends Command {
CommandDirectories commandDirectories;
- @Autowired ImageWsApi imageClient;
-
- @Autowired ScreenshotClient screenshotClient;
+ @Autowired ApiClient apiClient;
@Autowired LocaleMappingHelper localeMappingHelper;
/** Contains a map of locale for generating localized file a locales defined in the repository. */
Map localeMappings;
- Map repositoryLocales;
+ Map repositoryLocales;
+
+ ScreenshotWsApi screenshotClient;
+
+ ImageWsApi imageClient;
+
+ @PostConstruct
+ public void init() {
+ this.screenshotClient = new ScreenshotWsApi(this.apiClient);
+ this.imageClient = new ImageWsApi(this.apiClient);
+ }
@Override
public void execute() throws CommandException {
@@ -110,29 +124,32 @@ public void execute() throws CommandException {
.fg(Color.CYAN)
.a(repositoryParam)
.println(2);
- Repository repository = commandHelper.findRepositoryByName(repositoryParam);
+ try {
+ RepositoryRepository repository = this.commandHelper.findRepositoryByName(repositoryParam);
- commandDirectories = new CommandDirectories(sourceDirectoryParam);
- localeMappings = localeMappingHelper.getLocaleMapping(localeMappingParam);
- repositoryLocales = commandHelper.getSortedRepositoryLocales(repository);
+ commandDirectories = new CommandDirectories(sourceDirectoryParam);
+ localeMappings = localeMappingHelper.getLocaleMapping(localeMappingParam);
+ repositoryLocales = commandHelper.getSortedRepositoryLocales(repository);
- List listFilesWithExtensionInSourceDirectory =
- commandDirectories.listFilesWithExtensionInSourceDirectory("png", "jpg", "jpeg", "gif");
+ List listFilesWithExtensionInSourceDirectory =
+ commandDirectories.listFilesWithExtensionInSourceDirectory("png", "jpg", "jpeg", "gif");
- ScreenshotRun screenshotRun = new ScreenshotRun();
- screenshotRun.setRepository(repository);
+ ScreenshotRun screenshotRun = new ScreenshotRun();
+ screenshotRun.setRepository(RepositoryMapper.mapToRepository(repository));
- if (screenshotRunName == null) {
- screenshotRun.setName(UUID.randomUUID().toString());
- } else {
- screenshotRun.setName(screenshotRunName);
- }
+ if (screenshotRunName == null) {
+ screenshotRun.setName(UUID.randomUUID().toString());
+ } else {
+ screenshotRun.setName(screenshotRunName);
+ }
- for (Path imagePath : listFilesWithExtensionInSourceDirectory) {
- processImage(imagePath, screenshotRun);
+ for (Path imagePath : listFilesWithExtensionInSourceDirectory) {
+ processImage(imagePath, screenshotRun);
+ }
+ this.screenshotClient.createOrAddToScreenshotRun(screenshotRun);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
}
-
- screenshotClient.uploadScreenshots(screenshotRun);
}
void processImage(Path imagePath, ScreenshotRun screenshotRun) throws CommandException {
@@ -177,7 +194,9 @@ Locale getLocaleFromImagePath(Path path) throws InvalidLocaleException {
"The locale: " + localeStr + " is not supported by the repository");
}
- return repositoryLocales.get(localeStr);
+ return ofNullable(repositoryLocales.get(localeStr))
+ .map(RepositoryMapper::mapToLocale)
+ .orElse(null);
} catch (IllegalArgumentException iae) {
throw new InvalidLocaleException(
"The image: "
@@ -206,7 +225,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);
+ this.imageClient.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..76dac0edd8 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,17 +2,18 @@
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.AssetWsApiProxy;
+import com.box.l10n.mojito.cli.apiclient.exceptions.PollableTaskException;
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;
import com.box.l10n.mojito.cli.model.RepositoryLocaleRepository;
import com.box.l10n.mojito.cli.model.RepositoryRepository;
import com.box.l10n.mojito.cli.model.XliffExportBody;
-import com.box.l10n.mojito.rest.client.exception.PollableTaskException;
import com.google.common.base.MoreObjects;
+import jakarta.annotation.PostConstruct;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
@@ -70,12 +71,17 @@ public class TMExportCommand extends Command {
@Autowired CommandHelper commandHelper;
- @Autowired RepositoryWsApiHelper repositoryWsApiHelper;
-
- @Autowired AssetWsApi assetClient;
+ @Autowired private ApiClient apiClient;
CommandDirectories commandDirectories;
+ AssetWsApiProxy assetClient;
+
+ @PostConstruct
+ public void init() {
+ this.assetClient = new AssetWsApiProxy(this.apiClient);
+ }
+
@Override
public void execute() throws CommandException {
@@ -91,8 +97,12 @@ public void execute() throws CommandException {
logger.debug("Initialize targetBasename (use repository if no target bases name is specified)");
targetBasenameParam = MoreObjects.firstNonNull(targetBasenameParam, repositoryParam);
- RepositoryRepository repository =
- this.repositoryWsApiHelper.findRepositoryByName(repositoryParam);
+ RepositoryRepository repository;
+ try {
+ repository = this.commandHelper.findRepositoryByName(repositoryParam);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
List assets;
try {
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..196651b550 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,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.RepositoryWsApiProxy;
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;
@@ -12,6 +12,7 @@
import com.box.l10n.mojito.cli.filefinder.file.XliffFileType;
import com.box.l10n.mojito.cli.model.ImportRepositoryBody;
import com.box.l10n.mojito.cli.model.RepositoryRepository;
+import jakarta.annotation.PostConstruct;
import java.nio.file.Path;
import java.util.Arrays;
import org.fusesource.jansi.Ansi;
@@ -70,16 +71,21 @@ 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;
CommandDirectories commandDirectories;
+ RepositoryWsApiProxy repositoryClient;
+
+ @PostConstruct
+ public void init() {
+ this.repositoryClient = new RepositoryWsApiProxy(this.apiClient);
+ }
+
@Override
public void execute() throws CommandException {
@@ -90,7 +96,11 @@ public void execute() throws CommandException {
.a(repositoryParam)
.println(2);
- repository = this.repositoryWsApiHelper.findRepositoryByName(repositoryParam);
+ try {
+ repository = this.commandHelper.findRepositoryByName(repositoryParam);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
commandDirectories = new CommandDirectories(sourceDirectoryParam);
FileType xliffFileType = new XliffFileType();
@@ -131,7 +141,7 @@ protected void doImportFileMatch(FileMatch fileMatch) throws CommandException {
ImportRepositoryBody importRepositoryBody = new ImportRepositoryBody();
importRepositoryBody.setUpdateTM(updateTMParam);
importRepositoryBody.setXliffContent(getFileContent(fileMatch));
- repositoryClient.importRepository(importRepositoryBody, repository.getId());
+ this.repositoryClient.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..699d50d99c 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,14 +4,15 @@
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.ThirdPartyWsApi;
import com.box.l10n.mojito.cli.command.param.Param;
import com.box.l10n.mojito.cli.console.ConsoleWriter;
import com.box.l10n.mojito.cli.model.PollableTask;
import com.box.l10n.mojito.cli.model.RepositoryRepository;
import com.box.l10n.mojito.cli.model.ThirdPartySync;
+import jakarta.annotation.PostConstruct;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@@ -119,11 +120,16 @@ public class ThirdPartySyncCommand extends Command {
description = "Options to synchronize")
List options;
- @Autowired ThirdPartyWsApi thirdPartyClient;
-
@Autowired CommandHelper commandHelper;
- @Autowired RepositoryWsApiHelper repositoryWsApiHelper;
+ @Autowired ApiClient apiClient;
+
+ ThirdPartyWsApi thirdPartyClient;
+
+ @PostConstruct
+ public void init() {
+ this.thirdPartyClient = new ThirdPartyWsApi(this.apiClient);
+ }
private ThirdPartySync getThirdPartySync(RepositoryRepository repository) {
ThirdPartySync thirdPartySyncBody = new ThirdPartySync();
@@ -189,13 +195,12 @@ public void execute() throws CommandException {
.a(Objects.toString(options))
.println(2);
- RepositoryRepository repository =
- this.repositoryWsApiHelper.findRepositoryByName(repositoryParam);
+ try {
+ RepositoryRepository repository = this.commandHelper.findRepositoryByName(repositoryParam);
- ThirdPartySync thirdPartySyncBody = getThirdPartySync(repository);
+ ThirdPartySync thirdPartySyncBody = getThirdPartySync(repository);
- try {
- PollableTask pollableTask = thirdPartyClient.sync(thirdPartySyncBody);
+ PollableTask pollableTask = this.thirdPartyClient.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..39cfd3b091 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;
@@ -7,14 +8,22 @@
import com.box.l10n.mojito.cli.model.PageUser;
import com.box.l10n.mojito.cli.model.Pageable;
import com.box.l10n.mojito.cli.model.User;
-import com.box.l10n.mojito.rest.entity.Role;
+import com.box.l10n.mojito.cli.models.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();
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..28cddf1e92 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,15 +2,16 @@
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.VirtualAssetWsApi;
import com.box.l10n.mojito.cli.command.param.Param;
import com.box.l10n.mojito.cli.console.ConsoleWriter;
import com.box.l10n.mojito.cli.model.RepositoryRepository;
import com.box.l10n.mojito.cli.model.VirtualAsset;
-import com.box.l10n.mojito.rest.client.HttpClientErrorJson;
+import com.box.l10n.mojito.cli.models.HttpClientErrorJson;
import com.fasterxml.jackson.databind.ObjectMapper;
+import jakarta.annotation.PostConstruct;
import java.io.IOException;
import org.fusesource.jansi.Ansi;
import org.slf4j.Logger;
@@ -48,9 +49,16 @@ public class VirtualAssetCreateCommand extends Command {
description = Param.REPOSITORY_DESCRIPTION)
String pathParam;
- @Autowired VirtualAssetWsApi virtualAssetClient;
+ @Autowired private ApiClient apiClient;
- @Autowired RepositoryWsApiHelper repositoryWsApiHelper;
+ @Autowired CommandHelper commandHelper;
+
+ VirtualAssetWsApi virtualAssetClient;
+
+ @PostConstruct
+ public void init() {
+ this.virtualAssetClient = new VirtualAssetWsApi(this.apiClient);
+ }
private HttpClientErrorJson toHttpClientErrorJson(ApiException ae) {
try {
@@ -74,8 +82,12 @@ public void execute() throws CommandException {
.a(repositoryParam)
.println(2);
- RepositoryRepository repository =
- this.repositoryWsApiHelper.findRepositoryByName(repositoryParam);
+ RepositoryRepository repository;
+ try {
+ repository = this.commandHelper.findRepositoryByName(repositoryParam);
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
VirtualAsset virtualAsset = new VirtualAsset();
virtualAsset.setPath(pathParam);
@@ -84,7 +96,7 @@ public void execute() throws CommandException {
try {
consoleWriter.a(" - Create virtual asset: ").fg(Ansi.Color.CYAN).a(pathParam).println();
- virtualAsset = virtualAssetClient.createOrUpdateVirtualAsset(virtualAsset);
+ virtualAsset = this.virtualAssetClient.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/main/java/com/box/l10n/mojito/cli/models/ErrorMessage.java b/cli/src/main/java/com/box/l10n/mojito/cli/models/ErrorMessage.java
new file mode 100644
index 0000000000..9b0f9dd9fa
--- /dev/null
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/models/ErrorMessage.java
@@ -0,0 +1,32 @@
+package com.box.l10n.mojito.cli.models;
+
+public class ErrorMessage {
+
+ String type;
+ String message;
+ boolean expected;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public boolean isExpected() {
+ return expected;
+ }
+
+ public void setExpected(boolean expected) {
+ this.expected = expected;
+ }
+}
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/models/HttpClientErrorJson.java b/cli/src/main/java/com/box/l10n/mojito/cli/models/HttpClientErrorJson.java
new file mode 100644
index 0000000000..0cbdfa65cc
--- /dev/null
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/models/HttpClientErrorJson.java
@@ -0,0 +1,38 @@
+package com.box.l10n.mojito.cli.models;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+/**
+ * @author jeanaurambault
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class HttpClientErrorJson {
+
+ String status;
+ String message;
+ String exception;
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public String getException() {
+ return exception;
+ }
+
+ public void setException(String exception) {
+ this.exception = exception;
+ }
+}
diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/models/Role.java b/cli/src/main/java/com/box/l10n/mojito/cli/models/Role.java
new file mode 100644
index 0000000000..b58d154e9b
--- /dev/null
+++ b/cli/src/main/java/com/box/l10n/mojito/cli/models/Role.java
@@ -0,0 +1,19 @@
+package com.box.l10n.mojito.cli.models;
+
+public enum Role {
+ ROLE_PM,
+ ROLE_TRANSLATOR,
+ ROLE_ADMIN,
+ ROLE_USER;
+
+ public static Role fromString(String roleName) {
+ if (roleName == null || roleName.isBlank()) {
+ return null;
+ }
+
+ if (!roleName.startsWith("ROLE_")) {
+ roleName = "ROLE_" + roleName;
+ }
+ return Role.valueOf(roleName);
+ }
+}
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..a3fd7e2256 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,13 +1,11 @@
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;
import com.box.l10n.mojito.entity.TMTextUnitVariant;
-import com.box.l10n.mojito.rest.client.RepositoryClient;
-import com.box.l10n.mojito.rest.resttemplate.AuthenticatedRestTemplate;
-import com.box.l10n.mojito.rest.resttemplate.ResttemplateConfig;
import com.box.l10n.mojito.service.asset.AssetRepository;
import com.box.l10n.mojito.service.locale.LocaleService;
import com.box.l10n.mojito.service.repository.RepositoryService;
@@ -17,9 +15,7 @@
import com.box.l10n.mojito.service.tm.search.TextUnitSearcher;
import com.box.l10n.mojito.service.tm.search.TextUnitSearcherParameters;
import com.box.l10n.mojito.test.IOTestBase;
-import com.box.l10n.mojito.xml.XmlParsingConfiguration;
import com.google.common.io.Files;
-import jakarta.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -52,8 +48,6 @@ public class CLITestBase extends IOTestBase {
/** logger */
static Logger logger = LoggerFactory.getLogger(CLITestBase.class);
- @Autowired AuthenticatedRestTemplate authenticatedRestTemplate;
-
@Autowired protected RepositoryService repositoryService;
@Autowired LocaleService localeService;
@@ -62,10 +56,6 @@ public class CLITestBase extends IOTestBase {
@Autowired TMService tmService;
- @Autowired ResttemplateConfig resttemplateConfig;
-
- @Autowired RepositoryClient repositoryClient;
-
@Autowired AssetRepository assetRepository;
@Autowired TextUnitSearcher textUnitSearcher;
@@ -74,21 +64,7 @@ public class CLITestBase extends IOTestBase {
@LocalServerPort int port;
- @PostConstruct
- public void setPort() {
- logger.debug("Saving port number = {}", port);
- resttemplateConfig.setPort(port);
-
- XmlParsingConfiguration.disableXPathLimits();
- }
-
- public void resetHost() {
- resttemplateConfig.setHost("localhost");
- }
-
- public void setNonExistentHost() {
- resttemplateConfig.setHost("nonExistentHostAddress");
- }
+ @Autowired protected ApiClient apiClient;
public L10nJCommander getL10nJCommander() {
L10nJCommander l10nJCommander = new L10nJCommander();
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..efca22c15f 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,10 +9,11 @@
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.RepositoryWsApiProxy;
import com.box.l10n.mojito.cli.model.BranchBranchSummary;
import com.box.l10n.mojito.entity.Repository;
import com.box.l10n.mojito.service.branch.BranchRepository;
+import jakarta.annotation.PostConstruct;
import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.Comparator;
@@ -25,10 +26,15 @@
public class BranchDeleteCommandTest extends CLITestBase {
- @Autowired RepositoryWsApiHelper repositoryClient;
+ RepositoryWsApiProxy repositoryClient;
@Autowired BranchRepository branchRepository;
+ @PostConstruct
+ public void init() {
+ this.repositoryClient = new RepositoryWsApiProxy(this.apiClient);
+ }
+
@Test
public void delete() throws Exception {
Repository repository = createTestRepoUsingRepoService();
diff --git a/cli/src/test/java/com/box/l10n/mojito/cli/command/DropExportCommandTest.java b/cli/src/test/java/com/box/l10n/mojito/cli/command/DropExportCommandTest.java
index 9a64957efd..e4e7998c32 100644
--- a/cli/src/test/java/com/box/l10n/mojito/cli/command/DropExportCommandTest.java
+++ b/cli/src/test/java/com/box/l10n/mojito/cli/command/DropExportCommandTest.java
@@ -3,16 +3,19 @@
import static org.junit.Assert.assertEquals;
import com.box.l10n.mojito.cli.CLITestBase;
+import com.box.l10n.mojito.cli.apiclient.ApiClient;
+import com.box.l10n.mojito.cli.apiclient.ApiException;
+import com.box.l10n.mojito.cli.apiclient.AssetWsApiProxy;
+import com.box.l10n.mojito.cli.apiclient.DropWsApi;
+import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiProxy;
+import com.box.l10n.mojito.cli.model.AssetAssetSummary;
+import com.box.l10n.mojito.cli.model.PageDropDropSummary;
+import com.box.l10n.mojito.cli.model.Pageable;
import com.box.l10n.mojito.entity.Repository;
-import com.box.l10n.mojito.rest.client.AssetClient;
-import com.box.l10n.mojito.rest.client.DropClient;
-import com.box.l10n.mojito.rest.client.RepositoryClient;
-import com.box.l10n.mojito.rest.entity.Asset;
-import com.box.l10n.mojito.rest.entity.Drop;
-import com.box.l10n.mojito.rest.entity.Page;
import com.box.l10n.mojito.service.repository.RepositoryRepository;
import com.box.l10n.mojito.service.tm.TMImportService;
import com.google.common.collect.Sets;
+import jakarta.annotation.PostConstruct;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,12 +26,22 @@ public class DropExportCommandTest extends CLITestBase {
@Autowired TMImportService tmImport;
- @Autowired AssetClient assetClient;
+ AssetWsApiProxy assetClient;
- @Autowired DropClient dropClient;
@Autowired RepositoryRepository repositoryRepository;
- @Autowired RepositoryClient repositoryClient;
+ @Autowired ApiClient apiClient;
+
+ DropWsApi dropClient;
+
+ RepositoryWsApiProxy repositoryClient;
+
+ @PostConstruct
+ public void init() {
+ this.assetClient = new AssetWsApiProxy(this.apiClient);
+ this.dropClient = new DropWsApi(this.apiClient);
+ this.repositoryClient = new RepositoryWsApiProxy(this.apiClient);
+ }
@Test
public void export() throws Exception {
@@ -46,20 +59,27 @@ public void export() throws Exception {
RepositoryStatusChecker repositoryStatusChecker = new RepositoryStatusChecker();
waitForCondition(
"wait for repository stats to show forTranslationCount > 0 before exporting a drop",
- () ->
- repositoryStatusChecker.hasStringsForTranslationsForExportableLocales(
- repositoryClient.getRepositoryById(repository.getId())));
+ () -> {
+ try {
+ return repositoryStatusChecker.hasStringsForTranslationsForExportableLocales(
+ this.repositoryClient.getRepositoryById(repository.getId()));
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
+ });
- Page findAllBefore = dropClient.getDrops(repository.getId(), null, null, null);
+ PageDropDropSummary findAllBefore =
+ dropClient.getDrops(new Pageable(), repository.getId(), null, null);
getL10nJCommander().run("drop-export", "-r", repository.getName());
- Page findAllAfter = dropClient.getDrops(repository.getId(), null, null, null);
+ PageDropDropSummary findAllAfter =
+ dropClient.getDrops(new Pageable(), repository.getId(), null, null);
assertEquals(
"A Drop must have been added",
findAllBefore.getTotalElements() + 1,
- findAllAfter.getTotalElements());
+ (long) findAllAfter.getTotalElements());
}
@Test
@@ -75,7 +95,7 @@ public void exportFullyTranslated() throws Exception {
"-s",
getInputResourcesTestDir("source").getAbsolutePath());
- Asset asset =
+ AssetAssetSummary asset =
assetClient.getAssetByPathAndRepositoryId("source-xliff.xliff", repository.getId());
importTranslations(asset.getId(), "source-xliff_", "fr-FR");
importTranslations(asset.getId(), "source-xliff_", "ja-JP");
@@ -97,11 +117,13 @@ public void exportFullyTranslated() throws Exception {
.orElse(false);
});
- Page findAllBefore = dropClient.getDrops(repository.getId(), null, null, null);
+ PageDropDropSummary findAllBefore =
+ dropClient.getDrops(new Pageable(), repository.getId(), null, null);
getL10nJCommander().run("drop-export", "-r", repository.getName());
- Page findAllAfter = dropClient.getDrops(repository.getId(), null, null, null);
+ PageDropDropSummary findAllAfter =
+ dropClient.getDrops(new Pageable(), repository.getId(), null, null);
assertEquals(
"A Drop should not have been added",
@@ -122,17 +144,18 @@ public void exportReviewWithInheritance() throws Exception {
"-s",
getInputResourcesTestDir("source").getAbsolutePath());
- Asset asset =
+ AssetAssetSummary asset =
assetClient.getAssetByPathAndRepositoryId("source-xliff.xliff", repository.getId());
importTranslations(asset.getId(), "source-xliff_", "fr-FR");
importTranslations(asset.getId(), "source-xliff_", "ja-JP");
- Asset asset2 =
+ AssetAssetSummary asset2 =
assetClient.getAssetByPathAndRepositoryId("source2-xliff.xliff", repository.getId());
importTranslations(asset2.getId(), "source2-xliff_", "fr-FR");
importTranslations(asset2.getId(), "source2-xliff_", "ja-JP");
- Page findAllBefore = dropClient.getDrops(repository.getId(), null, null, null);
+ PageDropDropSummary findAllBefore =
+ dropClient.getDrops(new Pageable(), repository.getId(), null, null);
getL10nJCommander()
.run(
@@ -147,11 +170,12 @@ public void exportReviewWithInheritance() throws Exception {
"--use-inheritance"
});
- Page findAllAfter = dropClient.getDrops(repository.getId(), null, null, null);
+ PageDropDropSummary findAllAfter =
+ dropClient.getDrops(new Pageable(), repository.getId(), null, null);
assertEquals(
"A Drop must have been added",
findAllBefore.getTotalElements() + 1,
- findAllAfter.getTotalElements());
+ (long) findAllAfter.getTotalElements());
}
}
diff --git a/cli/src/test/java/com/box/l10n/mojito/cli/command/DropImportCommandTest.java b/cli/src/test/java/com/box/l10n/mojito/cli/command/DropImportCommandTest.java
index 4e5d12c84f..feb5b2754d 100644
--- a/cli/src/test/java/com/box/l10n/mojito/cli/command/DropImportCommandTest.java
+++ b/cli/src/test/java/com/box/l10n/mojito/cli/command/DropImportCommandTest.java
@@ -11,12 +11,14 @@
import com.box.l10n.mojito.boxsdk.BoxSDKService;
import com.box.l10n.mojito.boxsdk.BoxSDKServiceException;
import com.box.l10n.mojito.cli.CLITestBase;
+import com.box.l10n.mojito.cli.apiclient.ApiClient;
+import com.box.l10n.mojito.cli.apiclient.ApiException;
+import com.box.l10n.mojito.cli.apiclient.AssetWsApiProxy;
+import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiProxy;
import com.box.l10n.mojito.cli.console.Console;
+import com.box.l10n.mojito.cli.model.AssetAssetSummary;
import com.box.l10n.mojito.entity.Drop;
import com.box.l10n.mojito.entity.Repository;
-import com.box.l10n.mojito.rest.client.AssetClient;
-import com.box.l10n.mojito.rest.client.RepositoryClient;
-import com.box.l10n.mojito.rest.entity.Asset;
import com.box.l10n.mojito.service.drop.DropRepository;
import com.box.l10n.mojito.service.drop.DropService;
import com.box.l10n.mojito.service.drop.exporter.DropExporterException;
@@ -28,6 +30,7 @@
import com.box.l10n.mojito.service.tm.TMTextUnitCurrentVariantRepository;
import com.box.l10n.mojito.test.XliffUtils;
import com.google.common.io.Files;
+import jakarta.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -53,8 +56,6 @@ public class DropImportCommandTest extends CLITestBase {
@Autowired TMImportService tmImport;
- @Autowired AssetClient assetClient;
-
@Autowired TMTextUnitCurrentVariantRepository textUnitCurrentVariantRepository;
@Autowired LocaleService localeService;
@@ -67,7 +68,17 @@ public class DropImportCommandTest extends CLITestBase {
@Autowired DropRepository dropRepository;
- @Autowired private RepositoryClient repositoryClient;
+ @Autowired ApiClient apiClient;
+
+ RepositoryWsApiProxy repositoryClient;
+
+ AssetWsApiProxy assetClient;
+
+ @PostConstruct
+ public void init() {
+ this.repositoryClient = new RepositoryWsApiProxy(this.apiClient);
+ this.assetClient = new AssetWsApiProxy(this.apiClient);
+ }
@Test
public void dropImport() throws Exception {
@@ -82,12 +93,12 @@ public void dropImport() throws Exception {
"-s",
getInputResourcesTestDir("source").getAbsolutePath());
- Asset asset =
+ AssetAssetSummary asset =
assetClient.getAssetByPathAndRepositoryId("source-xliff.xliff", repository.getId());
importTranslations(asset.getId(), "source-xliff_", "fr-FR");
importTranslations(asset.getId(), "source-xliff_", "ja-JP");
- Asset asset2 =
+ AssetAssetSummary asset2 =
assetClient.getAssetByPathAndRepositoryId("source2-xliff.xliff", repository.getId());
importTranslations(asset2.getId(), "source2-xliff_", "fr-FR");
importTranslations(asset2.getId(), "source2-xliff_", "ja-JP");
@@ -95,9 +106,14 @@ public void dropImport() throws Exception {
RepositoryStatusChecker repositoryStatusChecker = new RepositoryStatusChecker();
waitForCondition(
"wait for repository stats to show forTranslationCount > 0 before exporting a drop",
- () ->
- repositoryStatusChecker.hasStringsForTranslationsForExportableLocales(
- repositoryClient.getRepositoryById(repository.getId())));
+ () -> {
+ try {
+ return repositoryStatusChecker.hasStringsForTranslationsForExportableLocales(
+ repositoryClient.getRepositoryById(repository.getId()));
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
+ });
getL10nJCommander().run("drop-export", "-r", repository.getName());
@@ -161,12 +177,12 @@ public void importFetched() throws Exception {
"-s",
getInputResourcesTestDir("source").getAbsolutePath());
- Asset asset =
+ AssetAssetSummary asset =
assetClient.getAssetByPathAndRepositoryId("source-xliff.xliff", repository.getId());
importTranslations(asset.getId(), "source-xliff_", "fr-FR");
importTranslations(asset.getId(), "source-xliff_", "ja-JP");
- Asset asset2 =
+ AssetAssetSummary asset2 =
assetClient.getAssetByPathAndRepositoryId("source2-xliff.xliff", repository.getId());
importTranslations(asset2.getId(), "source2-xliff_", "fr-FR");
importTranslations(asset2.getId(), "source2-xliff_", "ja-JP");
@@ -174,9 +190,14 @@ public void importFetched() throws Exception {
RepositoryStatusChecker repositoryStatusChecker = new RepositoryStatusChecker();
waitForCondition(
"wait for repository stats to show forTranslationCount > 0 before exporting a drop",
- () ->
- repositoryStatusChecker.hasStringsForTranslationsForExportableLocales(
- repositoryClient.getRepositoryById(repository.getId())));
+ () -> {
+ try {
+ return repositoryStatusChecker.hasStringsForTranslationsForExportableLocales(
+ repositoryClient.getRepositoryById(repository.getId()));
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
+ });
getL10nJCommander().run("drop-export", "-r", repository.getName());
diff --git a/cli/src/test/java/com/box/l10n/mojito/cli/command/DropXliffImportCommandTest.java b/cli/src/test/java/com/box/l10n/mojito/cli/command/DropXliffImportCommandTest.java
index 777461d90a..948e08eb38 100644
--- a/cli/src/test/java/com/box/l10n/mojito/cli/command/DropXliffImportCommandTest.java
+++ b/cli/src/test/java/com/box/l10n/mojito/cli/command/DropXliffImportCommandTest.java
@@ -5,11 +5,13 @@
import com.box.l10n.mojito.boxsdk.BoxSDKService;
import com.box.l10n.mojito.boxsdk.BoxSDKServiceException;
import com.box.l10n.mojito.cli.CLITestBase;
+import com.box.l10n.mojito.cli.apiclient.ApiClient;
+import com.box.l10n.mojito.cli.apiclient.ApiException;
+import com.box.l10n.mojito.cli.apiclient.AssetWsApiProxy;
+import com.box.l10n.mojito.cli.apiclient.RepositoryWsApiProxy;
+import com.box.l10n.mojito.cli.model.AssetAssetSummary;
import com.box.l10n.mojito.entity.Drop;
import com.box.l10n.mojito.entity.Repository;
-import com.box.l10n.mojito.rest.client.AssetClient;
-import com.box.l10n.mojito.rest.client.RepositoryClient;
-import com.box.l10n.mojito.rest.entity.Asset;
import com.box.l10n.mojito.service.drop.DropRepository;
import com.box.l10n.mojito.service.drop.DropService;
import com.box.l10n.mojito.service.drop.exporter.DropExporterException;
@@ -21,6 +23,7 @@
import com.box.l10n.mojito.service.tm.TMTextUnitCurrentVariantRepository;
import com.box.l10n.mojito.test.XliffUtils;
import com.google.common.io.Files;
+import jakarta.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -42,7 +45,7 @@ public class DropXliffImportCommandTest extends CLITestBase {
@Autowired TMImportService tmImport;
- @Autowired AssetClient assetClient;
+ AssetWsApiProxy assetClient;
@Autowired TMTextUnitCurrentVariantRepository textUnitCurrentVariantRepository;
@@ -58,7 +61,15 @@ public class DropXliffImportCommandTest extends CLITestBase {
@Autowired DropImportCommand dropImportCommand;
- @Autowired RepositoryClient repositoryClient;
+ @Autowired ApiClient apiClient;
+
+ RepositoryWsApiProxy repositoryClient;
+
+ @PostConstruct
+ public void init() {
+ this.assetClient = new AssetWsApiProxy(this.apiClient);
+ this.repositoryClient = new RepositoryWsApiProxy(this.apiClient);
+ }
@Test
public void dropXliffImport() throws Exception {
@@ -73,12 +84,12 @@ public void dropXliffImport() throws Exception {
"-s",
getInputResourcesTestDir("source").getAbsolutePath());
- Asset asset =
+ AssetAssetSummary asset =
assetClient.getAssetByPathAndRepositoryId("source-xliff.xliff", repository.getId());
importTranslations(asset.getId(), "source-xliff_", "fr-FR");
importTranslations(asset.getId(), "source-xliff_", "ja-JP");
- Asset asset2 =
+ AssetAssetSummary asset2 =
assetClient.getAssetByPathAndRepositoryId("source2-xliff.xliff", repository.getId());
importTranslations(asset2.getId(), "source2-xliff_", "fr-FR");
importTranslations(asset2.getId(), "source2-xliff_", "ja-JP");
@@ -86,9 +97,14 @@ public void dropXliffImport() throws Exception {
RepositoryStatusChecker repositoryStatusChecker = new RepositoryStatusChecker();
waitForCondition(
"wait for repository stats to show forTranslationCount > 0 before exporting a drop",
- () ->
- repositoryStatusChecker.hasStringsForTranslationsForExportableLocales(
- repositoryClient.getRepositoryById(repository.getId())));
+ () -> {
+ try {
+ return repositoryStatusChecker.hasStringsForTranslationsForExportableLocales(
+ this.repositoryClient.getRepositoryById(repository.getId()));
+ } catch (ApiException e) {
+ throw new CommandException(e.getMessage(), e);
+ }
+ });
getL10nJCommander().run("drop-export", "-r", repository.getName());
diff --git a/cli/src/test/java/com/box/l10n/mojito/cli/command/EvolveCommandTest.java b/cli/src/test/java/com/box/l10n/mojito/cli/command/EvolveCommandTest.java
index e6fbe889cd..6003db567c 100644
--- a/cli/src/test/java/com/box/l10n/mojito/cli/command/EvolveCommandTest.java
+++ b/cli/src/test/java/com/box/l10n/mojito/cli/command/EvolveCommandTest.java
@@ -1,10 +1,11 @@
package com.box.l10n.mojito.cli.command;
import com.box.l10n.mojito.cli.CLITestBase;
+import com.box.l10n.mojito.cli.model.LocaleRepository;
+import com.box.l10n.mojito.cli.model.RepositoryRepository;
import com.box.l10n.mojito.entity.Repository;
import com.box.l10n.mojito.evolve.Course;
import com.box.l10n.mojito.evolve.Evolve;
-import com.box.l10n.mojito.rest.entity.Locale;
import org.junit.Assume;
import org.junit.Test;
import org.slf4j.Logger;
@@ -30,14 +31,13 @@ public void writeJsonTo() {
EvolveCommand evolveCommand = new EvolveCommand();
evolveCommand.writeJsonTo = getTargetTestDir().toString();
- com.box.l10n.mojito.rest.entity.Repository repository =
- new com.box.l10n.mojito.rest.entity.Repository();
+ RepositoryRepository repository = new RepositoryRepository();
repository.setName("evolveRepository");
Course course = new Course();
course.setId("course1");
- Locale locale = new Locale();
+ LocaleRepository locale = new LocaleRepository();
locale.setBcp47Tag("fr-FR");
evolveCommand.writeJsonToFile(repository, course, locale, "{\"key\" : \"value\"}");
diff --git a/cli/src/test/java/com/box/l10n/mojito/cli/command/ExtractionCheckCommandTest.java b/cli/src/test/java/com/box/l10n/mojito/cli/command/ExtractionCheckCommandTest.java
index d33067d637..6ad433b072 100644
--- a/cli/src/test/java/com/box/l10n/mojito/cli/command/ExtractionCheckCommandTest.java
+++ b/cli/src/test/java/com/box/l10n/mojito/cli/command/ExtractionCheckCommandTest.java
@@ -1,6 +1,11 @@
package com.box.l10n.mojito.cli.command;
import static com.box.l10n.mojito.cli.command.checks.AbstractCliChecker.BULLET_POINT;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
@@ -8,10 +13,12 @@
import static org.mockito.Mockito.when;
import com.box.l10n.mojito.cli.CLITestBase;
+import com.box.l10n.mojito.cli.apiclient.ApiClient;
+import com.box.l10n.mojito.cli.apiclient.ApiException;
import com.box.l10n.mojito.cli.command.checks.CliCheckResult;
import com.box.l10n.mojito.cli.console.ConsoleWriter;
-import com.box.l10n.mojito.rest.resttemplate.AuthenticatedRestTemplate;
import com.google.common.collect.Lists;
+import com.squareup.okhttp.Call;
import java.util.List;
import org.fusesource.jansi.Ansi;
import org.junit.Assert;
@@ -580,7 +587,7 @@ public void runHardFailChecksWithInvalidCheckName() throws Exception {
/**
* this is a functional test for the {@link
- * com.box.l10n.mojito.cli.command.checks.AbstractCliChecker#getAddedTextUnitsExcludingInconsistentComments(List)}
+ * com.box.l10n.mojito.cli.command.checks.AbstractCliChecker#getAddedTextUnitsExcludingInconsistentComments(java.util.List)}
*
* If combination source+context is added again with a different comment we run the check and
* eventually reject it if it is not valid
@@ -787,62 +794,143 @@ public void testChecksSkippedIfSkipChecksEnabled() {
}
@Test
- public void testStatsAreReportedIfUrlTemplateSet() {
+ public void testStatsAreReportedIfUrlTemplateSet() throws ApiException {
ConsoleWriter consoleWriter = Mockito.mock(ConsoleWriter.class);
- AuthenticatedRestTemplate restTemplateMock = Mockito.mock(AuthenticatedRestTemplate.class);
+ ApiClient apiClientMock = Mockito.mock(ApiClient.class);
+ Call callMock = Mockito.mock(Call.class);
+ when(apiClientMock.buildCall(
+ anyString(),
+ anyString(),
+ anyList(),
+ anyList(),
+ any(),
+ anyMap(),
+ anyMap(),
+ any(),
+ any()))
+ .thenReturn(callMock);
when(consoleWriter.fg(isA(Ansi.Color.class))).thenReturn(consoleWriter);
when(consoleWriter.newLine()).thenReturn(consoleWriter);
when(consoleWriter.a(isA(String.class))).thenReturn(consoleWriter);
ExtractionCheckCommand extractionCheckCommand = new ExtractionCheckCommand();
extractionCheckCommand.consoleWriter = consoleWriter;
- extractionCheckCommand.restTemplate = restTemplateMock;
+ extractionCheckCommand.apiClient = apiClientMock;
extractionCheckCommand.statsUrlTemplate =
"http://someUrl.com/my_test_stat_{check_name}_{outcome}?value=1";
CliCheckResult success = new CliCheckResult(true, false, "testCheck1");
CliCheckResult failure = new CliCheckResult(false, false, "testCheck2");
extractionCheckCommand.reportStatistics(Lists.newArrayList(success, failure));
- verify(restTemplateMock, times(1))
- .put("http://someUrl.com/my_test_stat_testCheck1_success?value=1", null);
- verify(restTemplateMock, times(1))
- .put("http://someUrl.com/my_test_stat_testCheck2_failure?value=1", null);
+ verify(apiClientMock, times(1))
+ .buildCall(
+ eq("http://someUrl.com/my_test_stat_testCheck1_success?value=1"),
+ eq("PUT"),
+ anyList(),
+ anyList(),
+ any(),
+ anyMap(),
+ anyMap(),
+ any(),
+ any());
+ verify(apiClientMock, times(1))
+ .buildCall(
+ eq("http://someUrl.com/my_test_stat_testCheck2_failure?value=1"),
+ eq("PUT"),
+ anyList(),
+ anyList(),
+ any(),
+ anyMap(),
+ anyMap(),
+ any(),
+ any());
}
@Test
- public void testStatsAreNotReportedIfUrlTemplateIsNull() {
+ public void testStatsAreNotReportedIfUrlTemplateIsNull() throws ApiException {
ConsoleWriter consoleWriter = Mockito.mock(ConsoleWriter.class);
- AuthenticatedRestTemplate restTemplateMock = Mockito.mock(AuthenticatedRestTemplate.class);
+ ApiClient apiClientMock = Mockito.mock(ApiClient.class);
+ Call callMock = Mockito.mock(Call.class);
+ when(apiClientMock.buildCall(
+ anyString(),
+ anyString(),
+ anyList(),
+ anyList(),
+ any(),
+ anyMap(),
+ anyMap(),
+ any(),
+ any()))
+ .thenReturn(callMock);
when(consoleWriter.fg(isA(Ansi.Color.class))).thenReturn(consoleWriter);
when(consoleWriter.newLine()).thenReturn(consoleWriter);
when(consoleWriter.a(isA(String.class))).thenReturn(consoleWriter);
ExtractionCheckCommand extractionCheckCommand = new ExtractionCheckCommand();
extractionCheckCommand.consoleWriter = consoleWriter;
- extractionCheckCommand.restTemplate = restTemplateMock;
+ extractionCheckCommand.apiClient = apiClientMock;
extractionCheckCommand.statsUrlTemplate = null;
CliCheckResult success = new CliCheckResult(true, false, "testCheck1");
CliCheckResult failure = new CliCheckResult(false, false, "testCheck2");
extractionCheckCommand.reportStatistics(Lists.newArrayList(success, failure));
- verify(restTemplateMock, times(0))
- .put("http://someUrl.com/my_test_stat_testCheck1_success?value=1", null);
- verify(restTemplateMock, times(0))
- .put("http://someUrl.com/my_test_stat_testCheck2_failure?value=1", null);
+ verify(apiClientMock, times(0))
+ .buildCall(
+ eq("http://someUrl.com/my_test_stat_testCheck1_success?value=1"),
+ eq("PUT"),
+ anyList(),
+ anyList(),
+ any(),
+ anyMap(),
+ anyMap(),
+ any(),
+ any());
+ verify(apiClientMock, times(0))
+ .buildCall(
+ eq("http://someUrl.com/my_test_stat_testCheck2_failure?value=1"),
+ eq("PUT"),
+ anyList(),
+ anyList(),
+ any(),
+ anyMap(),
+ anyMap(),
+ any(),
+ any());
}
@Test
- public void testErrorReportingStatistics() {
+ public void testErrorReportingStatistics() throws ApiException {
ConsoleWriter consoleWriter = Mockito.mock(ConsoleWriter.class);
- AuthenticatedRestTemplate restTemplateMock = Mockito.mock(AuthenticatedRestTemplate.class);
+ ApiClient apiClientMock = Mockito.mock(ApiClient.class);
+ Call callMock = Mockito.mock(Call.class);
+ when(apiClientMock.buildCall(
+ anyString(),
+ anyString(),
+ anyList(),
+ anyList(),
+ any(),
+ anyMap(),
+ anyMap(),
+ any(),
+ any()))
+ .thenReturn(callMock);
when(consoleWriter.fg(isA(Ansi.Color.class))).thenReturn(consoleWriter);
when(consoleWriter.newLine()).thenReturn(consoleWriter);
when(consoleWriter.a(isA(String.class))).thenReturn(consoleWriter);
doThrow(new RestClientException("test exception"))
- .when(restTemplateMock)
- .put("http://someUrl.com/my_test_stat_testCheck1_success?value=1", null);
+ .when(apiClientMock)
+ .buildCall(
+ eq("http://someUrl.com/my_test_stat_testCheck1_success?value=1"),
+ eq("PUT"),
+ anyList(),
+ anyList(),
+ any(),
+ anyMap(),
+ anyMap(),
+ any(),
+ any());
ExtractionCheckCommand extractionCheckCommand = new ExtractionCheckCommand();
extractionCheckCommand.consoleWriter = consoleWriter;
- extractionCheckCommand.restTemplate = restTemplateMock;
+ extractionCheckCommand.apiClient = apiClientMock;
extractionCheckCommand.statsUrlTemplate =
"http://someUrl.com/my_test_stat_{check_name}_{outcome}?value=1";
CliCheckResult success = new CliCheckResult(true, false, "testCheck1");
diff --git a/cli/src/test/java/com/box/l10n/mojito/cli/command/ExtractionDiffCommandTest.java b/cli/src/test/java/com/box/l10n/mojito/cli/command/ExtractionDiffCommandTest.java
index ebfacc78e4..9288687f50 100644
--- a/cli/src/test/java/com/box/l10n/mojito/cli/command/ExtractionDiffCommandTest.java
+++ b/cli/src/test/java/com/box/l10n/mojito/cli/command/ExtractionDiffCommandTest.java
@@ -7,6 +7,7 @@
import static org.mockito.Mockito.verify;
import com.box.l10n.mojito.cli.CLITestBase;
+import com.box.l10n.mojito.cli.apiclient.ApiClient;
import com.box.l10n.mojito.cli.command.utils.SlackNotificationSender;
import com.box.l10n.mojito.entity.Repository;
import com.box.l10n.mojito.service.tm.search.TextUnitDTO;
@@ -35,9 +36,11 @@ public class ExtractionDiffCommandTest extends CLITestBase {
@Autowired TextUnitSearcher textUnitSearcher;
+ @Autowired ApiClient apiClient;
+
@Before
public void init() {
- resetHost();
+ this.apiClient.setBasePath("http://localhost:8080");
}
@Test
@@ -324,7 +327,7 @@ public void noDiffChangesNoDatabaseCalls() throws Exception {
"-fo",
"sometestoption=value1");
- setNonExistentHost();
+ this.apiClient.setBasePath("http://nonExistentHostAddress:8080");
L10nJCommander l10nJCommander = getL10nJCommander();
l10nJCommander.run(
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