Skip to content

Commit

Permalink
Fix patch support
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro93 authored and david-leifker committed Oct 14, 2024
1 parent 324c533 commit a9cb610
Showing 1 changed file with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,37 @@ public class FieldPathValidator extends AspectPayloadValidator {

/**
* Prevent any MCP for SchemaMetadata where field ids are duplicated (except for MCPs with {@link
* ChangeType#DELETE}).
* ChangeType#DELETE} and {@link ChangeType#PATCH}, the latter gets handled pre-commit to the DB).
*/
@Override
protected Stream<AspectValidationException> validateProposedAspects(
@Nonnull Collection<? extends BatchItem> mcpItems,
@Nonnull RetrieverContext retrieverContext) {
return mcpItems.stream()
.filter(i -> !ChangeType.DELETE.equals(i.getChangeType()))
.filter(
i ->
!ChangeType.DELETE.equals(i.getChangeType())
&& !ChangeType.PATCH.equals(i.getChangeType()))
.filter(
i ->
i.getAspectName().equals(SCHEMA_METADATA_ASPECT_NAME)
|| i.getAspectName().equals(EDITABLE_SCHEMA_METADATA_ASPECT_NAME))
.map(
i -> {
if (i.getAspectName().equals(SCHEMA_METADATA_ASPECT_NAME)) {
return processSchemaMetadataAspect(i);
} else {
return processEditableSchemaMetadataAspect(i);
}
})
.filter(Objects::nonNull);
}

@Override
protected Stream<AspectValidationException> validatePreCommitAspects(
@Nonnull Collection<ChangeMCP> changeMCPs, @Nonnull RetrieverContext retrieverContext) {
return changeMCPs.stream()
.filter(i -> ChangeType.PATCH.equals(i.getChangeType()))
.filter(
i ->
i.getAspectName().equals(SCHEMA_METADATA_ASPECT_NAME)
Expand Down Expand Up @@ -89,10 +112,4 @@ private static AspectValidationException processSchemaMetadataAspect(BatchItem i
}
return null;
}

@Override
protected Stream<AspectValidationException> validatePreCommitAspects(
@Nonnull Collection<ChangeMCP> changeMCPs, @Nonnull RetrieverContext retrieverContext) {
return Stream.empty();
}
}

0 comments on commit a9cb610

Please sign in to comment.