Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


From R14 onwards the Hooks Mechanism
Panel
nameidblue
0

CRM.COM provides hooks to all business methods that can be used to customize the existing business logic.

What does this section cover?

Table of Contents

Hooks Mechanism

The Hooks Mechanism gives you the ability to extend the existing functionality by intercepting main system processes. This can be achieved by implementing specific abstract methods that are called before and after main system methods such as construct, save, delete etc.

...


Extending Business Object Classes

To be able to extend the functionality of an existing Business Object EJB class you have to:

  1. Create a custom EJB class extending com.crm.businessobject.CRMBase and implementing com.crm.hooks.CRMBOHook interface.
  2. Declare your hook implementation class in hooks.xml file which is located under <your_custom_project_directory>/src/main/resources
  3. Implement the overridden methods. Note that even if you need to add no functionality for some of the overridden methods, make sure that they all return the given data object and not null.

Expand
titleExample


Code Block
languagejava
themeEclipselanguagejava
titleMYPLUGINCRMBOContactInformationBean.java
@Stateless
@LocalBean
public class MYPLUGINCRMBOContactInformationBean extends CRMBase implements CRMBOHook{
   
    public MYPLUGINCRMBOContactInformationBean() {
        // TODO Auto-generated constructor stub
    }
	@Override
	public CRMDO afterConstruct(CRMDO dto) throws Exception {
		CRMDOContactInformation contactInformation = (CRMDOContactInformation) dto;
		return dto;
	}
	@Override
	public CRMDO beforeSave(CRMDO dto) throws Exception {
		return dto;
	}
	@Override
	public CRMDO afterSave(CRMDO dto) throws Exception {
		return dto;
	}
	@Override
	public CRMDO beforeValidateOnSave(CRMDO dto) throws Exception {
		return dto;
	}
	@Override
	public CRMDO afterValidateOnSave(CRMDO dto) throws Exception {
		return dto;
	}
	@Override
	public CRMDO beforeValidateOnDelete(CRMDO dto) throws Exception {
		return dto;
	}
	@Override
	public CRMDO afterValidateOnDelete(CRMDO dto) throws Exception {
		return dto;
	}
	@Override
	public CRMDO beforeDelete(CRMDO dto) throws Exception {
		return dto;
	}
	@Override
	public CRMDO afterDelete(CRMDO dto) throws Exception {
		return dto;
	}
	@Override
	public CRMDO afterLoad(CRMDO dto) throws Exception {
		return dto;
	}


Code Block
language
languagexml
themeEclipse
xmltitlehooks.xml
<hookconfig>
	<hooks>
		...
		<hook>
			<serviceclass>CRMBOContactInformationBean</serviceclass>
			<interfacename>CRMBOHook</interfacename>
			<implementationclass>MYPLUGINCRMBOContactInformationBean</implementationclass>
		</hook>
	</hooks>
</hookconfig>

...


Extending Process Classes

To be able to extend the functionality of an existing Process EJB class you have to:

 

  1. Create a custom EJB class extending com.crm.process.CRMProcess and implementing one of the interfaces found in com.crm.hooks package. Keep in mind that there are available interfaces for some but not all processes.
  2. Declare your hook implementation class in hooks.xml file which is located under <your_custom_project_directory>/src/main/resources
  3. Implement the overridden methods. Note that even if you do not need to add any functionality for some of the overridden methods, make sure that they all return the given data object and not null.

Expand
titleExample


Code Block
languagejava
themeEclipselanguagejava
titleMYPLUGINCRMProcessServiceRequestBean.java
@Stateless
@LocalBean
public class MYPLUGINCRMProcessServiceRequestBean extends CRMProcess implements CRMProcessServiceRequestHook{
       
    public MYPLUGINCRMProcessServiceRequestBean() {
        super();
        // TODO Auto-generated constructor stub
    }
	@Override
	public CRMDOServiceRequest beforeCreate(CRMDOServiceRequest serviceRequest) throws Exception {
		serviceRequest.setUserField1("beforeCreate() hook test");
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest afterCreate(CRMDOServiceRequest serviceRequest) throws Exception {
		serviceRequest.setUserField2("afterCreate() hook test");
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest beforeComplete(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest afterComplete(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest beforeFinalAccept(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest afterFinalAccept(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest beforeFinalResolve(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest afterFinalResolve(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest beforeRespond(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest afterRespond(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest beforeResponseAccept(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest afterResponseAccept(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest beforeTemporaryAccept(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest afterTemporaryAccept(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest beforeTemporaryResolve(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest afterTemporaryResolve(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest beforeUpdate(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
	@Override
	public CRMDOServiceRequest afterUpdate(CRMDOServiceRequest serviceRequest) throws Exception {
		return serviceRequest;
	}
}


Code Block
language
languagexml
themeEclipse
xmltitlehooks.xml
<hookconfig>
	<hooks>
		...
		<hook>
			<serviceclass>CRMProcessServiceRequestBean</serviceclass>
			<interfacename>CRMProcessServiceRequestHook</interfacename>
			<implementationclass>MYPLUGINCRMProcessServiceRequestBean</implementationclass>
		</hook>
	</hooks>
</hookconfig>

...