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

Expose created entities after finalizing form #691

Merged
merged 36 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c15d279
Add dummy entities API for Collect
seadowg Sep 9, 2022
0798659
Spike out exposing created entity once form is finalized
seadowg Sep 9, 2022
19e83e7
Make sure entities are only created when they should be
seadowg Sep 13, 2022
c6e0d57
Support caching form def/instance with entities
seadowg Sep 13, 2022
6b458a7
Move back to using List for saveto refs
seadowg Sep 13, 2022
0b036bd
Remove id attribute from test forms
seadowg Sep 15, 2022
7b31a82
Make sure namespace prefix isn't hardcoded for entities
seadowg Sep 21, 2022
d4f3c49
Add test for selects
seadowg Sep 21, 2022
b547b78
Reimplement entity parsing and processing using plugin style architec…
seadowg Sep 21, 2022
b6ba302
Ignore entities:create if the namespace is incorrect
seadowg Sep 23, 2022
15a0861
Don't create entities if create is not relevant
seadowg Sep 23, 2022
444143d
Only parse dataset out during processing
seadowg Sep 23, 2022
8072261
Don't return all matching children in cases we don't expect more than…
seadowg Sep 23, 2022
a8e5023
Use forEach supported by Android API 21
seadowg Sep 23, 2022
488511c
Optimize imports
seadowg Sep 23, 2022
98aac67
Pull out common Extras
seadowg Sep 30, 2022
4aec176
Rename method
seadowg Sep 30, 2022
4497074
Rename field
seadowg Sep 30, 2022
ee3e78d
Make naming less ambiguous
seadowg Sep 30, 2022
de9ad87
Validate namespace for create action
seadowg Sep 30, 2022
96a057b
Add convenience method for getting namespaced children
seadowg Sep 30, 2022
d8d28c6
Move test
seadowg Sep 30, 2022
43fff8d
Ignore saveto attributes with incorrect namespaces
seadowg Sep 30, 2022
eb6568e
Use simpler parsing code
seadowg Sep 30, 2022
6946ecc
Make it easier to add processor that deals with multiple stages of parse
seadowg Sep 30, 2022
ced91b0
Validate entity version if defined in model
seadowg Sep 30, 2022
71b75af
Keep 'processor' consistent in naming
seadowg Oct 3, 2022
c3f86f2
Make sure forms without entities can be parsed
seadowg Oct 3, 2022
331acd6
Naming improvements
seadowg Oct 3, 2022
e978f64
Remove unsupported forEach
seadowg Oct 3, 2022
d4b9100
Simplify ExternalizableExtras
seadowg Oct 3, 2022
35652f6
Make sure only bind attributes with correct namespace are removed
seadowg Oct 3, 2022
f69c9b2
Add explicit parse exception
seadowg Oct 3, 2022
9b34f4c
Remove IOException from parse() method
seadowg Oct 3, 2022
c20aa0b
Correct version
seadowg Oct 3, 2022
9afa909
Check that parsing works with patch versions
seadowg Oct 4, 2022
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 @@ -38,6 +38,7 @@
import java.util.function.Consumer;
import org.javarosa.core.model.instance.TreeReference;
import org.javarosa.core.test.Scenario;
import org.javarosa.xform.parse.XFormParser;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Scope;
Expand Down Expand Up @@ -65,7 +66,7 @@ public static class ChildVaccinationState {
private List<TreeReference> endOfVisitRefs;

@Setup(Level.Trial)
public void initialize() {
public void initialize() throws XFormParser.ParseException {
Path formFile = prepareAssets("child_vaccination_VOL_tool_v12.xml").resolve("child_vaccination_VOL_tool_v12.xml");
vaccinationPenta1Ref = getRef("/data/household/child_repeat/penta1");
vaccinationPenta3Ref = getRef("/data/household/child_repeat/penta3");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.javarosa.core.util.JavaRosaCoreModule;
import org.javarosa.model.xform.XFormsModule;
import org.javarosa.xform.parse.FormParserHelper;
import org.javarosa.xform.parse.XFormParser;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Scope;
Expand All @@ -33,7 +34,7 @@ public static class FormDefCacheState {

@Setup(Level.Trial)
public void
initialize() throws IOException {
initialize() throws IOException, XFormParser.ParseException {
resourcePath = BenchmarkUtils.getNigeriaWardsXMLWithExternal2ndryInstance();
formDef = FormParserHelper.parse(resourcePath);
cachePath = getCachePath().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.javarosa.core.util.JavaRosaCoreModule;
import org.javarosa.model.xform.XFormsModule;
import org.javarosa.xform.parse.FormParserHelper;
import org.javarosa.xform.parse.XFormParser;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Scope;
Expand All @@ -32,7 +33,7 @@ public static class FormDefCacheState {
FormDef formDef;
@Setup(Level.Trial)
public void
initialize() throws IOException {
initialize() throws IOException, XFormParser.ParseException {
resourcePath = BenchmarkUtils.getNigeriaWardsXMLWithExternal2ndryInstance();
formDef = FormParserHelper.parse(resourcePath);
cachePath = getCachePath().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.javarosa.form.api.FormEntryModel;
import org.javarosa.form.api.FormEntryPrompt;
import org.javarosa.xform.parse.FormParserHelper;
import org.javarosa.xform.parse.XFormParser;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Scope;
Expand All @@ -32,7 +33,7 @@ public static class FormDefValidateState {
FormDef formDef;

@Setup(Level.Trial)
public void initialize() throws IOException {
public void initialize() throws IOException, XFormParser.ParseException {
Path resourcePath = BenchmarkUtils.getNigeriaWardsXMLWithExternal2ndryInstance();
formDef = FormParserHelper.parse(resourcePath);
FormEntryModel formEntryModel = new FormEntryModel(formDef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.javarosa.form.api.FormEntryModel;
import org.javarosa.form.api.FormEntryPrompt;
import org.javarosa.xform.parse.FormParserHelper;
import org.javarosa.xform.parse.XFormParser;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Scope;
Expand All @@ -33,7 +34,7 @@ public static class FormControllerAnswerQuestionState {
FormEntryModel formEntryModel;

@Setup(Level.Trial)
public void initialize() throws IOException {
public void initialize() throws IOException, XFormParser.ParseException {
Path formFile = BenchmarkUtils.getNigeriaWardsXMLWithExternal2ndryInstance();
FormDef formDef = FormParserHelper.parse(formFile);
formEntryModel = new FormEntryModel(formDef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.nio.file.Path;
import org.javarosa.xform.parse.FormParserHelper;
import org.javarosa.xform.parse.XFormParser;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Scope;
Expand All @@ -30,7 +31,7 @@ public void initialize() {

@Benchmark
public void
benchmarkParseExternalSecondaryInstance(FormParserHelperParseExternalInstanceBenchmarkState state, Blackhole bh) throws IOException {
benchmarkParseExternalSecondaryInstance(FormParserHelperParseExternalInstanceBenchmarkState state, Blackhole bh) throws IOException, XFormParser.ParseException {
bh.consume(FormParserHelper.parse(state.xFormFilePath));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.nio.file.Path;
import org.javarosa.xform.parse.FormParserHelper;
import org.javarosa.xform.parse.XFormParser;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Scope;
Expand All @@ -30,7 +31,7 @@ public void initialize() {

@Benchmark
public void
benchmarkParseInternalSecondaryInstanceForm(FormParserHelperParseInternalInstanceBenchmarkState state, Blackhole bh) throws IOException {
benchmarkParseInternalSecondaryInstanceForm(FormParserHelperParseInternalInstanceBenchmarkState state, Blackhole bh) throws IOException, XFormParser.ParseException {
bh.consume(FormParserHelper.parse(state.xFormFilePath));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.nio.file.Path;
import org.javarosa.xform.parse.FormParserHelper;
import org.javarosa.xform.parse.XFormParser;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Scope;
Expand All @@ -30,7 +31,7 @@ public void initialize() {

@Benchmark
public void
benchmarkParseInternalInstanceFormMinified(FormParserHelperParseInternalInstanceMinifiedBenchmarkState state, Blackhole bh) throws IOException {
benchmarkParseInternalInstanceFormMinified(FormParserHelperParseInternalInstanceMinifiedBenchmarkState state, Blackhole bh) throws IOException, XFormParser.ParseException {
bh.consume(FormParserHelper.parse(state.xFormFilePath));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class TreeElementPopulateState {
private FormDef formDef;

@Setup(Level.Trial)
public void initialize() throws IOException {
public void initialize() throws IOException, XFormParser.ParseException {
Path assetsDir = prepareAssets("nigeria_wards_external_combined.xml", "wards.xml", "lgas.xml", "populate-nodes-attributes-instance.xml");
Path formFile = assetsDir.resolve("nigeria_wards_external_combined.xml");
Path submissionFile = assetsDir.resolve("populate-nodes-attributes-instance.xml");
Expand Down
3 changes: 2 additions & 1 deletion src/jmh/java/org/javarosa/benchmarks/WhoVaBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.time.LocalDate;
import java.util.stream.IntStream;
import org.javarosa.core.test.Scenario;
import org.javarosa.xform.parse.XFormParser;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Scope;
Expand All @@ -42,7 +43,7 @@ public static class WhoVaState {
public Scenario scenario;

@Setup(Level.Trial)
public void initialize() {
public void initialize() throws XFormParser.ParseException {
scenario = init(prepareAssets("whova_form.xml").resolve("whova_form.xml"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.io.IOException;
import org.javarosa.core.test.Scenario;
import org.javarosa.xform.parse.XFormParser;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
Expand Down Expand Up @@ -46,7 +47,7 @@ public static class ExecutionPlan {
Scenario expressionInsideWithPositionCallScenario;

@Setup(Level.Invocation)
public void setUp() throws IOException {
public void setUp() throws IOException, XFormParser.ParseException {
expressionInsideScenario = getExpressionInsideScenario();
expressionInsideWithRefOutsideScenario = getExpressionInsideWithRefOutsideScenario();
sumExpressionOutsideScenario = getSumExpressionOutsideScenario();
Expand Down Expand Up @@ -95,7 +96,7 @@ public void createRepeat_withPositionExpression(ExecutionPlan plan, Blackhole bh
});
}

static Scenario getExpressionInsideScenario() throws IOException {
static Scenario getExpressionInsideScenario() throws IOException, XFormParser.ParseException {
return Scenario.init("Repeat with expression inside", html(
head(
title("Repeat with expression inside"),
Expand All @@ -117,7 +118,7 @@ static Scenario getExpressionInsideScenario() throws IOException {
)));
}

static Scenario getExpressionInsideWithRefOutsideScenario() throws IOException {
static Scenario getExpressionInsideWithRefOutsideScenario() throws IOException, XFormParser.ParseException {
return Scenario.init("Repeat with expression inside referencing outside", html(
head(
title("Repeat with expression inside referencing outside"),
Expand All @@ -139,7 +140,7 @@ static Scenario getExpressionInsideWithRefOutsideScenario() throws IOException {
)));
}

static Scenario getSumExpressionOutsideScenario() throws IOException {
static Scenario getSumExpressionOutsideScenario() throws IOException, XFormParser.ParseException {
return Scenario.init("Repeat with sum expression outside", html(
head(
title("Repeat with sum expression outside"),
Expand All @@ -161,7 +162,7 @@ static Scenario getSumExpressionOutsideScenario() throws IOException {
)));
}

static Scenario getExpressionInsideWithPositionCallScenario() throws IOException {
static Scenario getExpressionInsideWithPositionCallScenario() throws IOException, XFormParser.ParseException {
return Scenario.init("Repeat with expression inside referencing outside", html(
head(
title("Repeat with expression inside referencing outside"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.IOException;
import org.javarosa.core.test.Scenario;
import org.javarosa.xform.parse.XFormParser;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
Expand Down Expand Up @@ -40,7 +41,7 @@ public static class ExecutionPlan {
Scenario expressionInsideWithPositionCallScenario;

@Setup(Level.Invocation)
public void setUp() throws IOException {
public void setUp() throws IOException, XFormParser.ParseException {
expressionInsideScenario = getExpressionInsideScenario();
range(0, repeatCount).forEach(n -> {
expressionInsideScenario.next();
Expand Down
47 changes: 31 additions & 16 deletions src/main/java/org/javarosa/core/model/FormDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@

package org.javarosa.core.model;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import org.javarosa.core.log.WrappedException;
import org.javarosa.core.model.TriggerableDag.EventNotifierAccessor;
import org.javarosa.core.model.actions.ActionController;
Expand All @@ -55,12 +42,15 @@
import org.javarosa.core.services.locale.Localizer;
import org.javarosa.core.services.storage.IMetaData;
import org.javarosa.core.services.storage.Persistable;
import org.javarosa.core.util.Extras;
import org.javarosa.core.util.externalizable.DeserializationException;
import org.javarosa.core.util.externalizable.ExtUtil;
import org.javarosa.core.util.externalizable.ExtWrapListPoly;
import org.javarosa.core.util.externalizable.ExtWrapMap;
import org.javarosa.core.util.externalizable.ExtWrapNullable;
import org.javarosa.core.util.externalizable.ExtWrapTagged;
import org.javarosa.core.util.externalizable.Externalizable;
import org.javarosa.core.util.externalizable.ExternalizableExtras;
import org.javarosa.core.util.externalizable.PrototypeFactory;
import org.javarosa.debug.EvaluationResult;
import org.javarosa.debug.Event;
Expand All @@ -75,6 +65,22 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;

import static java.util.Collections.emptyList;

/**
* Definition of a form. This has some meta data about the form definition and a
* collection of groups together with question branching or skipping rules.
Expand All @@ -89,6 +95,7 @@ public class FormDef implements IFormElement, Localizable, Persistable, IMetaDat
public static final int TEMPLATING_RECURSION_LIMIT = 10;

private static EventNotifier defaultEventNotifier = new EventNotifierSilent();
private ExternalizableExtras extras = new ExternalizableExtras();

/**
* Takes a (possibly relative) reference, and makes it absolute based on its parent.
Expand Down Expand Up @@ -1002,9 +1009,9 @@ public void preloadInstance(TreeElement node) {
// }
}

public boolean postProcessInstance() {
public void postProcessInstance() {
actionController.triggerActionsFromEvent(Actions.EVENT_XFORMS_REVALIDATE, elementsWithActionTriggeredByToplevelEvent, this);
return postProcessInstance(mainInstance.getRoot());
postProcessInstance(mainInstance.getRoot());
}

/**
Expand Down Expand Up @@ -1112,6 +1119,8 @@ public void readExternal(DataInputStream dis, PrototypeFactory pf) throws IOExce

List<TreeReference> treeReferencesWithActions = (List<TreeReference>) ExtUtil.read(dis, new ExtWrapListPoly(), pf);
elementsWithActionTriggeredByToplevelEvent = getElementsFromReferences(treeReferencesWithActions);

extras = (ExternalizableExtras) ExtUtil.read(dis, ExternalizableExtras.class);
}

/**
Expand Down Expand Up @@ -1215,6 +1224,8 @@ public void writeExternal(DataOutputStream dos) throws IOException {
ExtUtil.write(dos, new ExtWrapNullable(actionController));
ExtUtil.write(dos, new ExtWrapListPoly(new ArrayList<>(actions)));
ExtUtil.write(dos, new ExtWrapListPoly(getReferencesFromElements(elementsWithActionTriggeredByToplevelEvent)));

ExtUtil.write(dos, extras);
}

/**
Expand Down Expand Up @@ -1600,7 +1611,7 @@ public String getAdditionalAttribute(String namespace, String name) {
@Override
public List<TreeElement> getAdditionalAttributes() {
// Not supported.
return Collections.emptyList();
return emptyList();
}

public <X extends XFormExtension> X getExtension(Class<X> extension) {
Expand Down Expand Up @@ -1690,4 +1701,8 @@ private String getFormXmlPath() {
public HashMap<String, DataInstance> getFormInstances() {
return formInstances;
}

public Extras<Externalizable> getExtras() {
return extras;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.javarosa.core.model.data.IAnswerData;
import org.javarosa.core.model.instance.utils.ITreeVisitor;
import org.javarosa.xpath.expr.XPathExpression;
import org.jetbrains.annotations.Nullable;

public interface AbstractTreeElement<T extends AbstractTreeElement> {

Expand All @@ -15,6 +16,13 @@ public interface AbstractTreeElement<T extends AbstractTreeElement> {

public abstract String getInstanceName();

@Nullable
public T getFirstChild(String name);

@Nullable
public T getFirstChild(String namespace, String name);

@Nullable
public abstract T getChild(String name, int multiplicity);

/**
Expand Down
Loading