ENTITY_LIFECYCLE_INTERCEPTION

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:

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++;

  }

}