-
Notifications
You must be signed in to change notification settings - Fork 107
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
Changes from 23 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
c15d279
Add dummy entities API for Collect
seadowg 0798659
Spike out exposing created entity once form is finalized
seadowg 19e83e7
Make sure entities are only created when they should be
seadowg c6e0d57
Support caching form def/instance with entities
seadowg 6b458a7
Move back to using List for saveto refs
seadowg 0b036bd
Remove id attribute from test forms
seadowg 7b31a82
Make sure namespace prefix isn't hardcoded for entities
seadowg d4f3c49
Add test for selects
seadowg b547b78
Reimplement entity parsing and processing using plugin style architec…
seadowg b6ba302
Ignore entities:create if the namespace is incorrect
seadowg 15a0861
Don't create entities if create is not relevant
seadowg 444143d
Only parse dataset out during processing
seadowg 8072261
Don't return all matching children in cases we don't expect more than…
seadowg a8e5023
Use forEach supported by Android API 21
seadowg 488511c
Optimize imports
seadowg 98aac67
Pull out common Extras
seadowg 4aec176
Rename method
seadowg 4497074
Rename field
seadowg ee3e78d
Make naming less ambiguous
seadowg de9ad87
Validate namespace for create action
seadowg 96a057b
Add convenience method for getting namespaced children
seadowg d8d28c6
Move test
seadowg 43fff8d
Ignore saveto attributes with incorrect namespaces
seadowg eb6568e
Use simpler parsing code
seadowg 6946ecc
Make it easier to add processor that deals with multiple stages of parse
seadowg ced91b0
Validate entity version if defined in model
seadowg 71b75af
Keep 'processor' consistent in naming
seadowg c3f86f2
Make sure forms without entities can be parsed
seadowg 331acd6
Naming improvements
seadowg e978f64
Remove unsupported forEach
seadowg d4b9100
Simplify ExternalizableExtras
seadowg 35652f6
Make sure only bind attributes with correct namespace are removed
seadowg f69c9b2
Add explicit parse exception
seadowg 9b34f4c
Remove IOException from parse() method
seadowg c20aa0b
Correct version
seadowg 9afa909
Check that parsing works with patch versions
seadowg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.javarosa.core.util; | ||
|
||
import java.util.HashMap; | ||
|
||
/** | ||
* Store for objects that allows them to be retrieved by type without any casting. | ||
* | ||
* @param <T> allows a super type to be enforced for all the stored objects | ||
*/ | ||
public class Extras<T> { | ||
|
||
protected final HashMap<String, T> map = new HashMap<>(); | ||
|
||
public void put(T extra) { | ||
map.put(extra.getClass().getName(), extra); | ||
} | ||
|
||
public <U extends T> U get(Class<U> key) { | ||
return (U) map.get(key.getName()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/org/javarosa/core/util/externalizable/ExtWrapExternalizable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.javarosa.core.util.externalizable; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
|
||
public class ExtWrapExternalizable extends ExternalizableWrapper { | ||
|
||
public ExtWrapExternalizable() { | ||
} | ||
|
||
public ExtWrapExternalizable(Externalizable externalizable) { | ||
this.val = externalizable; | ||
} | ||
|
||
@Override | ||
public ExternalizableWrapper clone(Object val) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void metaReadExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException { | ||
|
||
} | ||
|
||
@Override | ||
public void metaWriteExternal(DataOutputStream out) throws IOException { | ||
|
||
} | ||
|
||
@Override | ||
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException { | ||
try { | ||
String className = ExtUtil.readString(in); | ||
Class<?> clazz = Class.forName(className); | ||
|
||
this.val = ExtUtil.read(in, clazz); | ||
} catch (ClassNotFoundException e) { | ||
throw new DeserializationException("Couldn't find class from serialize class name!"); | ||
} | ||
} | ||
|
||
@Override | ||
public void writeExternal(DataOutputStream out) throws IOException { | ||
ExtUtil.write(out, val.getClass().getName()); | ||
ExtUtil.write(out, val); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/javarosa/core/util/externalizable/ExternalizableExtras.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.javarosa.core.util.externalizable; | ||
|
||
import org.javarosa.core.util.Extras; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
public class ExternalizableExtras extends Extras<Externalizable> implements Externalizable { | ||
|
||
@Override | ||
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException { | ||
HashMap<String, Externalizable> extras = (HashMap<String, Externalizable>) ExtUtil.read(in, new ExtWrapMap(String.class, new ExtWrapExternalizable()), pf); | ||
extras.forEach((s, externalizable) -> put(externalizable)); | ||
} | ||
|
||
@Override | ||
public void writeExternal(DataOutputStream out) throws IOException { | ||
HashMap<Object, Object> wrappedParseAttachments = new HashMap<>(); | ||
map.forEach((key, value) -> { | ||
wrappedParseAttachments.put(key, new ExtWrapExternalizable(value)); | ||
}); | ||
|
||
ExtUtil.write(out, new ExtWrapMap(wrappedParseAttachments)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.javarosa.entities; | ||
|
||
import kotlin.Pair; | ||
|
||
import java.util.List; | ||
|
||
public class Entity { | ||
|
||
public final String dataset; | ||
public final List<Pair<String, String>> properties; | ||
|
||
public Entity(String dataset, List<Pair<String, String>> properties) { | ||
this.dataset = dataset; | ||
this.properties = properties; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.javarosa.entities; | ||
|
||
import kotlin.Pair; | ||
import org.javarosa.core.model.FormDef; | ||
import org.javarosa.core.model.IDataReference; | ||
import org.javarosa.core.model.instance.FormInstance; | ||
import org.javarosa.entities.internal.Entities; | ||
import org.javarosa.entities.internal.EntityDatasetParser; | ||
import org.javarosa.entities.internal.EntityFormExtra; | ||
import org.javarosa.form.api.FormEntryModel; | ||
import org.javarosa.form.api.FormEntryFinalizer; | ||
import org.javarosa.model.xform.XPathReference; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.emptyList; | ||
|
||
public class EntityFinalizer implements FormEntryFinalizer { | ||
|
||
@Override | ||
public void processForm(FormEntryModel formEntryModel) { | ||
FormDef formDef = formEntryModel.getForm(); | ||
FormInstance mainInstance = formDef.getMainInstance(); | ||
|
||
EntityFormExtra entityFormExtra = formDef.getExtras().get(EntityFormExtra.class); | ||
List<Pair<XPathReference, String>> saveTos = entityFormExtra.getSaveTos(); | ||
|
||
String dataset = EntityDatasetParser.parseFirstDatasetToCreate(mainInstance); | ||
if (dataset != null) { | ||
List<Pair<String, String>> fields = saveTos.stream().map(saveTo -> { | ||
IDataReference reference = saveTo.getFirst(); | ||
String answer = mainInstance.resolveReference(reference).getValue().getDisplayText(); | ||
return new Pair<>(saveTo.getSecond(), answer); | ||
}).collect(Collectors.toList()); | ||
|
||
formEntryModel.getExtras().put(new Entities(asList(new Entity(dataset, fields)))); | ||
} else { | ||
formEntryModel.getExtras().put(new Entities(emptyList())); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the relationship between this and
ExtWrapBase
? Seems they're nearly identical? Should this maybe extendExtWrapBase
or is it possible/reasonable to useExtWrapBase
directly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I hadn't seen
ExtWrapBase
- will have a look at it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExtWrapBased
doesn't "externalize" the object's type meaning that it must be known at compile time. This doesn't work when externalizing a value that is being referenced by a super type like withExtras
.