Alexander Wels has uploaded a new change for review. Change subject: engine,userportal,webadmin: enhance locale selection ......................................................................
engine,userportal,webadmin: enhance locale selection - Added UnsupportedDisplayedLocales configuration variable to control which unsupported locales are displayed. Any locales in this list which are also in the UnsupportedLocaleFilter list will still be displayed. - Added UnsupportedLocalesFilter configuration variable to control which locales are unsupported. Any locale in this list will NOT be displayed unless they are also in the UnsupportedDisplayedLocales list. - Modified pom files to use the languages.properties as the source file of which locales are available, instead of being hardcoded in the pom file itself. Change-Id: I5b816694d6c34549360b189eb85c840688957bdb Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1096525 Signed-off-by: Alexander Wels <aw...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetConfigurationValueParameters.java A backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/servlet/UnsupportedLocaleHelper.java A backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/UnsupportedLocaleHelperTest.java M backend/manager/modules/welcome/src/main/java/org/ovirt/engine/core/WelcomeServlet.java M backend/manager/tools/src/test/resources/engine-config.properties M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/server/gwt/GwtDynamicHostPageServlet.java M frontend/webadmin/modules/frontend/src/main/resources/META-INF/resources/GwtHostPage.jsp M frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/server/gwt/AbstractGwtDynamicHostPageServletTest.java A frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/LocaleInfoData.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/view/AbstractLoginFormView.java M frontend/webadmin/modules/pom.xml M frontend/webadmin/modules/userportal-gwtp/pom.xml M frontend/webadmin/modules/webadmin/pom.xml 16 files changed, 395 insertions(+), 10 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/73/27973/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java index e859d71..6a790c2 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java @@ -614,7 +614,9 @@ configParameters.getConfigValue() == ConfigurationValues.ProductRPMVersion || configParameters.getConfigValue() == ConfigurationValues.ApplicationMode || configParameters.getConfigValue() == ConfigurationValues.UserMessageOfTheDay || - configParameters.getConfigValue() == ConfigurationValues.UserSessionTimeOutInterval) { + configParameters.getConfigValue() == ConfigurationValues.UserSessionTimeOutInterval || + configParameters.getConfigValue() == ConfigurationValues.UnsupportedLocalesFilter || + configParameters.getConfigValue() == ConfigurationValues.UnsupportedDisplayedLocales) { return runQueryImpl(actionType, parameters, false); } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java index 079267d..e191b40 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java @@ -1723,5 +1723,12 @@ @DefaultValueAttribute("3600") PMHealthCheckIntervalInSec, + @TypeConverterAttribute(String.class) + @DefaultValueAttribute("") + UnsupportedDisplayedLocales, + + @TypeConverterAttribute(String.class) + @DefaultValueAttribute("") + UnsupportedLocalesFilter, Invalid } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java index be6844d..af49870 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java @@ -126,7 +126,9 @@ IscsiMultipathingSupported, BootMenuSupported(ConfigAuthType.User), MixedDomainTypesInDataCenter, - KeystoneAuthUrl; + KeystoneAuthUrl, + UnsupportedDisplayedLocales, + UnsupportedLocalesFilter; public static enum ConfigAuthType { Admin, diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetConfigurationValueParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetConfigurationValueParameters.java index 2be04d0..8fc50e1 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetConfigurationValueParameters.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetConfigurationValueParameters.java @@ -7,7 +7,7 @@ _configValue = cVal; } - private ConfigurationValues _configValue; + private final ConfigurationValues _configValue; public ConfigurationValues getConfigValue() { return _configValue; @@ -33,6 +33,40 @@ } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((_configValue == null) ? 0 : _configValue.hashCode()); + result = prime * result + ((privateVersion == null) ? 0 : privateVersion.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + GetConfigurationValueParameters other = (GetConfigurationValueParameters) obj; + if (_configValue != other._configValue) { + return false; + } + if (privateVersion == null) { + if (other.privateVersion != null) { + return false; + } + } else if (!privateVersion.equals(other.privateVersion)) { + return false; + } + return true; + } + + @Override public String toString() { StringBuilder builder = new StringBuilder(50); builder.append("version: "); //$NON-NLS-1$ diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/servlet/UnsupportedLocaleHelper.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/servlet/UnsupportedLocaleHelper.java new file mode 100644 index 0000000..3cd438d --- /dev/null +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/servlet/UnsupportedLocaleHelper.java @@ -0,0 +1,62 @@ +package org.ovirt.engine.core.utils.servlet; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.ovirt.engine.core.common.config.ConfigCommon; +import org.ovirt.engine.core.common.interfaces.BackendLocal; +import org.ovirt.engine.core.common.queries.ConfigurationValues; +import org.ovirt.engine.core.common.queries.GetConfigurationValueParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class UnsupportedLocaleHelper { + /** + * Determine the intersection of the passed in 'all locale' list and the display locale list. All + * elements in the lists should be of format xx_YY, which is the standard Java Locale format. + * @param allLocales List of all available locale. + * @param displayLocales The list locale to display. + * @return A {@code List} containing the intersection of the two lists. + */ + public static List<String> getDisplayedLocales(List<String> allLocales, List<String> displayLocales, + List<String> unsupportedLocales) { + List<String> result = allLocales; + if (displayLocales == null) { + displayLocales = new ArrayList<String>(); + } + if (unsupportedLocales != null && !unsupportedLocales.isEmpty()) { + for (String unsupportedLocale: unsupportedLocales) { + unsupportedLocale = unsupportedLocale.trim(); + if (!displayLocales.contains(unsupportedLocale)) { + result.remove(unsupportedLocale); + } + } + } + Collections.sort(result); + return result; + } + + public static List<String> getLocalesKeys(BackendLocal backend, ConfigurationValues configValues) { + if (!configValues.equals(ConfigurationValues.UnsupportedLocalesFilter) + && !configValues.equals(ConfigurationValues.UnsupportedDisplayedLocales)) { + throw new IllegalArgumentException("Passed in config value not related to locales"); //$NON-NLS-1$ + } + List<String> result = new ArrayList<String>(); + String locales = backend.runPublicQuery(VdcQueryType.GetConfigurationValue, + new GetConfigurationValueParameters(configValues, + ConfigCommon.defaultConfigurationVersion)).getReturnValue(); + if (locales != null && !locales.isEmpty()) { + String[] localeKeys = locales.split(","); //$NON-NLS-1$ + for (String localeKey: localeKeys) { + try { + //Check for valid locale. + org.apache.commons.lang.LocaleUtils.toLocale(localeKey.trim()); + result.add(localeKey.trim()); + } catch (IllegalArgumentException iae) { + //The locale passed in is not valid, don't add it to the list. + } + } + } + return result; + } +} diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/UnsupportedLocaleHelperTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/UnsupportedLocaleHelperTest.java new file mode 100644 index 0000000..e41060f --- /dev/null +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/servlet/UnsupportedLocaleHelperTest.java @@ -0,0 +1,132 @@ +package org.ovirt.engine.core.utils.servlet; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.ovirt.engine.core.common.interfaces.BackendLocal; +import org.ovirt.engine.core.common.queries.ConfigurationValues; +import org.ovirt.engine.core.common.queries.GetConfigurationValueParameters; +import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +@RunWith(MockitoJUnitRunner.class) +public class UnsupportedLocaleHelperTest { + + @Mock + BackendLocal mockBackend; + + VdcQueryReturnValue returnValue; + + List<String> allLocales; + + @Before + public void setUp() throws Exception { + allLocales = getAllLocales(); + returnValue = new VdcQueryReturnValue(); + when(mockBackend.runPublicQuery(eq(VdcQueryType.GetConfigurationValue), + any(GetConfigurationValueParameters.class))).thenReturn(returnValue); + } + + @Test + public void testGetDisplayLocales() { + List<String> displayLocales = new ArrayList<String>(); + List<String> locales = UnsupportedLocaleHelper.getDisplayedLocales(allLocales, displayLocales, null); + assertNotNull("Result should not be null", locales); + assertEquals("There should be 8 locales", 8, locales.size()); + } + + @Test + public void testGetDisplayLocalesUnsupported() { + List<String> displayLocales = new ArrayList<String>(); + List<String> unSupportedLocales = new ArrayList<String>(); + unSupportedLocales.add("pt_BR"); + List<String> locales = UnsupportedLocaleHelper.getDisplayedLocales(allLocales, displayLocales, unSupportedLocales); + assertNotNull("Result should not be null", locales); + assertEquals("There should be 7 locales", 7, locales.size()); + assertFalse("Locales should not contain 'pt_BR'", locales.contains("pt_BR")); + } + + @Test + public void testGetDisplayLocalesWithUnsupportedHiding2() { + List<String> unSupportedLocales = new ArrayList<String>(); + unSupportedLocales.add("de_DE"); + List<String> locales = UnsupportedLocaleHelper.getDisplayedLocales(allLocales, new ArrayList<String>(), unSupportedLocales); + assertNotNull("Result should not be null", locales); + assertEquals("There should be 7 locales", 7, locales.size()); + assertFalse("Locales should not contain 'de_DE'", locales.contains("de_DE")); + } + + @Test + public void testGetDisplayLocalesWithUnsupportedShowing() { + List<String> unSupportedLocales = new ArrayList<String>(); + unSupportedLocales.add("de_DE"); + List<String> displayUnsupported = new ArrayList<String>(); + displayUnsupported.add("de_DE"); + List<String> locales = UnsupportedLocaleHelper.getDisplayedLocales(allLocales, displayUnsupported, + unSupportedLocales); + assertNotNull("Result should not be null", locales); + assertEquals("There should be 8 locales", 8, locales.size()); + assertTrue("Locales should contain 'de_DE'", locales.contains("de_DE")); + } + + @Test + public void testGetLocalesKeysUnSupported() { + returnValue.setReturnValue("ko_KR"); + List<String> locales = UnsupportedLocaleHelper.getLocalesKeys(mockBackend, + ConfigurationValues.UnsupportedLocalesFilter); + assertNotNull("Result should not be null", locales); + assertEquals("There should be 1 locales", 1, locales.size()); + assertEquals("Locale should be ko_KR", "ko_KR", locales.get(0)); + } + + @Test + public void testGetLocalesKeysWithInvalid() { + returnValue.setReturnValue("ko_KR, abcdds"); + List<String> locales = UnsupportedLocaleHelper.getLocalesKeys(mockBackend, + ConfigurationValues.UnsupportedLocalesFilter); + assertNotNull("Result should not be null", locales); + assertEquals("There should be 1 locales", 1, locales.size()); + assertEquals("Locale should be ko_KR", "ko_KR", locales.get(0)); + } + + @Test + public void testGetLocalesKeysDisplayLocalesEmpty() { + List<String> locales = UnsupportedLocaleHelper.getLocalesKeys(mockBackend, + ConfigurationValues.UnsupportedDisplayedLocales); + assertNotNull("Result should not be null", locales); + assertEquals("There should be 0 locales", 0, locales.size()); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetLocalesKeysInValidConfigurationValues() { + UnsupportedLocaleHelper.getLocalesKeys(mockBackend, ConfigurationValues.ApplicationMode); + fail("Should not get here"); + } + + private List<String> getAllLocales() { + List<String> result = new ArrayList<String>(); + result.add("de_DE"); + result.add("en_US"); + result.add("fr_FR"); + result.add("es_ES"); + result.add("ja_JP"); + result.add("ko_KR"); + result.add("pt_BR"); + result.add("zh_CN"); + return result; + } +} diff --git a/backend/manager/modules/welcome/src/main/java/org/ovirt/engine/core/WelcomeServlet.java b/backend/manager/modules/welcome/src/main/java/org/ovirt/engine/core/WelcomeServlet.java index 3ae65b1..b68ccf5 100644 --- a/backend/manager/modules/welcome/src/main/java/org/ovirt/engine/core/WelcomeServlet.java +++ b/backend/manager/modules/welcome/src/main/java/org/ovirt/engine/core/WelcomeServlet.java @@ -17,6 +17,7 @@ import org.ovirt.engine.core.common.queries.GetConfigurationValueParameters; import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.utils.servlet.LocaleFilter; +import org.ovirt.engine.core.utils.servlet.UnsupportedLocaleHelper; /** * This Servlet serves the welcome page to allow users to select either web admin or user portal. @@ -78,7 +79,9 @@ @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { - request.setAttribute(LOCALE_KEYS, LocaleFilter.getLocaleKeys()); + request.setAttribute(LOCALE_KEYS, UnsupportedLocaleHelper.getDisplayedLocales(LocaleFilter.getLocaleKeys(), + UnsupportedLocaleHelper.getLocalesKeys(backend, ConfigurationValues.UnsupportedDisplayedLocales), + UnsupportedLocaleHelper.getLocalesKeys(backend, ConfigurationValues.UnsupportedLocalesFilter))); String oVirtVersion = backend.runPublicQuery(VdcQueryType.GetConfigurationValue, new GetConfigurationValueParameters(ConfigurationValues.ProductRPMVersion, ConfigCommon.defaultConfigurationVersion)).getReturnValue(); @@ -91,4 +94,5 @@ dispatcher.include(request, response); } } + } diff --git a/backend/manager/tools/src/test/resources/engine-config.properties b/backend/manager/tools/src/test/resources/engine-config.properties index 0984739..c13535a 100644 --- a/backend/manager/tools/src/test/resources/engine-config.properties +++ b/backend/manager/tools/src/test/resources/engine-config.properties @@ -23,3 +23,6 @@ DomainName.alternateKey=domain_list MaxNumOfVmSockets.description=Max number of VM sockets. Version of this key is not general + +UnsupportedDisplayLocales.description=A comma separated list of locale keys that you want to display, this allows you to display some unsupported locales. +UnsupportedDisplayLocales.type=String diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/server/gwt/GwtDynamicHostPageServlet.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/server/gwt/GwtDynamicHostPageServlet.java index 51b2bba..669f724 100644 --- a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/server/gwt/GwtDynamicHostPageServlet.java +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/server/gwt/GwtDynamicHostPageServlet.java @@ -21,11 +21,13 @@ import org.ovirt.engine.core.branding.BrandingManager; import org.ovirt.engine.core.common.businessentities.DbUser; import org.ovirt.engine.core.common.interfaces.BackendLocal; +import org.ovirt.engine.core.common.queries.ConfigurationValues; import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.utils.servlet.LocaleFilter; import org.ovirt.engine.core.utils.servlet.ServletUtils; +import org.ovirt.engine.core.utils.servlet.UnsupportedLocaleHelper; /** * Renders the HTML host page of a GWT application. @@ -46,7 +48,8 @@ ATTR_MESSAGES("messages"), //$NON-NLS-1$ ATTR_BASE_CONTEXT_PATH("baseContextPath"), //$NON-NLS-1$ ATTR_LOCALE(LocaleFilter.LOCALE), - ATTR_APPLICATION_TYPE(BrandingFilter.APPLICATION_NAME); + ATTR_APPLICATION_TYPE(BrandingFilter.APPLICATION_NAME), + ATTR_DISPLAY_LOCALES("localeInfo"); //$NON-NLS-1$ private final String attributeKey; @@ -106,6 +109,7 @@ // Set the messages that need to be replaced. request.setAttribute(MD5Attributes.ATTR_MESSAGES.getKey(), getBrandingMessages(getApplicationTypeFromRequest(request), getLocaleFromRequest(request))); + request.setAttribute(MD5Attributes.ATTR_DISPLAY_LOCALES.getKey(), getLocaleInformation()); request.setAttribute(MD5Attributes.ATTR_BASE_CONTEXT_PATH.getKey(), getConfiguration(request)); // Set attribute for userInfo object DbUser loggedInUser = getLoggedInUser(request.getSession().getId()); @@ -179,6 +183,25 @@ return node.toString(); } + private String getLocaleInformation() { + ObjectNode node = mapper.createObjectNode(); + String displayedLocales = " "; //$NON-NLS-1$ + for (String localeString: UnsupportedLocaleHelper.getLocalesKeys(backend, + ConfigurationValues.UnsupportedDisplayedLocales)) { + displayedLocales += localeString + ","; //$NON-NLS-1$ + } + node.put(ConfigurationValues.UnsupportedDisplayedLocales.name(), + displayedLocales.substring(0, displayedLocales.length() - 1)); + String unSupportedLocales = " "; //$NON-NLS-1$ + for (String localeString: UnsupportedLocaleHelper.getLocalesKeys(backend, + ConfigurationValues.UnsupportedLocalesFilter)) { + unSupportedLocales += localeString + ","; //$NON-NLS-1$ + } + node.put(ConfigurationValues.UnsupportedLocalesFilter.name(), + unSupportedLocales.substring(0, unSupportedLocales.length() - 1)); + return node.toString(); + } + /** * Get a JavaScript associative array string that define the branding messages. * @param applicationName the application name. diff --git a/frontend/webadmin/modules/frontend/src/main/resources/META-INF/resources/GwtHostPage.jsp b/frontend/webadmin/modules/frontend/src/main/resources/META-INF/resources/GwtHostPage.jsp index 45bcdbc..da20366 100644 --- a/frontend/webadmin/modules/frontend/src/main/resources/META-INF/resources/GwtHostPage.jsp +++ b/frontend/webadmin/modules/frontend/src/main/resources/META-INF/resources/GwtHostPage.jsp @@ -25,6 +25,9 @@ <c:if test="${requestScope['messages'] != null}"> var messages = <c:out value="${requestScope['messages']}" escapeXml="false"/>; </c:if> + <c:if test="${requestScope['localeInfo'] != null}"> + var localeInfo = <c:out value="${requestScope['localeInfo']}" escapeXml="false"/>; + </c:if> <c:if test="${requestScope['baseContextPath'] != null}"> var baseContextPath = <c:out value="${requestScope['baseContextPath']}" escapeXml="false"/>; </c:if> diff --git a/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/server/gwt/AbstractGwtDynamicHostPageServletTest.java b/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/server/gwt/AbstractGwtDynamicHostPageServletTest.java index 13a5add..e242fb6 100644 --- a/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/server/gwt/AbstractGwtDynamicHostPageServletTest.java +++ b/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/server/gwt/AbstractGwtDynamicHostPageServletTest.java @@ -36,7 +36,9 @@ import org.ovirt.engine.core.branding.BrandingManager; import org.ovirt.engine.core.branding.BrandingTheme; import org.ovirt.engine.core.common.businessentities.DbUser; +import org.ovirt.engine.core.common.config.ConfigCommon; import org.ovirt.engine.core.common.interfaces.BackendLocal; +import org.ovirt.engine.core.common.queries.ConfigurationValues; import org.ovirt.engine.core.common.queries.GetConfigurationValueParameters; import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; @@ -185,6 +187,11 @@ public void testRunPublicQuery_GetConfigurationValue() { String sessionId = "sessionId"; //$NON-NLS-1$ VdcQueryType queryType = VdcQueryType.GetConfigurationValue; + VdcQueryReturnValue returnIntValue = new VdcQueryReturnValue(); + returnIntValue.setSucceeded(true); + returnIntValue.setReturnValue(Integer.valueOf(255)); + when(mockBackend.runPublicQuery(eq(VdcQueryType.GetConfigurationValue), + eq(mockConfigQueryParams))).thenReturn(returnIntValue); Object result = testServlet.runPublicQuery(queryType, mockConfigQueryParams, sessionId); assertThat(result, is(Integer.class)); verify(mockConfigQueryParams).setSessionId(sessionId); @@ -232,11 +239,25 @@ } void stubGetConfigurationValuePublicQuery() { - VdcQueryReturnValue returnValue = new VdcQueryReturnValue(); - returnValue.setSucceeded(true); - returnValue.setReturnValue(Integer.valueOf(255)); + VdcQueryReturnValue returnIntValue = new VdcQueryReturnValue(); + returnIntValue.setSucceeded(true); + returnIntValue.setReturnValue(Integer.valueOf(255)); when(mockBackend.runPublicQuery(eq(VdcQueryType.GetConfigurationValue), - isA(GetConfigurationValueParameters.class))).thenReturn(returnValue); + eq(new GetConfigurationValueParameters(ConfigurationValues.ApplicationMode, + ConfigCommon.defaultConfigurationVersion)))).thenReturn(returnIntValue); + when(mockBackend.runPublicQuery(eq(VdcQueryType.GetConfigurationValue), + eq(new GetConfigurationValueParameters(ConfigurationValues.UserSessionTimeOutInterval, + ConfigCommon.defaultConfigurationVersion)))).thenReturn(returnIntValue); + VdcQueryReturnValue returnStringValue = new VdcQueryReturnValue(); + returnStringValue.setSucceeded(true); + returnStringValue.setReturnValue(""); + when(mockBackend.runPublicQuery(eq(VdcQueryType.GetConfigurationValue), + eq(new GetConfigurationValueParameters(ConfigurationValues.UnsupportedDisplayedLocales, + ConfigCommon.defaultConfigurationVersion)))).thenReturn(returnStringValue); + when(mockBackend.runPublicQuery(eq(VdcQueryType.GetConfigurationValue), + eq(new GetConfigurationValueParameters(ConfigurationValues.UnsupportedLocalesFilter, + ConfigCommon.defaultConfigurationVersion)))).thenReturn(returnStringValue); + } } diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/LocaleInfoData.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/LocaleInfoData.java new file mode 100644 index 0000000..8768f5a --- /dev/null +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/utils/LocaleInfoData.java @@ -0,0 +1,63 @@ +package org.ovirt.engine.ui.common.utils; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.google.gwt.core.client.JavaScriptObject; + +public final class LocaleInfoData extends JavaScriptObject { + + protected LocaleInfoData() { + } + + public static native LocaleInfoData instance() /*-{ + return $wnd.localeInfo; + }-*/; + + private native String getUnsupportedDisplayLocaleString() /*-{ + return this.UnsupportedDisplayedLocales; + }-*/; + + private native String getUnsupportedLocalesFilterString() /*-{ + return this.UnsupportedLocalesFilter; + }-*/; + + public List<String> getUnsupportedDisplayLocales() { + return getLocaleValues(getUnsupportedDisplayLocaleString()); + } + + public List<String> getUnSupportedLocalesFilter() { + return getLocaleValues(getUnsupportedLocalesFilterString()); + } + + private List<String> getLocaleValues(String localeString) { + List<String> result = new ArrayList<String>(); + if (localeString != null && !localeString.isEmpty()) { + String[] locales = localeString.split(","); //$NON-NLS-1$ + for (String localeKey: locales) { + result.add(localeKey.trim()); + } + } + return result; + } + + public static String[] getFilteredLocaleNames(List<String> allLocaleNames, List<String> unsupportedDisplayLocales, + List<String> unsupportedLocalesFilter) { + List<String> result = new ArrayList<String>(); + result.addAll(allLocaleNames); + if (unsupportedDisplayLocales == null) { + unsupportedDisplayLocales = new ArrayList<String>(); + } + if (unsupportedLocalesFilter != null && !unsupportedLocalesFilter.isEmpty()) { + for (String unsupportedLocale: unsupportedLocalesFilter) { + unsupportedLocale = unsupportedLocale.trim(); + if (!unsupportedDisplayLocales.contains(unsupportedLocale)) { + result.remove(unsupportedLocale); + } + } + } + Collections.sort(result); + return result.toArray(new String[result.size()]); + } +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/view/AbstractLoginFormView.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/view/AbstractLoginFormView.java index 59ed186..7f6225c 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/view/AbstractLoginFormView.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/view/AbstractLoginFormView.java @@ -1,10 +1,13 @@ package org.ovirt.engine.ui.common.view; +import java.util.Arrays; + import org.gwtbootstrap3.client.ui.Label; import org.gwtbootstrap3.client.ui.ListBox; import org.gwtbootstrap3.client.ui.Well; import org.ovirt.engine.ui.common.CommonApplicationResources; import org.ovirt.engine.ui.common.idhandler.WithElementId; +import org.ovirt.engine.ui.common.utils.LocaleInfoData; import org.ovirt.engine.ui.common.widget.HasUiCommandClickHandlers; import org.ovirt.engine.ui.common.widget.PatternflyUiCommandButton; import org.ovirt.engine.ui.common.widget.editor.ListModelListBoxEditor; @@ -112,6 +115,8 @@ // Add the option to change the locale String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName(); String[] localeNames = LocaleInfo.getAvailableLocaleNames(); + localeNames = LocaleInfoData.getFilteredLocaleNames(Arrays.asList(localeNames), + LocaleInfoData.instance().getUnsupportedDisplayLocales(), LocaleInfoData.instance().getUnSupportedLocalesFilter()); // Populate the locale list box with available locales boolean foundDefaultLocale = false; diff --git a/frontend/webadmin/modules/pom.xml b/frontend/webadmin/modules/pom.xml index 211865d..2b735bc 100644 --- a/frontend/webadmin/modules/pom.xml +++ b/frontend/webadmin/modules/pom.xml @@ -204,7 +204,7 @@ <profile> <id>all-langs</id> <properties> - <gwt.locale>en_US,es_ES,fr_FR,ja_JP,pt_BR,zh_CN,de_DE,ko_KR</gwt.locale> + <gwt.locale>${gwt.availableLocales}</gwt.locale> </properties> </profile> <profile> diff --git a/frontend/webadmin/modules/userportal-gwtp/pom.xml b/frontend/webadmin/modules/userportal-gwtp/pom.xml index 99c869d..0a12fd2 100644 --- a/frontend/webadmin/modules/userportal-gwtp/pom.xml +++ b/frontend/webadmin/modules/userportal-gwtp/pom.xml @@ -204,6 +204,18 @@ <propertyExpansion>runNlsCheck=true</propertyExpansion> </configuration> </plugin> + <plugin> + <!-- Have to have this here as this dynamic property doesn't persist between poms so can't move it to parent --> + <groupId>com.github.goldin</groupId> + <artifactId>properties-maven-plugin</artifactId> + <version>0.2.5</version> + <configuration> + <property> + <name>gwt.availableLocales</name> + <value>{{ def bd=project.basedir; new File(db + 'backend/manager/modules/utils/src/main/resources/languages.properties').withInputStream { def prop = new Properties();prop.load(it);prop.keySet().sort().join(',')} }}</value> + </property> + </configuration> + </plugin> </plugins> </build> <profiles> diff --git a/frontend/webadmin/modules/webadmin/pom.xml b/frontend/webadmin/modules/webadmin/pom.xml index 706d3ca..13bcbb8 100644 --- a/frontend/webadmin/modules/webadmin/pom.xml +++ b/frontend/webadmin/modules/webadmin/pom.xml @@ -155,6 +155,18 @@ </resources> <plugins> <plugin> + <!-- Have to have this here as this dynamic property doesn't persist between poms so can't move it to parent --> + <groupId>com.github.goldin</groupId> + <artifactId>properties-maven-plugin</artifactId> + <version>0.2.5</version> + <configuration> + <property> + <name>gwt.availableLocales</name> + <value>{{ def bd=project.basedir; new File(db + 'backend/manager/modules/utils/src/main/resources/languages.properties').withInputStream { def prop = new Properties();prop.load(it);prop.keySet().sort().join(',')} }}</value> + </property> + </configuration> + </plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> -- To view, visit http://gerrit.ovirt.org/27973 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5b816694d6c34549360b189eb85c840688957bdb Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alexander Wels <aw...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches