### Implementing Customer Entity as JAX-RS Sub-Resource Source: https://github.com/re-engineering-domain-driven-design/accounting/blob/main/README.md This Java class represents a Customer entity as a JAX-RS sub-resource. It provides methods to retrieve customer details (get), and navigate to associated resources like source-evidences and accounts via sub-resource locators. ```java public class CustomerApi { private Customer customer; public CustomerApi(Customer customer) { this.customer = customer; } @GET public CustomerModel get(@Context UriInfo info) { return new CustomerModel(customer, info); } @Path("source-evidences") public SourceEvidencesApi sourceEvidences(@Context ResourceContext context) { return context.initResource(new SourceEvidencesApi(customer)); } @Path("accounts") public AccountsApi accounts() { return new AccountsApi(customer); } } ``` -------------------------------- ### Implementing Source Evidences as JAX-RS Sub-Resource Source: https://github.com/re-engineering-domain-driven-design/accounting/blob/main/README.md This Java class implements the SourceEvidences association as a JAX-RS sub-resource for a Customer. It provides endpoints for finding a specific source evidence by ID, retrieving all source evidences with pagination, and creating new source evidences via a POST request. ```java public class SourceEvidencesApi { private Customer customer; @Inject private SourceEvidenceReader reader; public SourceEvidencesApi(Customer customer) { this.customer = customer; } @GET @Path("{evidence-id}") public SourceEvidenceModel findById(@PathParam("evidence-id") String id, @Context UriInfo info) { return customer.sourceEvidences().findByIdentity(id).map(evidence -> SourceEvidenceModel.of(customer, evidence, info)) .orElseThrow(() -> new WebApplicationException(Response.Status.NOT_FOUND)); } @GET public CollectionModel findAll(@Context UriInfo info, @DefaultValue("0") @QueryParam("page") int page) { return new Pagination<>(customer.sourceEvidences().findAll(), 40).page(page, evidence -> SourceEvidenceModel.simple(customer, evidence, info), p -> sourceEvidences(info).queryParam("page", p).build(customer.getIdentity())); } @POST public Response create(String json, @Context UriInfo info) { SourceEvidence evidence = customer.add(reader.read(json) .orElseThrow(() -> new WebApplicationException(Response.Status.NOT_ACCEPTABLE)).description()); return Response.created(ApiTemplates.sourceEvidence(info).build(customer.getIdentity(), evidence.getIdentity())).build(); } } ``` -------------------------------- ### Exposing Root Association (Customers) as JAX-RS Root Resource Source: https://github.com/re-engineering-domain-driven-design/accounting/blob/main/README.md This Java class implements the root association 'Customers' as a JAX-RS root resource. It provides a constructor for dependency injection of the Customers object and a findById method to locate a specific customer, returning a CustomerApi sub-resource. ```java @Path("/customers") public class CustomersApi { private Customers customers; @Inject public CustomersApi(Customers customers) { this.customers = customers; } @Path("{id}") public CustomerApi findById(@PathParam("id") String id) { return customers.findById(id).map(CustomerApi::new).orElse(null); } } ``` -------------------------------- ### Java Entity Association Interfaces for Smart Domain Architecture Source: https://github.com/re-engineering-domain-driven-design/accounting/blob/main/README.md This code defines the core entities (Customer, Account, SourceEvidence) and their associations using inner interfaces within a Smart Domain Architecture pattern. It demonstrates how `HasMany` interfaces are used to manage relationships like `sourceEvidences` and `accounts` for `Customer`, and `transactions` for `Account` and `SourceEvidence`, encapsulating association manipulation logic within the entity. ```Java public class Customer implements Entity { private SourceEvidences sourceEvidences; private Accounts accounts; public HasMany> sourceEvidences() { return sourceEvidences; } public HasMany accounts() { return accounts; } public interface SourceEvidences extends HasMany> { SourceEvidence add(SourceEvidenceDescription description); } public interface Accounts extends HasMany { void update(Account account, Account.AccountChange change); } } public class Account implements Entity { private Transactions transactions; public HasMany transactions() { return transactions; } public interface Transactions extends HasMany { Transaction add(Account account, SourceEvidence evidence, TransactionDescription description); } } public interface SourceEvidence extends Entity { HasMany transactions(); interface Transactions extends HasMany { } } ``` -------------------------------- ### Implementing Reference Lifecycle for Account Transactions Source: https://github.com/re-engineering-domain-driven-design/accounting/blob/main/README.md This Java class demonstrates a 'reference' lifecycle for the association between account and transactions. It extends EntityList from reengineering.ddd.mybatis.database, indicating that transactions are loaded from the database on demand, suitable for large collections. ```java import reengineering.ddd.mybatis.database.EntityList; public class AccountTransactions extends EntityList implements Account.Transactions { } ``` -------------------------------- ### Implementing Aggregated Lifecycle for Source Evidence Transactions Source: https://github.com/re-engineering-domain-driven-design/accounting/blob/main/README.md This Java class demonstrates an 'aggregated' lifecycle for the association between source evidence and transactions. It extends EntityList from reengineering.ddd.mybatis.memory, implying that associated transactions are loaded into memory along with the source evidence. ```java import reengineering.ddd.mybatis.memory.EntityList; public class SourceEvidenceTransactions extends EntityList implements SourceEvidence.Transactions { } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.