Skip to content

Commit

Permalink
Started playing with evaluating things against date literals
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed Feb 21, 2022
1 parent 6907297 commit b858500
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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 ) );
}
}
}

0 comments on commit b858500

Please sign in to comment.