Created
July 25, 2018 13:44
-
-
Save francoislg/7f5c1bef175296af0a631b7fc9e10578 to your computer and use it in GitHub Desktop.
Implementation of "SpecificItemCondition<T>" in Coveo for Sitecore Hive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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