Skip to content

Commit

Permalink
Merge pull request #51 from EUSurvey/ESURVEY-6466-2
Browse files Browse the repository at this point in the history
ESURVEY-6466 export results failed in Export tab
  • Loading branch information
clam2310 authored Dec 10, 2019
2 parents 426a931 + f39efa1 commit 195e6fb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 43 deletions.
40 changes: 30 additions & 10 deletions src/main/java/com/ec/survey/tools/export/OdfExportCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,12 @@ private void parseAnswerSet(AnswerSet answerSet, List<String> answerrow, Publica

if (answerSet == null)
{
cell.setStringValue(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter)));
cell.setDisplayText(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter++)));
String v = answerrow.get(answerrowcounter++);
if (v != null && v.length() > 0)
{
cell.setStringValue(ConversionTools.removeHTMLNoEscape(v));
cell.setDisplayText(ConversionTools.removeHTMLNoEscape(v));
}
} else {
List<Answer> answers = answerSet.getAnswers(matrixQuestion.getId(), matrixQuestion.getUniqueId());

Expand All @@ -528,8 +532,12 @@ private void parseAnswerSet(AnswerSet answerSet, List<String> answerrow, Publica
cell = sheet.getCellByPosition(columnIndex++, rowIndex);
if (answerSet == null)
{
cell.setStringValue(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter)));
cell.setDisplayText(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter++)));
String v = answerrow.get(answerrowcounter++);
if (v != null && v.length() > 0)
{
cell.setStringValue(ConversionTools.removeHTMLNoEscape(v));
cell.setDisplayText(ConversionTools.removeHTMLNoEscape(v));
}
} else {
List<Answer> answers = answerSet.getAnswers(childQuestion.getId(), childQuestion.getUniqueId());

Expand Down Expand Up @@ -622,8 +630,12 @@ private void parseAnswerSet(AnswerSet answerSet, List<String> answerrow, Publica
cell = sheet.getCellByPosition(columnIndex++, rowIndex);
if (answerSet == null)
{
cell.setStringValue(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter)));
cell.setDisplayText(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter++)));
String v = answerrow.get(answerrowcounter++);
if (v != null && v.length() > 0)
{
cell.setStringValue(ConversionTools.removeHTMLNoEscape(v));
cell.setDisplayText(ConversionTools.removeHTMLNoEscape(v));
}
} else {
String answer = answerSet.getTableAnswer(table, tableRow, tableCol, false);
if (answer == null) answer = "";
Expand All @@ -638,8 +650,12 @@ private void parseAnswerSet(AnswerSet answerSet, List<String> answerrow, Publica
cell = sheet.getCellByPosition(columnIndex++, rowIndex);
if (answerSet == null)
{
cell.setStringValue(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter)));
cell.setDisplayText(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter++)));
String v = answerrow.get(answerrowcounter++);
if (v != null && v.length() > 0)
{
cell.setStringValue(ConversionTools.removeHTMLNoEscape(v));
cell.setDisplayText(ConversionTools.removeHTMLNoEscape(v));
}
} else {
List<Answer> answers = answerSet.getAnswers(question.getId(), question.getUniqueId());

Expand Down Expand Up @@ -718,8 +734,12 @@ private void parseAnswerSet(AnswerSet answerSet, List<String> answerrow, Publica
cell = sheet.getCellByPosition(columnIndex++, rowIndex);
if (answerSet == null)
{
cell.setStringValue(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter)));
cell.setDisplayText(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter++)));
String v = answerrow.get(answerrowcounter++);
if (v != null && v.length() > 0)
{
cell.setStringValue(ConversionTools.removeHTMLNoEscape(v));
cell.setDisplayText(ConversionTools.removeHTMLNoEscape(v));
}
} else {
List<Answer> answers = answerSet.getAnswers(question.getId(), question.getUniqueId());

Expand Down
69 changes: 36 additions & 33 deletions src/main/java/com/ec/survey/tools/export/XmlExportCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -794,44 +794,47 @@ void parseAnswerSet(Survey survey, XMLStreamWriter writer, List<Element> questio
} else {

String sanswers = row.get(answerrowcounter++);
String[] answers = sanswers.split(";");
for (String answer : answers)
{
if (answer.length() > 0) {
writer.writeStartElement("Answer");
writer.writeAttribute("qid", question.getUniqueId());
if (question instanceof ChoiceQuestion)
{
writer.writeAttribute("aid", answer);
} else if (question instanceof Upload)
{
StringBuilder text = new StringBuilder();
File file;
try {

if (answer.contains("|"))
{
answer = answer.substring(0, answer.indexOf("|"));
}

file = fileService.get(answer);
if (!uploadedFilesByQuestionUID.containsKey(question.getUniqueId()))
{
uploadedFilesByQuestionUID.put(question.getUniqueId(), new ArrayList<>());

if (sanswers != null) {
String[] answers = sanswers.split(";");
for (String answer : answers)
{
if (answer.length() > 0) {
writer.writeStartElement("Answer");
writer.writeAttribute("qid", question.getUniqueId());
if (question instanceof ChoiceQuestion)
{
writer.writeAttribute("aid", answer);
} else if (question instanceof Upload)
{
StringBuilder text = new StringBuilder();
File file;
try {

if (answer.contains("|"))
{
answer = answer.substring(0, answer.indexOf("|"));
}

file = fileService.get(answer);
if (!uploadedFilesByQuestionUID.containsKey(question.getUniqueId()))
{
uploadedFilesByQuestionUID.put(question.getUniqueId(), new ArrayList<>());
}
uploadedFilesByQuestionUID.get(question.getUniqueId()).add(file);

text.append((text.length() > 0) ? ";" : "").append(file.getName());
} catch (FileNotFoundException e) {
logger.error(e.getLocalizedMessage(), e);
}
uploadedFilesByQuestionUID.get(question.getUniqueId()).add(file);

text.append((text.length() > 0) ? ";" : "").append(file.getName());
} catch (FileNotFoundException e) {
logger.error(e.getLocalizedMessage(), e);
writer.writeCharacters(text.toString());
} else {
writer.writeCharacters(ConversionTools.removeInvalidHtmlEntities(answer));
}

writer.writeCharacters(text.toString());
} else {
writer.writeCharacters(ConversionTools.removeInvalidHtmlEntities(answer));
writer.writeEndElement(); //Answer
}

writer.writeEndElement(); //Answer
}
}
}
Expand Down

0 comments on commit 195e6fb

Please sign in to comment.