Skip to content

Commit

Permalink
Fixed no collected data crash
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisszmundy committed Apr 19, 2024
1 parent d26e0be commit af6e425
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
### Changed
- Output files are stored in separate execution time folders

### Fixed
- Fixed crash when no COLLECTED tag in .xml data file



## 2.0.3 [2024-04-02] - Update some dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ private boolean checkLunaticQuestionnaire(String questionnaireModelId, Element q
*/
private void readCollected(Element questionnaireNode, QuestionnaireData questionnaireData, VariablesMap variables) {

//Check collected data tag presence
if(questionnaireNode.getFirstChildElement("Data").getFirstChildElement(Constants.COLLECTED) == null){
log.warn("No collected data for survey unit " + questionnaireData.getIdentifier());
return;
}

// Xml collected variables nodes
Elements collectedVariablesNodes = questionnaireNode.getFirstChildElement("Data")
.getFirstChildElement(Constants.COLLECTED).getChildElements();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,19 @@ public void checkLevelOneContent(SurveyRawData data) {
}
}

@Test
void parseLunaticXml_noCollected() throws NullException {
//Given
SurveyRawData data = new SurveyRawData("TEST");
data.setMetadataModel(MetadataModelTest.createVariablesMap_oneLevel());
Path dataPath = Paths.get(dataSamplesFolder + "/lunatic_xml/fake-lunatic-data-3.xml");
LunaticXmlDataParser parser = new LunaticXmlDataParser(data);

//When
parser.parseSurveyData(dataPath,null);

//Then
assertEquals(1, data.getQuestionnairesCount());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="UTF-8"?>
<Campaign>
<Id>TEST02</Id>
<Label>Fake campaign with two levels of group</Label>
<SurveyUnits>
<SurveyUnit>
<Id>T0000001</Id>
<QuestionnaireModelId>TEST02</QuestionnaireModelId>
<Data>
<EXTERNAL>
<ADDRESS>
<COLLECTED type="string">742 Evergreen Terrace</COLLECTED>
<EDITED type="null" />
<INPUTED type="null" />
<FORCED type="null" />
<PREVIOUS type="null" />
</ADDRESS>
<HOUSEHOLD_INCOME>
<COLLECTED type="number">20000</COLLECTED>
<EDITED type="null" />
<INPUTED type="null" />
<FORCED type="null" />
<PREVIOUS type="null" />
</HOUSEHOLD_INCOME>
<FIRST_NAME>
<COLLECTED>
<COLLECTED type="string">Homer</COLLECTED>
<COLLECTED type="string">Marge</COLLECTED>
<COLLECTED type="string">Bart</COLLECTED>
<COLLECTED type="string">Lisa</COLLECTED>
<COLLECTED type="string">Maggie</COLLECTED>
<COLLECTED type="string">Maggie</COLLECTED>
<COLLECTED type="string">Santa's Little Helper</COLLECTED>
</COLLECTED>
<EDITED>
<EDITED type="null" />
</EDITED>
<INPUTED>
<INPUTED type="null" />
</INPUTED>
<FORCED>
<FORCED type="null" />
</FORCED>
<PREVIOUS>
<PREVIOUS type="null" />
</PREVIOUS>
</FIRST_NAME>
<LAST_NAME>
<COLLECTED>
<COLLECTED type="string">Simpson</COLLECTED>
<COLLECTED type="string">Simpson</COLLECTED>
<COLLECTED type="string">Simpson</COLLECTED>
<COLLECTED type="string">Simpson</COLLECTED>
<COLLECTED type="string">Simpson</COLLECTED>
<COLLECTED type="null" />
</COLLECTED>
<EDITED>
<EDITED type="null" />
</EDITED>
<INPUTED>
<INPUTED type="null" />
</INPUTED>
<FORCED>
<FORCED type="null" />
</FORCED>
<PREVIOUS>
<PREVIOUS type="null" />
</PREVIOUS>
</LAST_NAME>
<GENDER>
<COLLECTED>
<COLLECTED type="string">M</COLLECTED>
<COLLECTED type="string">F</COLLECTED>
<COLLECTED type="string">M</COLLECTED>
<COLLECTED type="string">F</COLLECTED>
<COLLECTED type="string">F</COLLECTED>
<COLLECTED type="null" />
</COLLECTED>
<EDITED>
<EDITED type="null" />
</EDITED>
<INPUTED>
<INPUTED type="null" />
</INPUTED>
<FORCED>
<FORCED type="null" />
</FORCED>
<PREVIOUS>
<PREVIOUS type="null" />
</PREVIOUS>
</GENDER>
<CAR_COLOR>
<COLLECTED>
<COLLECTED>
<COLLECTED type="string">Purple</COLLECTED>
</COLLECTED>
<COLLECTED>
<COLLECTED type="string">Red</COLLECTED>
</COLLECTED>
<COLLECTED>
<COLLECTED type="null" />
</COLLECTED>
<COLLECTED>
<COLLECTED type="null" />
</COLLECTED>
<COLLECTED>
<COLLECTED type="null" />
</COLLECTED>
<COLLECTED>
<COLLECTED type="null" />
</COLLECTED>
</COLLECTED>
<EDITED>
<EDITED>
<EDITED type="null" />
</EDITED>
</EDITED>
<INPUTED>
<INPUTED>
<INPUTED type="null" />
</INPUTED>
</INPUTED>
<FORCED>
<FORCED>
<FORCED type="null" />
</FORCED>
</FORCED>
<PREVIOUS>
<PREVIOUS>
<PREVIOUS type="null" />
</PREVIOUS>
</PREVIOUS>
</CAR_COLOR>
</EXTERNAL>
</Data>
</SurveyUnit>
</SurveyUnits>
</Campaign>

0 comments on commit af6e425

Please sign in to comment.