...
All business objects should be placed under com.crm.businessobject.* named packages and extend com.crm.businessobject.CRMBO.
Expand | ||
---|---|---|
| ||
Defining Bussiness Object Methods
...
To implement the basic business logic in our class, we will need to create the following methods:
The following method creates a new instance of the data object adding any business logic required.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
/** * Constructs a bank branch. * * @param mainDTO - the main data object * @return a bank branch * @throws Exception */ @Override protected CRMDO constructDO(CRMDO mainDTO) throws Exception { CRMDOBankBranch bankBranch = new CRMDOBankBranch(); ... if (mainDTO instanceof CRMDOBank) { bankBranch.setBank((CRMDOBank)mainDTO); } return bankBranch; } |
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.
The following method saves the data objects to the database. Any business logic required can be added (i.e. saving related data objects).
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
/** * Saves a bank branch. * * @param dto - the bank branch to save * @return the saved bank branch * @throws Exception */ @Override protected CRMDO saveDO(CRMDO dto) throws Exception { CRMDOBankBranch bankBranch = ...(CRMDOBankBranch)dto; saveDataObject(bankBranch); return bankBranch; } |
This method saves deletes the data objects to the database. In this method we this method, we add any business logic required to required to be executed when saving deleting an entity .(i.e. deleting related data objects). Note that records are not physically deleted but marked as deleted.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
/** * Deletes a bank branch. * * @param dto - the bank branch to delete * @return the deleted bank branch * @throws Exception */ @Override protected CRMDO deleteDO(CRMDO dto) throws Exception { ...return dto; } |
This method deletes validates 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. 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.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
/** * Validates a bank branch on save. * * @param dto - the bank branch to validate * @throws Exception */ @Override protected void validateDOonSave(CRMDO dto) throws Exception { CRMDOBankBranch bankBranch = (CRMDOBankBranch)dto; validateUniqueness(bankBranch); } |
This method can be used in cases where the data object must be unique. validateUniqueRecordAgainstDb and validateUniqueValueComboAgainstDb of CRMValidatorBean.java can be used to validate that there is no other data object having the same field value or having the same combination of fields values respectively.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
/** * Validates the uniqueness of a bank branch. * * @param bankBranch - the bank branch to validate * @throws Exception */ protected void validateUniqueness(CRMDOBankBranch bankBranch) throws Exception { //Validate that there is no other bank branch with the same name validatorBean.validateUniqueRecordAgainstDb( bankBranch, new String[]{"name"}, new String[]{"Name"}, "Branch", true, null); //Validate that there is no other bank branch with the same alternative code validatorBean.validateUniqueRecordAgainstDb( bankBranch, new String[]{"altCode"}, new String[]{"Alternative Code"}, "Branch", true, null); |
This method validates the data objects before saving to the database as deleted. Any validations that should be done before saving deleting the data object to the database should be performed in this method.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
/** * Validates a bank branch on delete. * * @param dto - the bank branch to validate * @throws Exception */ @Override protected void validateDOonDelete(CRMDO dto) throws Exception { ... } |
...
CRMDOBankBranch bankBranch = (CRMDOBankBranch)dto;
//Validate that the bank branch is not defined in any non-terminated accounts receivable payment preference
validateIfUsedByAccountsOnDelete(bankBranch);
} |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
/** * Returns the data object class of a bank. * * @return the data object class of the bank */ @Override protected Class<CRMDOBank> getDataObjectClass() { return CRMDOBank.class; } |
...