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

Make language slug available via session metadata #1630

Merged
merged 10 commits into from
Oct 23, 2024
2 changes: 1 addition & 1 deletion libs/commcare
Submodule commcare updated 23 files
+6 −2 src/cli/java/org/commcare/util/screen/EntityScreen.java
+8 −1 src/cli/java/org/commcare/util/screen/EntityScreenContext.java
+4 −0 src/cli/java/org/commcare/util/screen/SyncScreen.java
+1 −1 src/main/java/org/commcare/cases/util/StringUtils.java
+4 −0 src/main/java/org/commcare/core/network/CommCareNetworkServiceGenerator.java
+4 −4 src/main/java/org/commcare/core/process/CommCareInstanceInitializer.java
+6 −2 src/main/java/org/commcare/modern/session/SessionWrapper.java
+8 −3 src/main/java/org/commcare/session/CommCareSession.java
+14 −2 src/main/java/org/commcare/session/RemoteQuerySessionManager.java
+6 −3 src/main/java/org/commcare/session/SessionInstanceBuilder.java
+81 −0 src/main/java/org/commcare/util/DateRangeUtils.java
+3 −1 src/main/java/org/commcare/util/LogTypes.java
+1 −1 src/main/java/org/javarosa/core/model/FormDef.java
+1 −1 src/main/java/org/javarosa/core/model/instance/DataInstance.java
+6 −2 src/main/java/org/javarosa/core/model/instance/ExternalDataInstance.java
+5 −1 src/main/java/org/javarosa/core/model/instance/FormInstance.java
+1 −1 src/main/java/org/javarosa/core/model/instance/InstanceInitializationFactory.java
+2 −2 src/test/java/org/commcare/backend/suite/model/test/QueryModelTests.java
+1 −1 src/test/java/org/commcare/test/utilities/TestInstanceInitializer.java
+18 −0 src/test/java/org/commcare/util/DateRangeUtilsTest.java
+3 −0 src/test/java/org/commcare/util/reference/test/FuzzySearchTest.java
+1 −1 src/test/java/org/javarosa/core/model/instance/test/DummyInstanceInitializationFactory.java
+1 −1 src/translate/java/org/javarosa/engine/MockupProviderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public EntityDetailListResponse getDetails(@RequestBody SessionNavigationBean se
sessionNavigationBean.getCasesPerPage(),
sessionNavigationBean.getSelectedValues(),
null,
null,
isFuzzySearch);
BaseResponseBean baseResponseBean = runnerService.advanceSessionWithSelections(menuSession,
sessionNavigationBean.getSelections(),
Expand Down Expand Up @@ -110,6 +111,7 @@ public EntityDetailListResponse getDetails(@RequestBody SessionNavigationBean se
sessionNavigationBean.getSortIndex(),
sessionNavigationBean.getCasesPerPage(),
sessionNavigationBean.getSelectedValues(),
null,
detailSelection,
isFuzzySearch);
BaseResponseBean baseResponseBean = runnerService.advanceSessionWithSelections(
Expand Down Expand Up @@ -165,6 +167,7 @@ public EntityDetailListResponse getDetails(@RequestBody SessionNavigationBean se
public BaseResponseBean navigateSessionWithAuth(@RequestBody SessionNavigationBean sessionNavigationBean,
@CookieValue(Constants.POSTGRES_DJANGO_SESSION_ID) String authToken,
HttpServletRequest request) throws Exception {
String locale = sessionNavigationBean.getLocale();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does HQ get to know of current locale to send here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly not too sure! I just assumed all navigation request included the locale in the request body which gets set when initializing the sessionNavigationBean. Happy to be told otherwise but it's been accurately giving me the correct locale so far.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean HQ was already sending the current locale in the request body without us having to make a corresponding HQ change here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I believe so!

String[] selections = sessionNavigationBean.getSelections();
if (selections == null) {
selections = new String[0];
Expand All @@ -175,6 +178,7 @@ public BaseResponseBean navigateSessionWithAuth(@RequestBody SessionNavigationBe
sessionNavigationBean.getSortIndex(),
sessionNavigationBean.getCasesPerPage(),
sessionNavigationBean.getSelectedValues(),
locale,
null,
storageFactory.getPropertyManager().isFuzzySearchEnabled());
BaseResponseBean response = runnerService.advanceSessionWithSelections(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public EntityDetailResponse(Detail detail,
String title,
boolean isFuzzySearchEnabled) {
EntityScreenContext entityScreenContext = new EntityScreenContext(0, null, 0, Integer.MAX_VALUE, null,
null, isFuzzySearchEnabled);
null, null, isFuzzySearchEnabled);
TreeReference[] refs = references.toArray(new TreeReference[references.size()]);
List<Entity<TreeReference>> entityRefs = EntityScreenHelper.initEntities(ec, detail, entityScreenContext,
refs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import org.javarosa.core.model.instance.ExternalDataInstance;
import org.javarosa.core.model.instance.InstanceRoot;
import org.javarosa.core.model.instance.TreeElement;
import org.javarosa.core.services.locale.Localization;

import java.util.Arrays;
import java.util.Hashtable;

/**
Expand Down Expand Up @@ -50,7 +52,7 @@ protected InstanceRoot setupCaseData(ExternalDataInstance instance) {
}

@Override
protected InstanceRoot setupSessionData(ExternalDataInstance instance) {
protected InstanceRoot setupSessionData(ExternalDataInstance instance, String locale) {
if (this.mPlatform == null) {
throw new RuntimeException("Cannot generate session instance with undeclared platform!");
}
Expand All @@ -61,10 +63,22 @@ protected InstanceRoot setupSessionData(ExternalDataInstance instance) {

Hashtable<String, String> userProperties = u.getProperties();

String appLang = locale;
String[] locales = Localization.getGlobalLocalizerAdvanced().getAvailableLocales();
if (appLang == null || !Arrays.asList(locales).contains(appLang)) {
// the ordering is always ['default', <true default slug>, <all other slugs in order they were added>]
if (locales.length >= 2) {
appLang = locales[1];
} else {
// to pass tests
appLang = locales[0];
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My read of the code here is you are trying to get the current selected locale ? If so, think we can use Localization.getCurrentLocale() directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish I had known about this function sooner because this is doing exactly what I was looking to do from the start, without having to do all the unnecessary steps of passing the locale to the root generator function... I might end up reverting the commcare-core PR :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


TreeElement root =
SessionInstanceBuilder.getSessionInstance(sessionWrapper.getFrame(), getDeviceId(),
getVersionString(), getCurrentDrift(), u.getUsername(), u.getUniqueId(),
userProperties, getWindowWidth());
userProperties, getWindowWidth(), appLang);
root.setParent(instance.getBase());
return new ConcreteInstanceRoot(root);
}
Expand Down
Loading