Class SegmentMemberPersistenceHandler
java.lang.Object
com.broadleafcommerce.auth.user.listener.SegmentMemberPersistenceHandler
- All Implemented Interfaces:
com.broadleafcommerce.common.messaging.PersistenceHandler
public class SegmentMemberPersistenceHandler
extends Object
implements com.broadleafcommerce.common.messaging.PersistenceHandler
Handles creation and deletes of customer segment/customer relationships. Segments are stored on
the
User
in their user attributes.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSegmentMemberPersistenceHandler
(UserService<User> userService, com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
Method Summary
Modifier and TypeMethodDescriptionprotected Instant
getChangeTimestamp
(com.fasterxml.jackson.databind.JsonNode persistenceMessage) getCustomerSegments
(User user) getLastProcessedSegmentDate
(@NonNull String segmentId, @NonNull Map<String, Object> userAttributes) Gets the date of the last processed segment member persistence event.protected String
getLastProcessedSegmentDateAttributeName
(@NonNull String segmentId) Returns the composed attribute name in thelast_processed_segment_date:segmentId
format.protected Duration
Determines how long the event timestamp value in the user attributes remains valid.com.fasterxml.jackson.databind.ObjectMapper
String[]
protected UserService<User>
void
boolean
isNodeNull
(com.fasterxml.jackson.databind.JsonNode jsonNode) void
processStateChange
(com.fasterxml.jackson.databind.JsonNode entityJson) protected void
putLastProcessedSegmentDateInfo
(@NonNull String segmentId, @NonNull Map<String, Object> userAttributes, @NonNull Instant eventTimestamp) Puts the event timestamp value to the user attributes.protected void
removeStaleProcessedSegmentDateInfo
(@NonNull Map<String, Object> userAttributes) Removes the stale timestamp values from the user attributes.protected boolean
shouldProcessEvent
(@NonNull String segmentId, @NonNull Map<String, Object> userAttributes, @NonNull Instant eventTimestamp) Checks if this event should be processed.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
handle, isValidType, validate
-
Field Details
-
LAST_PROCESS_SEGMENT_DATE
Deprecated.in favour ofgetLastProcessedSegmentDateAttributeName(String)
- See Also:
-
LAST_PROCESSED_SEGMENT_DATE_ATTR_NAME_PREFIX
- See Also:
-
LAST_PROCESSED_SEGMENT_DATE_ATTR_NAME_FORMAT
- See Also:
-
-
Constructor Details
-
SegmentMemberPersistenceHandler
public SegmentMemberPersistenceHandler(UserService<User> userService, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
-
-
Method Details
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()- Specified by:
getObjectMapper
in interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
processStateChange
public void processStateChange(com.fasterxml.jackson.databind.JsonNode entityJson) - Specified by:
processStateChange
in interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
hook
- Specified by:
hook
in interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
getCustomerSegments
-
getChangeTimestamp
-
isNodeNull
public boolean isNodeNull(com.fasterxml.jackson.databind.JsonNode jsonNode) -
getSupportedSimpleTypeNames
- Specified by:
getSupportedSimpleTypeNames
in interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
shouldProcessEvent
protected boolean shouldProcessEvent(@NonNull @NonNull String segmentId, @NonNull @NonNull Map<String, Object> userAttributes, @NonNull @NonNull Instant eventTimestamp) Checks if this event should be processed. Returns true, if the event's "timestamp" date is after the latest processed timestamp stored in the user attributes, false otherwise.- Parameters:
segmentId
- the segment IDuserAttributes
- the user attributeseventTimestamp
- the timestamp of the current event- Returns:
- true, if the event's "timestamp" date is after the latest processed timestamp stored in the user attributes, false otherwise
-
getLastProcessedSegmentDate
protected Optional<Instant> getLastProcessedSegmentDate(@NonNull @NonNull String segmentId, @NonNull @NonNull Map<String, Object> userAttributes) Gets the date of the last processed segment member persistence event.- Parameters:
segmentId
- the segment IDuserAttributes
- the user attributes- Returns:
- Optional of the last processed segment date
-
putLastProcessedSegmentDateInfo
protected void putLastProcessedSegmentDateInfo(@NonNull @NonNull String segmentId, @NonNull @NonNull Map<String, Object> userAttributes, @NonNull @NonNull Instant eventTimestamp) Puts the event timestamp value to the user attributes.Additionally removes the stale timestamp values from the attributes.
- Parameters:
segmentId
- the segment IDuserAttributes
- the user attributeseventTimestamp
- the timestamp of the current event- See Also:
-
getLastProcessedSegmentDateAttributeName
Returns the composed attribute name in thelast_processed_segment_date:segmentId
format.- Parameters:
segmentId
- the segment ID- Returns:
- the composed attribute name
-
removeStaleProcessedSegmentDateInfo
protected void removeStaleProcessedSegmentDateInfo(@NonNull @NonNull Map<String, Object> userAttributes) Removes the stale timestamp values from the user attributes.- Parameters:
userAttributes
- the user attributes
-
getLastProcessedSegmentDateInfoTtl
Determines how long the event timestamp value in the user attributes remains valid. Defaults to 1 hour.- Returns:
- how long the event timestamp value in the user attributes remains valid
-
getUserService
-
getLastProcessedSegmentDateAttributeName(String)