Skip to end of banner
Go to start of banner

BO (Business Objects)

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 21 Next »

Business Objects

Business objects implement the software's business logic. They are responsible for handling data objects (constructing, loading, saving, deleting) and any other business logic related with the business module. For every data object, there is a business object that handles it. Business objects do not implement any process flows, but offer services to the Controller layer (UI, API, Process)

In CRM.COM Software, we implement the business object classes using EJBs (Enterprise Java Beans) J2EE server-side components, and more specifically we use Stateless Session Beans. More information about EJBs can be found here.

Creating the Business Object Classes

The first thing to do is to create an EJB that will handle our business objects. In order to create our class we must first decide the name of the package to place it in. Based on the business structure, the respective packages should be created. Based on CRM.COM naming conventions, all business objects are stored in the com.crm.businessobject package. Based on the module we are implementing, further packages are then created in here.

 

In this case, we will create the package com.crm.businessobject.accounts that will contain the module's business object classes, and create the CRMBOBankBean.java business object class.

 

 Creating CRMBOBankBean.java

 

Note that on EJB creation, we also specify the super class of the class we are creating, depending on the business logic of our class. In this case we select the com.crm.businessobject.CRMBO as the super class.

 

To implement the basic business logic in our class, we will need to create the following methods:

constructDO
    /**
     * Constructs a bank.
     * 
     * @param mainDTO - the main data object
     * @return a bank
     * @throws Exception
     */
	@Override
	protected CRMDO constructDO(CRMDO mainDTO) throws Exception {
		...
	}

This method creates a new instance of the data object. In this method we add any business logic required when creating a new entity. The mainDTO parameter is not null in case the data object to be created should be related with another data object.

 

saveDO
    /**
     * Saves a bank.
     * 
     * @param dto - the bank to save
     * @return the saved bank
     * @throws Exception
     */
	@Override
	protected CRMDO saveDO(CRMDO dto) throws Exception {
		...
	}

This method saves the data objects to the database. In this method we add any business logic required to be executed when saving an entity.

 

deleteDO
    /**
     * Deletes a bank.
     * 
     * @param dto - the bank to delete
     * @return the deleted bank
     * @throws Exception
     */
	@Override
	protected CRMDO deleteDO(CRMDO dto) throws Exception {
		...
	}

This method deletes the data objects. In this method we add any business logic required to be executed when deleting an entity. Note that records are not physically deleted but marked as deleted. 

 

validateDOonSave
    /**
     * Validates a bank on save.
     * 
     * @param dto - the bank to validate
     * @throws Exception
     */
	@Override
	protected void validateDOonSave(CRMDO dto) throws Exception {
		...
	}

This method validates the data objects before saving to the database. Any validations that should be done before saving the data object to the database should be performed in this method.

 

validateDOonDelete
    /**
     * Validates a bank on delete.
     * 
     * @param dto - the bank to validate
     * @throws Exception
     */
	@Override
	protected void validateDOonDelete(CRMDO dto) throws Exception {
		...
	}

This method validates the data objects before saving to the database as deleted. Any validations that should be done before deleting the data object should be performed in this method.

 

getDataObjectClass
    /**
     * Returns the data object class of a bank.
     * 
     * @return the data object class of the bank
     */
	@Override
	protected Class<CRMDOBank> getDataObjectClass() {
		return CRMDOBank.class;
	}

This method returns the class of the data object that is handled by the specific business object. It is used mainly to construct the HQL (Hibernate Query Language) dynamically.

 

getDefaultAssociations
    /**
     * Returns the default associated data objects of a bank.
     * 
     * @return the default associated data objects of the bank
     */
	@Override
	public ArrayList<String> getDefaultAssociations() {
		
		ArrayList<String> defaultAssociations = new ArrayList<String>();
		...
		return defaultAssociations;
	}

This method returns a list of the associated data objects that should be loaded by default when loading a data object. It is called by abstract functionality to load the data objects associated data objects.

 

getSequenceNumber
    /**
     * Returns the next sequence number of a bank.
     * 
     * @param dto - the bank to return the next sequence number for
     * @return the next sequence number of the bank
     * @throws Exception
     */
	@Override
	protected String getSequenceNumber(CRMDO dto) throws Exception {
		...
	}

This method returns a sequence number that is set on the data object in case it has a number property. It is called by abstract functionality to set the data object's number when saving the data object.

 

getMandatoryFields
    /**
     * Returns the mandatory fields of a bank.
     * 
     * @param dto - the bank to return the mandatory fields for
     * @return the mandatory fields of the bank
     * @throws Exception
     */
	@Override
	protected LinkedHashMap<String, String> getMandatoryFields(CRMDO dto) throws Exception {
		
		LinkedHashMap<String, String> mandatoryFields = new LinkedHashMap<String, String>();
		...
		return mandatoryFields;
	}

This method returns a list of the data object's mandatory fields (fields that should be always set). This method is called by abstract functionality to validate that all mandatory fields are set.

 

To start implementing the controller layer, go to Developing the Controller layer

  • No labels