Class UpdateValidationDomainMapperMember

java.lang.Object
com.broadleafcommerce.data.tracking.core.mapping.UpdateValidationDomainMapperMember
All Implemented Interfaces:
com.broadleafcommerce.common.extension.data.DataRoutePartitionAware, DomainMapper, DomainMapperMember, IdAware, org.springframework.core.Ordered

public class UpdateValidationDomainMapperMember extends Object implements DomainMapperMember, IdAware

A special DomainMapperMember which is responsible for validating the id variable state for update requests. Update requests (including replace) include a path parameter in the API that identifies the entity receiving the update. However, the payload may also contain an id value that may end up being applied during the mapping phase to the repository state. This mapper member performs some lightweight checks and mitigations:

  1. If the id in the payload is null, change it's value to the requested id from the path parameter
  2. If the id in the payload is populated, and it matches the path parameter, pass through
  3. If the id in the payload is populated, and does not match the path parameter, throw a ValidationException.
Generally, in our API implementations, the path parameter ends up being supplied as the first argument in CrudEntityService.replace(String, Object, ContextInfo) and CrudEntityService.update(String, Object, ContextInfo), and is used to find the entity which will be replaced or updated. If found, this is the entity that becomes the repositoryDomain argument to fromBusinessDomain(Object, Object, ContextInfo). Thus, its contextId can be reliably used as the "path parameter" source of truth on what the ID should be, and this implementation uses it as such.
Author:
Jeff Fischer
  • Constructor Details

    • UpdateValidationDomainMapperMember

      public UpdateValidationDomainMapperMember()
  • Method Details

    • getDataRoutePartition

      public String getDataRoutePartition()
      Specified by:
      getDataRoutePartition in interface com.broadleafcommerce.common.extension.data.DataRoutePartitionAware
    • fromBusinessDomain

      public <D> D fromBusinessDomain(@Nullable Object businessDomain, @Nullable D repositoryDomain, @Nullable ContextInfo contextInfo)
      Validates the identifier value state for a mutation request. Confirms the repository entity requested for update matches the id in the payload, if applicable.
      Specified by:
      fromBusinessDomain in interface DomainMapperMember
      Type Parameters:
      D - The repository entity type
      Parameters:
      businessDomain - The business instance containing the relevant property information
      repositoryDomain - The repository specific instance to affect and return
      contextInfo - The context information used to make tracking determinations relevant to sandboxing and multitenant concerns. See TrackableRepository for more info on persistence behavior based on context.
      Returns:
      The validated (possibly altered) repository entity instance
    • modifyMap

      public <D, P> D modifyMap(D repositoryDomain, P businessDomain, ContextInfo contextInfo, boolean allowNull)
      Validates the identifier value state for a mutation request. Confirms the repository entity requested for update matches the id in the payload, if applicable.
      Specified by:
      modifyMap in interface DomainMapper
      Type Parameters:
      D - The repository entity type
      P - The projection type
      Parameters:
      repositoryDomain - The persistence domain instance to modify
      businessDomain - The business instance containing changes to map to the repository domain
      contextInfo - The context information used to make tracking determinations relevant to sandboxing and multitenant concerns. See TrackableRepository for more info on persistence behavior based on context.
      allowNull - Whether or not null values in properties in the payload instance should be ignored during the mapping operation.
      Returns:
      The validated (possibly altered) repository entity instance
    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface DomainMapperMember
      Specified by:
      getOrder in interface org.springframework.core.Ordered