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 Summary
ConstructorsConstructorDescriptionDefaultCustomerRatingService(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 Summary
Modifier and TypeMethodDescriptionaddRatingByCustomer(RatingRequest ratingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Add a newRatingDetail.protected voidaddRatingToSummary(RatingSummary ratingSummary, int rating, boolean approved) Update the fields onRatingSummarynecessary to add a new rating.protected DcreateRatingDetail(RatingRequest ratingRequest, S ratingSummary) protected ScreateRatingSummary(String targetId, String targetType, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Create a newRatingSummaryfor the given target and type.voiddeleteRatingByCustomer(String id, String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Delete a rating.protected StringdetermineDetailStatus(D ratingDetail) CheckRatingDetailfields to determine status.protected voideditRatingDetail(D ratingDetail, RatingRequest ratingRequest) Updates fields on an existingRatingDetail.protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtilsprotected intprotected intprotected SgetOrCreateRatingSummary(RatingRequest ratingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Read theRatingSummaryfor the target of the givenRatingRequest.protected RatingDetailService<D>protected RatingSummaryService<S>protected com.broadleafcommerce.common.extension.TypeFactoryprotected booleanlookupRatingDetail(String targetId, String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Look up aRatingDetailfor a specific item and customer.org.springframework.data.domain.Page<D>readAllRatingsByCustomer(String customerId, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Read all of a customer'sRatingDetailsprotected voidremoveRatingFromSummary(RatingSummary ratingSummary, int rating, boolean approved) Update the fields onRatingSummarynecessary to remove a rating.updateRatingByCustomer(String id, RatingRequest ratingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Update an existingRatingDetail.protected SupdateSummary(S ratingSummary, D ratingDetail, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Add the new rating to theRatingSummaryand save.protected voidvalidateCustomer(String customerId) Validate that the given customerId matches the authenticated user.protected voidvalidateRatingRange(RatingRequest ratingRequest) Validates that the rating amount on the request is within the configured range.protected voidvalidateRatingRequest(RatingRequest ratingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Validate the RatingRequest.protected voidvalidateUnique(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
-
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:CustomerRatingServiceRead all of a customer'sRatingDetails- Specified by:
readAllRatingsByCustomerin interfaceCustomerRatingService<D extends RatingDetail>- Parameters:
customerId- The customer that created the rating.page- information about which page of results to return from the databasecontextInfo- 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:CustomerRatingServiceAdd a newRatingDetail. This will also update the correspondingRatingSummary.- Specified by:
addRatingByCustomerin interfaceCustomerRatingService<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:CustomerRatingServiceUpdate an existingRatingDetail. The status will reset to PENDING if there is a review title or review text. This will also update the correspondingRatingSummary.- Specified by:
updateRatingByCustomerin interfaceCustomerRatingService<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:CustomerRatingServiceDelete a rating. This will also update the correspondingRatingSummary.- Specified by:
deleteRatingByCustomerin interfaceCustomerRatingService<D extends RatingDetail>- Parameters:
id- The id of the RatingDetail to delete.customerId- The customer that owns the RatingDetail to deletecontext- Context information around sandbox and multitenant state.
-
createRatingDetail
- Parameters:
ratingRequest- The rating form from the customer to populate the detail.ratingSummary- TheRatingSummaryfor the target of this rating.- Returns:
- A new, non-persisted,
RatingDetail
-
editRatingDetail
Updates fields on an existingRatingDetail. 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 aRatingDetailfor a specific item and customer.- Parameters:
targetId- The target of the rating, eg PRODUCT or VARIANTcustomerId- The ID of the customer that owns the rating.context- The context of the operation- Returns:
- An optional containing the
RatingDetailby the customer for the targeted item
-
getOrCreateRatingSummary
protected S getOrCreateRatingSummary(RatingRequest ratingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Read the
RatingSummaryfor the target of the givenRatingRequest. 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
RatingSummaryfor the target of the givenRatingRequest.
-
createRatingSummary
protected S createRatingSummary(String targetId, String targetType, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Create a newRatingSummaryfor the given target and type.- Parameters:
targetId- The id of the target of the rating, eg product id or variant id.targetType- TheRatingTargetType.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 theRatingSummaryand save.- Parameters:
ratingSummary- The summary to update.ratingDetail- TheRatingDetailbeing added.context- Context information around sandbox and multitenant state.- Returns:
- The updated, persisted RatingSummary
-
addRatingToSummary
Update the fields onRatingSummarynecessary to add a new rating.- Parameters:
ratingSummary- The summary to update.rating- The numerical rating.approved- If the corresponding review is approved.
-
removeRatingFromSummary
Update the fields onRatingSummarynecessary to remove a rating.- Parameters:
ratingSummary- The summary to update.rating- The numerical rating.approved- If the corresponding review was approved.
-
determineDetailStatus
CheckRatingDetailfields 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- TheRatingDetailto evaluate.- Returns:
- The
RatingDetailStatusfor the givenRatingDetail.
-
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 customercontext- Context information for database operations
-
validateCustomer
Validate that the given customerId matches the authenticated user. This checksallowAnonymousRatingto 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 customercontext- Context information for database operations
-
validateRatingRange
Validates that the rating amount on the request is within the configured range. SeeRatingAndReviewServiceProperties.minimumRatingandRatingAndReviewServiceProperties.maximumRating.- Parameters:
ratingRequest- The rating form from the customer
-
getRatingDetailService
-
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()
-