Class DefaultAccountRoleService<P extends AccountRole>

  • All Implemented Interfaces:
    AccountRoleService<P>, com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>

    public class DefaultAccountRoleService<P extends AccountRole>
    extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
    implements AccountRoleService<P>
    Default implementation of the AccountRoleService.
    Author:
    Samarth Dhruva (samarthd), Chris Kittrell (ckittrell)
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultAccountRoleService​(AccountRoleRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, AccountPermissionHydrationService permissionHydrationService, AccountRoleContextValidator<P> accountRoleContextValidator, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator, com.broadleafcommerce.common.messaging.PersistenceProducer persistenceProducer, com.broadleafcommerce.common.messaging.notification.NotificationStateService notificationStateService, com.broadleafcommerce.common.messaging.notification.NotificationManager notificationManager, com.broadleafcommerce.common.messaging.notification.MessageSerializationHelper messageSerializationHelper, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected P convertFromPersistentDomain​(@NonNull Object persistedDomain, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Similar to MappableCrudEntityHelper.convertFromPersistentDomain(Object), except will invoke DomainMapperManager.fromRepositoryDomain(BusinessTypeAware, ContextInfo) with the given context argument instead of just null.
      P create​(P role, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Creates the role.
      protected com.broadleafcommerce.data.tracking.core.Trackable createInternal​(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Mostly copied from MappableCrudEntityHelper.create(Object, CrudRepository), but overridden to support notifying on persistence events via #notifyPersistenceProducer(NotificationStateAware).
      void delete​(@NonNull String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Deletes the given role.
      boolean existsById​(@NonNull String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Reports whether there exists a role in the data store whose AccountRole.getId() ()} is equal to the given id.
      boolean existsByNameAndIdNot​(@NonNull String name, String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Reports whether there exists a role in the data store whose AccountRole.getName() is equal to the given name and whose AccountRole.getId() is not equal to the given id.
      protected AccountRoleContextValidator<P> getAccountRoleContextValidator()  
      protected com.broadleafcommerce.common.messaging.notification.MessageSerializationHelper getMessageSerializationHelper()  
      protected com.broadleafcommerce.common.messaging.notification.NotificationManager getNotificationManager()  
      protected com.broadleafcommerce.common.messaging.notification.NotificationStateService getNotificationStateService()  
      protected AccountPermissionHydrationService getPermissionHydrationService()  
      protected com.broadleafcommerce.common.messaging.PersistenceProducer getPersistenceProducer()  
      protected AccountRoleRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()  
      protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator()  
      org.springframework.data.domain.Page<P> readAllByName​(@NonNull String name, org.springframework.data.domain.Pageable pageable, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Reads roles in the data store, filtering to those whose name contains the given value.
      Optional<P> readByIdOptional​(@NonNull String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Read a single role by id.
      P replace​(@NonNull String id, P role, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Replaces the given role.
      protected com.broadleafcommerce.data.tracking.core.Trackable replaceInternal​(@NonNull String id, P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Mostly copied from MappableCrudEntityHelper.replace(String, Object, CrudRepository), but overridden to support notifying on persistence events via #notifyPersistenceProducer(NotificationStateAware).
      protected void throwIfErrors​(@NonNull org.springframework.validation.Errors errors)  
      protected void validateNoChildrenOfRoleBeforeDeletion​(@NonNull String roleToDeleteId)
      Given a role that is requested to be deleted, checks that it does not have any child roles in the data store.
      • Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService

        getRsqlHelper, readAll, readAll, readAll, readAll
      • Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService

        convertFromPersistentDomain, convertToPersistentDomain, createAll, createAllAllowingPartialSuccess, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, update, updateAll, updateAllAllowingPartialSuccess, updateSort
      • Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService

        createAll, createAllAllowingPartialSuccess, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess, updateSort
      • Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService

        readAll, readAll, readAll, readAll
    • Constructor Detail

      • DefaultAccountRoleService

        public DefaultAccountRoleService​(AccountRoleRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository,
                                         AccountPermissionHydrationService permissionHydrationService,
                                         AccountRoleContextValidator<P> accountRoleContextValidator,
                                         com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator,
                                         com.broadleafcommerce.common.messaging.PersistenceProducer persistenceProducer,
                                         com.broadleafcommerce.common.messaging.notification.NotificationStateService notificationStateService,
                                         com.broadleafcommerce.common.messaging.notification.NotificationManager notificationManager,
                                         com.broadleafcommerce.common.messaging.notification.MessageSerializationHelper messageSerializationHelper,
                                         com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper)
    • Method Detail

      • readByIdOptional

        public Optional<P> readByIdOptional​(@NonNull
                                            @NonNull String id,
                                            @Nullable
                                            com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: AccountRoleService
        Read a single role by id.

        Similar to CrudEntityService.readByContextId(String, ContextInfo), but does not throw an exception if the entity is not found.

        Specified by:
        readByIdOptional in interface AccountRoleService<P extends AccountRole>
        Parameters:
        id - the id of the role to find
        Returns:
        an Optional containing the role if found, otherwise Optional.empty()
      • readAllByName

        public org.springframework.data.domain.Page<P> readAllByName​(@NonNull
                                                                     @NonNull String name,
                                                                     @Nullable
                                                                     org.springframework.data.domain.Pageable pageable,
                                                                     @Nullable
                                                                     com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: AccountRoleService
        Reads roles in the data store, filtering to those whose name contains the given value. Results are restricted to only the roles accessible from the given context as described in the class-level javadocs.
        Specified by:
        readAllByName in interface AccountRoleService<P extends AccountRole>
        Parameters:
        name - the value that role names must contain in order to match
        pageable - describes the page of results to return
        context - context information about multitenant state
        Returns:
        roles accessible in the current context that match the given name
      • existsById

        public boolean existsById​(@NonNull
                                  @NonNull String id,
                                  @Nullable
                                  com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: AccountRoleService
        Reports whether there exists a role in the data store whose AccountRole.getId() ()} is equal to the given id. Results are restricted to only the roles accessible from the given context as described in the class-level javadocs.
        Specified by:
        existsById in interface AccountRoleService<P extends AccountRole>
        Parameters:
        id - the value that the role's id must not equal in order to match
        context - context information about multitenant state
        Returns:
        true if there exists a role accessible from the given context matching the given name and not matching the given id, false otherwise
      • existsByNameAndIdNot

        public boolean existsByNameAndIdNot​(@NonNull
                                            @NonNull String name,
                                            @Nullable
                                            String id,
                                            @Nullable
                                            com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: AccountRoleService
        Reports whether there exists a role in the data store whose AccountRole.getName() is equal to the given name and whose AccountRole.getId() is not equal to the given id. Results are restricted to only the roles accessible from the given context as described in the class-level javadocs.
        Specified by:
        existsByNameAndIdNot in interface AccountRoleService<P extends AccountRole>
        Parameters:
        name - the value that role name must equal in order to match
        id - (optional) the value that the role's id must not equal in order to match. If this value is null, then results will not be filtered by their id.
        context - context information about multitenant state
        Returns:
        true if there exists a role accessible from the given context matching the given name and not matching the given id, false otherwise
      • create

        public P create​(@NonNull
                        P role,
                        @Nullable
                        com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: AccountRoleService
        Creates the role.

        Emits an OperationAwarePersistenceMessage to the PersistenceProducer.TYPE channel.

        Specified by:
        create in interface AccountRoleService<P extends AccountRole>
        Specified by:
        create in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends AccountRole>
        Overrides:
        create in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends AccountRole>
        Parameters:
        role - the role to create
        context - context information about multitenant state
        Returns:
        the role after it has been created in the data store
      • createInternal

        protected com.broadleafcommerce.data.tracking.core.Trackable createInternal​(@NonNull
                                                                                    P businessInstance,
                                                                                    @Nullable
                                                                                    com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Mostly copied from MappableCrudEntityHelper.create(Object, CrudRepository), but overridden to support notifying on persistence events via #notifyPersistenceProducer(NotificationStateAware).
        Parameters:
        businessInstance - The business domain instance. In general, the DomainMapperManager is responsible for converting to a repository platform type for persistence.
        context -
        Returns:
        The new entity instance in the form of a persisted type instance.
        Throws:
        com.broadleafcommerce.common.error.validation.ValidationException - if the given businessInstance could not be created
      • replace

        public P replace​(@NonNull
                         @NonNull String id,
                         @NonNull
                         P role,
                         @Nullable
                         com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: AccountRoleService
        Replaces the given role.

        Emits an OperationAwarePersistenceMessage to the PersistenceProducer.TYPE channel.

        Specified by:
        replace in interface AccountRoleService<P extends AccountRole>
        Specified by:
        replace in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends AccountRole>
        Overrides:
        replace in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends AccountRole>
        Parameters:
        id - the id of the role to replace
        role - the replacement role
        context - context information about multitenant state
        Returns:
        the role after it has been replaced in the data store
      • replaceInternal

        protected com.broadleafcommerce.data.tracking.core.Trackable replaceInternal​(@NonNull
                                                                                     @NonNull String id,
                                                                                     @NonNull
                                                                                     P businessInstance,
                                                                                     @Nullable
                                                                                     com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Mostly copied from MappableCrudEntityHelper.replace(String, Object, CrudRepository), but overridden to support notifying on persistence events via #notifyPersistenceProducer(NotificationStateAware).
        Parameters:
        id - The id for the entity.
        businessInstance - The payload type that domain class should be converted to. In general, the payload is what the rest API responds with.
        context -
        Returns:
        The replaced entity instance in the form of a persisted instance, or EntityMissingException if not available.
        Throws:
        com.broadleafcommerce.common.error.validation.ValidationException - if the given businessInstance failed validation on replacement
        com.broadleafcommerce.data.tracking.core.exception.EntityMissingException - if a managed instance corresponding to the given id could not be found
      • delete

        public void delete​(@NonNull
                           @NonNull String id,
                           @Nullable
                           com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: AccountRoleService
        Deletes the given role.

        Emits an OperationAwarePersistenceMessage to the PersistenceProducer.TYPE channel.

        Specified by:
        delete in interface AccountRoleService<P extends AccountRole>
        Specified by:
        delete in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends AccountRole>
        Overrides:
        delete in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends AccountRole>
        Parameters:
        id - the ID of the role to delete
        context - context information about multitenant state
      • validateNoChildrenOfRoleBeforeDeletion

        protected void validateNoChildrenOfRoleBeforeDeletion​(@NonNull
                                                              @NonNull String roleToDeleteId)
        Given a role that is requested to be deleted, checks that it does not have any child roles in the data store. This protects against descendants being suddenly orphaned.
        Parameters:
        roleToDeleteId - the id of the role which should be validated to have no children in the data store
        Throws:
        InvalidAccountRoleDeleteException - if the role has children in the data store
      • throwIfErrors

        protected void throwIfErrors​(@NonNull
                                     @NonNull org.springframework.validation.Errors errors)
      • convertFromPersistentDomain

        protected P convertFromPersistentDomain​(@NonNull
                                                @NonNull Object persistedDomain,
                                                @Nullable
                                                com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Similar to MappableCrudEntityHelper.convertFromPersistentDomain(Object), except will invoke DomainMapperManager.fromRepositoryDomain(BusinessTypeAware, ContextInfo) with the given context argument instead of just null.

        Ensures MutabilityContextStateMapperMember will have a context to base its mutability determination on.

        Parameters:
        persistedDomain - the persisted-domain instance to convert to the business domain
        context - context information surrounding multitenant state
      • getRepository

        protected AccountRoleRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
        Overrides:
        getRepository in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends AccountRole>
      • getValidator

        protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator()
      • getPersistenceProducer

        protected com.broadleafcommerce.common.messaging.PersistenceProducer getPersistenceProducer()
      • getNotificationStateService

        protected com.broadleafcommerce.common.messaging.notification.NotificationStateService getNotificationStateService()
      • getNotificationManager

        protected com.broadleafcommerce.common.messaging.notification.NotificationManager getNotificationManager()
      • getMessageSerializationHelper

        protected com.broadleafcommerce.common.messaging.notification.MessageSerializationHelper getMessageSerializationHelper()