1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.okapi.connectors.google.v3;
20
21 import com.acumenvelocity.ath.common.Const;
22
23 import net.sf.okapi.common.MimeTypeMapper;
24 import net.sf.okapi.common.ParametersDescription;
25 import net.sf.okapi.common.StringParameters;
26 import net.sf.okapi.common.uidescription.EditorDescription;
27 import net.sf.okapi.common.uidescription.IEditorDescriptionProvider;
28 import net.sf.okapi.common.uidescription.TextInputPart;
29
30
31
32
33 public class GoogleMTv3Parameters extends StringParameters implements IEditorDescriptionProvider {
34
35 private static final String PROJECT_LOCATION = "projectLocation";
36 private static final String API_KEY = "apiKey";
37 private static final String CREDENTIALS_PATH = "credentialsPath";
38
39 private static final String GLOSSARY_PROJECT_ID = "glossaryProjectId";
40 private static final String GLOSSARY_PROJECT_LOCATION = "glossaryProjectLocation";
41 private static final String GLOSSARY_ID = "glossaryId";
42
43 private static final String MODEL_PROJECT_ID = "modelProjectId";
44 private static final String MODEL_PROJECT_LOCATION = "modelProjectLocation";
45 private static final String MODEL_ID = "modelId";
46
47 private static final String RETRY_MS = "retryIntervalMs";
48 private static final String RETRY_COUNT = "retryCount";
49 private static final String FAILURES_BEFORE_ABORT = "failuresBeforeAbort";
50 private static final String MIME_TYPE = "mimeType";
51
52 public GoogleMTv3Parameters() {
53 }
54
55 public String getProjectLocation() {
56 return getString(PROJECT_LOCATION);
57 }
58
59 public void setProjectLocation(String projectLocation) {
60 setString(PROJECT_LOCATION, projectLocation);
61 }
62
63 public String getApiKey() {
64 return getString(API_KEY);
65 }
66
67 public void setApiKey(String apiKey) {
68 setString(API_KEY, apiKey);
69 }
70
71 public String getCredentialsPath() {
72 return getString(CREDENTIALS_PATH);
73 }
74
75 public void setCredentialsPath(String credentialsPath) {
76 setString(CREDENTIALS_PATH, credentialsPath);
77 }
78
79 public String getGlossaryProjectId() {
80 return getString(GLOSSARY_PROJECT_ID);
81 }
82
83 public void setGlossaryProjectId(String glossaryProjectId) {
84 setString(GLOSSARY_PROJECT_ID, glossaryProjectId);
85 }
86
87 public String getGlossaryProjectLocation() {
88 return getString(GLOSSARY_PROJECT_LOCATION);
89 }
90
91 public void setGlossaryProjectLocation(String glossaryProjectLocation) {
92 setString(GLOSSARY_PROJECT_LOCATION, glossaryProjectLocation);
93 }
94
95 public String getGlossaryId() {
96 return getString(GLOSSARY_ID);
97 }
98
99 public void setGlossaryId(String glossaryId) {
100 setString(GLOSSARY_ID, glossaryId);
101 }
102
103 public String getModelProjectId() {
104 return getString(MODEL_PROJECT_ID);
105 }
106
107 public void setModelProjectId(String modelProjectId) {
108 setString(MODEL_PROJECT_ID, modelProjectId);
109 }
110
111 public String getModelProjectLocation() {
112 return getString(MODEL_PROJECT_LOCATION);
113 }
114
115 public void setModelProjectLocation(String modelProjectLocation) {
116 setString(MODEL_PROJECT_LOCATION, modelProjectLocation);
117 }
118
119 public String getModelId() {
120 return getString(MODEL_ID);
121 }
122
123 public void setModelId(String modelId) {
124 setString(MODEL_ID, modelId);
125 }
126
127 public int getRetryIntervalMs() {
128 return getInteger(RETRY_MS);
129 }
130
131 public void setRetryIntervalMs(int retryMs) {
132 setInteger(RETRY_MS, retryMs);
133 }
134
135 public int getRetryCount() {
136 return getInteger(RETRY_COUNT);
137 }
138
139 public void setRetryCount(int retryCount) {
140 setInteger(RETRY_COUNT, retryCount);
141 }
142
143 public int getFailuresBeforeAbort() {
144 return getInteger(FAILURES_BEFORE_ABORT);
145 }
146
147 public void setFailuresBeforeAbort(int failuresBeforeAbort) {
148 setInteger(FAILURES_BEFORE_ABORT, failuresBeforeAbort);
149 }
150
151 public String getMimeType() {
152 return getString(MIME_TYPE);
153 }
154
155 public void setMimeType(String mimeType) {
156 setString(MIME_TYPE, mimeType);
157 }
158
159 @Override
160 public void reset() {
161 super.reset();
162
163 setProjectLocation(Const.ATH_GCP_PROJECT_LOCATION);
164 setApiKey(null);
165 setCredentialsPath(null);
166 setGlossaryProjectId(null);
167 setGlossaryProjectLocation(null);
168 setGlossaryId(null);
169 setModelProjectId(null);
170 setModelProjectLocation(null);
171 setModelId(null);
172
173
174 setMimeType(MimeTypeMapper.PLAIN_TEXT_MIME_TYPE);
175
176 setRetryIntervalMs(10 * 1000);
177 setRetryCount(10);
178 setFailuresBeforeAbort(-1);
179 }
180
181 @Override
182 public ParametersDescription getParametersDescription() {
183 ParametersDescription desc = new ParametersDescription(this);
184
185 desc.add(PROJECT_LOCATION,
186 "Project Location",
187 "The location for translation requests (default: global)");
188
189 desc.add(API_KEY,
190 "Google API key",
191 "The Google API key to identify the application/user");
192
193 desc.add(CREDENTIALS_PATH,
194 "Service Account Credentials Path",
195 "Path to the service account JSON key file (alternative to API key)");
196
197 desc.add(GLOSSARY_PROJECT_ID,
198 "Glossary Project ID",
199 "The Google Cloud project ID for the glossary (optional, defaults to translation project)");
200
201 desc.add(GLOSSARY_PROJECT_LOCATION,
202 "Glossary Project Location",
203 "The location for the glossary project (optional, defaults to translation location)");
204
205 desc.add(GLOSSARY_ID,
206 "Glossary ID",
207 "The glossary ID to use for translation (optional, must be in GCS)");
208
209 desc.add(MODEL_PROJECT_ID,
210 "Model Project ID",
211 "The Google Cloud project ID for the custom model (optional, defaults to translation project)");
212
213 desc.add(MODEL_PROJECT_LOCATION,
214 "Model Project Location",
215 "The location for the model project (optional, defaults to translation location)");
216
217 desc.add(MODEL_ID,
218 "Model",
219 "Custom translation model ID (optional)");
220
221 desc.add(MIME_TYPE,
222 "MIME Type",
223 "Content MIME type (text/plain or text/html)");
224
225 desc.add(RETRY_MS,
226 "Retry Interval (ms)",
227 "Time to wait before retrying a failed query");
228
229 desc.add(RETRY_COUNT,
230 "Retry Count",
231 "Number of retries to attempt before failing");
232
233 desc.add(FAILURES_BEFORE_ABORT,
234 "Failures before abort",
235 "Number of times we let queries fail (after retries) before aborting the process");
236
237 return desc;
238 }
239
240 @Override
241 public EditorDescription createEditorDescription(ParametersDescription paramsDesc) {
242 EditorDescription desc = new EditorDescription("Google Cloud Translation v3 Connector Settings",
243 true, false);
244
245 desc.addTextInputPart(paramsDesc.get(PROJECT_LOCATION));
246
247 TextInputPart tip = desc.addTextInputPart(paramsDesc.get(API_KEY));
248 tip.setPassword(true);
249
250 desc.addTextInputPart(paramsDesc.get(CREDENTIALS_PATH));
251
252 desc.addTextInputPart(paramsDesc.get(GLOSSARY_PROJECT_ID));
253 desc.addTextInputPart(paramsDesc.get(GLOSSARY_PROJECT_LOCATION));
254 desc.addTextInputPart(paramsDesc.get(GLOSSARY_ID));
255
256 desc.addTextInputPart(paramsDesc.get(MODEL_PROJECT_ID));
257 desc.addTextInputPart(paramsDesc.get(MODEL_PROJECT_LOCATION));
258 desc.addTextInputPart(paramsDesc.get(MODEL_ID));
259
260 desc.addTextInputPart(paramsDesc.get(MIME_TYPE));
261
262 desc.addTextInputPart(paramsDesc.get(RETRY_MS));
263 desc.addTextInputPart(paramsDesc.get(RETRY_COUNT));
264 desc.addTextInputPart(paramsDesc.get(FAILURES_BEFORE_ABORT));
265
266 return desc;
267 }
268 }