Skip to content

Commit 7fae993

Browse files
authored
Merge pull request #59 from simplelocalize/feat/export-customer-translations
Feat/export customer translations
2 parents 7fff4fc + 2b58609 commit 7fae993

File tree

12 files changed

+150
-54
lines changed

12 files changed

+150
-54
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.simplelocalize</groupId>
66
<artifactId>simplelocalize-cli</artifactId>
7-
<version>2.0.4</version>
7+
<version>2.0.5</version>
88
<packaging>jar</packaging>
99
<name>simplelocalize-cli</name>
1010
<description>Official SimpleLocalize Command Line Interface</description>

src/main/java/io/simplelocalize/cli/SimplelocalizeCliCommand.java

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,16 @@ public static void main(String[] args)
5252
public void extract(
5353
@Option(names = {"--apiKey"}, description = "Project API Key") String apiKey,
5454
@Option(names = {"--projectType"}, description = "Project type tells CLI how to find i18n keys in your project files") String projectType,
55-
@Option(names = {"--searchDir"}, description = "(Optional) Search directory tells CLI where to look for project files which may contain translation keys. Default: ./") String searchDirectory
55+
@Option(names = {"--searchDir"}, description = "(Optional) Search directory tells CLI where to look for project files which may contain translation keys. Default: ./") String searchDirectory,
56+
@Option(names = {"--baseUrl"}, description = "(Optional) Set custom server URL") String baseUrl
5657
)
5758
{
5859
ConfigurationLoader configurationLoader = new ConfigurationLoader();
5960
Configuration configuration = configurationLoader.loadOrGetDefault(configurationFilePath);
61+
if (StringUtils.isNotEmpty(baseUrl))
62+
{
63+
configuration.setBaseUrl(baseUrl);
64+
}
6065
if (StringUtils.isNotEmpty(apiKey))
6166
{
6267
configuration.setApiKey(apiKey);
@@ -69,7 +74,11 @@ public void extract(
6974
{
7075
configuration.setSearchDir(searchDirectory);
7176
}
72-
SimpleLocalizeClient client = SimpleLocalizeClient.withProductionServer(configuration.getApiKey());
77+
if (StringUtils.isNotEmpty(searchDirectory))
78+
{
79+
configuration.setSearchDir(searchDirectory);
80+
}
81+
SimpleLocalizeClient client = SimpleLocalizeClient.create(configuration.getBaseUrl(), configuration.getApiKey());
7382
ExtractCommand extractCommand = new ExtractCommand(client, configuration);
7483
extractCommand.invoke();
7584
}
@@ -85,11 +94,14 @@ public void sync(
8594
@Option(names = {"--downloadPath"}, description = "Directory where translations should be downloaded") String downloadPath,
8695
@Option(names = {"--downloadFormat"}, description = "Download format for translation file") String downloadFormat,
8796
@Option(names = {"--downloadOptions"}, split = ",", description = "(Optional) Download options") List<String> downloadOptions,
88-
@Option(names = {"--languageKey"}, description = "(Optional) Specify language key for single file upload") String languageKey
97+
@Option(names = {"--languageKey"}, description = "(Optional) Specify language key for single file upload") String languageKey,
98+
@Option(names = {"--customerId"}, description = "(Optional) Download translations for given customerId") String customerId,
99+
@Option(names = {"--baseUrl"}, description = "(Optional) Set custom server URL") String baseUrl
100+
89101
) throws IOException
90102
{
91-
upload(apiKey, uploadPath, uploadFormat, uploadOptions, languageKey);
92-
download(apiKey, downloadPath, downloadFormat, downloadOptions, languageKey);
103+
upload(apiKey, uploadPath, uploadFormat, uploadOptions, languageKey, customerId, baseUrl);
104+
download(apiKey, downloadPath, downloadFormat, downloadOptions, languageKey, customerId, baseUrl);
93105
}
94106

95107
@Command(
@@ -100,11 +112,17 @@ public void upload(
100112
@Option(names = {"--uploadPath"}, description = "Path to file with translation or translation keys to upload. Use '{lang}' to define language key if you are uploading more than one file with translations.") String uploadPath,
101113
@Option(names = {"--uploadFormat"}, description = "Translations or keys format") String uploadFormat,
102114
@Option(names = {"--uploadOptions"}, split = ",", description = "(Optional) Read more about 'uploadOptions' param at docs.simplelocalize.io") List<String> uploadOptions,
103-
@Option(names = {"--languageKey"}, description = "(Optional) Specify language key for single file upload") String languageKey
115+
@Option(names = {"--languageKey"}, description = "(Optional) Specify language key for single file upload") String languageKey,
116+
@Option(names = {"--customerId"}, description = "(Optional) Upload translations for given customerId") String customerId,
117+
@Option(names = {"--baseUrl"}, description = "(Optional) Set custom server URL") String baseUrl
104118
) throws IOException
105119
{
106120
ConfigurationLoader configurationLoader = new ConfigurationLoader();
107121
Configuration configuration = configurationLoader.loadOrGetDefault(configurationFilePath);
122+
if (StringUtils.isNotEmpty(baseUrl))
123+
{
124+
configuration.setBaseUrl(baseUrl);
125+
}
108126

109127
if (StringUtils.isNotEmpty(apiKey))
110128
{
@@ -126,14 +144,20 @@ public void upload(
126144
configuration.setLanguageKey(languageKey);
127145
}
128146

147+
if (StringUtils.isNotEmpty(customerId))
148+
{
149+
configuration.setCustomerId(customerId);
150+
}
151+
129152
if (uploadOptions != null)
130153
{
131154
configuration.setUploadOptions(uploadOptions);
132155
}
133156

134157
ConfigurationValidator configurationValidator = new ConfigurationValidator();
135158
configurationValidator.validateUploadConfiguration(configuration);
136-
UploadCommand uploadCommand = new UploadCommand(configuration);
159+
SimpleLocalizeClient client = SimpleLocalizeClient.create(configuration.getBaseUrl(), configuration.getApiKey());
160+
UploadCommand uploadCommand = new UploadCommand(client, configuration);
137161
uploadCommand.invoke();
138162
}
139163

@@ -145,11 +169,17 @@ public void download(
145169
@Option(names = {"--downloadPath"}, description = "Directory where translations should be downloaded") String downloadPath,
146170
@Option(names = {"--downloadFormat"}, description = "Download format for translation file") String downloadFormat,
147171
@Option(names = {"--downloadOptions"}, split = ",", description = "(Optional) Download options") List<String> downloadOptions,
148-
@Option(names = {"--languageKey"}, description = "(Optional) Setup languageKey parameter to download file with only one language translations") String languageKey
172+
@Option(names = {"--languageKey"}, description = "(Optional) Setup languageKey parameter to download file with only one language translations") String languageKey,
173+
@Option(names = {"--customerId"}, description = "(Optional) Download translations for given customerId") String customerId,
174+
@Option(names = {"--baseUrl"}, description = "(Optional) Set custom server URL") String baseUrl
149175
)
150176
{
151177
ConfigurationLoader configurationLoader = new ConfigurationLoader();
152178
Configuration configuration = configurationLoader.loadOrGetDefault(configurationFilePath);
179+
if (StringUtils.isNotEmpty(baseUrl))
180+
{
181+
configuration.setBaseUrl(baseUrl);
182+
}
153183

154184
if (StringUtils.isNotEmpty(apiKey))
155185
{
@@ -167,13 +197,17 @@ public void download(
167197
{
168198
configuration.setLanguageKey(languageKey);
169199
}
200+
if (StringUtils.isNotEmpty(customerId))
201+
{
202+
configuration.setCustomerId(customerId);
203+
}
170204
if (downloadOptions != null)
171205
{
172206
configuration.setDownloadOptions(downloadOptions);
173207
}
174208
ConfigurationValidator configurationValidator = new ConfigurationValidator();
175209
configurationValidator.validateDownloadConfiguration(configuration);
176-
SimpleLocalizeClient client = SimpleLocalizeClient.withProductionServer(configuration.getApiKey());
210+
SimpleLocalizeClient client = SimpleLocalizeClient.create(configuration.getBaseUrl(), configuration.getApiKey());
177211
DownloadCommand downloadCommand = new DownloadCommand(client, configuration);
178212
downloadCommand.invoke();
179213
}

src/main/java/io/simplelocalize/cli/Version.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public class Version
44
{
55

6-
public static final String NUMBER = "2.0.4";
6+
public static final String NUMBER = "2.0.5";
77

88
private Version()
99
{

src/main/java/io/simplelocalize/cli/client/SimpleLocalizeClient.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
public class SimpleLocalizeClient
3232
{
33-
private static final String PRODUCTION_BASE_URL = "https://api.simplelocalize.io";
3433

3534
private static final String ERROR_MESSAGE_PATH = "$.msg";
3635
private final HttpClient httpClient;
@@ -53,16 +52,11 @@ public SimpleLocalizeClient(String baseUrl, String apiKey)
5352
.build();
5453
}
5554

56-
public static SimpleLocalizeClient withCustomServer(String baseUrl, String apiKey)
55+
public static SimpleLocalizeClient create(String baseUrl, String apiKey)
5756
{
5857
return new SimpleLocalizeClient(baseUrl, apiKey);
5958
}
6059

61-
public static SimpleLocalizeClient withProductionServer(String apiKey)
62-
{
63-
return withCustomServer(PRODUCTION_BASE_URL, apiKey);
64-
}
65-
6660
public void uploadKeys(Collection<String> keys) throws IOException, InterruptedException
6761
{
6862
URI uri = uriFactory.buildSendKeysURI();

src/main/java/io/simplelocalize/cli/client/SimpleLocalizeUriFactory.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ URI buildDownloadUri(DownloadRequest downloadRequest)
3838
{
3939
endpointUrl += "&downloadOptions=" + String.join(",", downloadOptions);
4040
}
41+
42+
String customerId = downloadRequest.getCustomerId();
43+
if (StringUtils.isNotEmpty(customerId))
44+
{
45+
endpointUrl += "&customerId=" + customerId;
46+
}
47+
4148
return URI.create(endpointUrl);
4249
}
4350

@@ -63,6 +70,12 @@ URI buildUploadUri(UploadRequest uploadRequest)
6370
endpointUrl += "&namespace=" + namespace;
6471
}
6572

73+
String customerId = uploadRequest.getCustomerId();
74+
if (StringUtils.isNotEmpty(customerId))
75+
{
76+
endpointUrl += "&customerId=" + customerId;
77+
}
78+
6679
return URI.create(endpointUrl);
6780
}
6881

src/main/java/io/simplelocalize/cli/client/dto/DownloadRequest.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class DownloadRequest
77
{
88
private String format;
99
private String languageKey;
10+
private String customerId;
1011
private List<String> options;
1112

1213
public String getFormat()
@@ -24,10 +25,31 @@ public List<String> getOptions()
2425
return options;
2526
}
2627

28+
public String getCustomerId()
29+
{
30+
return customerId;
31+
}
32+
33+
@Override
34+
public boolean equals(Object o)
35+
{
36+
if (this == o) return true;
37+
if (o == null || getClass() != o.getClass()) return false;
38+
DownloadRequest that = (DownloadRequest) o;
39+
return Objects.equals(format, that.format) && Objects.equals(languageKey, that.languageKey) && Objects.equals(customerId, that.customerId) && Objects.equals(options, that.options);
40+
}
41+
42+
@Override
43+
public int hashCode()
44+
{
45+
return Objects.hash(format, languageKey, customerId, options);
46+
}
47+
2748
public static final class DownloadRequestBuilder
2849
{
2950
private String format;
3051
private String languageKey;
52+
private String customerId;
3153
private List<String> options;
3254

3355
private DownloadRequestBuilder()
@@ -51,6 +73,12 @@ public DownloadRequestBuilder withLanguageKey(String languageKey)
5173
return this;
5274
}
5375

76+
public DownloadRequestBuilder withCustomerId(String customerId)
77+
{
78+
this.customerId = customerId;
79+
return this;
80+
}
81+
5482
public DownloadRequestBuilder withOptions(List<String> downloadOptions)
5583
{
5684
this.options = downloadOptions;
@@ -63,22 +91,8 @@ public DownloadRequest build()
6391
downloadRequest.options = this.options;
6492
downloadRequest.format = this.format;
6593
downloadRequest.languageKey = this.languageKey;
94+
downloadRequest.customerId = this.customerId;
6695
return downloadRequest;
6796
}
6897
}
69-
70-
@Override
71-
public boolean equals(Object o)
72-
{
73-
if (this == o) return true;
74-
if (o == null || getClass() != o.getClass()) return false;
75-
DownloadRequest that = (DownloadRequest) o;
76-
return Objects.equals(format, that.format) && Objects.equals(languageKey, that.languageKey) && Objects.equals(options, that.options);
77-
}
78-
79-
@Override
80-
public int hashCode()
81-
{
82-
return Objects.hash(format, languageKey, options);
83-
}
8498
}

src/main/java/io/simplelocalize/cli/client/dto/UploadRequest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class UploadRequest
1313
private List<String> options;
1414
private String namespace;
1515

16+
private String customerId;
17+
1618
public Path getPath()
1719
{
1820
return path;
@@ -38,6 +40,11 @@ public String getNamespace()
3840
return namespace;
3941
}
4042

43+
public String getCustomerId()
44+
{
45+
return customerId;
46+
}
47+
4148
@Override
4249
public boolean equals(Object o)
4350
{
@@ -48,22 +55,25 @@ public boolean equals(Object o)
4855
Objects.equals(languageKey, that.languageKey) &&
4956
Objects.equals(format, that.format) &&
5057
Objects.equals(options, that.options) &&
58+
Objects.equals(customerId, that.customerId) &&
5159
Objects.equals(namespace, that.namespace);
5260
}
5361

5462
@Override
5563
public int hashCode()
5664
{
57-
return Objects.hash(path, languageKey, format, options, namespace);
65+
return Objects.hash(path, languageKey, format, options, customerId, namespace);
5866
}
5967

68+
6069
public static final class UploadFileRequestBuilder
6170
{
6271
private Path uploadPath;
6372
private String languageKey;
6473
private String uploadFormat;
6574
private List<String> uploadOptions;
6675
private String namespace;
76+
private String customerId;
6777

6878
private UploadFileRequestBuilder()
6979
{
@@ -104,6 +114,12 @@ public UploadFileRequestBuilder withNamespace(String namespace)
104114
return this;
105115
}
106116

117+
public UploadFileRequestBuilder withCustomerId(String customerId)
118+
{
119+
this.customerId = customerId;
120+
return this;
121+
}
122+
107123

108124
public UploadRequest build()
109125
{
@@ -113,6 +129,7 @@ public UploadRequest build()
113129
uploadRequest.options = this.uploadOptions;
114130
uploadRequest.path = this.uploadPath;
115131
uploadRequest.namespace = this.namespace;
132+
uploadRequest.customerId = this.customerId;
116133
return uploadRequest;
117134
}
118135
}

src/main/java/io/simplelocalize/cli/command/DownloadCommand.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,12 @@ public DownloadCommand(SimpleLocalizeClient client, Configuration configuration)
2626
this.client = client;
2727
}
2828

29-
public DownloadCommand(Configuration configuration)
30-
{
31-
this.configuration = configuration;
32-
this.client = SimpleLocalizeClient.withProductionServer(configuration.getApiKey());
33-
}
34-
3529
public void invoke()
3630
{
3731
String downloadPath = configuration.getDownloadPath();
3832
String downloadFormat = configuration.getDownloadFormat();
3933
String languageKey = configuration.getLanguageKey();
34+
String customerId = configuration.getCustomerId();
4035
List<String> downloadOptions = configuration.getDownloadOptions();
4136

4237
if (downloadPath.contains(TemplateKeys.NAMESPACE_TEMPLATE_KEY))
@@ -53,6 +48,7 @@ public void invoke()
5348
DownloadRequest downloadRequest = aDownloadRequest()
5449
.withFormat(downloadFormat)
5550
.withOptions(downloadOptions)
51+
.withCustomerId(customerId)
5652
.withLanguageKey(languageKey)
5753
.build();
5854

0 commit comments

Comments
 (0)