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:- If the id in the payload is null, change it's value to the requested id from the path parameter
- If the id in the payload is populated, and it matches the path parameter, pass through
- If the id in the payload is populated, and does not match the path parameter, throw a
ValidationException
.
CrudEntityService.replace(String, Object, ContextInfo)
andCrudEntityService.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 therepositoryDomain
argument tofromBusinessDomain(Object, Object, ContextInfo)
. Thus, itscontextId
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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.broadleafcommerce.data.tracking.core.mapping.IdAware
IdAware.Id
-
-
Constructor Summary
Constructors Constructor Description UpdateValidationDomainMapperMember()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <D> D
fromBusinessDomain(Object businessDomain, D repositoryDomain, ContextInfo contextInfo)
Validates the identifier value state for a mutation request.String
getDataRoutePartition()
int
getOrder()
<D,P>
DmodifyMap(D repositoryDomain, P businessDomain, ContextInfo contextInfo, boolean allowNull)
Validates the identifier value state for a mutation request.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.broadleafcommerce.data.tracking.core.mapping.DomainMapper
deleteMap, getBusinessDomainType
-
Methods inherited from interface com.broadleafcommerce.data.tracking.core.mapping.DomainMapperMember
fromRepositoryDomain
-
-
-
-
Method Detail
-
getDataRoutePartition
public String getDataRoutePartition()
- Specified by:
getDataRoutePartition
in interfacecom.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 interfaceDomainMapperMember
- Type Parameters:
D
- The repository entity type- Parameters:
businessDomain
- The business instance containing the relevant property informationrepositoryDomain
- The repository specific instance to affect and returncontextInfo
- The context information used to make tracking determinations relevant to sandboxing and multitenant concerns. SeeTrackableRepository
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 interfaceDomainMapper
- Type Parameters:
D
- The repository entity typeP
- The projection type- Parameters:
repositoryDomain
- The persistence domain instance to modifybusinessDomain
- The business instance containing changes to map to the repository domaincontextInfo
- The context information used to make tracking determinations relevant to sandboxing and multitenant concerns. SeeTrackableRepository
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 interfaceDomainMapperMember
- Specified by:
getOrder
in interfaceorg.springframework.core.Ordered
-
-