Entity Builders

If Domain modelling is enabled, the SDK provides Builders for entities. These builders can be easily used to construct entities using the builder pattern which allow to write readable, understandable code to set up complex objects.

Namespace entity builders

  • Each namespace has its own entity builder grouping usually prefixed with the namespace prefix.

  • Namespace with prefix cc would get a CcEntityBuilder class that can be injected and groups all the entity builders in that domain.

For example:

// Import Entity Builder of namespace prefixed by cc
import de.cards.sdk.domain.cc.facade;

// Declaring Entity Builder for namespace cc
@Autowired
protected CcEntityBuilder ccEntityBuilder;

// Using Entity Builder to construct an entity "CreditCard"
CreditCard creditCardEntity = ccEntityBuilder.getCreditCard().setName("John Doe").build();

Domain entity builder

Besides Namespace entity builders, the SDK also provides a DomainEntityBuilder which groups all namespace entity builders of domain namespaces.

Tip:

You can inject the DomainEntityBuilder into your implementation code as shown below. Additionally, in the implementation of services, agents and commands, it is available automatically as entityBuilder, derived from the base class.

// Import DomainEntityBuilder
import de.cards.sdk.domain.facade.DomainEntityBuilder;

// Declare & Inject Domain Entity Builder
@Autowired
private DomainEntityBuilder domainEntityBuilder;

// Use the Domain Entity Builder to create an entity that was modelled in domain namespace 
// with prefix: cc
Owner owner = this.domainEntityBuilder.getCc().getOwner().build();

// use default entityBuilder derived from the base class
// Create a customer entity that exists in a domain namespace prefixed by cc.
Customer customer = entityBuilder.getCC().getCustomer()
        .setCustomerId("Customer Id")
        .setCustomerName("Joh Doe")
        .setAmixCard(new AmixCard("some id", CardType.debit))
        .build();
Tip:

Please also see Integration entity builder.