Description: Limited to code that may be executed before an entity is created, updated, or deleted. Any additional changes to the entity can only be made using the EFieldChanges class. For example, it is possible to use an Entity Life Cycle Interceptor (ELI) to:
Have N4 send an email to a container's trucking company including the details of a pre-advised container when the container gets created.
Have N4 send appointment details to the trucking company when a new appointment gets created.
Validate the previous category of a container when the category gets updated. If the category used to be 'import' and if the container has already exceeded the number of free days, the category change could get rejected for billing reasons.
When you update certain attributes (specifiable in the extension) of a Railcar Type, automatically update all of the individual railcars using that Railcar Type.
Capture data to be deleted and send it to the responsible parties for audit purposes.
N4 executes ELIs as part of the database persistence operation interception, just before the entity persistence operation is committed.
N4 does not support triggering an ENTITY_LIFECYCLE_INTERCEPTION type code extension during the execution of another ENTITY_LIFECYCLE_INTERCEPTION type code extension.
Abstract Base Class: AbstractEntityLifecycleInterceptor
Interface: EEntityLifecycleInterceptor
Module: Framework
Version Added: 2.2
Requires Code Extension Name or Name Pattern: No
Code Extension Name or Name Pattern: N/A
Where to specify code extensions of this type: To configure a code extension of this type, you must create and enable an extension trigger for the entity to which you want to tie the extension. You do this in the Extension Triggers view (on page 1). After you create the extension and a trigger, N4 invokes the extension at the next time the entity reaches the trigger point. For example, if you have set up a code extension to update all of the individual railcars using a particular Railcar Type, the extension executes when that Railcar Type is edited.
System-Seeded Code Extensions Using this Type: N/A
Code example
The following code implements an entity lifecycle interception.
import com.navis.external.framework.entity.AbstractEntityLifecycleInterceptor;
import com.navis.external.framework.entity.EEntityView;
import com.navis.external.framework.util.EFieldChanges;
import com.navis.external.framework.util.EFieldChangesView;
import com.navis.sandbox.SandboxField;
import com.navis.sandbox.business.Foo;
import com.navis.framework.business.atoms.OneOrTwoEnum
import com.navis.external.framework.ECallingContext;
/**
* test calling context
*/
public class FooEntityInterceptorCallingContext extends AbstractEntityLifecycleInterceptor {
/**
* put variform id on custom fields to check in the test
*/
public void onCreate(EEntityView inEntity, EFieldChangesView inOriginalFieldChanges,
EFieldChanges inMoreFieldChanges) {
ECallingContext context = this.getCallingContext();
if (context != null) {
String variformId = context.getPrimaryVariformId();
inMoreFieldChanges.setFieldChange(SandboxField.FOO_CUSTOM1, context.getSessionType().getName());
inMoreFieldChanges.setFieldChange(SandboxField.FOO_CUSTOM2, variformId);
this.log("You have called with: " + context);
this.log("FOO_ENTITY_EVENT_ACTION: " + (String)context.getAttribute("FOO_ENTITY_EVENT_ACTION"));
}
Foo.PREPROCESS_EXTENSION_INSERT_COUNT++;
}
/**
* put variform id on FOO_CUSTOM2
*/
public void onUpdate(EEntityView inEntity, EFieldChangesView inOriginalFieldChanges, EFieldChanges inMoreFieldChanges) {
ECallingContext context = this.getCallingContext();
if (context != null) {
String variformId = context.getPrimaryVariformId();
inMoreFieldChanges.setFieldChange(SandboxField.FOO_CUSTOM3, variformId);
this.log("You have called with: " + context);
}
Foo.PREPROCESS_EXTENSION_UPDATE_COUNT++;
}
public void validateChanges(EEntityView inEntity, EFieldChangesView inFieldChanges) {
Foo.PREPROCESS_EXTENSION_VALIDATION_COUNT++;
}
}