Class OperationAwarePersistenceHandler

java.lang.Object
com.broadleafcommerce.auth.user.listener.AuthDataUpdatePersistenceHandler
com.broadleafcommerce.auth.user.listener.OperationAwarePersistenceHandler
All Implemented Interfaces:
com.broadleafcommerce.common.messaging.PersistenceHandler
Direct Known Subclasses:
AdminPermissionPersistenceHandler, AdminRolePersistenceHandler, AdminUserPersistenceHandler

public abstract class OperationAwarePersistenceHandler extends AuthDataUpdatePersistenceHandler
Handles messages from the Persistence channel, asserting that they contain operation type, id, and timestamp information. This is designed to perform a replacement of existing data within this service with data from other services.
Author:
Samarth Dhruva (samarthd)
  • Constructor Summary

    Constructors
    Constructor
    Description
    OperationAwarePersistenceHandler(com.fasterxml.jackson.databind.ObjectMapper mapper)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Instant
    getChangeTimestamp(com.fasterxml.jackson.databind.JsonNode persistenceMessage)
     
    protected String
    getEntityIdOrThrow(com.fasterxml.jackson.databind.JsonNode persistenceMessage)
     
    protected Optional<com.fasterxml.jackson.databind.JsonNode>
    getNonNullField(String fieldName, com.fasterxml.jackson.databind.JsonNode json)
    Gets the field with the given name from the json and returns an optional containing it if not null.
    protected com.broadleafcommerce.data.tracking.core.type.OperationType
    getValidOperationTypeOrThrow(com.fasterxml.jackson.databind.JsonNode persistenceMessage)
     
    protected abstract void
    processCreateOperation(String entityId, Instant changeTimestamp, com.fasterxml.jackson.databind.JsonNode entityJson)
    Invoked if the persistence message had an OperationType of OperationType.CREATE.
    protected abstract void
    processDeleteOperation(String entityId, Instant changeTimestamp, com.fasterxml.jackson.databind.JsonNode entityJson)
    Invoked if the persistence message had an OperationType of OperationType.DELETE.
    protected void
    processStateChange(@NonNull String entityId, @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType, @NonNull Instant changeTimestamp, @NonNull com.fasterxml.jackson.databind.JsonNode entityJson)
     
    void
    processStateChange(com.fasterxml.jackson.databind.JsonNode entityJson)
     
    protected abstract void
    processUpdateOperation(String entityId, Instant changeTimestamp, com.fasterxml.jackson.databind.JsonNode entityJson)
    Invoked if the persistence message had an OperationType of OperationType.UPDATE.

    Methods inherited from class com.broadleafcommerce.auth.user.listener.AuthDataUpdatePersistenceHandler

    getObjectMapper, handle, isNodeNull, isValidType

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.broadleafcommerce.common.messaging.PersistenceHandler

    getSupportedSimpleTypeNames, hook, validate
  • Constructor Details

    • OperationAwarePersistenceHandler

      public OperationAwarePersistenceHandler(com.fasterxml.jackson.databind.ObjectMapper mapper)
  • Method Details

    • processStateChange

      public void processStateChange(com.fasterxml.jackson.databind.JsonNode entityJson)
    • getValidOperationTypeOrThrow

      protected com.broadleafcommerce.data.tracking.core.type.OperationType getValidOperationTypeOrThrow(com.fasterxml.jackson.databind.JsonNode persistenceMessage)
    • getNonNullField

      protected Optional<com.fasterxml.jackson.databind.JsonNode> getNonNullField(String fieldName, com.fasterxml.jackson.databind.JsonNode json)
      Gets the field with the given name from the json and returns an optional containing it if not null.
      Parameters:
      fieldName - the name of the field to get from the json
      json - the json from which the field should be retrieved
      Returns:
      an Optional containing the JsonNode of the field if found and not null, Optional.empty() otherwise
    • getChangeTimestamp

      protected Instant getChangeTimestamp(com.fasterxml.jackson.databind.JsonNode persistenceMessage)
    • getEntityIdOrThrow

      protected String getEntityIdOrThrow(com.fasterxml.jackson.databind.JsonNode persistenceMessage)
    • processStateChange

      protected void processStateChange(@NonNull @NonNull String entityId, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType, @NonNull @NonNull Instant changeTimestamp, @NonNull @NonNull com.fasterxml.jackson.databind.JsonNode entityJson) throws IOException
      Throws:
      IOException
    • processCreateOperation

      protected abstract void processCreateOperation(String entityId, Instant changeTimestamp, com.fasterxml.jackson.databind.JsonNode entityJson) throws IOException
      Invoked if the persistence message had an OperationType of OperationType.CREATE.
      Parameters:
      entityId - the ID found on the persistence message. Guaranteed non-empty.
      changeTimestamp - the timestamp found on the persistence message. Guaranteed non-null.
      entityJson - the persistence message json itself. Guaranteed non-null.
      Throws:
      IOException
    • processUpdateOperation

      protected abstract void processUpdateOperation(String entityId, Instant changeTimestamp, com.fasterxml.jackson.databind.JsonNode entityJson) throws IOException
      Invoked if the persistence message had an OperationType of OperationType.UPDATE.
      Parameters:
      entityId - the entity ID found on the persistence message. Guaranteed non-empty.
      changeTimestamp - the timestamp found on the persistence message. Guaranteed non-null.
      entityJson - the persistence message json itself. Guaranteed non-null.
      Throws:
      IOException
    • processDeleteOperation

      protected abstract void processDeleteOperation(String entityId, Instant changeTimestamp, com.fasterxml.jackson.databind.JsonNode entityJson) throws IOException
      Invoked if the persistence message had an OperationType of OperationType.DELETE.
      Parameters:
      entityId - the entity ID found on the persistence message. Guaranteed non-empty.
      changeTimestamp - the timestamp found on the persistence message. Guaranteed non-null.
      entityJson - the persistence message json itself. Guaranteed non-null.
      Throws:
      IOException