Class DefaultSubscriptionItemService<P extends SubscriptionItem>

java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.subscription.service.impl.DefaultSubscriptionItemService<P>
All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, SubscriptionItemService<P>

public class DefaultSubscriptionItemService<P extends SubscriptionItem> extends com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P> implements SubscriptionItemService<P>
  • Field Details

    • repo

      protected SubscriptionItemRepository<com.broadleafcommerce.data.tracking.core.Trackable> repo
    • subscriptionitemAdjustmentService

      @Autowired protected SubscriptionItemAdjustmentService<SubscriptionItemAdjustment> subscriptionitemAdjustmentService
    • transitionListener

      @Autowired(required=false) protected com.broadleafcommerce.data.tracking.core.messaging.TransitionListener transitionListener
    • subscriptionRepository

      @Autowired protected SubscriptionRepository<com.broadleafcommerce.data.tracking.core.Trackable> subscriptionRepository
  • Constructor Details

    • DefaultSubscriptionItemService

      public DefaultSubscriptionItemService(SubscriptionItemRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.CrudEntityHelper helper)
  • Method Details

    • findById

      public Optional<P> findById(String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Specified by:
      findById in interface SubscriptionItemService<P extends SubscriptionItem>
    • findActiveBySubscriptionId

      public List<P> findActiveBySubscriptionId(String subscriptionId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SubscriptionItemService
      Finds all active subscription items by subscription id
      Specified by:
      findActiveBySubscriptionId in interface SubscriptionItemService<P extends SubscriptionItem>
    • findAllBySubscriptionId

      public List<P> findAllBySubscriptionId(String subscriptionId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SubscriptionItemService
      Finds all subscription items by subscription id, including archived records
      Specified by:
      findAllBySubscriptionId in interface SubscriptionItemService<P extends SubscriptionItem>
    • findAllBySubscriptionIdsIn

      public org.springframework.data.domain.Page<P> findAllBySubscriptionIdsIn(Collection<String> subscriptionIds, @Nullable org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SubscriptionItemService
      Finds all subscriptionItems by their subscriptionIds
      Specified by:
      findAllBySubscriptionIdsIn in interface SubscriptionItemService<P extends SubscriptionItem>
      Parameters:
      subscriptionIds - The collection of subscriptionIds for which the subscriptionItems are to be fetched
      pageable - Describes the page of results to return
      contextInfo - The context info
      Returns:
      A Page of subscriptionItems
    • create

      public P create(P subscriptionItemRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      create in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends SubscriptionItem>
      Overrides:
      create in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends SubscriptionItem>
    • createAll

      public List<P> createAll(List<P> requests, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      createAll in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends SubscriptionItem>
      Overrides:
      createAll in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends SubscriptionItem>
    • createAllAllowingPartialSuccess

      public com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<P> createAllAllowingPartialSuccess(List<P> requests, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      createAllAllowingPartialSuccess in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends SubscriptionItem>
      Overrides:
      createAllAllowingPartialSuccess in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends SubscriptionItem>
    • replace

      public P replace(String id, P subscriptionItemRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      replace in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends SubscriptionItem>
      Overrides:
      replace in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends SubscriptionItem>
    • replaceAll

      public List<P> replaceAll(List<com.broadleafcommerce.data.tracking.core.service.Update<P>> subscriptionItemRequests, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      replaceAll in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends SubscriptionItem>
      Overrides:
      replaceAll in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends SubscriptionItem>
    • replaceAllAllowingPartialSuccess

      public com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<P> replaceAllAllowingPartialSuccess(List<com.broadleafcommerce.data.tracking.core.service.Update<P>> subscriptionItemRequests, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      replaceAllAllowingPartialSuccess in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends SubscriptionItem>
      Overrides:
      replaceAllAllowingPartialSuccess in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends SubscriptionItem>
    • update

      public P update(String id, P subscriptionItemRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      update in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends SubscriptionItem>
      Overrides:
      update in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends SubscriptionItem>
    • updateAll

      public List<P> updateAll(List<com.broadleafcommerce.data.tracking.core.service.Update<P>> subscriptionItemRequests, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      updateAll in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends SubscriptionItem>
      Overrides:
      updateAll in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends SubscriptionItem>
    • updateAllAllowingPartialSuccess

      public com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<P> updateAllAllowingPartialSuccess(List<com.broadleafcommerce.data.tracking.core.service.Update<P>> subscriptionItemRequests, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      updateAllAllowingPartialSuccess in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends SubscriptionItem>
      Overrides:
      updateAllAllowingPartialSuccess in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends SubscriptionItem>
    • delete

      public void delete(String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      delete in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends SubscriptionItem>
      Overrides:
      delete in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends SubscriptionItem>
    • commit

      public void commit(String subscriptionId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SubscriptionItemService
      Apply any uncommitted changes to the production state. Subscriptions are not only locked during a modification flow, but changes are also stored in a temporary modification state. When the modification flow is complete, this method is called to finalize the changes.

      Special note, during the modification flow, any retrieval of the subscription (and dependents) will return the modified state. However, the billing view of the subscription will continue to see the unmodified state until this method is called and the changes are finalized.

      Specified by:
      commit in interface SubscriptionItemService<P extends SubscriptionItem>
      Parameters:
      subscriptionId - the subscription to commit
      contextInfo - context information around multi-tenant state
    • revert

      public void revert(String subscriptionId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SubscriptionItemService
      Revert any uncommitted changes. This will remove any changes that have been made during the modification flow and leave the production state untouched.
      Specified by:
      revert in interface SubscriptionItemService<P extends SubscriptionItem>
      Parameters:
      subscriptionId - the subscription to revert
      contextInfo - context information around multi-tenant state
      See Also:
    • createItemAdjustments

      protected List<SubscriptionItemAdjustment> createItemAdjustments(@NonNull P subscriptionItemRequest, @NonNull P subscriptionItemSaved, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • replaceItemAdjustments

      protected List<SubscriptionItemAdjustment> replaceItemAdjustments(@NonNull @NonNull List<P> subscriptionItemRequests, @NonNull @NonNull List<P> subscriptionItemsSaved, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Goes through each subscriptionItemRequests and create, replace, or delete SubscriptionItemAdjustments as needed.
      Parameters:
      subscriptionItemRequests - the original SubscriptionItems to be replaced or updated. This is needed to grab the SubscriptionItemAdjustments since the subscriptionItemsSaved have empty lists
      subscriptionItemsSaved - the updated SubscriptionItems that were successfully persisted. These will be used to update with the latest SubscriptionItemAdjustments
      contextInfo - the current context info
      Returns:
      the SubscriptionItemAdjustments that were created or replaced