/** * Utility method to enrich the error message with. * * @param message * The error message * @param context * The failed execution context * @return Enriched error message */ private static String prefix(String message, ExecutionContext context) { return "Rule: \'" + context.getDefinition().getName() + "\' failed with error: " + message; }
/** * Constructor. */ public RuleDefinitionBuilder() { objectUnderConstruction = new RuleDefinition(); }
/** * Sets {@link RuleDefinition#fireCondition}. * * @param fireCondition * New value for {@link RuleDefinition#fireCondition} */ public void setFireCondition(FireCondition fireCondition) { objectUnderConstruction.setFireCondition(fireCondition); }
@Override public TagInjection visit(TagValue annotation, Field field) { return new TagInjection(annotation.type(), field, annotation.injectionStrategy()); } });
@Override public ActionMethod visit(Action annotation, Method method) throws RuleDefinitionException { return new ActionMethod(method, annotation.resultTag(), annotation.resultQuantity()); } });
@Override public ConditionMethod visit(Condition annotation, Method method) throws RuleDefinitionException { return new ConditionMethod(annotation.name(), annotation.hint(), method); } });
@Override public SessionVariableInjection visit(SessionVariable annotation, Field field) { return new SessionVariableInjection(annotation.name(), annotation.optional(), field); } });
/** * {@inheritDoc} */ @Override public Object determineValueToInject(ExecutionContext context) throws RuleExecutionException { // Fail fast if value is missing completely and not optional. if (!isOptional() && !context.getSessionParameters().containsKey(getVariableName())) { throw new RuleExecutionException("Non optional session variable \'" + getVariableName() + "\' not available.", context); } // This might return null if a null value is available for a certain key. // Needs to be discussed how to handle this. return context.getSessionParameters().get(getVariableName()); }
/** * {@inheritDoc} */ @Override public void store(RuleOutput output) { if (output.hasConditionFailures()) { conditionFailures.put(output.getEmbeddedTagType(), output); } else { allOutputs.put(output.getEmbeddedTagType(), output); } }
@BeforeMethod public void init() { context = new ExecutionContext(definition, dummy, input, variables); }
/** * {@inheritDoc} */ @Override public String toString() { return "TagInjection [type=" + type + ", injectionStrategy=" + injectionStrategy + ", getInjectee()=" + getInjectee() + "]"; }
/** * Sets {@link RuleDefinition#variableInjections}. * * @param variableInjections * New value for {@link RuleDefinition#variableInjections} */ public void setSessionVariableInjections(List<SessionVariableInjection> variableInjections) { objectUnderConstruction.setSessionVariableInjections(variableInjections); }
/** * Sets {@link RuleDefinition#tagInjections}. * * @param tagInjections * New value for {@link RuleDefinition#tagInjections} */ public void setTagInjections(List<TagInjection> tagInjections) { objectUnderConstruction.setTagInjections(tagInjections); }
/** * Sets {@link RuleDefinition#description}. * * @param description * New value for {@link RuleDefinition#description} */ public void setDescription(String description) { objectUnderConstruction.setDescription(description); }
/** * Sets {@link RuleDefinition#implementation}. * * @param implementation * New value for {@link RuleDefinition#implementation} */ public void setImplementation(Class<?> implementation) { objectUnderConstruction.setImplementation(implementation); }
/** * Sets {@link RuleDefinition#name}. * * @param name * New value for {@link RuleDefinition#name} */ public void setName(String name) { objectUnderConstruction.setName(name); }
/** * Sets {@link RuleDefinition#actionMethod}. * * @param actionMethod * New value for {@link RuleDefinition#actionMethod} */ public void setActionMethod(ActionMethod actionMethod) { objectUnderConstruction.setActionMethod(actionMethod); }
/** * Sets {@link RuleDefinition#conditionMethods}. * * @param conditionMethods * New value for {@link RuleDefinition#conditionMethods} */ public void setConditionMethods(List<ConditionMethod> conditionMethods) { objectUnderConstruction.setConditionMethods(conditionMethods); }
/** * {@inheritDoc} */ @Override public String toString() { return "SessionVariableInjection [variableName=" + variableName + ", optional=" + optional + ", getInjectee()=" + getInjectee() + "]"; }
/** * {@inheritDoc} */ @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = (prime * result) + (this.optional ? 1231 : 1237); result = (prime * result) + ((this.variableName == null) ? 0 : this.variableName.hashCode()); return result; }