D
- The domain type the repository manages@NoRepositoryBean public interface TrackableRepository<D extends Trackable> extends org.springframework.data.repository.Repository<D,String>, com.broadleafcommerce.common.messaging.notification.NotificationStateRepository, com.broadleafcommerce.common.extension.DomainTypeAware
Repository
version targeted specifically at maintaining persistence
for Trackable
domain objects. Actual maintenance of Tracking
state during a save
operation, including ChangeDetail
, SandboxInfo
and CatalogInfo
information is generally performed by a DefaultTrackableDomainMapperMemberSupport
instance prior to passing to the repository.
Fetch behavior may be enhanced by including an additional Narrow
annotation to an
extending interface that also utilizes the Repository
annotation. Narrow annotations take a required NarrowExecutor
class argument. The
NarrowExecutor is responsible for executing the fetch query defined by the repository query
method (or by direct Query definitions through repository specific helper - for example -
JpaNarrowingHelper). Furthermore, it is responsible for possibly enhancing the query to perform
additional filtering, such as sandbox narrowing and/or catalog filtering.
As a framework, we generaly want to provide the possibility for consumption of repository data by
vanilla services that are agnostic to the platform specific nature of a given repository
defintion (e.g. a Jpa repository). To achieve this, we generally employ a two-step pattern for
setting up a new repository definition in a microservice. First, an interface that extends from
TrackableRepository
is created. The generics on this interface are kept purposefully
general and any general query methods are added here. If specific implementations of a method are
required per database platform, an additional interface may be defined and fragment
implementation created for each platform. A bean whose id matches the [fragment interface
name]Impl pattern should be defined in the platform config (e.g. JpaConfig) to allow the correct
fragment implementation to be identified and loaded for execution as part of the Spring Data
repository proxy. If overriding existing methods from the TrackableRepository interface, it is
important that the overriding method declared in the fragment implementation has a matching
signature. for example, to override the save(Trackable, ContextInfo)
method
implementation, use a concrete method declaration in your fragment implementation similar to
this:
public Trackable save(Trackable catalog, ContextInfo contextInfo) { // do something interesting }
See https://docs.spring.io/spring-data/commons/docs/current/reference/html/#repositories.single-repository-behavior for more information on adding explicit query code behavior to Spring Data repositories.
@NoRepositoryBean
public interface ProductRepository<D extends Trackable, I> extends TrackableRepository<D, I>
{Page<D> findAllByNameContainingIgnoreCase(String query, Pageable page, ContextInfo contextInfo);
}
Next, a platform specific interface is created to reference the database specific definition. An
optional Narrow
annotation may also be included. This interface is generally empty,
unless there is a method to be defined that is truly only possible on a specific platform (e.g.
something that can only be done in JpaDB).
Service implementations should inject an instance of the general repository interface, and as a result, remain database platform agnostic while using a common interface.@Repository
@Narrow(JpaNarrowExecutor.class)
public interface JpaProductRepository<D extends JpaProduct> extends ProductRepository<D, String>
{ }
Support for a specific platform repository should be enabled via configuration. For example,
@Configuration
@EnableJpaRepositories(
basePackages = "com.broadleafcommerce.adminnavigation.provider.jpa.repository", repositoryFactoryBeanClass = JpaTrackableRepositoryFactoryBean.class)@EntityScan(basePackages = "com.broadleafcommerce.menu.provider.jpa.domain")
@AutoConfigureAfter(JpaDataAutoConfiguration.class)
public class AdminNavigationJpaAutoConfiguration {}
Modifier and Type | Method and Description |
---|---|
D |
archive(D entity,
ContextInfo contextInfo)
Archive a record so that it is no longer considered active and is filtered out of results.
|
boolean |
existsByContextId(String contextId,
ContextInfo contextInfo)
Retrieve whether or not an active instance of the item exists for the given context id after
any narrowing context is applied.
|
List<D> |
findAll(ContextInfo contextInfo)
Retrieve all domain instances.
|
List<D> |
findAll(ContextInfo contextInfo,
Class<D> type)
Retrieve all domain instances.
|
org.springframework.data.domain.Page<D> |
findAll(org.springframework.data.domain.Pageable pageable,
ContextInfo contextInfo)
Retrieve all domain instances, a page at a time.
|
org.springframework.data.domain.Page<D> |
findAll(org.springframework.data.domain.Pageable pageable,
ContextInfo contextInfo,
Class<D> type)
Retrieve all domain instances, a page at a time.
|
List<D> |
findAll(org.springframework.data.domain.Sort sort,
ContextInfo contextInfo)
Retrieve all domain instances using a sort.
|
List<D> |
findAll(org.springframework.data.domain.Sort sort,
ContextInfo contextInfo,
Class<D> type)
Retrieve all domain instances using a sort.
|
Iterable<D> |
findAllByContextId(Iterable<String> contextIds,
ContextInfo contextInfo)
Retrieve all domain instances based on a list of context ids (see
Trackable.getContextId() ). |
Optional<D> |
findByContextId(String contextId,
ContextInfo contextInfo)
Retrieve a domain instance based on the context id (see
Trackable.getContextId() ). |
Optional<D> |
findByContextIdAndCatalog(String contextId,
String catalogId,
ContextInfo contextInfo)
Retrieve a domain instance based on the context id (see
Trackable.getContextId() ). |
Optional<D> |
findByNativeId(Object id)
Finds the entity corresponding to the given native id.
|
default TransitionPackage<D> |
findDeployable(WorkflowDeployRequest request)
Retrieve the domain item identified via
WorkflowDeployRequest and also retrieve any
domain item existing at the requested target position (if any). |
Sortable |
findMaxSortMember(Sortable example,
String maxSort,
ContextInfo contextInfo)
Given an example member from a sort group, find the first member from that group whose sort
value is less than maxSort.
|
Sortable |
findMinSortMember(Sortable example,
String minSort,
ContextInfo contextInfo)
Given an example member from a sort group, find the first member from that group whose sort
value is greater than minSort.
|
D |
findOriginal(String contextId,
String catalogId,
String applicationId,
String author,
String stage,
String sandboxId,
Integer level)
Given context information, find the original state for the workflow transition operation.
|
default TransitionPackage<D> |
findPromotable(WorkflowPromoteRequest request)
Retrieve the domain item identified via
WorkflowPromoteRequest and also retrieve any
domain item existing at the requested target position (if any). |
default TransitionPackage<D> |
findPromoteOrientedItems(TargetRelatedRequest request)
Find items positioned for original and tracking from the perspective of a promotion request.
|
default TransitionPackage<D> |
findRebasable(WorkflowRebaseRequest request)
Retrieve the domain item identified via
WorkflowRebaseRequest and also retrieve any
domain item existing at the requested target position (if any). |
default TransitionPackage<D> |
findRejectable(WorkflowRejectRequest request)
Retrieve the domain item identified via
WorkflowRejectRequest and also retrieve any
domain item existing at the requested target position (if any). |
default D |
findRevertable(WorkflowRevertRequest request)
Retrieve the domain item identified via
WorkflowRevertRequest . |
D |
findTarget(String contextId,
String catalogId,
String applicationId,
String author,
String stage,
String sandboxId,
Integer level,
Set<String> visibleFromCatalog)
Given context information, find the target state (if any) for the workflow transition
operation.
|
default Class<?> |
getDomainType() |
org.springframework.data.repository.core.EntityInformation<D,String> |
getEntityInformation()
Retrieve information about the domain type backing this repository.
|
TrackableBehaviorUtil |
getTrackableBehaviorUtil()
Get a utility that is capable of determining the
TrackableBehavior state for a domain
class. |
List<Class<?>> |
getTypesToRegisterInMappingContext()
Should return the domain type along with all of its extensions that are registered as managed
entities.
|
boolean |
pruneChangeDetails(Object nativeId)
Updates the entity whose native id matches the given
nativeId , setting its
Tracking.getChangeDetails() to null . |
void |
pruneRestingNotificationStates(Duration beforeNow)
Performs an update on all records to prune all
NotificationStates
from NotificationStateAware.getNotificationStates() which satisfy the following criteria:
NotificationState.isAcked() is true or
NotificationState.isStopped() is true
NotificationState.getChangeTimestamp() is before Instant.now() minus the
beforeNow duration
|
void |
purgeObsoleteSandboxData(Duration beforeNow)
Hard-deletes all records which satisfy the following criteria:
Tracking.getSandbox() has its archived property
set to true
All NotificationStateAware.getNotificationStates() (if there are any) are either
acked or stopped
All Tracking.getChangeDetails() (if there are any) have a
timestamp that is before Instant.now() minus the
beforeNow duration
|
D |
save(D entity,
ContextInfo contextInfo)
Insert (if not exists) or update the domain instance in the datastore.
|
Iterable<D> |
saveAll(Iterable<D> entities,
ContextInfo contextInfo)
Insert (if not exists) or update all the domain instances in the datastore.
|
void |
setTrackableBehaviorUtil(TrackableBehaviorUtil behaviorUtil)
Set a utility that is capable of determining the
TrackableBehavior state for a domain
class. |
@Policy(operationTypes={UPDATE,DELETE,CREATE}, param=0) @NonNull D save(@NonNull D entity, @Nullable ContextInfo contextInfo)
entity
- The Trackable
instancecontextInfo
- context information related to multitenancy. Often used to validate
visibility and mutability of persistence operations for a catalog.@Policy(operationTypes={UPDATE,DELETE,CREATE}, param=0) @NonNull Iterable<D> saveAll(@NonNull Iterable<D> entities, @Nullable ContextInfo contextInfo)
entities
- The Trackable
instancescontextInfo
- context information related to multitenancy. Often used to validate
visibility and mutability of persistence operations for a catalog.@Policy(operationTypes=READ) @Nullable Sortable findMinSortMember(@NonNull Sortable example, @Nullable String minSort, @Nullable ContextInfo contextInfo)
This can be used to find a member before which to sort the example. In such a case, the minSort value is the sort position of the member after which the example will be sorted. In this case, the reason to get the minSortMember (i.e., the one to sort example before) would be to ensure that example's new sorting value is between minSort and minSortMember's sort value, thereby avoiding collisions.
example
- The example member of the group used to fashion a query that restricts to the
groupminSort
- Results are filtered to be greater than this valuecontextInfo
- context information related to multitenancy. Often used to validate
visibility and mutability of persistence operations for a catalog.@Policy(operationTypes=READ) @Nullable Sortable findMaxSortMember(@NonNull Sortable example, @Nullable String maxSort, @Nullable ContextInfo contextInfo)
This is essentially the complement to
findMinSortMember(Sortable, String, ContextInfo)
. Instead of finding the member
before which to sort example using the sorting value of the member after which to sort
example, this finds the position-after-member given the sort value of the
position-before-member.
example
- The example member of the group used to fashion a query that restricts to the
groupmaxSort
- Results are filtered to be less than this valuecontextInfo
- context information related to multitenancy. Often used to validate
visibility and mutability of persistence operations for a catalog.@Policy(operationTypes=READ) @NonNull Optional<D> findByContextId(@NonNull String contextId, @Nullable ContextInfo contextInfo)
Trackable.getContextId()
). If
a NarrowExecutor
implementation was specified via Narrow
, the result should
be narrowed based on sandbox and catalog state.contextId
- An identifying idcontextInfo
- Request context information around sandbox and multitenant state@Policy(operationTypes=READ) @NonNull Optional<D> findByContextIdAndCatalog(@NonNull String contextId, @NonNull String catalogId, @Nullable ContextInfo contextInfo)
Trackable.getContextId()
).
Also restrict the result to a single catalog. This is only useful for catalog discriminated
domain types.contextId
- An identifying idcatalogId
- The catalog to restrict the result tocontextInfo
- Request context information around sandbox and multitenant state@Policy(operationTypes=READ) boolean existsByContextId(@NonNull String contextId, @Nullable ContextInfo contextInfo)
contextId
- An identifying idcontextInfo
- Request context information around sandbox and multitenant state@Policy(operationTypes=DELETE, param=0) @NonNull D archive(@NonNull D entity, @Nullable ContextInfo contextInfo)
Tracking.getArchived()
field being set to
True. For sandbox records, both Tracking.getArchived()
and
SandboxInfo.getArchived()
are set to True.entity
- The Trackable
instance to save as archivedcontextInfo
- context information related to multitenancy. Often used to validate
visibility and mutability of persistence operations for a catalog.@Policy(operationTypes=DELETE) void purgeObsoleteSandboxData(@NonNull Duration beforeNow)
Tracking.getSandbox()
has its archived
property
set to trueNotificationStateAware.getNotificationStates()
(if there are any) are either
acked
or stopped
Tracking.getChangeDetails()
(if there are any) have a
timestamp
that is before Instant.now()
minus the
beforeNow
duration
After that, performs an update on all records to prune all ChangeDetails
which satisfy the following criteria:
obsolete
is truetimestamp
is before Instant.now()
minus the
beforeNow
durationbeforeNow
- duration used to determine whether sandbox data is outdated. The current
time minus this duration is the age cutoff that will be used.@Policy(operationTypes=UPDATE) void pruneRestingNotificationStates(@NonNull Duration beforeNow)
NotificationStates
from NotificationStateAware.getNotificationStates()
which satisfy the following criteria:
NotificationState.isAcked()
is true
or
NotificationState.isStopped()
is true
NotificationState.getChangeTimestamp()
is before Instant.now()
minus the
beforeNow
durationbeforeNow
- NotificationStates
whose
timestamps
are older than the current
time minus this duration will be pruned@Policy(operationTypes=UPDATE) boolean pruneChangeDetails(@NonNull Object nativeId)
nativeId
, setting its
Tracking.getChangeDetails()
to null
.nativeId
- the native id of the entity whose change details should be set to
null
true
if the update was successful, false
otherwise@Policy(operationTypes=READ) @NonNull List<D> findAll(@Nullable ContextInfo contextInfo)
NarrowExecutor
implementation was specified via
Narrow
, the result should be narrowed based on sandbox and catalog state.contextInfo
- Request context information around sandbox and multitenant state@Policy(operationTypes=READ) @NonNull List<D> findAll(@Nullable ContextInfo contextInfo, @NonNull Class<D> type)
NarrowExecutor
implementation was specified via
Narrow
, the result should be narrowed based on sandbox and catalog state.contextInfo
- Request context information around sandbox and multitenant statetype
- The results will be limited to the explicit type@Policy(operationTypes=READ) @NonNull Iterable<D> findAllByContextId(@NonNull Iterable<String> contextIds, @Nullable ContextInfo contextInfo)
Trackable.getContextId()
). If a NarrowExecutor
implementation was specified
via Narrow
, the result should be narrowed based on sandbox and catalog state.contextIds
- A list of identifying idscontextInfo
- Request context information around sandbox and multitenant state@Policy(operationTypes=READ) @NonNull org.springframework.data.domain.Page<D> findAll(@NonNull org.springframework.data.domain.Pageable pageable, @Nullable ContextInfo contextInfo)
NarrowExecutor
implementation
was specified via Narrow
, the result should be narrowed based on sandbox and catalog
state.pageable
- Information regarding the current page of data to retrievecontextInfo
- Request context information around sandbox and multitenant state@Policy(operationTypes=READ) @NonNull org.springframework.data.domain.Page<D> findAll(@NonNull org.springframework.data.domain.Pageable pageable, @Nullable ContextInfo contextInfo, @NonNull Class<D> type)
NarrowExecutor
implementation
was specified via Narrow
, the result should be narrowed based on sandbox and catalog
state.pageable
- Information regarding the current page of data to retrievecontextInfo
- Request context information around sandbox and multitenant statetype
- The results will be limited to the explicit type@Policy(operationTypes=READ) @NonNull List<D> findAll(@NonNull org.springframework.data.domain.Sort sort, @Nullable ContextInfo contextInfo)
NarrowExecutor
implementation was
specified via Narrow
, the result should be narrowed based on sandbox and catalog
state.sort
- The sorting information used to define the sort for the query resultscontextInfo
- Request context information around sandbox and multitenant state@Policy(operationTypes=READ) @NonNull List<D> findAll(@NonNull org.springframework.data.domain.Sort sort, @Nullable ContextInfo contextInfo, @NonNull Class<D> type)
NarrowExecutor
implementation was
specified via Narrow
, the result should be narrowed based on sandbox and catalog
state.sort
- The sorting information used to define the sort for the query resultscontextInfo
- Request context information around sandbox and multitenant statetype
- The results will be limited to the explicit typeorg.springframework.data.repository.core.EntityInformation<D,String> getEntityInformation()
void setTrackableBehaviorUtil(TrackableBehaviorUtil behaviorUtil)
TrackableBehavior
state for a domain
class.behaviorUtil
- A utility that is capable of determining the TrackableBehavior
state for a domain class.TrackableBehaviorUtil getTrackableBehaviorUtil()
TrackableBehavior
state for a domain
class.TrackableBehavior
state for a
domain class.default Class<?> getDomainType()
getDomainType
in interface com.broadleafcommerce.common.extension.DomainTypeAware
List<Class<?>> getTypesToRegisterInMappingContext()
MappingContext
about which persistent entities are
available.@Policy(operationTypes=READ) @NonNull Optional<D> findByNativeId(@NonNull Object id)
id
- the native id to find the entity forOptional.empty()
otherwisedefault TransitionPackage<D> findPromoteOrientedItems(TargetRelatedRequest request)
request
- Request that includes properties identifying a sandbox target state@NonNull default TransitionPackage<D> findPromotable(@NonNull WorkflowPromoteRequest request)
WorkflowPromoteRequest
and also retrieve any
domain item existing at the requested target position (if any). The purpose of this call is
to establish origin and target in order to advance all or some of the state of the origin
object to the state of the target object in the workflow for a promotion.
Target position is determined by two values in the PromotionRequest: targetSandBoxId, and
targetLevel. In most cases, the targetSandBoxId remains the same and the targetLevel
increases incrementally beyond TrackingLevel.USER
until the final deployment
PromotionRequest, which uses a targetLevel of TrackingLevel.PRODUCTION
. Different
targetSandboxId values can be used to compose isolated sandbox flows. Furthermore, different
targetStage values can be used to further inform the system about state in a more complex
composed flow.
request
- container for holding information about the originating domain item and target
position for the promotion@NonNull default TransitionPackage<D> findRebasable(@NonNull WorkflowRebaseRequest request)
WorkflowRebaseRequest
and also retrieve any
domain item existing at the requested target position (if any). The purpose of this call is
to establish origin and target in order to move any missing changes by another author in the
target to the original. In this way, the original state is brought up-to-date with the
target. If the original contains conflicting changes, the original changes should win.
Target position is determined by two values in the PromotionRequest: targetSandBoxId, and
targetLevel. In most cases, the targetSandBoxId remains the same and the targetLevel
increases incrementally beyond TrackingLevel.USER
until the final deployment
PromotionRequest, which uses a targetLevel of TrackingLevel.PRODUCTION
. Different
targetSandboxId values can be used to compose isolated sandbox flows. Furthermore, different
targetStage values can be used to further inform the system about state in a more complex
composed flow.
request
- container for holding information about the originating domain item and target
position for the promotion@NonNull default TransitionPackage<D> findDeployable(@NonNull WorkflowDeployRequest request)
WorkflowDeployRequest
and also retrieve any
domain item existing at the requested target position (if any). The purpose of this call is
to establish origin and target in order to advance all or some of the state of the origin
object to the state of the target object in the workflow for a deployment.
Target position is determined by two values in the PromotionRequest: targetSandBoxId, and
targetLevel. In most cases, the targetSandBoxId remains the same and the targetLevel
increases incrementally beyond TrackingLevel.USER
until the final deployment
PromotionRequest, which uses a targetLevel of TrackingLevel.PRODUCTION
. Different
targetSandboxId values can be used to compose isolated sandbox flows. Furthermore, different
targetStage values can be used to further inform the system about state in a more complex
composed flow.
request
- container for holding information about the originating domain item and target
position for the deployment@NonNull default TransitionPackage<D> findRejectable(@NonNull WorkflowRejectRequest request)
WorkflowRejectRequest
and also retrieve any
domain item existing at the requested target position (if any). The purpose of this call is
to establish origin and target in order to reverse all or some of the state of the origin
object to the state of the target object in the workflow for a rejection.
Target position is determined by two values in the PromotionRequest: targetSandBoxId, and
targetLevel. In most cases, the targetSandBoxId remains the same and the targetLevel
increases incrementally beyond TrackingLevel.USER
until the final deployment
PromotionRequest, which uses a targetLevel of TrackingLevel.PRODUCTION
. Different
targetSandboxId values can be used to compose isolated sandbox flows. Furthermore, different
targetStage values can be used to further inform the system about state in a more complex
composed flow.
request
- container for holding information about the originating domain item and target
position for the rejection@Nullable default D findRevertable(@NonNull WorkflowRevertRequest request)
WorkflowRevertRequest
. The purpose of this
call is to establish origin in order to reverse the state of the origin object.request
- container for holding information about the originating domain itemD findOriginal(String contextId, @Nullable String catalogId, @Nullable String applicationId, @Nullable String author, @Nullable String stage, @Nullable String sandboxId, Integer level)
contextId
- The identifier for the sandboxable itemcatalogId
- Any catalog to which the original is related (if any)applicationId
- Any application to which the original is related (if any)author
- The author of the entity. Used when the original is a user level sandbox state.stage
- Additional identifying informationsandboxId
- The sandbox in which the original state existslevel
- The tracking level at which the original state resides@Nullable D findTarget(String contextId, @Nullable String catalogId, @Nullable String applicationId, @Nullable String author, @Nullable String stage, @Nullable String sandboxId, Integer level, Set<String> visibleFromCatalog)
contextId
- The identifier for the sandboxable itemcatalogId
- Any catalog to which the target is related (if any)applicationId
- Any application to which the original is related (if any)author
- The author of the entity. Used when the target is a user level sandbox state.stage
- Additional identifying informationsandboxId
- The sandbox in which the target state existslevel
- The tracking level at which the target state residesvisibleFromCatalog
- other catalogs that are visible based on the catalogIdCopyright © 2021. All rights reserved.