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
- Update reference question initialization code to check for unlinked reference questions
  any time a form is edited, not just when a form is created
  - Search for any reference questions on the form that do not have an answer
  - Check if the missing questions have an existing answer section. If so, generate an answer
  - Try to find a source answer for any existing or newly created unanswered reference answers
    - Prioritize pulling source answers from forms that are already referenced by other
      reference answers in this form for consistency
- Add test case in ReferenceTestCopied form
  • Loading branch information
acrowthe committed Nov 8, 2024
1 parent 530f6b7 commit 011e4d3
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import javax.jcr.Node;

import org.apache.jackrabbit.oak.api.Type;

/**
* Basic utilities for working with Questionnaires.
*
Expand Down Expand Up @@ -190,4 +192,12 @@ public interface QuestionnaireUtils
* @return the question's description, or an empty string if no description is present
*/
String getQuestionDescription(Node question);

/**
* Retrieve the Oak {@code Type} mapping for this question's answers.
*
* @param question a {@code cards:Question} node
* @return the Oak {@code Type} for this question's answer or {@code Type.STRING} if it could not be determined
*/
Type<?> getAnswerType(Node question);
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,39 +375,4 @@ public String toString()
+ (this.node == null ? "" : " node: " + this.node.toString()) + " }";
}
}

protected Type<?> getAnswerType(final Node questionNode)
{
Type<?> result = Type.STRING;
try {
final String dataTypeString = questionNode.getProperty("dataType").getString();
switch (dataTypeString) {
case "long":
result = Type.LONG;
break;
case "double":
result = Type.DOUBLE;
break;
case "decimal":
result = Type.DECIMAL;
break;
case "boolean":
// Long, not boolean
result = Type.LONG;
break;
case "date":
result = (questionNode.hasProperty("dateFormat") && "yyyy".equals(
questionNode.getProperty("dateFormat").getString().toLowerCase()))
? Type.LONG
: Type.DATE;
break;
default:
result = Type.STRING;
}
} catch (RepositoryException e) {
getLogger().warn("Error typing value for question. " + e.getMessage());
// It's OK to assume String by default
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void computeAnswer(final Map.Entry<Node, NodeBuilder> entry, NodeState f
try {
final Node question = entry.getKey();
final NodeBuilder answer = entry.getValue();
Type<?> resultType = getAnswerType(question);
Type<?> resultType = this.questionnaireUtils.getAnswerType(question);

ExpressionUtils.ExpressionResult expressionResult = this.expressionUtils.evaluate(question,
answersByQuestionName, resultType, changedQuestions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.jcr.RepositoryException;

import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.oak.api.Type;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

Expand Down Expand Up @@ -181,4 +182,39 @@ public String getQuestionDescription(final Node question)
{
return isQuestion(question) ? StringUtils.defaultString(getStringProperty(question, "description")) : "";
}

@Override
public Type<?> getAnswerType(final Node question)
{
Type<?> result = Type.STRING;
try {
final String dataTypeString = question.getProperty("dataType").getString();
switch (dataTypeString) {
case "long":
result = Type.LONG;
break;
case "double":
result = Type.DOUBLE;
break;
case "decimal":
result = Type.DECIMAL;
break;
case "boolean":
// Long, not boolean
result = Type.LONG;
break;
case "date":
result = (question.hasProperty("dateFormat") && "yyyy".equals(
question.getProperty("dateFormat").getString().toLowerCase()))
? Type.LONG
: Type.DATE;
break;
default:
result = Type.STRING;
}
} catch (RepositoryException e) {
// Default to STRING
}
return result;
}
}
Loading

0 comments on commit 011e4d3

Please sign in to comment.