Skip to content

Commit

Permalink
Added ability to pass in literals to fflib_Criteria
Browse files Browse the repository at this point in the history
Started work on Date Literals for use with fflib_Criteria
  • Loading branch information
rob-baillie-ortoo committed Feb 21, 2022
1 parent 234dc61 commit 6907297
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,11 @@ public virtual with sharing class fflib_Criteria
this.embraced = embraced;
}

// TODO: move - consider adding to the original library
public interface Literal {
String toLiteral();
}

/**
* @param value The value to convert
*
Expand All @@ -777,6 +782,12 @@ public virtual with sharing class fflib_Criteria
{
if (value == null) return 'null';

// TODO: test this
if ( value instanceOf Literal )
{
return ((Literal)value).toLiteral();
}

if (value instanceof String || value instanceof Id)
{
String manipulated = (String) value;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/**
* Class that provides a list of inner classes that can be used as targets for comparisons in ortoo_Criteria.
*
* Specifically, the classes represent the different Date Literals that SOQL supports
*
* @group fflib Extension
*/
public inherited sharing class ortoo_DateLiterals
{
// TODO: consider 'compare' - how do we do that?
private interface Literal extends fflib_Criteria.Literal {}

public class Today implements Literal
{
public String toLiteral()
{
return 'TODAY';
}
}

public class Yesterday implements Literal
{
public String toLiteral()
{
return 'YESTERDAY';
}
}

public class LastWeek implements Literal
{
public String toLiteral()
{
return 'LAST_WEEK';
}
}

public class ThisWeek implements Literal
{
public String toLiteral()
{
return 'THIS_WEEK';
}
}

public class NextWeek implements Literal
{
public String toLiteral()
{
return 'NEXT_WEEK';
}
}

public class LastMonth implements Literal
{
public String toLiteral()
{
return 'LAST_MONTH';
}
}

public class ThisMonth implements Literal
{
public String toLiteral()
{
return 'THIS_MONTH';
}
}

public class NextMonth implements Literal
{
public String toLiteral()
{
return 'NEXT_MONTH';
}
}

public class Last90Days implements Literal
{
public String toLiteral()
{
return 'LAST_90_DAYS';
}
}

public class Next90Days implements Literal
{
public String toLiteral()
{
return 'NEXT_90_DAYS';
}
}

public class LastNDays extends NumericallyQualifiedLiteral
{
public LastNDays( Integer numberOfThings )
{
super( numberOfThings, 'LAST_N_DAYS' );
}
}

public class NextNDays extends NumericallyQualifiedLiteral
{
public NextNDays( Integer numberOfThings )
{
super( numberOfThings, 'NEXT_N_DAYS' );
}
}

public class LastNWeeks extends NumericallyQualifiedLiteral
{
public LastNWeeks( Integer numberOfThings )
{
super( numberOfThings, 'LAST_N_WEEKS' );
}
}

public class NextNWeeks extends NumericallyQualifiedLiteral
{
public NextNWeeks( Integer numberOfThings )
{
super( numberOfThings, 'NEXT_N_WEEKS' );
}
}

public class LastNMonths extends NumericallyQualifiedLiteral
{
public LastNMonths( Integer numberOfThings )
{
super( numberOfThings, 'LAST_N_MONTHS' );
}
}

public class NextNMonths extends NumericallyQualifiedLiteral
{
public NextNMonths( Integer numberOfThings )
{
super( numberOfThings, 'NEXT_N_MONTHS' );
}
}

private abstract class NumericallyQualifiedLiteral implements Literal
{
Integer numberOfThings;
String baseLiteral;

protected NumericallyQualifiedLiteral( Integer numberOfThings, String baseLiteral )
{
Contract.requires( numberOfThings != null, 'constructor called with a null numberOfThings' );
Contract.requires( baseLiteral != null, 'constructor called with a null baseLiteral' );

this.numberOfThings = numberOfThings;
this.baseLiteral = baseLiteral;
}

public String toLiteral()
{
return this.baseLiteral + ':' + this.numberOfThings;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>52.0</apiVersion>
<status>Active</status>
</ApexClass>

0 comments on commit 6907297

Please sign in to comment.