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 Details

  • 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 interface com.broadleafcommerce.common.messaging.PersistenceHandler
    • processStateChange

      public void processStateChange(com.fasterxml.jackson.databind.JsonNode entityJson)
      Specified by:
      processStateChange in interface com.broadleafcommerce.common.messaging.PersistenceHandler
    • hook

      @StreamListener("persistenceInputSegmentMember") public void hook(String entityJson)
      Specified by:
      hook in interface com.broadleafcommerce.common.messaging.PersistenceHandler
    • getCustomerSegments

      protected Set<String> getCustomerSegments(User user)
    • getChangeTimestamp

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

      public boolean isNodeNull(com.fasterxml.jackson.databind.JsonNode jsonNode)
    • getSupportedSimpleTypeNames

      public String[] getSupportedSimpleTypeNames()
      Specified by:
      getSupportedSimpleTypeNames in interface com.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 ID
      userAttributes - the user attributes
      eventTimestamp - 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 ID
      userAttributes - 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 ID
      userAttributes - the user attributes
      eventTimestamp - the timestamp of the current event
      See Also:
    • getLastProcessedSegmentDateAttributeName

      protected String getLastProcessedSegmentDateAttributeName(@NonNull @NonNull String segmentId)
      Returns the composed attribute name in the last_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

      protected Duration 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

      protected UserService<User> getUserService()