Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #864 from lognaturel/ssm-randomize
Browse files Browse the repository at this point in the history
  • Loading branch information
lognaturel authored May 6, 2020
2 parents 9bffa68 + 7197baa commit 4b7130a
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/org/opendatakit/briefcase/export/FormDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ private static Map<String, QuestionDef> getFormControls(FormDef formDef) {
// instance that is not external
if (secondaryInstance != null && !(secondaryInstance instanceof ExternalDataInstance))
try {
// Never randomize the choice order to ensure stable column order when using split select multiples
itemsetBinding.randomize = false;
formDef.populateDynamicChoices(itemsetBinding, (TreeReference) control.getBind().getReference());
} catch (NullPointerException e) {
// Ignore (see https://github.com/opendatakit/briefcase/issues/789)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.opendatakit.briefcase.export;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class ExportToCsvExplodeRandomizedChoiceListTest {
private ExportToCsvScenario scenario;

@Before
public void setUp() {
scenario = ExportToCsvScenario.setUp("choice-lists-randomize");
}

@After
public void tearDown() {
scenario.tearDown();
}

@Test
public void exportWithSplitSelectMultiple_hasStableColumnOrder() {
scenario.runExportExplodedChoiceLists();
scenario.assertSameContent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<data id="choice-lists-randomize" instanceID="uuid:39f3dd36-161e-47cb-a1a4-395831d253a7" submissionDate="2020-04-26T08:58:20.525Z">
<select_multiple>a</select_multiple>
<n0:meta xmlns:n0="http://openrosa.org/xforms">
<n0:instanceID>uuid:39f3dd36-161e-47cb-a1a4-395831d253a7</n0:instanceID>
</n0:meta>
</data>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SubmissionDate,select_multiple,select_multiple/a,select_multiple/b,select_multiple/c,select_multiple/d,select_multiple/e,meta-instanceID,KEY
"Apr 26, 2020 8:58:20 AM",a,1,0,0,0,0,uuid:39f3dd36-161e-47cb-a1a4-395831d253a7,uuid:39f3dd36-161e-47cb-a1a4-395831d253a7
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<h:html xmlns:h="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/2002/xforms">
<h:head>
<h:title>Randomize choice list</h:title>
<model>
<instance>
<data id="choice-lists-randomize">
<select_multiple/>
<meta>
<instanceID/>
</meta>
</data>
</instance>
<instance id="choices">
<root>
<item>
<name>a</name>
<label>A</label>
</item>
<item>
<name>b</name>
<label>B</label>
</item>
<item>
<name>c</name>
<label>C</label>
</item>
<item>
<name>d</name>
<label>D</label>
</item>
<item>
<name>e</name>
<label>E</label>
</item>
</root>
</instance>
<bind nodeset="/data/select_multiple" type="string"/>
<bind calculate="concat('uuid:', uuid())" nodeset="/data/meta/instanceID" readonly="true()" type="string"/>
</model>
</h:head>
<h:body>
<select ref="/data/select_multiple">
<itemset nodeset="randomize(instance('choices')/root/item)">
<value ref="name"/>
<label ref="label"/>
</itemset>
</select>
</h:body>
</h:html>

0 comments on commit 4b7130a

Please sign in to comment.