org.jharks.workflow.conditions.DynaResponseExistCondition Maven / Gradle / Ivy
package org.jharks.workflow.conditions;
import java.util.List;
import org.jharks.workflow.Answer;
import org.jharks.workflow.SessionHistory;
/**
* The class will check whether any response exist for a dynamic
* question. A dynamic question is composed of configured question
* id that is conditional upon a current property set within the
* SessionHistory object.
*
* This class takes two attributes that should be configured
* as <property> elements of the <rule-condition> tag:
*
* - questionId - the key of the question to check for any reponses
* in the
SessionHistory.
* - propertyName - the session property name to append to the dynamic
* questionId key.
*
*
* If the property name is set the value currently set for the property in the
* session will be appended to the questionId. The session responseSet will
* then be interrogated for any reponses to the dynamic key (questionId +
* property value).
*
* For example, to check whether any reponses exists for the medication question
* when within a Problem Class processing loop you could use a transition
* configured as:
*
* <transition name="moveAllergySpecial" next-state="alSp1">
* <rule type="org.jharks.workflow.rules.GenericOrRule">
* <rule-condition type="org.jharks.workflow.conditions
* .DynaResponseExistCondition">
* <property name="questionId" value="medQ1"/>
* <property name="propertyName" value="Problem Class"/>
* </rule-condition>
* </rule>
* </transition>
*
*
* @author Michael J. Rizzo
* @version 1.0
*/
public class DynaResponseExistCondition extends ResponseExistCondition {
/** The session property which will be used in building dynamic key */
private String propertyName;
/**
* @see org.jharks.workflow.RuleCondition#checkCondition(
* java.lang.Object)
*/
public boolean checkCondition(Object param) {
if (param instanceof SessionHistory) {
SessionHistory sh = (SessionHistory) param;
StringBuffer sb = new StringBuffer();
if(getQuestionId() != null) {
sb.append(getQuestionId());
}
if (getPropertyName() != null) {
String prop = (String) sh.getProperty(getPropertyName());
if (prop != null && (! prop.trim().equals("")))
sb.append("-")
.append(prop);
}
List responses = sh.getResponses(sb.toString());
if (responses != null && responses.size() > 0) {
return true;
}
return false;
} else {
throw new ClassCastException("Expecting Session History Object.");
}
}
/**
* Return the configured session property name.
* @return Returns the propertyName.
*/
public String getPropertyName() {
return propertyName;
}
/**
* Set the session property name to be used in buidling the dynamic
* question key.
* @param propertyName The propertyName to set.
*/
public void setPropertyName(String propertyName) {
this.propertyName = propertyName;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy