Class DefaultCustomerRatingService<D extends RatingDetail,S extends RatingSummary>

java.lang.Object
com.broadleafcommerce.ratings.service.DefaultCustomerRatingService<D,S>
All Implemented Interfaces:
CustomerRatingService<D>

public class DefaultCustomerRatingService<D extends RatingDetail,S extends RatingSummary> extends Object implements CustomerRatingService<D>
  • Constructor Details

    • DefaultCustomerRatingService

      public DefaultCustomerRatingService(RatingDetailService<D> ratingDetailService, RatingSummaryService<S> ratingSummaryService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils, boolean allowAnonymousRating, int minRating, int maxRating)
  • Method Details

    • readAllRatingsByCustomer

      public org.springframework.data.domain.Page<D> readAllRatingsByCustomer(String customerId, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CustomerRatingService
      Read all of a customer's RatingDetails
      Specified by:
      readAllRatingsByCustomer in interface CustomerRatingService<D extends RatingDetail>
      Parameters:
      customerId - The customer that created the rating.
      page - information about which page of results to return from the database
      contextInfo - Context information around sandbox and multitenant state.
      Returns:
      A page of RatingDetail
    • addRatingByCustomer

      public D addRatingByCustomer(RatingRequest ratingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CustomerRatingService
      Add a new RatingDetail. This will also update the corresponding RatingSummary.
      Specified by:
      addRatingByCustomer in interface CustomerRatingService<D extends RatingDetail>
      Parameters:
      ratingRequest - The data to populate the detail.
      context - Context information around sandbox and multitenant state.
      Returns:
      A persisted RatingDetail
    • updateRatingByCustomer

      public D updateRatingByCustomer(String id, RatingRequest ratingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CustomerRatingService
      Update an existing RatingDetail. The status will reset to PENDING if there is a review title or review text. This will also update the corresponding RatingSummary.
      Specified by:
      updateRatingByCustomer in interface CustomerRatingService<D extends RatingDetail>
      Parameters:
      id - The id of the RatingDetail to edit.
      ratingRequest - The data to populate the detail.
      context - Context information around sandbox and multitenant state.
      Returns:
      The updated RatingDetail
    • deleteRatingByCustomer

      public void deleteRatingByCustomer(String id, String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CustomerRatingService
      Delete a rating. This will also update the corresponding RatingSummary.
      Specified by:
      deleteRatingByCustomer in interface CustomerRatingService<D extends RatingDetail>
      Parameters:
      id - The id of the RatingDetail to delete.
      customerId - The customer that owns the RatingDetail to delete
      context - Context information around sandbox and multitenant state.
    • createRatingDetail

      protected D createRatingDetail(RatingRequest ratingRequest, S ratingSummary)
      Create a new RatingDetail from the given RatingRequest and RatingSummary
      Parameters:
      ratingRequest - The rating form from the customer to populate the detail.
      ratingSummary - The RatingSummary for the target of this rating.
      Returns:
      A new, non-persisted, RatingDetail
    • editRatingDetail

      protected void editRatingDetail(D ratingDetail, RatingRequest ratingRequest)
      Updates fields on an existing RatingDetail. Status will be re-evaluated.
      Parameters:
      ratingDetail - The detail to update.
      ratingRequest - The rating form from the customer to populate the detail.
    • lookupRatingDetail

      protected Optional<D> lookupRatingDetail(String targetId, String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Look up a RatingDetail for a specific item and customer.
      Parameters:
      targetId - The target of the rating, eg PRODUCT or VARIANT
      customerId - The ID of the customer that owns the rating.
      context - The context of the operation
      Returns:
      An optional containing the RatingDetail by the customer for the targeted item
    • getOrCreateRatingSummary

      protected S getOrCreateRatingSummary(RatingRequest ratingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)

      Read the RatingSummary for the target of the given RatingRequest. Create a new summary if one does not already exist.

      If this is a VARIANT request, also lookup the parent product's summary and create a new one if necessary.

      Parameters:
      ratingRequest - Provides rating target and type.
      context - Context information around sandbox and multitenant state.
      Returns:
      The RatingSummary for the target of the given RatingRequest.
    • createRatingSummary

      protected S createRatingSummary(String targetId, String targetType, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Create a new RatingSummary for the given target and type.
      Parameters:
      targetId - The id of the target of the rating, eg product id or variant id.
      targetType - The RatingTargetType.
      context - Context information around sandbox and multitenant state.
      Returns:
      A new, persisted, RatingSummary.
    • updateSummary

      protected S updateSummary(S ratingSummary, D ratingDetail, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Add the new rating to the RatingSummary and save.
      Parameters:
      ratingSummary - The summary to update.
      ratingDetail - The RatingDetail being added.
      context - Context information around sandbox and multitenant state.
      Returns:
      The updated, persisted RatingSummary
    • addRatingToSummary

      protected void addRatingToSummary(RatingSummary ratingSummary, int rating, boolean approved)
      Update the fields on RatingSummary necessary to add a new rating.
      Parameters:
      ratingSummary - The summary to update.
      rating - The numerical rating.
      approved - If the corresponding review is approved.
    • removeRatingFromSummary

      protected void removeRatingFromSummary(RatingSummary ratingSummary, int rating, boolean approved)
      Update the fields on RatingSummary necessary to remove a rating.
      Parameters:
      ratingSummary - The summary to update.
      rating - The numerical rating.
      approved - If the corresponding review was approved.
    • determineDetailStatus

      protected String determineDetailStatus(D ratingDetail)
      Check RatingDetail fields to determine status. This checks the review and review title or edited review and review title. If the fields are null, then review is NOT_NEEDED. Otherwise, PENDING.
      Parameters:
      ratingDetail - The RatingDetail to evaluate.
      Returns:
      The RatingDetailStatus for the given RatingDetail.
    • validateRatingRequest

      protected void validateRatingRequest(RatingRequest ratingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Validate the RatingRequest. Exceptions will be thrown for any validation failures.
      Parameters:
      ratingRequest - The rating form from the customer
      context - Context information for database operations
    • validateCustomer

      protected void validateCustomer(@Nullable String customerId)
      Validate that the given customerId matches the authenticated user. This checks allowAnonymousRating to determine if non-authenticated users are allowed to submit ratings with a null customer id.
      Parameters:
      customerId - The customerId to validate
      Throws:
      RatingDetailException - If the given customer id is not for the authenticated user
    • validateUnique

      protected void validateUnique(RatingRequest ratingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Validate that there is not an existing rating for the target item by the customer
      Parameters:
      ratingRequest - The rating form from the customer
      context - Context information for database operations
    • validateRatingRange

      protected void validateRatingRange(RatingRequest ratingRequest)
      Validates that the rating amount on the request is within the configured range. See RatingAndReviewServiceProperties.minimumRating and RatingAndReviewServiceProperties.maximumRating.
      Parameters:
      ratingRequest - The rating form from the customer
    • getRatingDetailService

      protected RatingDetailService<D> getRatingDetailService()
    • getRatingSummaryService

      protected RatingSummaryService<S> getRatingSummaryService()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getAuthenticationUtils

      protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils()
    • isAllowAnonymousRating

      protected boolean isAllowAnonymousRating()
    • getMinRating

      protected int getMinRating()
    • getMaxRating

      protected int getMaxRating()