Base Entity Classes
To support the object-oriented Domain Driven Architecture, there is a set of Java entity classes in the org.opentaps.domain.base.entities package for all the entities defined with the ofbiz entity engine, both from the original ofbiz applications and the opentaps applications. The entity classes contain all the fields of the entity, accessor (get/set) methods for each field, and fromMap and toMap methods to convert the Java class to a Map.
The entity classes are automatically generated using a freemarker template hot-deploy/opentaps-common/templates/BaseEntity.ftl, based on the entitymodel.xml definitions for all the entities, including view-entities and fields defined by the extend-entity tags, and the Java types defined in the fieldtype XML files for the entity engine. To generate base entities, from the opentaps directory,
$ ant make-base-entities
It will clear out all the files in the base entities package, start opentaps and load the delegator, and then regenerate the Java classes based on the current entity definitions.
The base entity Java classes could be used as a replacement for the ofbiz GenericEntity/GenericValue objects. To go from a GenericValue to a Java class, use the Repository.loadFromGeneric methods, such as:
Repository repository = new Repository(delegator); List enumerationEntities = repository.loadFromGeneric(Enumeration.class, enumerations);
When you are working from a repository, you should use the loadFromGeneric method which also sets the repository for a new object:
GenericValue value = getDelegator().findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId)); Invoice invoice = (Invoice) this.loadFromGeneric(Invoice.class, value, this);
These methods uses reflection to access the fromMap method of entity classes. They can create a one object from one GenericValue or a List of objects from a List of GenericValues.
To go from a Java class, you can simply use the toMap method to create a GenericValue, such as:
Enumeration enumeration = new Enumeration(); // set its values GenericValue value = new GenericValue(enumeration.toMap());
DO NOT MODIFY THESE BASE ENTITY CLASSES. They should be automatically generated every time your data model changes, so all your changes will be overwritten. If you have more complex classes, extend these base entity classes and implement the additional methods there.