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
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
ConstructorsConstructorDescriptionOperationAwarePersistenceHandler(com.fasterxml.jackson.databind.ObjectMapper mapper) -
Method Summary
Modifier and TypeMethodDescriptionprotected InstantgetChangeTimestamp(com.fasterxml.jackson.databind.JsonNode persistenceMessage) protected StringgetEntityIdOrThrow(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.OperationTypegetValidOperationTypeOrThrow(com.fasterxml.jackson.databind.JsonNode persistenceMessage) protected abstract voidprocessCreateOperation(String entityId, Instant changeTimestamp, com.fasterxml.jackson.databind.JsonNode entityJson) Invoked if the persistence message had anOperationTypeofOperationType.CREATE.protected abstract voidprocessDeleteOperation(String entityId, Instant changeTimestamp, com.fasterxml.jackson.databind.JsonNode entityJson) Invoked if the persistence message had anOperationTypeofOperationType.DELETE.protected voidprocessStateChange(@NonNull String entityId, @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType, @NonNull Instant changeTimestamp, @NonNull com.fasterxml.jackson.databind.JsonNode entityJson) voidprocessStateChange(com.fasterxml.jackson.databind.JsonNode entityJson) protected abstract voidprocessUpdateOperation(String entityId, Instant changeTimestamp, com.fasterxml.jackson.databind.JsonNode entityJson) Invoked if the persistence message had anOperationTypeofOperationType.UPDATE.Methods inherited from class com.broadleafcommerce.auth.user.listener.AuthDataUpdatePersistenceHandler
getObjectMapper, handle, isNodeNull, isValidTypeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 jsonjson- the json from which the field should be retrieved- Returns:
- an
Optionalcontaining theJsonNodeof the field if found and not null,Optional.empty()otherwise
-
getChangeTimestamp
-
getEntityIdOrThrow
-
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 anOperationTypeofOperationType.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 anOperationTypeofOperationType.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 anOperationTypeofOperationType.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
-