Working with the Domain Driven Architecture
Here are some tips for working with the Domain Driven Architecture:
Contents
Instantiating Services and Repositories
If you have a domain, the easiest way to instantiate a Service or Repository from your domain is to use the instantiateService or instantiateRepository methods, like this:
public OrderInventoryService getOrderInventoryService() throws ServiceException { return instantiateService(OrderInventoryService.class); }
This will automatically set up the Infrastructure and User for your Service or Repository.
Documenting your Services
Since your domain Services do not have to be routed through the ofbiz service engine, you should put the documentation in the Java method so that they would show up in the Java docs as well. For example:
/** * Adds a <code>LockboxBatchItemDetail</code> to an existing <code>LockboxBatchItem</code>. * @throws ServiceException if an error occurs * @see #setLockboxBatchId required input <code>lockboxBatchId</code> * @see #setItemSeqId required input <code>itemSeqId</code> * @see #setAmountToApply required input <code>amountToApply</code> * @see #setCashDiscount required input <code>cashDiscount</code> * @see #setPartyId optional input <code>partyId</code> * @see #setInvoiceId optional input <code>invoiceId</code> */
Messages from Your Services
Working with Entity Field Names
Each base entity has an enumeration listing its fields, and this enumeration is used in the framework API instead of using string literals. This means it is possible to use the IDE autocompletion but also that the resulting code is no longer at risk of resulting in runtime errors due to typos.
For example, when writing condition maps for the repository find methods, the repository provides a map method which allows you to write the map like this:
findOne(Order.class, map(Order.Fields.orderId, "WS10000")); findList(OrderItemAssoc.class, map(OrderItemAssoc.Fields.orderId, "WS10000", OrderItemAssoc.Fields.orderItemSeqId, "00001"));
It is also used when retrieving distinct field values from a list, like for example:
List<OrderItem> items = findList(OrderItem.class, map(OrderItem.Fields.orderId, "WS10000")); Set productIdsInOrder = Entity.getDistinctFieldValues(items, OrderItem.Fields.productId);