Class BaseCrudEntityService<P>
- Type Parameters:
P- The business domain type
- All Implemented Interfaces:
CrudEntityService<P>
- Direct Known Subclasses:
BaseRsqlCrudEntityService,DefaultCommonApplicationService,DefaultCommonCatalogService
CrudEntityService can extend from this class as a
convenience to inherit CRUD behavior for a particular business domain type. By default, this
class in turn defers to CrudEntityHelper in order to allow easier refactoring of core
functionality.
If a service implementation spans several repository types, then it is recommended to inject the
CrudEntityHelper rather than extend this class.
- Author:
- Nathan Moore (nathandmoore)
-
Constructor Summary
ConstructorsConstructorDescriptionBaseCrudEntityService(TrackableRepository<T> repository, CrudEntityHelper helper) -
Method Summary
Modifier and TypeMethodDescriptionprotected PconvertFromPersistentDomain(Trackable domain, ContextInfo contextInfo) protected TrackableconvertToPersistentDomain(P businessInstance, Class<Trackable> persistentType, ContextInfo contextInfo) create(P businessInstance, ContextInfo context) Create an instance of an entity based on a business instance containing relavant property values.createAll(List<P> businessInstances, ContextInfo context) Create multiple narrowed instances of an entity at once based on the business instances containing relevant property values.createAllAllowingPartialSuccess(List<P> businessInstances, ContextInfo context) Creates multiple narrowed instances of an entity at once based on the business instances containing relevant property values.voiddelete(String id, ContextInfo context) Perform a delete operation on the entity identified by the context id.protected CrudEntityHelperprotected TrackableRepository<Trackable>protected SortPositionStrategy<P>readAll(ContextInfo context) Read a list of narrowed instances in the form of the business instance.org.springframework.data.domain.Page<P>readAll(org.springframework.data.domain.Pageable pageable, ContextInfo context) Read a page of narrowed instances in the form of the business instance.readAll(org.springframework.data.domain.Sort sort, ContextInfo context) Read a list of narrowed instances in the form of the business instance.readAllByContextId(Iterable<String> ids, ContextInfo context) Retrieve all business instances based on a list of context ids.readByContextId(String id, ContextInfo context) Read a single instance of an entity in the form of a business domain.replace(String id, P businessInstance, ContextInfo context) Replace a single, narrowed instance of an entity based on a business instance containing relevant property values.replaceAll(List<Update<P>> replacements, ContextInfo context) Replace multiple narrowed instances of an entity at once based on the business instance containing relevant property values.replaceAllAllowingPartialSuccess(List<Update<P>> replacements, ContextInfo context) Replace multiple narrowed instances of an entity at once based on the business instances containing relevant property values.voidsetSortPositionStrategy(SortPositionStrategy<P> sortPositionStrategy) update(String id, P businessInstance, ContextInfo context) Update a single, narrowed instance of an entity based on a business instance containing relevant property values.updateAll(List<Update<P>> updates, 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.updateAllAllowingPartialSuccess(List<Update<P>> updates, ContextInfo context) Updates all of the items managed by the backing repository in the form of the business instances containing property values.updateSort(SortPositionRequest sortPositionRequest, ContextInfo context) Apply a sort field value change
-
Constructor Details
-
BaseCrudEntityService
-
-
Method Details
-
setSortPositionStrategy
@Autowired public void setSortPositionStrategy(@Nullable SortPositionStrategy<P> sortPositionStrategy) -
readByContextId
Description copied from interface:CrudEntityServiceRead a single instance of an entity in the form of a business domain.- Specified by:
readByContextIdin interfaceCrudEntityService<P>- 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
-
readAllByContextId
Description copied from interface:CrudEntityServiceRetrieve all business instances based on a list of context ids.- Specified by:
readAllByContextIdin interfaceCrudEntityService<P>- 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
public org.springframework.data.domain.Page<P> readAll(@NonNull org.springframework.data.domain.Pageable pageable, @Nullable ContextInfo context) Description copied from interface:CrudEntityServiceRead a page of narrowed instances in the form of the business instance.- Specified by:
readAllin interfaceCrudEntityService<P>- Parameters:
pageable- The current page informationcontext- 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
Description copied from interface:CrudEntityServiceRead a list of narrowed instances in the form of the business instance.- Specified by:
readAllin interfaceCrudEntityService<P>- 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
public List<P> readAll(@NonNull org.springframework.data.domain.Sort sort, @Nullable ContextInfo context) Description copied from interface:CrudEntityServiceRead a list of narrowed instances in the form of the business instance. Also apply the given sort.- Specified by:
readAllin interfaceCrudEntityService<P>- Parameters:
sort- The sort to be performed on the resultscontext- 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
Description copied from interface:CrudEntityServiceUpdate a single, narrowed instance of an entity based on a business instance containing relevant property values. SeeTrackableRepositoryfor more information on entity persistence behavior in light of sandboxing and multitenant concerns.- Specified by:
updatein interfaceCrudEntityService<P>- 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
EntityMissingExceptionif not available. - See Also:
-
updateAll
Description copied from interface:CrudEntityServiceA 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
updatesmust exist in the backing repository and pass validation, else the entire batch will failFor an alternative that allows partial success, see
CrudEntityService.updateAllAllowingPartialSuccess(List, ContextInfo).- Specified by:
updateAllin interfaceCrudEntityService<P>- Parameters:
updates- each update to the repository domaincontext- 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
EntityMissingExceptionif not available. - See Also:
-
updateAllAllowingPartialSuccess
public BulkPersistenceResponse<P> updateAllAllowingPartialSuccess(List<Update<P>> updates, ContextInfo context) Description copied from interface:CrudEntityServiceUpdates all of the items managed by the backing repository in the form of the business instances containing property values.Each item contained within
updatesmust 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
CrudEntityService.updateAll(List, ContextInfo).- Specified by:
updateAllAllowingPartialSuccessin interfaceCrudEntityService<P>- Parameters:
updates- each update to the repository domaincontext- 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:
-
updateSort
public P updateSort(@NonNull SortPositionRequest sortPositionRequest, @Nullable ContextInfo context) Description copied from interface:CrudEntityServiceApply a sort field value change- Specified by:
updateSortin interfaceCrudEntityService<P>- Parameters:
sortPositionRequest- Information about the item being moved and the position to which it's movingcontext- 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
-
replace
Description copied from interface:CrudEntityServiceReplace a single, narrowed instance of an entity based on a business instance containing relevant property values.- Specified by:
replacein interfaceCrudEntityService<P>- 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
EntityMissingExceptionif not available. - See Also:
-
replaceAll
Description copied from interface:CrudEntityServiceReplace multiple narrowed instances of an entity at once based on the business instance containing relevant property values.All items contained within
replacementsmust exist in the backing repository and pass validation, else the entire batch will failSee
CrudEntityService.replaceAllAllowingPartialSuccess(List, ContextInfo)for an alternative that allows partial success.- Specified by:
replaceAllin interfaceCrudEntityService<P>- Parameters:
replacements- all replacements to the repository domaincontext- 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
EntityMissingExceptionif any of the items were not found - See Also:
-
replaceAllAllowingPartialSuccess
public BulkPersistenceResponse<P> replaceAllAllowingPartialSuccess(List<Update<P>> replacements, ContextInfo context) Description copied from interface:CrudEntityServiceReplace multiple narrowed instances of an entity at once based on the business instances containing relevant property values.Each item contained within
replacementsmust 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
CrudEntityService.replaceAll(List, ContextInfo)for an alternative that does not allow partial success.- Specified by:
replaceAllAllowingPartialSuccessin interfaceCrudEntityService<P>- Parameters:
replacements- all replacements to the repository domaincontext- 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
Description copied from interface:CrudEntityServiceCreate an instance of an entity based on a business instance containing relavant property values.- Specified by:
createin interfaceCrudEntityService<P>- Parameters:
businessInstance- The business domain instance. In general, theDomainMapperManageris 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.
- See Also:
-
createAll
Description copied from interface:CrudEntityServiceCreate multiple narrowed instances of an entity at once based on the business instances containing relevant property values.All items contained within
businessInstancesmust pass validation, else the entire batch will fail.See
CrudEntityService.createAllAllowingPartialSuccess(List, ContextInfo)for an alternative where partial success is allowed.- Specified by:
createAllin interfaceCrudEntityService<P>- Parameters:
businessInstances- all instances to create in the data storecontext- 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
- See Also:
-
createAllAllowingPartialSuccess
public BulkPersistenceResponse<P> createAllAllowingPartialSuccess(List<P> businessInstances, ContextInfo context) Description copied from interface:CrudEntityServiceCreates multiple narrowed instances of an entity at once based on the business instances containing relevant property values.Each item contained within
businessInstanceswill 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
CrudEntityService.createAll(List, ContextInfo)for an alternative that does not allow partial success.- Specified by:
createAllAllowingPartialSuccessin interfaceCrudEntityService<P>- Parameters:
businessInstances- all instances to create in the data storecontext- 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
Description copied from interface:CrudEntityServicePerform 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 throughDomainMapper.deleteMap(Object, ContextInfo).- Specified by:
deletein interfaceCrudEntityService<P>- 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.
-
convertFromPersistentDomain
-
convertToPersistentDomain
protected Trackable convertToPersistentDomain(P businessInstance, Class<Trackable> persistentType, ContextInfo contextInfo) -
getRepository
-
getHelper
-
getSortPositionStrategy
-