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 void
addRatingToSummary
(RatingSummary ratingSummary, int rating, boolean approved) Update the fields onRatingSummary
necessary to add a new rating.protected D
createRatingDetail
(RatingRequest ratingRequest, S ratingSummary) protected S
createRatingSummary
(String targetId, String targetType, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Create a newRatingSummary
for the given target and type.void
deleteRatingByCustomer
(String id, String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Delete a rating.protected String
determineDetailStatus
(D ratingDetail) CheckRatingDetail
fields to determine status.protected void
editRatingDetail
(D ratingDetail, RatingRequest ratingRequest) Updates fields on an existingRatingDetail
.protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils
protected int
protected int
protected S
getOrCreateRatingSummary
(RatingRequest ratingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Read theRatingSummary
for the target of the givenRatingRequest
.protected RatingDetailService<D>
protected RatingSummaryService<S>
protected com.broadleafcommerce.common.extension.TypeFactory
protected boolean
lookupRatingDetail
(String targetId, String customerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Look up aRatingDetail
for 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'sRatingDetail
sprotected void
removeRatingFromSummary
(RatingSummary ratingSummary, int rating, boolean approved) Update the fields onRatingSummary
necessary to remove a rating.updateRatingByCustomer
(String id, RatingRequest ratingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Update an existingRatingDetail
.protected S
updateSummary
(S ratingSummary, D ratingDetail, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Add the new rating to theRatingSummary
and save.protected void
validateCustomer
(String customerId) Validate that the given customerId matches the authenticated user.protected void
validateRatingRange
(RatingRequest ratingRequest) Validates that the rating amount on the request is within the configured range.protected void
validateRatingRequest
(RatingRequest ratingRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Validate the RatingRequest.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
-
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'sRatingDetail
s- Specified by:
readAllRatingsByCustomer
in 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:CustomerRatingService
Add a newRatingDetail
. This will also update the correspondingRatingSummary
.- Specified by:
addRatingByCustomer
in 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:CustomerRatingService
Update 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:
updateRatingByCustomer
in 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:CustomerRatingService
Delete a rating. This will also update the correspondingRatingSummary
.- Specified by:
deleteRatingByCustomer
in 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
- TheRatingSummary
for 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 aRatingDetail
for 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
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 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
RatingSummary
for the target of the givenRatingRequest
.
-
createRatingSummary
protected S createRatingSummary(String targetId, String targetType, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Create a newRatingSummary
for 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 theRatingSummary
and save.- Parameters:
ratingSummary
- The summary to update.ratingDetail
- TheRatingDetail
being added.context
- Context information around sandbox and multitenant state.- Returns:
- The updated, persisted RatingSummary
-
addRatingToSummary
Update the fields onRatingSummary
necessary 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 onRatingSummary
necessary to remove a rating.- Parameters:
ratingSummary
- The summary to update.rating
- The numerical rating.approved
- If the corresponding review was approved.
-
determineDetailStatus
CheckRatingDetail
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
- TheRatingDetail
to evaluate.- Returns:
- The
RatingDetailStatus
for 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 checksallowAnonymousRating
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 customercontext
- Context information for database operations
-
validateRatingRange
Validates that the rating amount on the request is within the configured range. SeeRatingAndReviewServiceProperties.minimumRating
andRatingAndReviewServiceProperties.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()
-