Skip to content
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
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ workflows:
branches:
ignore:
- master
- ^v((20)[0-9]{2})\.\d+\.x$
- /^v\d+\.\d+.x$/
- compile:
requires:
- hold_pr
Expand All @@ -370,7 +370,7 @@ workflows:
branches:
only:
- master
- ^v((20)[0-9]{2})\.\d+\.x$
- /^v\d+\.\d+.x$/
- check_quality:
requires:
- compile
Expand Down Expand Up @@ -412,15 +412,15 @@ workflows:
- compile:
filters:
tags:
only: /^v((20)[0-9]{2})\.\d+\.\d+$/ # matches semvers like v1.2.3
only: /^v\d+\.\d+.\d+$/
branches:
ignore: /.*/
- create_dependency_backup:
requires:
- compile
filters:
tags:
only: /^v((20)[0-9]{2})\.\d+\.\d+$/ # matches semvers like v1.2.3
only: /^v\d+\.\d+.\d+$/
branches:
ignore: /.*/

3 changes: 2 additions & 1 deletion collect_app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ the specific language governing permissions and limitations under the License.
android:name="org.odk.collect.draw.DrawActivity"
android:theme="@style/Theme.Collect"
tools:replace="android:theme"
android:screenOrientation="landscape" />
android:screenOrientation="landscape"
android:resizeableActivity="false"/>
<activity android:name=".activities.InstanceChooserList" />
<activity
android:name=".formlists.blankformlist.BlankFormListActivity"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.odk.collect.android.javarosawrapper

import org.odk.collect.android.formentry.audit.AuditConfig
import org.odk.collect.android.utilities.FormNameUtils

data class InstanceMetadata(
@JvmField val instanceId: String?,
private val rawInstanceName: String?,
@JvmField val auditConfig: AuditConfig?
) {
@JvmField val instanceName: String? = FormNameUtils.normalizeFormName(rawInstanceName, false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -1010,76 +1010,41 @@ public ByteArrayPayload getSubmissionXml() throws IOException {
getSubmissionDataReference());
}

/**
* Traverse the submission looking for the first matching tag in depth-first order.
*/
private TreeElement findDepthFirst(TreeElement parent, String name) {
int len = parent.getNumChildren();
for (int i = 0; i < len; ++i) {
TreeElement e = parent.getChildAt(i);
if (name.equals(e.getName())) {
return e;
} else if (e.getNumChildren() != 0) {
TreeElement v = findDepthFirst(e, name);
if (v != null) {
return v;
}
}
}
return null;
}

public InstanceMetadata getSubmissionMetadata() {
FormDef formDef = formEntryController.getModel().getForm();
TreeElement rootElement = formDef.getInstance().getRoot();

TreeElement trueSubmissionElement;
// Determine the information about the submission...
SubmissionProfile p = formDef.getSubmissionProfile();
if (p == null || p.getRef() == null) {
trueSubmissionElement = rootElement;
} else {
IDataReference ref = p.getRef();
trueSubmissionElement = formDef.getInstance().resolveReference(ref);
// resolveReference returns null if the reference is to the root element...
if (trueSubmissionElement == null) {
trueSubmissionElement = rootElement;
}
}

// and find the depth-first meta block in this...
TreeElement e = findDepthFirst(trueSubmissionElement, "meta");
TreeElement meta = rootElement.getFirstChild("meta");

String instanceId = null;
String instanceName = null;
AuditConfig auditConfig = null;

if (e != null) {
List<TreeElement> v;
if (meta != null) {
List<TreeElement> metaElements;

// instance id...
v = e.getChildrenWithName(INSTANCE_ID);
if (v.size() == 1) {
IAnswerData sa = v.get(0).getValue();
metaElements = meta.getChildrenWithName(INSTANCE_ID);
if (metaElements.size() == 1) {
IAnswerData sa = metaElements.get(0).getValue();
if (sa != null) {
instanceId = sa.getDisplayText();
}
}

// instance name...
v = e.getChildrenWithName(INSTANCE_NAME);
if (v.size() == 1) {
IAnswerData sa = v.get(0).getValue();
metaElements = meta.getChildrenWithName(INSTANCE_NAME);
if (metaElements.size() == 1) {
IAnswerData sa = metaElements.get(0).getValue();
if (sa != null) {
instanceName = sa.getDisplayText();
}
}

// timing element...
v = e.getChildrenWithName(AUDIT);
if (v.size() == 1) {
metaElements = meta.getChildrenWithName(AUDIT);
if (metaElements.size() == 1) {

TreeElement auditElement = v.get(0);
TreeElement auditElement = metaElements.get(0);

String locationPriority = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-priority");
String locationMinInterval = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-min-interval");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public void whenInstanceFileAndAuditConfigNull_getAuditEventLogger_isNotNull() t
assertThat(formController.getAuditEventLogger(), notNullValue());
}

@Test
public void getSubmissionMetadata_usesTopLevelMeta_whenMultipleMetaSectionsExist() throws Exception {
FormController formController = createFormController(MULTIPLE_META_SECTIONS);
assertThat(formController.getSubmissionMetadata().instanceName, is(notNullValue()));
}

//region indexIsInFieldList
@Test
Expand Down Expand Up @@ -149,6 +154,7 @@ private FormController createFormController(String xform) throws IOException, XF
ByteArrayInputStream inputStream = new ByteArrayInputStream(xform.getBytes());
final FormEntryModel fem = new FormEntryModel(XFormUtils.getFormFromInputStream(inputStream));
final FormEntryController formEntryController = new FormEntryController(fem);
formEntryController.getModel().getForm().initialize(true, null);
return new JavaRosaFormController(Files.createTempDir(), formEntryController, File.createTempFile("instance", ""));
}

Expand Down Expand Up @@ -293,4 +299,40 @@ private FormController createFormController(String xform) throws IOException, XF
" </group>\n" +
" </h:body>\n" +
"</h:html>\n";

private static final String MULTIPLE_META_SECTIONS = "<?xml version=\"1.0\"?>\n" +
"<h:html xmlns=\"http://www.w3.org/2002/xforms\" xmlns:h=\"http://www.w3.org/1999/xhtml\" xmlns:entities=\"http://www.opendatakit.org/xforms/entities\" xmlns:jr=\"http://openrosa.org/javarosa\">\n" +
" <h:head>\n" +
" <h:title>Multiple meta sections</h:title>\n" +
" <model entities:entities-version=\"2024.1.0\">\n" +
" <instance>\n" +
" <data id=\"multiple-meta-sections\">\n" +
" <group>\n" +
" <question>xxx</question>\n" +
" <meta>\n" +
" <entity dataset=\"entity_test\" create=\"1\" id=\"\">\n" +
" <label/>\n" +
" </entity>\n" +
" </meta>\n" +
" </group>\n" +
" <meta>\n" +
" <instanceName/>\n" +
" </meta>\n" +
" </data>\n" +
" </instance>\n" +
" <bind nodeset=\"/data/group/question\" type=\"int\"/>\n" +
" <bind nodeset=\"/data/group/meta/entity/@id\" readonly=\"true()\" type=\"string\"/>\n" +
" <setvalue ref=\"/data/group/meta/entity/@id\" event=\"odk-instance-first-load\" value=\"uuid()\"/>\n" +
" <bind nodeset=\"/data/group/meta/entity/label\" calculate=\"/data/group/question\" readonly=\"true()\" type=\"string\"/>\n" +
" <bind nodeset=\"/data/meta/instanceName\" type=\"string\" calculate=\"uuid()\"/>\n" +
" </model>\n" +
" </h:head>\n" +
" <h:body>\n" +
" <group ref=\"/data/group\">\n" +
" <input ref=\"/data/group/question\">\n" +
" <label>Question</label>\n" +
" </input>\n" +
" </group>\n" +
" </h:body>\n" +
"</h:html>\n";
}
11 changes: 7 additions & 4 deletions draw/src/main/java/org/odk/collect/draw/DrawView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ class DrawView(context: Context, attrs: AttributeSet?) : View(context, attrs) {

override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
resetImage(w, h)

if (!::bitmap.isInitialized) {
resetImage(w, h)
}
}

override fun onDraw(canvas: Canvas) {
Expand Down Expand Up @@ -168,14 +171,14 @@ class DrawView(context: Context, attrs: AttributeSet?) : View(context, attrs) {
paint.color = originalColor
}

private fun resetImage(w: Int, h: Int) {
private fun resetImage(width: Int, height: Int) {
val backgroundBitmapFile = File(imagePath)
if (backgroundBitmapFile.exists()) {
bitmap = ImageFileUtils.getBitmapScaledToDisplay(backgroundBitmapFile, h, w, true)!!
bitmap = ImageFileUtils.getBitmapScaledToDisplay(backgroundBitmapFile, height, width, true)!!
.copy(Bitmap.Config.ARGB_8888, true)
canvas = Canvas(bitmap)
} else {
bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
canvas = Canvas(bitmap)
canvas.drawColor(Color.WHITE)
if (isSignature) {
Expand Down