forked from box/mojito
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
Refactor other commands
- Loading branch information
Showing
105 changed files
with
2,945 additions
and
7,932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,4 @@ release.properties | |
/tmp/ | ||
/local/ | ||
.vscode/ | ||
/webapp/src/main/resources/openapi.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AiChecksWsApiProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.box.l10n.mojito.cli.apiclient; | ||
|
||
import com.box.l10n.mojito.cli.model.AICheckRequest; | ||
import com.box.l10n.mojito.cli.model.AICheckResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class AiChecksWsApiProxy extends AiChecksWsApi { | ||
/** logger */ | ||
static Logger logger = LoggerFactory.getLogger(AiChecksWsApiProxy.class); | ||
|
||
public AiChecksWsApiProxy(ApiClient apiClient) { | ||
super(apiClient); | ||
} | ||
|
||
@Override | ||
public AICheckResponse executeAIChecks(AICheckRequest body) throws ApiException { | ||
logger.debug("Received request to execute AI checks"); | ||
return super.executeAIChecks(body); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AiPromptWsApiProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.box.l10n.mojito.cli.apiclient; | ||
|
||
import com.box.l10n.mojito.cli.model.AIPromptContextMessageCreateRequest; | ||
import com.box.l10n.mojito.cli.model.AIPromptCreateRequest; | ||
import com.box.l10n.mojito.cli.model.AITranslationLocalePromptOverridesRequest; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class AiPromptWsApiProxy extends AiPromptWsApi { | ||
/** logger */ | ||
static Logger logger = LoggerFactory.getLogger(AssetWsApiProxy.class); | ||
|
||
public AiPromptWsApiProxy(ApiClient apiClient) { | ||
super(apiClient); | ||
} | ||
|
||
@Override | ||
public String deleteRepositoryLocalePromptOverrides( | ||
AITranslationLocalePromptOverridesRequest body) throws ApiException { | ||
logger.debug("Received request to delete repository locale prompt overrides"); | ||
return super.deleteRepositoryLocalePromptOverrides(body); | ||
} | ||
|
||
@Override | ||
public String createOrUpdateRepositoryLocalePromptOverrides( | ||
AITranslationLocalePromptOverridesRequest body) throws ApiException { | ||
logger.debug("Received request to create or update repository locale prompt overrides"); | ||
return super.createOrUpdateRepositoryLocalePromptOverrides(body); | ||
} | ||
|
||
@Override | ||
public void addPromptToRepository(Long promptId, String repositoryName, String promptType) | ||
throws ApiException { | ||
logger.debug("Received request to add prompt id {} to {} repository", promptId, repositoryName); | ||
super.addPromptToRepository(promptId, repositoryName, promptType); | ||
} | ||
|
||
@Override | ||
public Long createPrompt(AIPromptCreateRequest body) throws ApiException { | ||
logger.debug("Received request to create prompt"); | ||
return super.createPrompt(body); | ||
} | ||
|
||
@Override | ||
public Long createPromptMessage(AIPromptContextMessageCreateRequest body) throws ApiException { | ||
logger.debug("Received request to create prompt context message"); | ||
return super.createPromptMessage(body); | ||
} | ||
|
||
@Override | ||
public void deletePrompt(Long promptId) throws ApiException { | ||
logger.debug("Received request to delete prompt id {}", promptId); | ||
super.deletePrompt(promptId); | ||
} | ||
|
||
@Override | ||
public void deletePromptMessage(Long contextMessageId) throws ApiException { | ||
logger.debug("Received request to delete prompt message id {}", contextMessageId); | ||
super.deletePromptMessage(contextMessageId); | ||
} | ||
} |
32 changes: 0 additions & 32 deletions
32
cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AssetWsApiHelper.java
This file was deleted.
Oops, something went wrong.
109 changes: 109 additions & 0 deletions
109
cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AssetWsApiProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package com.box.l10n.mojito.cli.apiclient; | ||
|
||
import com.box.l10n.mojito.cli.command.CommandException; | ||
import com.box.l10n.mojito.cli.model.AssetAssetSummary; | ||
import com.box.l10n.mojito.cli.model.ImportLocalizedAssetBody; | ||
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.XliffExportBody; | ||
import java.util.List; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.util.Assert; | ||
|
||
public class AssetWsApiProxy extends AssetWsApi { | ||
|
||
/** logger */ | ||
static Logger logger = LoggerFactory.getLogger(AssetWsApiProxy.class); | ||
|
||
public static final String OUTPUT_BCP47_TAG = "en-x-pseudo"; | ||
|
||
public AssetWsApiProxy(ApiClient apiClient) { | ||
super(apiClient); | ||
} | ||
|
||
public AssetAssetSummary getAssetByPathAndRepositoryId(String path, Long repositoryId) | ||
throws CommandException, ApiException { | ||
Assert.notNull(path, "path must not be null"); | ||
Assert.notNull(repositoryId, "repository must not be null"); | ||
|
||
List<AssetAssetSummary> assets = this.getAssets(repositoryId, path, null, null, null); | ||
if (!assets.isEmpty()) { | ||
return assets.getFirst(); | ||
} else { | ||
throw new CommandException( | ||
"Could not find asset with path = [" + path + "] at repo id [" + repositoryId + "]"); | ||
} | ||
} | ||
|
||
@Override | ||
public LocalizedAssetBody getLocalizedAssetForContent( | ||
LocalizedAssetBody body, Long assetId, Long localeId) throws ApiException { | ||
logger.debug( | ||
"Getting localized asset with asset id = {}, locale id = {}, outputBcp47tag: {}", | ||
assetId, | ||
localeId, | ||
body.getOutputBcp47tag()); | ||
return super.getLocalizedAssetForContent(body, assetId, localeId); | ||
} | ||
|
||
@Override | ||
public ImportLocalizedAssetBody importLocalizedAsset( | ||
ImportLocalizedAssetBody body, Long assetId, Long localeId) throws ApiException { | ||
logger.debug("Import localized asset with asset id = {}, locale id = {}", assetId, localeId); | ||
return super.importLocalizedAsset(body, assetId, localeId); | ||
} | ||
|
||
@Override | ||
public PollableTask getLocalizedAssetForContentParallel( | ||
MultiLocalizedAssetBody body, Long assetId) throws ApiException { | ||
logger.debug("Getting localized assets with asset id = {}", assetId); | ||
return super.getLocalizedAssetForContentParallel(body, assetId); | ||
} | ||
|
||
@Override | ||
public PollableTask getLocalizedAssetForContentAsync(LocalizedAssetBody body, Long assetId) | ||
throws ApiException { | ||
logger.debug( | ||
"Getting localized asset with asset id = {}, locale id = {}, outputBcp47tag: {}", | ||
assetId, | ||
body.getLocaleId(), | ||
body.getOutputBcp47tag()); | ||
return super.getLocalizedAssetForContentAsync(body, assetId); | ||
} | ||
|
||
@Override | ||
public List<Long> getAssetIds(Long repositoryId, Boolean deleted, Boolean virtual, Long branchId) | ||
throws ApiException { | ||
Assert.notNull(repositoryId, "The repositoryId must not be null"); | ||
return super.getAssetIds(repositoryId, deleted, virtual, branchId); | ||
} | ||
|
||
@Override | ||
public PollableTask deleteAssetsOfBranches(List<Long> body, Long branchId) throws ApiException { | ||
logger.debug("Deleting assets by asset ids = {} or branch id: {}", body.toString(), branchId); | ||
return super.deleteAssetsOfBranches(body, branchId); | ||
} | ||
|
||
@Override | ||
public List<AssetAssetSummary> getAssets( | ||
Long repositoryId, String path, Boolean deleted, Boolean virtual, Long branchId) | ||
throws ApiException { | ||
logger.debug("Get assets by path = {} repo id = {} deleted = {}", path, repositoryId, deleted); | ||
return super.getAssets(repositoryId, path, deleted, virtual, branchId); | ||
} | ||
|
||
@Override | ||
public XliffExportBody xliffExportAsync(XliffExportBody body, String bcp47tag, Long assetId) | ||
throws ApiException { | ||
logger.debug("Export asset id: {} for locale: {}", assetId, bcp47tag); | ||
return super.xliffExportAsync(body, bcp47tag, assetId); | ||
} | ||
|
||
@Override | ||
public XliffExportBody xliffExport(Long assetId, Long tmXliffId) throws ApiException { | ||
logger.debug("Get exported xliff for asset id: {} for tm xliff id: {}", assetId, tmXliffId); | ||
return super.xliffExport(assetId, tmXliffId); | ||
} | ||
} |
21 changes: 2 additions & 19 deletions
21
cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AuthenticatedApiClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,18 @@ | ||
package com.box.l10n.mojito.cli.apiclient; | ||
|
||
import com.squareup.okhttp.OkHttpClient; | ||
import jakarta.annotation.PostConstruct; | ||
import java.net.CookieHandler; | ||
import java.net.CookieManager; | ||
import java.net.CookiePolicy; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class AuthenticatedApiClient extends ApiClient { | ||
|
||
private CookieManager cookieManager; | ||
|
||
@PostConstruct | ||
public void init() { | ||
this.cookieManager = this.getCookieManager(); | ||
public AuthenticatedApiClient() { | ||
this.setHttpClient(this.getOkHttpClient()); | ||
} | ||
|
||
private CookieManager getCookieManager() { | ||
CookieManager cookieManager = new CookieManager(); | ||
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER); | ||
CookieHandler.setDefault(cookieManager); | ||
return cookieManager; | ||
} | ||
|
||
private OkHttpClient getOkHttpClient() { | ||
OkHttpClient httpClient = new OkHttpClient(); | ||
httpClient | ||
.interceptors() | ||
.add(new AuthenticatedApiInterceptor(this.cookieManager, this.getBasePath())); | ||
httpClient.interceptors().add(new AuthenticatedApiInterceptor(this.getBasePath())); | ||
return httpClient; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
cli/src/main/java/com/box/l10n/mojito/cli/apiclient/ImageWsApiProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.box.l10n.mojito.cli.apiclient; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ImageWsApiProxy extends ImageWsApi { | ||
/** logger */ | ||
static Logger logger = LoggerFactory.getLogger(ImageWsApiProxy.class); | ||
|
||
public ImageWsApiProxy(ApiClient apiClient) { | ||
super(apiClient); | ||
} | ||
|
||
@Override | ||
public void uploadImage(byte[] body, String imageName) throws ApiException { | ||
logger.debug("Upload image with name = {}", imageName); | ||
super.uploadImage(body, imageName); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
cli/src/main/java/com/box/l10n/mojito/cli/apiclient/LocaleWsApiProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.box.l10n.mojito.cli.apiclient; | ||
|
||
import com.box.l10n.mojito.cli.command.CommandException; | ||
import com.box.l10n.mojito.cli.model.Locale; | ||
import java.util.List; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class LocaleWsApiProxy extends LocaleWsApi { | ||
/** logger */ | ||
static Logger logger = LoggerFactory.getLogger(LocaleWsApiProxy.class); | ||
|
||
public LocaleWsApiProxy(ApiClient apiClient) { | ||
super(apiClient); | ||
} | ||
|
||
public Locale getLocaleByBcp47Tag(String bcp47Tag) throws ApiException { | ||
logger.debug("Getting locale for BCP47 tag: {}", bcp47Tag); | ||
|
||
List<Locale> locales = this.getLocales(bcp47Tag); | ||
|
||
if (locales.size() != 1) { | ||
throw new CommandException("Could not find locale with BCP47 tag: " + bcp47Tag); | ||
} | ||
|
||
return locales.getFirst(); | ||
} | ||
|
||
@Override | ||
public List<Locale> getLocales(String bcp47Tag) throws ApiException { | ||
logger.debug("Getting all locales"); | ||
return super.getLocales(bcp47Tag); | ||
} | ||
} |
Oops, something went wrong.