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
ConstructorDescriptionOperationAwarePersistenceHandler
(com.fasterxml.jackson.databind.ObjectMapper mapper) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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 anOperationType
ofOperationType.CREATE
.protected abstract void
processDeleteOperation
(String entityId, Instant changeTimestamp, com.fasterxml.jackson.databind.JsonNode entityJson) Invoked if the persistence message had anOperationType
ofOperationType.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 anOperationType
ofOperationType.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 jsonjson
- the json from which the field should be retrieved- Returns:
- an
Optional
containing theJsonNode
of 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 anOperationType
ofOperationType.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 anOperationType
ofOperationType.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 anOperationType
ofOperationType.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
-