Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import org.commcare.formplayer.beans.ResponseMetaData;
import org.commcare.formplayer.beans.SessionNavigationBean;
import org.commcare.formplayer.beans.SubmitResponseBean;
import org.commcare.formplayer.beans.menus.BaseResponseBean;
import org.commcare.formplayer.beans.menus.EntityDetailListResponse;
import org.commcare.formplayer.beans.menus.EntityDetailResponse;
import org.commcare.formplayer.beans.menus.LocationRelevantResponseBean;
import org.commcare.formplayer.beans.menus.*;
import org.commcare.formplayer.services.FormplayerStorageFactory;
import org.commcare.formplayer.services.MenuSessionFactory;
import org.commcare.formplayer.services.ResponseMetaDataTracker;
Expand All @@ -35,6 +32,8 @@
import org.springframework.web.server.ResponseStatusException;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

import jakarta.servlet.http.HttpServletRequest;

Expand Down Expand Up @@ -185,6 +184,8 @@ public BaseResponseBean navigateSessionWithAuth(@RequestBody SessionNavigationBe
sessionNavigationBean.getFormSessionId()
);

logCaseTypeColumnIfPresent(response, "controller", log);

setResponseMetaData(response);

SubmitResponseBean formSubmissionResponse = handleAutoFormSubmission(request, sessionNavigationBean,
Expand All @@ -197,6 +198,38 @@ public BaseResponseBean navigateSessionWithAuth(@RequestBody SessionNavigationBe
}
}

public static void logCaseTypeColumnIfPresent(BaseResponseBean response, String label, Log log) {

if (response instanceof EntityListResponse entityListResponse &&
entityListResponse.getEntities().length > 0 &&
entityListResponse.getHeaders().length > 0 &&
entityListResponse.getHeaders()[0].equals("Case Type")
) {
StringBuilder sb = new StringBuilder("USH-6370 Checking at '" + label + "' ");

Set<String> caseTypes = new HashSet<>();
for (EntityBean entity : entityListResponse.getEntities()) {
caseTypes.add(entity.getData()[0].toString());
}
if (caseTypes.size() > 1) {
sb.append("mismatch");
sb.append("\nExpected all 'Case Type's to be the same at '")
.append(label)
.append("'. Got: ")
.append(caseTypes);
} else {
sb.append("ok");
}
for (EntityBean entity : entityListResponse.getEntities()) {
sb.append("\n")
.append(entity.getId())
.append(": ")
.append(entity.getData()[0].toString());
}
log.error(sb.toString());
}
}

private void setResponseMetaData(BaseResponseBean response) {
ResponseMetaData responseMetaData = new ResponseMetaData(responseMetaDataTracker.isAttemptRestore(),
responseMetaDataTracker.isNewInstall());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.commcare.formplayer.util.Constants.TOGGLE_SPLIT_SCREEN_CASE_SEARCH;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.commcare.cases.entity.Entity;
import org.commcare.core.graph.model.GraphData;
import org.commcare.core.graph.util.GraphException;
Expand Down Expand Up @@ -29,11 +31,7 @@
import org.springframework.web.util.UriBuilder;
import org.springframework.web.util.UriTemplate;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Vector;
import java.util.*;
import java.util.function.Predicate;

import datadog.trace.api.Trace;
Expand All @@ -42,6 +40,8 @@
* Created by willpride on 4/13/16.
*/
public class EntityListResponse extends MenuBean {
private static final Log log = LogFactory.getLog(EntityListResponse.class);

private EntityBean[] entities;
private DisplayElement[] actions;
private String redoLast;
Expand Down Expand Up @@ -83,25 +83,69 @@ public EntityListResponse(EntityScreen nextScreen) {
// subscreen should be of type EntityListSubscreen in order to init this response class
Subscreen subScreen = nextScreen.getCurrentScreen();
if (subScreen instanceof EntityListSubscreen) {
EntityListSubscreen entityListScreen = ((EntityListSubscreen)nextScreen.getCurrentScreen());
EntityListSubscreen entityListScreen = ((EntityListSubscreen) nextScreen.getCurrentScreen());
Vector<Action> entityListActions = entityListScreen.getActions();
this.actions = processActions(nextScreen.getSession(), entityListActions);
this.redoLast = processRedoLast(entityListActions);

List<Entity<TreeReference>> entityList = entityListScreen.getEntities();
StringBuilder sb1 = new StringBuilder("USH-6370 Checking at 'entityListScreen.getEntities' ");
Set<String> caseTypes = new HashSet<>();
for (Entity<TreeReference> e: entityList) {
caseTypes.add(e.getData()[0].toString());
}
if (caseTypes.size() > 1) {
sb1.append("mismatch");
sb1.append("\nExpected all 'Case Type's to be the same at. Got: ")
.append(caseTypes);
} else {
sb1.append("ok");
}
EntityScreenContext entityScreenContext = nextScreen.getEntityScreenContext();
int casesPerPage = entityScreenContext.getCasesPerPage();
casesPerPage = Math.min(casesPerPage, MAX_CASES_PER_PAGE);
int offset = entityScreenContext.getOffSet();
Detail detail = nextScreen.getShortDetail();
List<Entity<TreeReference>> entitesForPage = paginateEntities(entityList, detail, casesPerPage,
offset);
// StringBuilder sb2 = new StringBuilder("USH-6370 Checking at 'paginateEntities' ");
// caseTypes = new HashSet<>();
// for (Entity<TreeReference> e: entityList) {
// caseTypes.add(e.getData()[0].toString());
// }
// if (caseTypes.size() > 1) {
// sb2.append("mismatch");
// sb2.append("\nExpected all 'Case Type's to be the same. Got: ")
// .append(caseTypes);
// } else {
// sb2.append("ok");
// }
EvaluationContext ec = nextScreen.getEvalContext();
SessionWrapper session = nextScreen.getSession();
EntityDatum neededDatum = (EntityDatum)session.getNeededDatum();
EntityDatum neededDatum = (EntityDatum) session.getNeededDatum();
List<EntityBean> entityBeans = processEntitiesForCaseList(entitesForPage, ec, neededDatum);
entities = new EntityBean[entityBeans.size()];
entityBeans.toArray(entities);

// caseTypes = new HashSet<>();
// for (EntityBean entity : entities) {
// caseTypes.add(entity.getData()[0].toString());
// }
// StringBuilder sb = new StringBuilder("USH-6370 Checking at 'processEntitiesForCaseList' ");
// if (caseTypes.size() > 1) {
// sb.append("mismatch");
// sb.append("\nExpected all 'Case Type's to be the same. Got: ")
// .append(caseTypes);
// for (EntityBean entity : entities) {
// sb.append("\n")
// .append(entity.getId())
// .append(": ")
// .append(entity.getData()[0].toString());
// }
// } else {
// sb.append("ok");
// }

setNoItemsText(getNoItemsTextLocaleString(detail));
setSelectText(getSelectTextLocaleString(detail));
hasDetails = nextScreen.getLongDetail() != null;
Expand All @@ -117,19 +161,25 @@ public EntityListResponse(EntityScreen nextScreen) {
this.sortIndices = detail.getOrderedFieldIndicesForSorting();
isMultiSelect = nextScreen instanceof MultiSelectEntityScreen;
if (isMultiSelect) {
maxSelectValue = ((MultiSelectEntityScreen)nextScreen).getMaxSelectValue();
maxSelectValue = ((MultiSelectEntityScreen) nextScreen).getMaxSelectValue();
}
if (detail.getGroup() != null) {
groupHeaderRows = detail.getGroup().getHeaderRows();
}

QueryScreen queryScreen = nextScreen.getQueryScreen();
if (queryScreen != null) {
// sb.append("\nqueryScreen");
setQueryKey(queryScreen.getQueryKey());
if (FeatureFlagChecker.isToggleEnabled(TOGGLE_SPLIT_SCREEN_CASE_SEARCH)) {
queryResponse = new QueryResponseBean(queryScreen);
}
}
if (this.headers.length > 0 && this.headers[0].equals("Case Type")) {
log.error(sb1.toString());
// log.error(sb2.toString());
// log.error(sb.toString());
}
}
}

Expand Down Expand Up @@ -168,10 +218,22 @@ private static EntityBean[] processEntitiesForCaseDetail(Detail detail, TreeRefe
public static List<EntityBean> processEntitiesForCaseList(List<Entity<TreeReference>> entityList,
EvaluationContext ec,
EntityDatum neededDatum) {
StringBuilder sb = new StringBuilder("USH-6370 Checking in 'processEntitiesForCaseList' ");

List<EntityBean> entities = new ArrayList<>();
StringBuilder innerSb = new StringBuilder();
for (Entity<TreeReference> entity : entityList) {
entities.add(toEntityBean(entity, ec, neededDatum));
EntityBean bean = toEntityBean(entity, ec, neededDatum, innerSb);
entities.add(bean);
}
if (innerSb.isEmpty()) {
sb.append("ok");
} else {
sb.append("missmatch")
.append(innerSb);
}

log.error(sb.toString());
return entities;
}

Expand Down Expand Up @@ -235,14 +297,29 @@ public boolean isHasDetails() {
// Converts the Given Entity to EntityBean
@Trace
private static EntityBean toEntityBean(Entity<TreeReference> entity,
EvaluationContext ec, EntityDatum neededDatum) {
EvaluationContext ec, EntityDatum neededDatum, StringBuilder sb) {
Object[] entityData = entity.getData();
Object[] data = new Object[entityData.length];
String id = getEntityId(entity.getElement(), neededDatum, ec);

// Log entity conversion details
// log.error(String.format("toEntityBean: ref=%s, id=%s, rawData[0]=%s",
// entity.getElement().toString(),
// id,
// entityData.length > 0 ? entityData[0] : "none"));


EntityBean entityBean = new EntityBean(id);
for (int i = 0; i < entityData.length; i++) {
data[i] = processData(entityData[i]);
if (i == 0 && !String.valueOf(entityData[i]).equals(String.valueOf(data[i]))) {
sb.append("\n").append(id)
.append(" Data[").append(i).append("] changed during processing: ")
.append(entityData[i]).append(" -> ").append(data[i]);
}
}


entityBean.setData(data);
entityBean.setGroupKey(entity.getGroupKey());
entityBean.setAltText(entity.getAltText());
Expand Down
Loading
Loading