Skip to content

Commit

Permalink
logging for autoselect bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Jtang-1 committed Nov 14, 2024
1 parent e410ccf commit a6cd6ad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cli/java/org/commcare/util/screen/EntityScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public EntityScreen(boolean handleCaseIndex, boolean needsFullInit, SessionWrapp
public void evaluateAutoLaunch(String nextInput) throws CommCareSessionException {
EvaluationContext subContext = getAutoLaunchEvaluationContext(nextInput);
for (Action action : mShortDetail.getCustomActions(evalContext)) {
System.out.println("in evaluateAutoLaunch, action: " + action);
if (action.isAutoLaunchAction(subContext)) {
// Supply an empty case list so we can "select" from it later using getEntityFromID
mCurrentScreen = new EntityListSubscreen(mShortDetail, new Vector<>(), evalContext,
Expand Down Expand Up @@ -235,10 +236,13 @@ protected void setSession(SessionWrapper session) throws CommCareSessionExceptio
}

evalContext = mSession.getEvaluationContext();
System.out.println("in setSession, evalContext: " + evalContext);
}

@Trace
private Vector<TreeReference> expandEntityReferenceSet(EvaluationContext context) {
System.out.println("in expandEntityReferenceSet, mNeededDatum: " + mNeededDatum);
System.out.println("in expandEntityReferenceSet, mNeededDatum.getNodeset(): " + mNeededDatum.getNodeset());
return evalContext.expandReference(mNeededDatum.getNodeset());
}

Expand Down Expand Up @@ -506,6 +510,8 @@ public boolean evalAndExecuteAutoLaunchAction(String nextInput, CommCareSession
throws CommCareSessionException {
evaluateAutoLaunch(nextInput);
if (getAutoLaunchAction() != null) {
// JT NOTE for some reason, when autoselect for entry datum is true, this evaluates to false
// when autoselect for entry datum is false, it evaluates to true
setPendingAction(getAutoLaunchAction());
executePendingAction(session);
return true;
Expand Down
11 changes: 11 additions & 0 deletions src/cli/java/org/commcare/util/screen/MultiSelectEntityScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import java.util.Arrays;

/**
* Variation of EntityScreen to allow for selection of multiple entities at once
*/
Expand Down Expand Up @@ -70,21 +72,28 @@ public void updateSelection(String input, TreeReference[] selectedRefs)

@Override
protected boolean shouldAutoSelect() {
// System.out.println("in show autoselect");
// System.out.println("mneededdatum " + mNeededDatum);
return mNeededDatum.isAutoSelectEnabled() && references.size() != 0;
}

@Override
public boolean autoSelectEntities(SessionWrapper session) {
System.out.println("Starting autoSelectEntities with " + references.size() + " references");
int selectionSize = references.size();
if (validateSelectionSize(selectionSize)) {
System.out.println("Selection size " + selectionSize + " validated successfully");
String[] evaluatedValues = new String[selectionSize];
for (int i = 0; i < selectionSize; i++) {
evaluatedValues[i] = getReturnValueFromSelection(references.elementAt(i));
System.out.println("Evaluated value " + (i + 1) + ": " + evaluatedValues[i]);
}
processSelectionIntoInstance(evaluatedValues, getNeededDatumId());
System.out.println("Processed selection into instance with datum ID: " + getNeededDatumId());
updateSession(session);
return true;
}
System.out.println("Auto-selection failed validation check");
return false;
}

Expand Down Expand Up @@ -169,6 +178,8 @@ private void processSelectedValues(String[] selectedValues)
TreeReference currentReference = getAndValidateEntityReference(selectedValues[i]);
evaluatedValues[i] = getReturnValueFromSelection(currentReference);
}
System.out.println("in processSelectedValues, evaluatedValues: " + Arrays.toString(evaluatedValues));
System.out.println("in processSelectedValues, getNeededDatumId(): " + getNeededDatumId());
processSelectionIntoInstance(evaluatedValues, getNeededDatumId());
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/commcare/suite/model/EntityDatum.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,13 @@ public TreeReference getEntityFromID(EvaluationContext ec, String elementId) {
return null;
}
}

@Override
public String toString() {
return "EntityDatum{" +
"nodeset=" + nodeset +
", shortDetail='" + shortDetail + '\'' +
", autoSelectEnabled=" + autoSelectEnabled +
'}';
}
}

0 comments on commit a6cd6ad

Please sign in to comment.