Skip to content

Commit

Permalink
Merge branch 'master' into commcare_2.54
Browse files Browse the repository at this point in the history
  • Loading branch information
avazirna authored Oct 28, 2024
2 parents cc9cd15 + 7cc0932 commit 6eda5a3
Show file tree
Hide file tree
Showing 29 changed files with 426 additions and 151 deletions.
4 changes: 2 additions & 2 deletions .github/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ We try to keep both these branches in sync with each other the best we can. To d

1. If you are working on a Formplayer change, you will want to start by checking out `your_feature_branch` from `formplayer` as the base branch. Make changes on `your_feature_branch` and create your original PR against `formplayer` branch.

2. Now you will need to duplicate this PR by making another PR against `master`. Make sure the branch for this PR is not deleted. Then create the comment `duplicate this PR`. If the PR has already been merged, comment `duplicate this PR <starting-commit-id> <ending-commit-id>`. The `ending-commit-id` should be the last non-merge commit in the PR. This should result in a Github Actions workflow duplicating your PR against `master`. Go to the duplicate PR, close and re-open it to run the Github checks against it.
2. Now you will need to duplicate this PR by making another PR against `master`. Make sure the branch for this PR is is merged and is not deleted. Then create the comment `duplicate this PR <starting-commit-id> <ending-commit-id>`. The `ending-commit-id` should be the last non-merge commit in the PR. This should result in a Github Actions workflow duplicating your PR against `master`. Go to the duplicate PR, close and re-open it to run the Github checks against it.

3. In order for us to test that your PR against `master` doesn't break anything on CommCare Android, you need to run android side tests with your PR.
To do this -
Expand All @@ -23,7 +23,7 @@ To do this -

1. If you are working on a CommCare Android change, you will want to start by checking out `your_feature_branch` from `master` as the base branch. Make changes on `your_feature_branch` and create your original PR against `master` branch.

2. Now you will need to duplicate this PR by making another PR against `formplayer`. Make sure the branch for this PR is not deleted. Then create the comment `duplicate this PR`. If the PR has already been merged, comment `duplicate this PR <starting-commit-id> <ending-commit-id>`. The `ending-commit-id` should be the last non-merge commit in the PR. This should result in a Github Actions workflow duplicating your PR against `formplayer`. Go to the duplicate PR, close and re-open it to run the Github checks against it.
2. Now you will need to duplicate this PR by making another PR against `formplayer`. Make sure the branch for this PR is is merged and is not deleted. Then create the comment `duplicate this PR <starting-commit-id> <ending-commit-id>`. The `ending-commit-id` should be the last non-merge commit in the PR. This should result in a Github Actions workflow duplicating your PR against `formplayer`. Go to the duplicate PR, close and re-open it to run the Github checks against it.

3. In order for us to test that your PR against `formplayer` doesn't break anything on Formplayer, we need to run formplayer side tests with your PR.
To do this -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Holds essential meta data associated with the entity screen
*/
public class EntityScreenContext {
public class EntityScreenContext extends ScreenContext{
private final int mOffSet;
private final String mSearchText;
private final int mSortIndex;
Expand All @@ -21,6 +21,7 @@ public class EntityScreenContext {

public EntityScreenContext(int offset, String searchText, int sortIndex, int casesPerPage,
String[] selectedValues, String detailSelection, boolean isFuzzySearch) {
super(true);
mOffSet = offset;
mSearchText = searchText;
mSortIndex = sortIndex;
Expand All @@ -31,6 +32,11 @@ public EntityScreenContext(int offset, String searchText, int sortIndex, int cas
}

public EntityScreenContext() {
this(true);
}

public EntityScreenContext(boolean respectRelevancy) {
super(respectRelevancy);
mOffSet = 0;
mSearchText = null;
mSortIndex = 0;
Expand Down
14 changes: 14 additions & 0 deletions src/cli/java/org/commcare/util/screen/MenuScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ public boolean handleAutoMenuAdvance(SessionWrapper sessionWrapper, boolean resp
return false;
}

/**
* Checks whether a menu with given menuId exists and is a visible option on menu screen
* @param menuId id of the menu we want to check visiblility for
* @return true if menu exists and is visible, false otherwise
*/
public boolean isMenuVisible(String menuId) {
for (MenuDisplayable menuDisplayable : getMenuDisplayables()) {
if(menuDisplayable.getCommandID().contentEquals(menuId)){
return true;
}
}
return false;
}

class ScreenLogger implements LoggerInterface {

@Override
Expand Down
13 changes: 13 additions & 0 deletions src/cli/java/org/commcare/util/screen/ScreenContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.commcare.util.screen;
public class ScreenContext {

private boolean respectRelevancy;

public ScreenContext(boolean respectRelevancy) {
this.respectRelevancy = respectRelevancy;
}

public boolean isRespectRelevancy() {
return respectRelevancy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ public TreeReference getRef() {
return ref;
}

@Override
public void clearVolatiles() {
ref = null;
TreeElement cache = cache();
if (cache != null) {
cache.clearVolatiles();
}
}

//Context Sensitive Methods
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ public TreeReference getRef() {
return cachedRef;
}

@Override
public void clearVolatiles() {
cachedRef = null;
if (elements != null) {
for (T element : elements) {
element.clearVolatiles();
}
}
}

private void expireCachedRef() {
cachedRef = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public TreeReference getRef() {
return wrapped.getRef();
}

@Override
public void clearVolatiles() {
wrapped.clearVolatiles();
}

@Override
public String getName() {
return wrapped.getName();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/commcare/cases/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private static int LevenshteinDistance(String s0, String s1) {
for (int j = 1; j < len1; j++) {

// initial cost of skipping prefix in String s1
newcost[0] = j - 1;
newcost[0] = j;

// transformation cost for each letter in s0
for (int i = 1; i < len0; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface HttpResponseProcessor {
/**
* Http response was in the 200s
*/
void processSuccess(int responseCode, InputStream responseData);
void processSuccess(int responseCode, InputStream responseData, String apiVersion);

/**
* Http response was in the 400s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

public interface ResponseStreamAccessor {
InputStream getResponseStream() throws IOException;
String getApiVersion();
}
33 changes: 22 additions & 11 deletions src/main/java/org/commcare/core/network/ModernHttpRequester.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*
* @author Phillip Mates ([email protected])
*/
public class ModernHttpRequester implements ResponseStreamAccessor {
public class ModernHttpRequester {
/**
* How long to wait when opening network connection in milliseconds
*/
Expand Down Expand Up @@ -87,7 +87,23 @@ public void makeRequestAndProcess() {
}
try {
response = makeRequest();
processResponse(responseProcessor, response.code(), this);
final ModernHttpRequester requester = this;
processResponse(responseProcessor, response.code(), new ResponseStreamAccessor() {
/**
* Only gets called if response processor is supplied
* @return Input Stream from cache
* @throws IOException if an io error happens while reading or writing to cache
*/
@Override
public InputStream getResponseStream() throws IOException {
return requester.getResponseStream(response);
}

@Override
public String getApiVersion() {
return requester.getApiVersion();
}
});
} catch (IOException e) {
e.printStackTrace();
responseProcessor.handleIOException(e);
Expand Down Expand Up @@ -153,7 +169,8 @@ public static void processResponse(HttpResponseProcessor responseProcessor,
responseProcessor.handleIOException(e);
return;
}
responseProcessor.processSuccess(responseCode, responseStream);
String apiVersion = streamAccessor.getApiVersion();
responseProcessor.processSuccess(responseCode, responseStream, apiVersion);
} finally {
StreamsUtil.closeStream(responseStream);
}
Expand Down Expand Up @@ -181,14 +198,8 @@ public InputStream getResponseStream(Response<ResponseBody> response) throws IOE
return cache.retrieveCache();
}

/**
* Only gets called if response processor is supplied
* @return Input Stream from cache
* @throws IOException if an io error happens while reading or writing to cache
*/
@Override
public InputStream getResponseStream() throws IOException {
return getResponseStream(response);
public String getApiVersion() {
return response != null ? response.headers().get("x-api-current-version") : null;
}

public static RequestBody getPostBody(Multimap<String, String> inputs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,15 @@ protected InstanceRoot setupSessionData(ExternalDataInstance instance) {
TreeElement root =
SessionInstanceBuilder.getSessionInstance(sessionWrapper.getFrame(), getDeviceId(),
getVersionString(), getCurrentDrift(), u.getUsername(), u.getUniqueId(),
u.getProperties());
u.getProperties(), getWindowWidth());
root.setParent(instance.getBase());
return new ConcreteInstanceRoot(root);
}

protected String getWindowWidth() {
return sessionWrapper.getWindowWidth();
}

protected long getCurrentDrift() {
return 0;
}
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/org/commcare/modern/session/SessionWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,26 @@ public class SessionWrapper extends CommCareSession implements SessionWrapperInt
final protected CommCarePlatform mPlatform;
protected CommCareInstanceInitializer initializer;
protected RemoteInstanceFetcher remoteInstanceFetcher;
/**
* A string representing the width of the user's screen in pixels.
* To be used in a display condition determining what content to show to the user.
*/
private String windowWidth;

public SessionWrapper(CommCareSession session, CommCarePlatform platform, UserSandbox sandbox,
RemoteInstanceFetcher remoteInstanceFetcher) {
this(platform, sandbox, remoteInstanceFetcher);
RemoteInstanceFetcher remoteInstanceFetcher, String windowWidth) {
this(platform, sandbox, remoteInstanceFetcher, windowWidth);
this.frame = session.getFrame();
this.setFrameStack(session.getFrameStack());
}


public SessionWrapper(CommCareSession session, CommCarePlatform platform, UserSandbox sandbox, String windowWidth) {
this(session, platform, sandbox, null, windowWidth);
}

public SessionWrapper(CommCareSession session, CommCarePlatform platform, UserSandbox sandbox) {
this(session, platform, sandbox, null);
this(session, platform, sandbox, null, null);
}

public SessionWrapper(CommCarePlatform platform, UserSandbox sandbox) {
Expand All @@ -43,11 +52,12 @@ public SessionWrapper(CommCarePlatform platform, UserSandbox sandbox) {
this.mPlatform = platform;
}

public SessionWrapper(CommCarePlatform platform, UserSandbox sandbox, RemoteInstanceFetcher remoteInstanceFetcher) {
public SessionWrapper(CommCarePlatform platform, UserSandbox sandbox, RemoteInstanceFetcher remoteInstanceFetcher, String windowWidth) {
super(platform);
this.mSandbox = sandbox;
this.mPlatform = platform;
this.remoteInstanceFetcher = remoteInstanceFetcher;
this.windowWidth = windowWidth;
}

/**
Expand Down Expand Up @@ -119,4 +129,8 @@ public void stepBack() {
public RemoteInstanceFetcher getRemoteInstanceFetcher() {
return remoteInstanceFetcher;
}

public String getWindowWidth() {
return this.windowWidth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class SessionInstanceBuilder {
public static TreeElement getSessionInstance(SessionFrame frame, String deviceId,
String appversion, long drift,
String username, String userId,
Hashtable<String, String> userFields) {
Hashtable<String, String> userFields, String windowWidth) {
TreeElement sessionRoot = new TreeElement("session", 0);

addSessionNavData(sessionRoot, frame);
addMetadata(sessionRoot, deviceId, appversion, username, userId, drift);
addMetadata(sessionRoot, deviceId, appversion, username, userId, drift, windowWidth);
addUserProperties(sessionRoot, userFields);

return sessionRoot;
Expand Down Expand Up @@ -88,14 +88,15 @@ private static String getCalloutSearchResultCount(StackFrameStep step) {

private static void addMetadata(TreeElement sessionRoot, String deviceId,
String appversion, String username,
String userId, long drift) {
String userId, long drift, String windowWidth) {
TreeElement sessionMeta = new TreeElement("context", 0);

addData(sessionMeta, "deviceid", deviceId);
addData(sessionMeta, "appversion", appversion);
addData(sessionMeta, "username", username);
addData(sessionMeta, "userid", userId);
addData(sessionMeta, "drift", String.valueOf(drift));
addData(sessionMeta, "window_width", windowWidth);

sessionRoot.addChild(sessionMeta);
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/javarosa/core/model/FormDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Vector;

Expand Down Expand Up @@ -1855,4 +1854,13 @@ public String dispatchSendCallout(String url, Multimap<String, String> paramMap)
return sendCalloutHandler.performHttpCalloutForResponse(url, paramMap);
}
}

// Checks if the form element at given form Index belongs to a non counted repeat
public boolean isNonCountedRepeat(FormIndex formIndex) {
IFormElement currentElement = getChild(formIndex);
if (currentElement instanceof GroupDef && ((GroupDef)currentElement).isRepeat()) {
return ((GroupDef)currentElement).getCountReference() == null;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public interface AbstractTreeElement<T extends AbstractTreeElement> {

String getNamespace();

// clear any cache maintained by the TreeElement implementation
void clearVolatiles();

/**
* TODO: Worst method name ever. Don't use this unless you know what's up.
* @param predicates possibly list of predicates to be evaluated. predicates will be removed from list if they are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,20 @@ public TreeReference getRef() {
return refCache;
}

@Override
public void clearVolatiles() {
refCache = null;
if (children != null) {
for (T child : children) {
child.clearVolatiles();
}
}
if (attributes != null) {
for (T attribute : attributes) {
attribute.clearVolatiles();
}
}
}

@Override
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ public void setCacheHost(CacheHost cacheHost) {
this.mCacheHost = cacheHost;
}

/**
* Cleans reference caches maintained by the instance and TreeElements contained in the contextNode
*/
public void cleanCache() {
referenceCache.clear();
getBase().clearVolatiles();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ public TreeReference getRef() {
return TreeReference.rootRef();
}

@Override
public void clearVolatiles() {
if (child != null) {
child.clearVolatiles();
}
}

@Override
public String getName() {
return null;
Expand Down
Loading

0 comments on commit 6eda5a3

Please sign in to comment.