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

Suite model change: Adds Endpoint action in detail #1342

Merged
merged 2 commits into from
Oct 5, 2023
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
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 @@ -8,6 +8,7 @@
import org.commcare.session.CommCareSession;
import org.commcare.suite.model.Action;
import org.commcare.suite.model.Detail;
import org.commcare.suite.model.Endpoint;
import org.commcare.suite.model.EntityDatum;
import org.commcare.suite.model.SessionDatum;
import org.commcare.util.CommCarePlatform;
Expand Down Expand Up @@ -408,6 +409,11 @@ public Detail getLongDetail() {
return mPlatform.getDetail(longDetailId);
}

@Nullable
public Endpoint getEndpoint(String endpointId) {
return mPlatform.getEndpoint(endpointId);
}

public String[] getDetailListTitles(EvaluationContext subContext, TreeReference reference) {
Detail[] mLongDetailList = getLongDetailList(reference);
String[] titles = new String[mLongDetailList.length];
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/commcare/suite/model/DetailField.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.io.DataOutputStream;
import java.io.IOException;

import javax.annotation.Nullable;

/**
* Detail Fields represent the <field> elements of a suite's detail
* definitions. The model contains the relevent text templates as well
Expand Down Expand Up @@ -44,6 +46,9 @@ public class DetailField implements Externalizable {
private String templateWidthHint = null;
private String printIdentifier;

@Nullable
private EndpointAction endpointAction;

/**
* Optional hint which provides a hint for whether rich media should be
* displayed based on <text> returning a URI. May be either 'image' or
Expand Down Expand Up @@ -201,6 +206,7 @@ public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOExcep
horizontalAlign = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
verticalAlign = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
cssID = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
endpointAction = (EndpointAction)ExtUtil.read(in, new ExtWrapNullable(EndpointAction.class), pf);
}

@Override
Expand Down Expand Up @@ -230,6 +236,7 @@ public void writeExternal(DataOutputStream out) throws IOException {
ExtUtil.writeString(out, ExtUtil.emptyIfNull(horizontalAlign));
ExtUtil.writeString(out, ExtUtil.emptyIfNull(verticalAlign));
ExtUtil.writeString(out, ExtUtil.emptyIfNull(cssID));
ExtUtil.write(out, new ExtWrapNullable(endpointAction));
}

public int getGridX() {
Expand All @@ -256,6 +263,11 @@ public String getVerticalAlign() {
return verticalAlign;
}

@Nullable
public EndpointAction getEndpointAction() {
return endpointAction;
}

public String getFontSize() {
return fontSize;
}
Expand Down Expand Up @@ -382,5 +394,9 @@ public void setFontSize(String fontSize) {
public void setCssID(String id) {
field.cssID = id;
}

public void setEndpointAction(EndpointAction endpointAction) {
field.endpointAction = endpointAction;
}
}
}
45 changes: 45 additions & 0 deletions src/main/java/org/commcare/suite/model/EndpointAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.commcare.suite.model;

import org.javarosa.core.util.externalizable.DeserializationException;
import org.javarosa.core.util.externalizable.ExtUtil;
import org.javarosa.core.util.externalizable.Externalizable;
import org.javarosa.core.util.externalizable.PrototypeFactory;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class EndpointAction implements Externalizable {

private String endpointId;
private boolean isBackground;

public EndpointAction() {
}

public EndpointAction(String endpointId, boolean isBackground) {
this.endpointId = endpointId;
this.isBackground = isBackground;
}

@Override
public void readExternal(DataInputStream in, PrototypeFactory pf)
throws IOException, DeserializationException {
endpointId = ExtUtil.readString(in);
isBackground = ExtUtil.readBool(in);
}

@Override
public void writeExternal(DataOutputStream out) throws IOException {
ExtUtil.writeString(out, endpointId);
ExtUtil.writeBool(out, isBackground);
}

public String getEndpointId() {
return endpointId;
}

public boolean isBackground() {
return isBackground;
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/commcare/util/CommCarePlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.List;
import java.util.Vector;

import javax.annotation.Nullable;

/**
* TODO: This isn't really a great candidate for a
* singleton interfaces. It should almost certainly be
Expand Down Expand Up @@ -116,6 +118,7 @@ public Entry getEntry(String entryId) {
return null;
}

@Nullable
public Endpoint getEndpoint(String endpointId) {
for(Suite s : getInstalledSuites()) {
Endpoint endpoint = s.getEndpoint(endpointId);
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/org/commcare/xml/DetailFieldParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.commcare.suite.model.DetailField;
import org.commcare.suite.model.DetailTemplate;
import org.commcare.suite.model.EndpointAction;
import org.commcare.suite.model.Text;
import org.javarosa.core.model.Constants;
import org.javarosa.xml.util.InvalidStructureException;
Expand Down Expand Up @@ -73,9 +74,9 @@ public DetailField parse() throws InvalidStructureException, IOException, XmlPul
} else {
throw new InvalidStructureException("detail <field> with no <template>!", parser);
}
if (nextTagInBlock("field")) {
while (nextTagInBlock("field")) {
//sort details
checkNode(new String[]{"sort", "background"});
checkNode(new String[]{"sort", "background", "endpoint_action"});

String name = parser.getName().toLowerCase();

Expand All @@ -84,11 +85,24 @@ public DetailField parse() throws InvalidStructureException, IOException, XmlPul
} else if (name.equals("background")) {
// background tag in fields is deprecated
skipBlock("background");
} else if (name.equals("endpoint_action")){
parseEndpointAction(builder);
}
}
return builder.build();
}

private void parseEndpointAction(DetailField.Builder builder) throws InvalidStructureException {
String id = parser.getAttributeValue(null, "endpoint_id");
if (id == null) {
throw new InvalidStructureException("No endpoint_id defined for endpoint_action for detail field ",
parser);
}
String background = parser.getAttributeValue(null, "background");
boolean isBackground = "true".equals(background);
builder.setEndpointAction(new EndpointAction(id, isBackground));
}

private void parseStyle(DetailField.Builder builder) throws InvalidStructureException, IOException, XmlPullParserException {
//style
if (parser.getName().toLowerCase().equals("style")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import org.commcare.resources.model.UnresolvedResourceException;
import org.commcare.suite.model.AssertionSet;
import org.commcare.suite.model.Callout;
import org.commcare.suite.model.Detail;
import org.commcare.suite.model.DetailField;
import org.commcare.suite.model.EndpointAction;
import org.commcare.suite.model.GeoOverlay;
import org.commcare.suite.model.Global;
import org.commcare.suite.model.Menu;
Expand Down Expand Up @@ -207,4 +209,13 @@ public void testMenuAssertions() {
AssertionSet assertions = menuWithAssertionsBlock.getAssertions();
Assert.assertNotNull(assertions);
}

@Test
public void testDetailWithFieldAction() {
Detail detail = mApp.getSession().getPlatform().getDetail("m0_case_short");
DetailField field = detail.getFields()[0];
EndpointAction endpointAction = field.getEndpointAction();
assertEquals("case_list",endpointAction.getEndpointId());
assertEquals(true, endpointAction.isBackground());
}
}
1 change: 1 addition & 0 deletions src/test/resources/app_structure/suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<xpath function="case_name"/>
</text>
</sort>
<endpoint_action endpoint_id="case_list" background="true"/>
</field>
</detail>
<detail id="m0_case_long">
Expand Down