Skip to content

Commit

Permalink
CARDS-2571: Reference Questions do not work inside Conditional Sections
Browse files Browse the repository at this point in the history
Fix bug where incorrect form would be prioritized
  • Loading branch information
acrowthe committed Nov 8, 2024
1 parent 2987bc3 commit 2dc5c5b
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ private void iterateAnswers(final NodeBuilder node, Set<NodeBuilder> unlinkedRef
Node sourceAnswer = this.serviceSession.getNode(
node.getProperty("copiedFrom").getValue(Type.REFERENCE));
Node form = this.formUtils.getForm(sourceAnswer);
String questionnaireId = this.formUtils.getQuestionnaireIdentifier(form);
sourceForms.add(questionnaireId);
sourceForms.add(form.getIdentifier());
}
} catch (RepositoryException e) {
// Unable to process answer - do nothing
Expand Down Expand Up @@ -382,7 +381,7 @@ private ReferenceAnswer getAnswer(String questionPath, Set<String> sourceForms)
Node answer;
// Prioritize answers in forms that are already referenced
Optional<Node> priorityAnswer = answers.stream().filter(a ->
sourceForms.contains(this.formUtils.getQuestionnaireIdentifier(this.formUtils.getForm(a))))
sourceForms.contains(getIdentifierOrNull(this.formUtils.getForm(a))))
.findAny();
if (priorityAnswer.isPresent()) {
answer = priorityAnswer.get();
Expand All @@ -401,6 +400,15 @@ private ReferenceAnswer getAnswer(String questionPath, Set<String> sourceForms)
return null;
}

private String getIdentifierOrNull(Node node)
{
try {
return node.getIdentifier();
} catch (RepositoryException e) {
return null;
}
}

private Object serializeValue(final Object rawValue)
{
if (rawValue instanceof Calendar) {
Expand Down

0 comments on commit 2dc5c5b

Please sign in to comment.