Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
RHBPMS-1004: Localize simulation start/end dates and interval (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Lindop authored and csadilek committed May 25, 2016
1 parent 7a43993 commit 8040aac
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# translation auto-copied from project jbpm-designer, version 6.2.0, document org.jbpm/jbpm-designer-api/org/jbpm/designer/resources/i18n/DesignerConstants, author angela.garcia
ORYX.I18N.Language=en_us
ORYX.I18N.Language=es
# translation auto-copied from project jbpm-designer, version 6.2.0, document org.jbpm/jbpm-designer-api/org/jbpm/designer/resources/i18n/DesignerConstants, author angela.garcia
ORYX.I18N.Oryx.noBackendDefined=\u00A1Precauci\u00F3n\! \\nNo hay un backend definido.\\n El modelo solicitado no se puede cargar. Trate de cargar una configuraci\u00F3n con un plugin para guardar.
# translation auto-copied from project jbpm-designer, version 6.2.0, document org.jbpm/jbpm-designer-api/org/jbpm/designer/resources/i18n/DesignerConstants, author angela.garcia
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# translation auto-copied from project jbpm-designer, version 6.2.0, document org.jbpm/jbpm-designer-api/org/jbpm/designer/resources/i18n/DesignerConstants, author croe@redhat.com
ORYX.I18N.Language=en_us
ORYX.I18N.Language=fr
# translation auto-copied from project jbpm-designer, version 6.2.0, document org.jbpm/jbpm-designer-api/org/jbpm/designer/resources/i18n/DesignerConstants, author croe@redhat.com
ORYX.I18N.Oryx.noBackendDefined=Attention\! \\nAucun backend d\u00E9fini.\\n Le mod\u00E8le demand\u00E9 ne peut pas \u00EAtre charg\u00E9. Essayez de t\u00E9l\u00E9charger une configuration avec un plugin sauvegard\u00E9.
# translation auto-copied from project jbpm-designer, version 6.2.0, document org.jbpm/jbpm-designer-api/org/jbpm/designer/resources/i18n/DesignerConstants, author croe@redhat.com
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# translation auto-copied from project jbpm-designer, version 6.2.0, document org.jbpm/jbpm-designer-api/org/jbpm/designer/resources/i18n/DesignerConstants, author ldelima@redhat.com
ORYX.I18N.Language=en_us
ORYX.I18N.Language=pt_BR
# translation auto-copied from project jbpm-designer, version 6.2.0, document org.jbpm/jbpm-designer-api/org/jbpm/designer/resources/i18n/DesignerConstants, author ldelima@redhat.com
ORYX.I18N.Oryx.noBackendDefined=Aten\u00E7\u00E3o\! \\nNenhum Backend definido.\\n O modelo solicitado n\u00E3o pode ser carregado. Tente carregar a configura\u00E7\u00E3o com um plugin salvar.
# translation auto-copied from project jbpm-designer, version 6.2.0, document org.jbpm/jbpm-designer-api/org/jbpm/designer/resources/i18n/DesignerConstants, author ldelima@redhat.com
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# translation auto-copied from project jbpm-designer, version 6.2.0, document org.jbpm/jbpm-designer-api/org/jbpm/designer/resources/i18n/DesignerConstants, author xi.huang
ORYX.I18N.Language=\u7B80\u4F53\u4E2D\u6587
ORYX.I18N.Language=zh_CN
# translation auto-copied from project jbpm-designer, version 6.2.0, document org.jbpm/jbpm-designer-api/org/jbpm/designer/resources/i18n/DesignerConstants, author xi.huang
ORYX.I18N.Oryx.noBackendDefined=\u8B66\u544A\! \\n\u672A\u5B9A\u4E49\u540E\u53F0\u3002\\n \u65E0\u6CD5\u52A0\u8F7D\u6240\u8BF7\u6C42\u7684\u6A21\u578B\u3002\u5C1D\u8BD5\u52A0\u8F7D\u5E26\u6709\u4FDD\u5B58\u63D2\u4EF6\u7684\u914D\u7F6E\u3002
# translation auto-copied from project jbpm-designer, version 6.2.0, document org.jbpm/jbpm-designer-api/org/jbpm/designer/resources/i18n/DesignerConstants, author xi.huang
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ORYX.I18N.Language=en_us
ORYX.I18N.Language=zh_TW
ORYX.I18N.Oryx.noBackendDefined=\u8ACB\u6CE8\u610F\uFF01\\n\u672A\u5B9A\u7FA9\u5F8C\u7AEF\u3002\\n \u8ACB\u6C42\u7684\u578B\u865F\u7121\u6CD5\u8F09\u5165\u3002\u8ACB\u5617\u8A66\u8F09\u5165\u4E00\u9805\u542B\u6709\u5132\u5B58\u5916\u639B\u7A0B\u5F0F\u7684\u914D\u7F6E\u3002
ORYX.I18N.Oryx.pleaseWait=jBPM Web Designer \u8F09\u5165\u4E2D\u3002\u8ACB\u7A0D\u5019...
ORYX.I18N.Oryx.notLoggedOn=\u672A\u767B\u5165
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.inject.Inject;
import javax.servlet.ServletConfig;
Expand Down Expand Up @@ -133,6 +134,9 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
String numInstances = req.getParameter("numinstances");
String interval = req.getParameter("interval");
String intervalUnit = req.getParameter("intervalunit");
String language = req.getParameter("language");
String simTestStartTime = req.getParameter("simteststarttime");
String simTestEndTime = req.getParameter("simtestendtime");

if (profile == null) {
profile = _profileService.findProfile(req, profileName);
Expand Down Expand Up @@ -255,9 +259,17 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
simInfoKeys.put("id", simInfo.getProcessId() == null ? "" : simInfo.getProcessId());
simInfoKeys.put("name", simInfo.getProcessName() == null? "" : simInfo.getProcessName());
simInfoKeys.put("executions", simInfo.getNumberOfExecutions());
SimpleDateFormat infoDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss");
String simStartStr = infoDateFormat.format(new Date(simInfo.getStartTime()));
String simEndStr = infoDateFormat.format(new Date(simInfo.getEndTime()));
SimpleDateFormat infoDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss", getLocale(language));
long startTime = simInfo.getStartTime();
if (simTestStartTime != null && simTestStartTime.length() > 0) {
startTime = Long.parseLong(simTestStartTime);
}
long endTime = simInfo.getEndTime();
if (simTestEndTime != null && simTestEndTime.length() > 0) {
endTime = Long.parseLong(simTestEndTime);
}
String simStartStr = infoDateFormat.format(new Date(startTime));
String simEndStr = infoDateFormat.format(new Date(endTime));
simInfoKeys.put("starttime", simStartStr);
simInfoKeys.put("endtime", simEndStr);
simInfoKeys.put("version", simInfo.getProcessVersion() == null? "" : simInfo.getProcessVersion());
Expand Down Expand Up @@ -733,5 +745,22 @@ private String presentInterval(int interval, String intervalUnit) {
}
return retVal;
}

private Locale getLocale(String language) {
if (language != null && language.length() > 0) {
int iUnderscore = language.indexOf('_');
if (iUnderscore > 0) {
String lang = language.substring(0, iUnderscore);
String region = language.substring(iUnderscore + 1).toUpperCase();
return new Locale(lang, region);
}
else {
return new Locale(language);
}
}
else {
return Locale.getDefault();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,43 @@ public void testGetPathInfoLocalizedNames() throws Exception {
assertTrue(responseText.contains("paths"));
}

@Test
public void testLocalizedStartEndTime() throws Exception {

SimulationServlet simulationServlet = new SimulationServlet();
simulationServlet.setProfile(new JbpmProfileImpl());

// Request json is encoded
String rawJson = readFile("BPSim_i18nNames.json");
String encodedJson = Base64.encodeBase64String(UriUtils.encode(rawJson.toString()).getBytes("UTF-8"));

// setup parameters
Map<String, String> params = new HashMap<String, String>();
params.put("json", encodedJson);
params.put("action", SimulationServlet.ACTION_RUNSIMULATION);
params.put("language", "ru_RU");
params.put("ppdata", "Email,Log,Rest,WebService");
params.put("numinstances", "10");
params.put("interval", "5");
params.put("intervalUnit", "minutes");
params.put("simteststarttime", "1464083491796");
params.put("simtestendtime", "1465776165148");

TestHttpServletResponse response = new TestHttpServletResponse();
simulationServlet.doPost(new TestHttpServletRequest(params), response);

int responseStatus = response.getStatus();
assertEquals(0, responseStatus);

// Response json is encoded
String encodedResponseText = new String(response.getContent());
assertNotNull(encodedResponseText);
String responseText = UriUtils.decode(new String(Base64.decodeBase64(encodedResponseText), "UTF-8"));
assertNotNull(responseText);
assertTrue(responseText.contains("май"));
assertTrue(responseText.contains("июн"));
}

private String readFile(String fileName) throws Exception {
URL fileURL = SimulationServletTest.class.getResource(fileName);
return new String(Files.readAllBytes(Paths.get(fileURL.toURI())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ ORYX.Plugins.Simulation = Clazz.extend({
ppdata: ORYX.PREPROCESSING,
numinstances: instancesInput,
interval: intervalInput,
intervalunit: intervalUnit
intervalunit: intervalUnit,
language: ORYX.I18N.Language
}
});
}.bind(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ORYX.Plugins.SimulationResults = Clazz.extend({
</tr> \
<tr> \
<td><span style="font-size: 10px"><b>' + ORYX.I18N.View.sim.resultsInterval + '</b></span></td> \
<td><span style="font-size: 10px">' + simInfo[0].interval + '</span></td> \
<td><span style="font-size: 10px">' + this.translateInterval(simInfo[0].interval) + '</span></td> \
</tr> \
</table>';
if(simInfo) {
Expand Down Expand Up @@ -504,6 +504,26 @@ ORYX.Plugins.SimulationResults = Clazz.extend({
else {
return timeUnit;
}
}
},
translateInterval: function(interval) {
if (interval) {
var iSpace = interval.indexOf(' ');
if (iSpace > 0) {
var value = interval.substring(0, iSpace);
var units = interval.substring(iSpace + 1);
units = this.getIntervalTimeUnit(units);
return value + ' ' + units;
}
}
return interval;
},
getIntervalTimeUnit : function (timeUnit) {
if (ORYX.I18N.propertyNamesValue[timeUnit] !== undefined) {
return ORYX.I18N.propertyNamesValue[timeUnit];
}
else {
return timeUnit;
}
}

});

0 comments on commit 8040aac

Please sign in to comment.