Skip to content

Instantly share code, notes, and snippets.

@francoislg
Created July 25, 2018 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francoislg/7f5c1bef175296af0a631b7fc9e10578 to your computer and use it in GitHub Desktop.
Save francoislg/7f5c1bef175296af0a631b7fc9e10578 to your computer and use it in GitHub Desktop.
Implementation of "SpecificItemCondition<T>" in Coveo for Sitecore Hive
public class SpecificItemCondition<T> : WhenCondition<T>, ICoveoCondition<T>
where T : RuleContext
{
private readonly IQueryNodeBuilder m_NodeBuilder;
private readonly ILocalizedStringFetcher m_LocalizedStringFetcher;
public ID ItemId { get; set; }
public SpecificItemCondition () : this (StaticServiceRegistrer.GetService<IQueryNodeBuilder> (),
StaticServiceRegistrer.GetService<ILocalizedStringFetcher> ()) { }
internal SpecificItemCondition (IQueryNodeBuilder p_QueryNodeBuilder,
ILocalizedStringFetcher p_LocalizedStringFetcher) {
Precondition.NotNull (p_QueryNodeBuilder, () => () => p_QueryNodeBuilder);
Precondition.NotNull (p_LocalizedStringFetcher, () => () => p_LocalizedStringFetcher);
m_NodeBuilder = p_QueryNodeBuilder;
m_LocalizedStringFetcher = p_LocalizedStringFetcher;
}
public IQueryNode GetQueryNode (ConditionContext p_Context) {
return m_NodeBuilder.BuildFieldNode (BuiltinFields.ID,
QueryNodeOperator.ExactMatch,
ItemId.ToShortID ().ToString ());
}
public RuleCondition<T> GetWrappedCondition () {
return this;
}
public void ValidateCondition (IErrorReport p_Report) {
Precondition.NotNull (p_Report, () => () => p_Report);
if (ItemId == (ID) null) {
p_Report.AddError (m_LocalizedStringFetcher[LocalizedStringKeys.CONDITION_MUST_HAVE_A_VALUE]);
}
}
protected override bool Execute (T p_RuleContext) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment