Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially reverse "Make language slug available via session metadata" #1447

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/cli/java/org/commcare/util/screen/EntityScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -44,7 +42,6 @@ public EntityScreenContext(boolean respectRelevancy) {
mSortIndex = 0;
mCasesPerPage = DEFAULT_CASES_PER_PAGE;
mSelectedValues = null;
mLocale = null;
mDetailSelection = null;
fuzzySearch = false;
}
Expand All @@ -69,10 +66,6 @@ public String[] getSelectedValues() {
return mSelectedValues;
}

public String getLocale() {
return mLocale;
}

public String getDetailSelection() {
return mDetailSelection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) {
Expand Down Expand Up @@ -236,15 +236,15 @@ 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!");
}
User u = mSandbox.getLoggedInUserUnsafe();
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);
}
Expand All @@ -253,6 +253,10 @@ protected String getWindowWidth() {
return sessionWrapper.getWindowWidth();
}

protected String getLocale() {
return Localization.getCurrentLocale();
}

protected long getCurrentDrift() {
return 0;
}
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/org/commcare/modern/session/SessionWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> instancesToInclude) {
return getEvaluationContext(getIIF(), commandId, instancesToInclude, null);
return getEvaluationContext(getIIF(), commandId, instancesToInclude);
}

@Override
Expand All @@ -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() {
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/org/commcare/session/CommCareSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -630,8 +626,7 @@ public EvaluationContext getEvaluationContext(InstanceInitializationFactory iif,
*/
public EvaluationContext getEvaluationContext(InstanceInitializationFactory iif,
String command,
Set<String> instancesToInclude,
String locale) {
Set<String> instancesToInclude) {
if (command == null) {
return new EvaluationContext(null);
}
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/javarosa/core/model/FormDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ExternalDataInstance getSpecializedExternalDataInstance(ExternalDataInsta
}

@Nonnull
public InstanceRoot generateRoot(ExternalDataInstance instance, String locale) {
public InstanceRoot generateRoot(ExternalDataInstance instance) {
return ConcreteInstanceRoot.NULL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Loading