Interface CrudEntityService<P>

Type Parameters:
P - The payload type
All Known Subinterfaces:
CommonApplicationService<P>, CommonCatalogService<P>, RsqlCrudEntityService<P>
All Known Implementing Classes:
BaseCrudEntityService, BaseRsqlCrudEntityService, DefaultCommonApplicationService, DefaultCommonCatalogService

public interface CrudEntityService<P>
Base service API for a given entity type. Includes basic CRUD behavior. Implementations are generally backed by a TrackableRepository instance. Instances are intended to manage Trackable domain. Instances generally perform mapping between a projection object and repository domain object via the DomainMapperManager.
Author:
Jeff Fischer
  • Method Details

    • readByContextId

      P readByContextId(@NonNull String id, @Nullable ContextInfo context)
      Read a single instance of an entity in the form of a business domain.
      Parameters:
      id - The context id for the entity. This is the id by which the business recognizes the item.
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      The narrowed entity instance in the form of a business instance
      Throws:
      EntityMissingException - if no entity is found with the given id
    • readAllByContextId

      Iterable<P> readAllByContextId(@NonNull Iterable<String> ids, @Nullable ContextInfo context)
      Retrieve all business instances based on a list of context ids.
      Parameters:
      ids - A list of context ids for the entitys. This is the id by which the business recognizes the item.
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      The narrowed iterable collection of data in the form of business instances
    • readAll

      org.springframework.data.domain.Page<P> readAll(@NonNull org.springframework.data.domain.Pageable pageable, @Nullable ContextInfo context)
      Read a page of narrowed instances in the form of the business instance.
      Parameters:
      pageable - The current page information
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      The narrowed page of data in the form of business instances
    • readAll

      List<P> readAll(@Nullable ContextInfo context)
      Read a list of narrowed instances in the form of the business instance.
      Parameters:
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      The narrowed list of data in the form of business instances
    • readAll

      List<P> readAll(@NonNull org.springframework.data.domain.Sort sort, @Nullable ContextInfo context)
      Read a list of narrowed instances in the form of the business instance. Also apply the given sort.
      Parameters:
      sort - The sort to be performed on the results
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      The narrowed list of sorted data in the form of business instances
    • update

      P update(@NonNull String id, @NonNull P businessInstance, @Nullable ContextInfo context)
      Update a single, narrowed instance of an entity based on a business instance containing relevant property values. See TrackableRepository for more information on entity persistence behavior in light of sandboxing and multitenant concerns.
      Parameters:
      id - The context id for the entity. This is the id by which the business recognizes the item.
      businessInstance - The payload type that domain class should be converted to. In general, the payload is what the rest API responds with.
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      The updated, narrowed entity instance in the form of a payload instance, or EntityMissingException if not available.
      Throws:
      com.broadleafcommerce.common.error.validation.ValidationException - if the businessInstance failed validation
      EntityMissingException - if a managed instance corresponding to the given id could not be found
      See Also:
    • updateAll

      List<P> updateAll(@NonNull List<Update<P>> updates, @Nullable ContextInfo context)
      A bulk operation that updates all of the items managed by the backing repository in the form of the business entity containing property values.

      All items contained within updates must exist in the backing repository and pass validation, else the entire batch will fail

      For an alternative that allows partial success, see updateAllAllowingPartialSuccess(List, ContextInfo).

      Parameters:
      updates - each update to the repository domain
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      all of the updated, narrowed entity instance in the form of a payload instance, or EntityMissingException if not available.
      Throws:
      com.broadleafcommerce.common.error.validation.BulkValidationException - if any of the instances within the updates fail validation
      EntityMissingException - if any managed instances corresponding to the given Update.getId() could not be found
      See Also:
    • updateAllAllowingPartialSuccess

      BulkPersistenceResponse<P> updateAllAllowingPartialSuccess(@NonNull List<Update<P>> updates, @Nullable ContextInfo context)
      Updates all of the items managed by the backing repository in the form of the business instances containing property values.

      Each item contained within updates must exist in the backing repository and pass validation, or it will be added to the failed list in the response and not persisted. All successfully found and validated items will be persisted.

      For an alternative that does not allow partial success, see updateAll(List, ContextInfo).

      Parameters:
      updates - each update to the repository domain
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      a response containing a list of any entities which failed, and a list of the successfully updated, narrowed entity instances in the form of a payload instance
      See Also:
    • replace

      P replace(@NonNull String id, @NonNull P businessInstance, @Nullable ContextInfo context)
      Replace a single, narrowed instance of an entity based on a business instance containing relevant property values.
      Parameters:
      id - The context id for the entity. This is the id by which the business recognizes the item.
      businessInstance - The payload type that domain class should be converted to. In general, the payload is what the rest API responds with.
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      The replaced, narrowed entity instance in the form of a payload instance, or EntityMissingException if not available.
      Throws:
      com.broadleafcommerce.common.error.validation.ValidationException - if the given businessInstance failed validation on replacement
      EntityMissingException - if a managed instance corresponding to the given id could not be found
      See Also:
    • replaceAll

      List<P> replaceAll(@NonNull List<Update<P>> replacements, @Nullable ContextInfo context)
      Replace multiple narrowed instances of an entity at once based on the business instance containing relevant property values.

      All items contained within replacements must exist in the backing repository and pass validation, else the entire batch will fail

      See replaceAllAllowingPartialSuccess(List, ContextInfo) for an alternative that allows partial success.

      Parameters:
      replacements - all replacements to the repository domain
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      all of the replaced, narrowed entity instances in the form of a payload instance, or EntityMissingException if any of the items were not found
      Throws:
      com.broadleafcommerce.common.error.validation.BulkValidationException - if any of the the given replacements failed validation on replacement
      EntityMissingException - if any of the managed instances corresponding to the given Update.getId() could not be found
      See Also:
    • replaceAllAllowingPartialSuccess

      BulkPersistenceResponse<P> replaceAllAllowingPartialSuccess(@NonNull List<Update<P>> replacements, @Nullable ContextInfo context)
      Replace multiple narrowed instances of an entity at once based on the business instances containing relevant property values.

      Each item contained within replacements must exist in the backing repository and pass validation, or it will be added to the failed list in the response and not persisted. All successfully found and validated items will be persisted.

      See replaceAll(List, ContextInfo) for an alternative that does not allow partial success.

      Parameters:
      replacements - all replacements to the repository domain
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      a response containing a list of any entities which failed, and a list of the successfully replaced, narrowed entity instances in the form of a payload instance
      See Also:
    • create

      P create(@NonNull P businessInstance, @Nullable ContextInfo context)
      Create an instance of an entity based on a business instance containing relavant property values.
      Parameters:
      businessInstance - The business domain instance. In general, the DomainMapperManager is responsible for converting to a repository platform type for persistence.
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      The new entity instance in the form of a business type instance.
      Throws:
      com.broadleafcommerce.common.error.validation.ValidationException - if the given businessInstance could not be created
      See Also:
    • createAll

      List<P> createAll(@NonNull List<P> businessInstances, @Nullable ContextInfo context)
      Create multiple narrowed instances of an entity at once based on the business instances containing relevant property values.

      All items contained within businessInstances must pass validation, else the entire batch will fail.

      See createAllAllowingPartialSuccess(List, ContextInfo) for an alternative where partial success is allowed.

      Parameters:
      businessInstances - all instances to create in the data store
      context - Context information used to discriminate the correct version of an entity by context id when multiple versions may be available across sandboxes, catalogs and applications.
      Returns:
      all of the created, narrowed entity instances in the form of a payload instance
      Throws:
      com.broadleafcommerce.common.error.validation.BulkValidationException - if any of the the given businessInstances failed validation
      See Also:
    • createAllAllowingPartialSuccess

      BulkPersistenceResponse<P> createAllAllowingPartialSuccess(@NonNull List<P> businessInstances, @Nullable ContextInfo context)
      Creates multiple narrowed instances of an entity at once based on the business instances containing relevant property values.

      Each item contained within businessInstances will be validated, and if it fails validation, it will be added to the failed list in the response and not persisted. All successfully validated items will be persisted.

      See createAll(List, ContextInfo) for an alternative that does not allow partial success.

      Parameters:
      businessInstances - all instances to create in the data store
      context - Context information used to discriminate the correct version of an entity by context id when multiple versions may be available across sandboxes, catalogs and applications.
      Returns:
      a response containing a list of any entities which failed, and a list of the successfully created, narrowed entity instances in the form of a payload instance
      See Also:
    • delete

      void delete(@NonNull String id, @Nullable ContextInfo context)
      Perform a delete operation on the entity identified by the context id. This could result in an archival, or a raw delete, depending on the result of processing through DomainMapper.deleteMap(Object, ContextInfo).
      Parameters:
      id - The context id for the entity. This is the id by which the business recognizes the item.
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Throws:
      EntityMissingException - if no instance was found in the backing store corresponding to id
    • updateSort

      P updateSort(@NonNull SortPositionRequest sortPositionRequest, @Nullable ContextInfo context)
      Apply a sort field value change
      Parameters:
      sortPositionRequest - Information about the item being moved and the position to which it's moving
      context - ontext information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      The updated business domain