Class AdminRolePersistenceHandler

  • All Implemented Interfaces:
    com.broadleafcommerce.common.messaging.PersistenceHandler

    public class AdminRolePersistenceHandler
    extends OperationAwarePersistenceHandler
    Handles messages from the Persistence channel for AdminRole data to update UserRole. This is designed to perform a replacement of existing data within this service from the admin user service.
    Author:
    Samarth Dhruva (samarthd)
    • Constructor Detail

      • AdminRolePersistenceHandler

        public AdminRolePersistenceHandler​(UserRoleService<UserRole> userRoleService,
                                           com.fasterxml.jackson.databind.ObjectMapper mapper,
                                           com.broadleafcommerce.common.extension.TypeFactory typeFactory)
    • Method Detail

      • hook

        @StreamListener("persistenceInputAdminRole")
        public void hook​(String entityJson)
      • processCreateOperation

        protected void processCreateOperation​(@NonNull
                                              @NonNull String entityId,
                                              @NonNull
                                              @NonNull Instant changeTimestamp,
                                              @NonNull
                                              @NonNull com.fasterxml.jackson.databind.JsonNode entityJson)
                                       throws IOException
        Description copied from class: OperationAwarePersistenceHandler
        Invoked if the persistence message had an OperationType of OperationType.CREATE.
        Specified by:
        processCreateOperation in class OperationAwarePersistenceHandler
        Parameters:
        entityId - the ID found on the persistence message. Guaranteed non-empty.
        changeTimestamp - the timestamp found on the persistence message. Guaranteed non-null.
        entityJson - the persistence message json itself. Guaranteed non-null.
        Throws:
        IOException
      • mapUpdatesFromRequest

        protected void mapUpdatesFromRequest​(AdminRole request,
                                             UserRole target)
      • processUpdateOperation

        protected void processUpdateOperation​(@NonNull
                                              @NonNull String entityId,
                                              @NonNull
                                              @NonNull Instant changeTimestamp,
                                              @NonNull
                                              @NonNull com.fasterxml.jackson.databind.JsonNode entityJson)
                                       throws IOException
        Description copied from class: OperationAwarePersistenceHandler
        Invoked if the persistence message had an OperationType of OperationType.UPDATE.
        Specified by:
        processUpdateOperation in class OperationAwarePersistenceHandler
        Parameters:
        entityId - the entity ID found on the persistence message. Guaranteed non-empty.
        changeTimestamp - the timestamp found on the persistence message. Guaranteed non-null.
        entityJson - the persistence message json itself. Guaranteed non-null.
        Throws:
        IOException
      • performReplacementIfEligible

        protected void performReplacementIfEligible​(@NonNull
                                                    @NonNull String entityId,
                                                    @NonNull
                                                    @NonNull UserRole existing,
                                                    @NonNull
                                                    @NonNull AdminRole request,
                                                    @NonNull
                                                    @NonNull Instant changeTimestamp)
      • processDeleteOperation

        protected void processDeleteOperation​(@NonNull
                                              @NonNull String entityId,
                                              @NonNull
                                              @NonNull Instant changeTimestamp,
                                              @NonNull
                                              @NonNull com.fasterxml.jackson.databind.JsonNode entityJson)
                                       throws IOException
        Archives the given entity.

        Note that if an existing record is not found, one will be created in an archived state. The motivation for this is to protect against out-of-order messages (ex: "Delete" message on an entity arrives before the "Create"). By establishing a pre-existing record in an archived state with a timestamp, any subsequent persistence message received can be compared against this record's timestamp and appropriately discarded as outdated rather than triggering creation of a new record.

        Specified by:
        processDeleteOperation in class OperationAwarePersistenceHandler
        Parameters:
        entityId - the entity ID found on the persistence message. Guaranteed non-empty.
        changeTimestamp - the timestamp found on the persistence message. Guaranteed non-null.
        entityJson - the persistence message json itself. Guaranteed non-null.
        Throws:
        IOException
      • performArchivalReplacementIfEligible

        protected void performArchivalReplacementIfEligible​(@NonNull
                                                            @NonNull String entityId,
                                                            @NonNull
                                                            @NonNull UserRole existing,
                                                            @NonNull
                                                            @NonNull Instant changeTimestamp)
      • modifyForArchival

        protected void modifyForArchival​(UserRole target)
        Mimic what UserRoleService.archive(String) would do to mark this record as archived.
        Parameters:
        target - the instance to modify
      • updatePermissions

        protected void updatePermissions​(AdminRole request,
                                         UserRole role)
        We will not validate these references by querying for them, as the associated permissions may not yet be synchronized to the authentication service. We trust the admin user service to have pre-validated these associations, and thus eventually no references will be broken.

        TODO https://github.com/BroadleafCommerce/AuthenticationServices/issues/182

        Parameters:
        request - the request whose permissions should be used to replace the existing data
        role - the target on which the permissions will be replaced
      • updateBasicRoleInfo

        protected void updateBasicRoleInfo​(AdminRole request,
                                           UserRole role)
      • updateRoleTenantRestrictions

        protected void updateRoleTenantRestrictions​(AdminRole request,
                                                    UserRole role)
      • getSupportedSimpleTypeNames

        public String[] getSupportedSimpleTypeNames()
      • getTypeFactory

        protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()