diff --git a/framework/default/fflib-apex-extensions/default/classes/criteria/fflib_Criteria.cls b/framework/default/fflib-apex-extensions/default/classes/criteria/fflib_Criteria.cls index 63db20059e1..9c7608a61f6 100755 --- a/framework/default/fflib-apex-extensions/default/classes/criteria/fflib_Criteria.cls +++ b/framework/default/fflib-apex-extensions/default/classes/criteria/fflib_Criteria.cls @@ -772,6 +772,10 @@ public virtual with sharing class fflib_Criteria public interface Literal { String toLiteral(); } + // TODO: move - consider adding to the original library + public interface Evaluatable { + Object toValue(); + } /** * @param value The value to convert diff --git a/framework/default/ortoo-core/default/classes/FrameworkErrorCodes.cls b/framework/default/ortoo-core/default/classes/FrameworkErrorCodes.cls index 101110e471f..26746ece8bf 100644 --- a/framework/default/ortoo-core/default/classes/FrameworkErrorCodes.cls +++ b/framework/default/ortoo-core/default/classes/FrameworkErrorCodes.cls @@ -22,11 +22,13 @@ public inherited sharing class FrameworkErrorCodes { public final static String CONFIGURATION_WITH_INVALID_CLASS = 'APP-00002'; public final static String CONFIGURATION_WITH_INVALID_SOBJECT_TYPE = 'APP-00003'; - public final static String DML_ON_INACCESSIBLE_FIELDS = '00000'; - public final static String DML_INSERT_NOT_ALLOWED = '00001'; - public final static String DML_UPDATE_NOT_ALLOWED = '00002'; - public final static String DML_DELETE_NOT_ALLOWED = '00003'; - public final static String DML_PUBLISH_NOT_ALLOWED = '00004'; + public final static String NON_EVALUATABLE_CRITERIA = 'CRI-00000'; + + public final static String DML_ON_INACCESSIBLE_FIELDS = '0000000'; + public final static String DML_INSERT_NOT_ALLOWED = '0000001'; + public final static String DML_UPDATE_NOT_ALLOWED = '0000002'; + public final static String DML_DELETE_NOT_ALLOWED = '0000003'; + public final static String DML_PUBLISH_NOT_ALLOWED = '0000004'; public final static String SELECTOR_UNBOUND_COUNT_QUERY = '0000000'; diff --git a/framework/default/ortoo-core/default/classes/fflib-extension/ortoo_DateLiterals.cls b/framework/default/ortoo-core/default/classes/fflib-extension/ortoo_DateLiterals.cls index 4243c6e8103..d9a832fe47b 100644 --- a/framework/default/ortoo-core/default/classes/fflib-extension/ortoo_DateLiterals.cls +++ b/framework/default/ortoo-core/default/classes/fflib-extension/ortoo_DateLiterals.cls @@ -7,26 +7,52 @@ */ public inherited sharing class ortoo_DateLiterals { + public class NonEvaluatableException extends ortoo_Exception {} + // TODO: consider 'compare' - how do we do that? private interface Literal extends fflib_Criteria.Literal {} + private interface Evaluatable extends fflib_Criteria.Evaluatable {} - public class Today implements Literal + public class Today implements Literal, Evaluatable { public String toLiteral() { return 'TODAY'; } + + public Date toValue() + { + return Date.today(); + } } - public class Yesterday implements Literal + public class Yesterday implements Literal, Evaluatable { public String toLiteral() { return 'YESTERDAY'; } + + public Date toValue() + { + return Date.today().addDays(-1); + } } - public class LastWeek implements Literal + public class Tomorrow implements Literal, Evaluatable + { + public String toLiteral() + { + return 'TOMORROW'; + } + + public Date toValue() + { + return Date.today().addDays(+1); + } + } + + public class LastWeek extends NonEvaluatableLiteral implements Literal { public String toLiteral() { @@ -157,4 +183,14 @@ public inherited sharing class ortoo_DateLiterals return this.baseLiteral + ':' + this.numberOfThings; } } + + private abstract class NonEvaluatableLiteral implements Evaluatable + { + public Object toValue() + { + throw new NonEvaluatableException( 'Literals of type ' + ObjectUtils.getClassName( this ) + ' cannot be evaluated in-memory' ) + .setErrorCode( FrameworkErrorCodes.NON_EVALUATABLE_CRITERIA ) + .addContext( 'ClassName', ObjectUtils.getClassName( this ) ); + } + } } \ No newline at end of file