diff --git a/src/cli/java/org/commcare/util/screen/EntityScreen.java b/src/cli/java/org/commcare/util/screen/EntityScreen.java index 48991212a7..5768fc875d 100755 --- a/src/cli/java/org/commcare/util/screen/EntityScreen.java +++ b/src/cli/java/org/commcare/util/screen/EntityScreen.java @@ -233,12 +233,8 @@ protected void setSession(SessionWrapper session) throws CommCareSessionExceptio if (mShortDetail == null) { throw new CommCareSessionException("Missing detail definition for: " + detailId); } - EntityScreenContext context = getEntityScreenContext(); - String locale = null; - if (context != null) { - locale = context.getLocale(); - } - evalContext = mSession.getEvaluationContextWithLocale(locale); + + evalContext = mSession.getEvaluationContext(); } @Trace diff --git a/src/cli/java/org/commcare/util/screen/EntityScreenContext.java b/src/cli/java/org/commcare/util/screen/EntityScreenContext.java index 562963b7d2..4a8f5735d7 100644 --- a/src/cli/java/org/commcare/util/screen/EntityScreenContext.java +++ b/src/cli/java/org/commcare/util/screen/EntityScreenContext.java @@ -9,7 +9,6 @@ public class EntityScreenContext extends ScreenContext{ private final int mSortIndex; private final int mCasesPerPage; private final String[] mSelectedValues; - private final String mLocale; /** * If requesting a case detail will be a case id, else null. When the case id is given it is used to short @@ -21,14 +20,13 @@ public class EntityScreenContext extends ScreenContext{ private final boolean fuzzySearch; public EntityScreenContext(int offset, String searchText, int sortIndex, int casesPerPage, - String[] selectedValues, String locale, String detailSelection, boolean isFuzzySearch) { + String[] selectedValues, String detailSelection, boolean isFuzzySearch) { super(true); mOffSet = offset; mSearchText = searchText; mSortIndex = sortIndex; mCasesPerPage = casesPerPage == 0 ? DEFAULT_CASES_PER_PAGE : casesPerPage; mSelectedValues = selectedValues; - mLocale = locale; mDetailSelection = detailSelection; fuzzySearch = isFuzzySearch; } @@ -44,7 +42,6 @@ public EntityScreenContext(boolean respectRelevancy) { mSortIndex = 0; mCasesPerPage = DEFAULT_CASES_PER_PAGE; mSelectedValues = null; - mLocale = null; mDetailSelection = null; fuzzySearch = false; } @@ -69,10 +66,6 @@ public String[] getSelectedValues() { return mSelectedValues; } - public String getLocale() { - return mLocale; - } - public String getDetailSelection() { return mDetailSelection; } diff --git a/src/main/java/org/commcare/core/process/CommCareInstanceInitializer.java b/src/main/java/org/commcare/core/process/CommCareInstanceInitializer.java index 165dbbc4d9..467708c978 100644 --- a/src/main/java/org/commcare/core/process/CommCareInstanceInitializer.java +++ b/src/main/java/org/commcare/core/process/CommCareInstanceInitializer.java @@ -74,7 +74,7 @@ public ExternalDataInstance getSpecializedExternalDataInstance(ExternalDataInsta @Override @Nonnull - public InstanceRoot generateRoot(ExternalDataInstance instance, String locale) { + public InstanceRoot generateRoot(ExternalDataInstance instance) { String ref = instance.getReference(); if (ref.contains(LedgerInstanceTreeElement.MODEL_NAME)) { return setupLedgerData(instance); @@ -83,7 +83,7 @@ public InstanceRoot generateRoot(ExternalDataInstance instance, String locale) { } else if (ref.contains("fixture")) { return setupFixtureData(instance); } else if (instance.getReference().contains("session")) { - return setupSessionData(instance, locale); + return setupSessionData(instance); } else if (ref.startsWith(ExternalDataInstance.JR_REMOTE_REFERENCE)) { return setupExternalDataInstance(instance, ref, SessionFrame.STATE_QUERY_REQUEST); } else if (ref.startsWith(JR_SELECTED_ENTITIES_REFERENCE)) { @@ -236,7 +236,7 @@ protected TreeElement loadFixtureRoot(ExternalDataInstance instance, } } - protected InstanceRoot setupSessionData(ExternalDataInstance instance, String locale) { + protected InstanceRoot setupSessionData(ExternalDataInstance instance) { if (this.mPlatform == null) { throw new RuntimeException("Cannot generate session instance with undeclared platform!"); } @@ -244,7 +244,7 @@ protected InstanceRoot setupSessionData(ExternalDataInstance instance, String lo TreeElement root = SessionInstanceBuilder.getSessionInstance(sessionWrapper.getFrame(), getDeviceId(), getVersionString(), getCurrentDrift(), u.getUsername(), u.getUniqueId(), - u.getProperties(), getWindowWidth(), locale); + u.getProperties(), getWindowWidth(), getLocale()); root.setParent(instance.getBase()); return new ConcreteInstanceRoot(root); } @@ -253,6 +253,10 @@ protected String getWindowWidth() { return sessionWrapper.getWindowWidth(); } + protected String getLocale() { + return Localization.getCurrentLocale(); + } + protected long getCurrentDrift() { return 0; } diff --git a/src/main/java/org/commcare/modern/session/SessionWrapper.java b/src/main/java/org/commcare/modern/session/SessionWrapper.java index 3885a328ef..53c205da03 100644 --- a/src/main/java/org/commcare/modern/session/SessionWrapper.java +++ b/src/main/java/org/commcare/modern/session/SessionWrapper.java @@ -63,14 +63,10 @@ public EvaluationContext getEvaluationContext() { return getEvaluationContext(getIIF()); } - public EvaluationContext getEvaluationContextWithLocale(String locale) { - return getEvaluationContext(getIIF(), locale); - } - @Override public EvaluationContext getRestrictedEvaluationContext(String commandId, Set instancesToInclude) { - return getEvaluationContext(getIIF(), commandId, instancesToInclude, null); + return getEvaluationContext(getIIF(), commandId, instancesToInclude); } @Override @@ -85,7 +81,7 @@ public EvaluationContext getEvaluationContextWithAccumulatedInstances(String com * @return The evaluation context relevant for the provided command id */ public EvaluationContext getEvaluationContext(String commandId) { - return getEvaluationContext(getIIF(), commandId, null, null); + return getEvaluationContext(getIIF(), commandId, null); } public CommCareInstanceInitializer getIIF() { diff --git a/src/main/java/org/commcare/session/CommCareSession.java b/src/main/java/org/commcare/session/CommCareSession.java index 312881e973..76b5cb7bcd 100644 --- a/src/main/java/org/commcare/session/CommCareSession.java +++ b/src/main/java/org/commcare/session/CommCareSession.java @@ -614,11 +614,7 @@ public void clearAllState() { * @return Evaluation context for current session state */ public EvaluationContext getEvaluationContext(InstanceInitializationFactory iif) { - return this.getEvaluationContext(iif, getCommand(), null, null); - } - - public EvaluationContext getEvaluationContext(InstanceInitializationFactory iif, String locale) { - return this.getEvaluationContext(iif, getCommand(), null, locale); + return this.getEvaluationContext(iif, getCommand(), null); } /** @@ -630,8 +626,7 @@ public EvaluationContext getEvaluationContext(InstanceInitializationFactory iif, */ public EvaluationContext getEvaluationContext(InstanceInitializationFactory iif, String command, - Set instancesToInclude, - String locale) { + Set instancesToInclude) { if (command == null) { return new EvaluationContext(null); } @@ -666,7 +661,7 @@ public EvaluationContext getEvaluationContext(InstanceInitializationFactory iif, for (Enumeration en = instancesInScope.keys(); en.hasMoreElements(); ) { String key = (String)en.nextElement(); - instancesInScope.put(key, instancesInScope.get(key).initialize(iif, key, locale)); + instancesInScope.put(key, instancesInScope.get(key).initialize(iif, key)); } addInstancesFromFrame(instancesInScope, iif); diff --git a/src/main/java/org/javarosa/core/model/FormDef.java b/src/main/java/org/javarosa/core/model/FormDef.java index 167b02ff9c..30b86e31b2 100755 --- a/src/main/java/org/javarosa/core/model/FormDef.java +++ b/src/main/java/org/javarosa/core/model/FormDef.java @@ -1451,7 +1451,7 @@ public void initialize(boolean newInstance, boolean isCompletedInstance, Instanc for (Enumeration en = formInstances.keys(); en.hasMoreElements(); ) { String instanceId = (String)en.nextElement(); DataInstance instance = formInstances.get(instanceId); - formInstances.put(instanceId, instance.initialize(factory, instanceId, null)); + formInstances.put(instanceId, instance.initialize(factory, instanceId)); } setEvaluationContext(this.exprEvalContext); diff --git a/src/main/java/org/javarosa/core/model/instance/DataInstance.java b/src/main/java/org/javarosa/core/model/instance/DataInstance.java index b9ab8c9260..724f2e7cd7 100644 --- a/src/main/java/org/javarosa/core/model/instance/DataInstance.java +++ b/src/main/java/org/javarosa/core/model/instance/DataInstance.java @@ -279,7 +279,7 @@ public void setID(int recordid) { this.recordid = recordid; } - public abstract DataInstance initialize(InstanceInitializationFactory initializer, String instanceId, String locale); + public abstract DataInstance initialize(InstanceInitializationFactory initializer, String instanceId); public CacheHost getCacheHost() { return mCacheHost; diff --git a/src/main/java/org/javarosa/core/model/instance/ExternalDataInstance.java b/src/main/java/org/javarosa/core/model/instance/ExternalDataInstance.java index e11d7c89ed..93a25493fd 100644 --- a/src/main/java/org/javarosa/core/model/instance/ExternalDataInstance.java +++ b/src/main/java/org/javarosa/core/model/instance/ExternalDataInstance.java @@ -137,19 +137,15 @@ public void writeExternal(DataOutputStream out) throws IOException { } @Override - public DataInstance initialize(InstanceInitializationFactory initializer, String instanceId, String locale) { + public DataInstance initialize(InstanceInitializationFactory initializer, String instanceId) { base = new InstanceBase(instanceId); - InstanceRoot instanceRoot = initializer.generateRoot(this, locale); + InstanceRoot instanceRoot = initializer.generateRoot(this); // this indirectly calls `this.copyFromSource` via the InstanceRoot so that we call the // correct method based on the type instanceRoot.setupNewCopy(this); return initializer.getSpecializedExternalDataInstance(this); } - public DataInstance initialize(InstanceInitializationFactory initializer, String instanceId) { - return initialize(initializer, instanceId, null); - } - public void copyFromSource(InstanceRoot instanceRoot) { root = instanceRoot.getRoot(); base.setChild(root); diff --git a/src/main/java/org/javarosa/core/model/instance/FormInstance.java b/src/main/java/org/javarosa/core/model/instance/FormInstance.java index 462a6b098f..fef23d147d 100644 --- a/src/main/java/org/javarosa/core/model/instance/FormInstance.java +++ b/src/main/java/org/javarosa/core/model/instance/FormInstance.java @@ -245,17 +245,13 @@ public static boolean isHomogeneous(TreeElement a, TreeElement b) { } @Override - public DataInstance initialize(InstanceInitializationFactory initializer, String instanceId, String locale) { + public DataInstance initialize(InstanceInitializationFactory initializer, String instanceId) { this.instanceid = instanceId; root.setInstanceName(instanceId); return this; } - public DataInstance initialize(InstanceInitializationFactory initializer, String instanceId) { - return initialize(initializer, instanceId, null); - } - @Override public String[] getMetaDataFields() { return new String[]{META_XMLNS, META_ID}; diff --git a/src/main/java/org/javarosa/core/model/instance/InstanceInitializationFactory.java b/src/main/java/org/javarosa/core/model/instance/InstanceInitializationFactory.java index 47f5bac03f..f22c9627a4 100644 --- a/src/main/java/org/javarosa/core/model/instance/InstanceInitializationFactory.java +++ b/src/main/java/org/javarosa/core/model/instance/InstanceInitializationFactory.java @@ -17,7 +17,7 @@ public ExternalDataInstance getSpecializedExternalDataInstance(ExternalDataInsta } @Nonnull - public InstanceRoot generateRoot(ExternalDataInstance instance, String locale) { + public InstanceRoot generateRoot(ExternalDataInstance instance) { return ConcreteInstanceRoot.NULL; } } diff --git a/src/test/java/org/commcare/backend/suite/model/test/QueryModelTests.java b/src/test/java/org/commcare/backend/suite/model/test/QueryModelTests.java index 9daf61d4e0..a71191b5cf 100644 --- a/src/test/java/org/commcare/backend/suite/model/test/QueryModelTests.java +++ b/src/test/java/org/commcare/backend/suite/model/test/QueryModelTests.java @@ -78,12 +78,12 @@ public void testScreenCreatesVirtualInstance() throws Exception { // test loading instance with new ref ExternalDataInstance instance = new ExternalDataInstance("jr://instance/search-input/registry1", "custom-id"); - Assert.assertNotNull(session.getIIF().generateRoot(instance, null).getRoot()); + Assert.assertNotNull(session.getIIF().generateRoot(instance).getRoot()); // test that we can still load instances using the legacy ref ExternalDataInstance legacyInstance = new ExternalDataInstance("jr://instance/search-input", "search-input:registry1"); - Assert.assertNotNull(session.getIIF().generateRoot(legacyInstance, null).getRoot()); + Assert.assertNotNull(session.getIIF().generateRoot(legacyInstance).getRoot()); } @NotNull diff --git a/src/test/java/org/commcare/test/utilities/TestInstanceInitializer.java b/src/test/java/org/commcare/test/utilities/TestInstanceInitializer.java index 6ed5c96e99..00e83a8997 100644 --- a/src/test/java/org/commcare/test/utilities/TestInstanceInitializer.java +++ b/src/test/java/org/commcare/test/utilities/TestInstanceInitializer.java @@ -31,7 +31,7 @@ public ExternalDataInstance getSpecializedExternalDataInstance(ExternalDataInsta } @Override - public InstanceRoot generateRoot(ExternalDataInstance instance, String locale) { + public InstanceRoot generateRoot(ExternalDataInstance instance) { String ref = instance.getReference(); if (ref.contains(CaseInstanceTreeElement.MODEL_NAME)) { CaseInstanceTreeElement root = new CaseInstanceTreeElement(instance.getBase(), sandbox.getCaseStorage()); diff --git a/src/test/java/org/javarosa/core/model/instance/test/DummyInstanceInitializationFactory.java b/src/test/java/org/javarosa/core/model/instance/test/DummyInstanceInitializationFactory.java index 07eacf0c27..c70ba9b2ab 100644 --- a/src/test/java/org/javarosa/core/model/instance/test/DummyInstanceInitializationFactory.java +++ b/src/test/java/org/javarosa/core/model/instance/test/DummyInstanceInitializationFactory.java @@ -18,7 +18,7 @@ public ExternalDataInstance getSpecializedExternalDataInstance(ExternalDataInsta return instance; } @Override - public InstanceRoot generateRoot(ExternalDataInstance instance, String locale) { + public InstanceRoot generateRoot(ExternalDataInstance instance) { throw new RuntimeException("Loading external instances isn't supported " + "using this instance initialization factory."); } diff --git a/src/translate/java/org/javarosa/engine/MockupProviderFactory.java b/src/translate/java/org/javarosa/engine/MockupProviderFactory.java index 5c09a0e33a..4a2eb209c6 100644 --- a/src/translate/java/org/javarosa/engine/MockupProviderFactory.java +++ b/src/translate/java/org/javarosa/engine/MockupProviderFactory.java @@ -29,7 +29,7 @@ public ExternalDataInstance getSpecializedExternalDataInstance(ExternalDataInsta } @Override - public InstanceRoot generateRoot(ExternalDataInstance instance, String locale) { + public InstanceRoot generateRoot(ExternalDataInstance instance) { String ref = instance.getReference(); if(instances.containsKey(ref)) {