Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CARDS-2571: Reference Questions do not work inside Conditional Sections #1802

Open
wants to merge 2 commits into
base: CARDS-2509
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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