Skip to content

Commit

Permalink
Merge pull request #18 from jondavis9898/master
Browse files Browse the repository at this point in the history
Add templates for fflib_DomainObjectBuilder and update Domain Class
  • Loading branch information
joeferraro committed Mar 14, 2016
2 parents 449df9c + 8be9adc commit d5224fc
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ApexClass/DomainClass.cls
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,16 @@ public class {{ api_name }} extends fflib_SObjectDomain
}
}

public class Constructor implements fflib_SObjectDomain.IConstructable
public class Constructor implements fflib_SObjectDomain.IConstructable2
{
public fflib_SObjectDomain construct(List<SObject> sObjectList)
{
return new {{ api_name }}(sObjectList);
}

public fflib_SObjectDomain construct(List<SObject> sObjectList, SObjectType sObjectType)
{
return new {{ api_name }}(sObjectList);
}
}
}
54 changes: 54 additions & 0 deletions ApexClass/DomainObjectBuilderBaseClass.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* See https://github.com/financialforcedev/fflib-apex-common for more info
*
* Install library via
* https://githubsfdeploy.herokuapp.com/app/githubdeploy/financialforcedev/fflib-apex-common
*/

/**
* Base class for Domain specific builders implementing the Test Data Builder pattern as described
* by Nate Pryce (http://www.natpryce.com/) and Object Mother Pattern (http://www.c2.com/cgi/wiki?ObjectMother)
*
* For more guidelines and details see
* https://github.com/financialforcedev/fflib-apex-common
* https://github.com/financialforcedev/fflib-apex-common-samplecode
**/
public abstract class {{ api_name }} extends fflib_DomainObjectBuilder
{
/**
* @description Constructs the Builder class with the specified SObjectType
*
* @param type The SObject type that the builder will build
**/
protected {{ api_name }}(SObjectType type)
{
super(type);
}

/**
* @description Copy Constructor that constructs the Builder class based on the builder specified
*
* @param copyFrom The builder to copy/clone this instance from
**/
protected {{ api_name }}({{ api_name }} copyFrom)
{
super(copyFrom);
}

/**
* @description Helper method to obtain the default Unit Of Work for use with persist methods
**/
protected virtual fflib_ISObjectUnitOfWork createUnitOfWork()
{
/**
* @todo If using Application class concept from the Apex Enterprise Patterns, change the below to
* return from Application.UnitOfWork.newInstance().
* If not using the Application class concept, add the default SObjectTypes that should be
* passed to Unit Of work construction. This method will be called by derived builders
* during persist() method call.
*/

//return Application.UnitOfWork.newInstance();
return new fflib_SObjectUnitOfWork(new List<SObjectType> {});
}
}
144 changes: 144 additions & 0 deletions ApexClass/DomainObjectBuilderClass.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/**
* See https://github.com/financialforcedev/fflib-apex-common for more info
*
* Install library via
* https://githubsfdeploy.herokuapp.com/app/githubdeploy/financialforcedev/fflib-apex-common
*/

/**
* Domain specific class implementing the Test Data Builder pattern as described by Nate Pryce
* (http://www.natpryce.com/) and Object Mother Pattern (http://www.c2.com/cgi/wiki?ObjectMother)
*
* For more guidelines and details see
* https://github.com/financialforcedev/fflib-apex-common
* https://github.com/financialforcedev/fflib-apex-common-samplecode
**/
public class {{ api_name }} extends {{ base_name }}
{
/**
* @description Default constructor
**/
private {{ api_name }}()
{
super({{ object_name }}.SObjectType);
}

/**
* @description Copy Constructor that constructs the Builder class based on the builder specified
*
* @param copyFrom The builder to copy/clone this instance from
**/
private {{ api_name }}({{ api_name }} copyFrom)
{
super(copyFrom);
}

/**
* @description Creates an existing SObject without issuing DML
*
* @remarks Wrapper method to base class to allow for casting of specific SObjectType
**/
public {{ object_name }} build()
{
return ({{ object_name }})build(false);
}

/**
* @description Creates an New SObject (No Id) without issuing DML
*
* @remarks Wrapper method to base class to allow for casting of specific SObjectType
**/
public {{ object_name }} buildNew()
{
return ({{ object_name }})build(true);
}

/**
* @description Persists builder and its related data through Unit Of Work
*
* @remarks Wrapper method to base class to allow for casting of specific SObjectType
**/
public {{ object_name }} persist(fflib_ISObjectUnitOfWork uow)
{
return ({{ object_name }})persistBuilder(uow);
}

/**
* @description Persists builder and its related data using default unit of work
*
* @remarks Wrapper method to base class to allow for casting of specific SObjectType
**/
public {{ object_name }} persist()
{
return persist(createUnitOfWork());
}

/**
* @description Registers instance for persistance via persistBuilders
*
* @remarks Wrapper method to base class to allow for casting of specific SObjectType
**/
public {{ api_name }} register()
{
return ({{ api_name }})registerBuilder();
}

/**
* @description Returns Contact SObject associated to this builder
*
* @remarks Wrapper method to base class to allow for casting of specific SObjectType
**/
public {{ object_name }} Record
{
get { return ({{ object_name }})getRecord(); }
private set;
}

/**
* @description Returns a Clone of this instance
**/
public {{ api_name }} but()
{
return new {{ api_name }}(this);
}

/**
* @description Object Mother method for an empty {{ api_name }} instance
**/
public static {{ api_name }} {{ mother_name }}()
{
return new {{ api_name }}();
}

/*
* @todo Add additional Object Mother methods for commonly used values
*
* For more examples see https://github.com/financialforcedev/fflib-apex-common-samplecode
*
*
public static {{ api_name }} {{ mother_name }}WithRequiredFields()
{
return {{ mother_name }}()
.withName('Test Name')
.withType('My Type');
}
*/

/*
* @todo Add methods to set field values
*
* For more examples see https://github.com/financialforcedev/fflib-apex-common-samplecode
*
public {{ api_name }} withName(String value)
{
set({{ object_name }}.Name, value);
return this;
}
public {{ api_name }} withAccount(Account_t value)
{
setParent({{ object_name }}.AccountId, value);
return this;
}
*/
}
41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,47 @@
}
]
},
{
"name":"DomainObjectBuilder",
"file_name":"DomainObjectBuilderClass.cls",
"description":"Apex Enterprise Patterns Domain Object Builder Class",
"author":"Jon Davis @jondavis9898",
"params":[
{
"name":"api_name",
"description":"Domain Object Builder class name",
"default":"Invoice_t"
},
{
"name":"base_name",
"description":"Domain Object Builder Base class name",
"default":"Domain_t"
},
{
"name":"object_name",
"description":"API name of the Standard or Custom Object",
"default":"Invoice__c"
},
{
"name":"mother_name",
"description":"Method name for empty Builder Object Mother method",
"default":"anInvoice"
}
]
},
{
"name":"DomainObjectBuilderBase",
"file_name":"DomainObjectBuilderBaseClass.cls",
"description":"Apex Enterprise Patterns Domain Object Builder Base Class",
"author":"Jon Davis @jondavis9898",
"params":[
{
"name":"api_name",
"description":"Domain Object Builder Base class name",
"default":"Domain_t"
}
]
},
{
"name":"Email Service",
"file_name":"EmailServiceApexClass.cls",
Expand Down

0 comments on commit d5224fc

Please sign in to comment.