mirror of
https://github.com/datahub-project/datahub.git
synced 2025-10-16 03:18:45 +00:00
fix(structuredProps) Add validation that ID and qualifiedName have no… (#11930)
This commit is contained in:
parent
28cc8caf65
commit
2878c65ceb
@ -89,6 +89,9 @@ public class PropertyDefinitionValidator extends AspectPayloadValidator {
|
|||||||
item.getAspect(StructuredPropertyDefinition.class);
|
item.getAspect(StructuredPropertyDefinition.class);
|
||||||
|
|
||||||
versionFormatCheck(item, newDefinition.getVersion()).ifPresent(exceptions::addException);
|
versionFormatCheck(item, newDefinition.getVersion()).ifPresent(exceptions::addException);
|
||||||
|
urnIdCheck(item).ifPresent(exceptions::addException);
|
||||||
|
qualifiedNameCheck(item, newDefinition.getQualifiedName())
|
||||||
|
.ifPresent(exceptions::addException);
|
||||||
|
|
||||||
if (item.getPreviousSystemAspect() != null) {
|
if (item.getPreviousSystemAspect() != null) {
|
||||||
|
|
||||||
@ -192,4 +195,20 @@ public class PropertyDefinitionValidator extends AspectPayloadValidator {
|
|||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Optional<AspectValidationException> urnIdCheck(MCPItem item) {
|
||||||
|
if (item.getUrn().getId().contains(" ")) {
|
||||||
|
return Optional.of(AspectValidationException.forItem(item, "Urn ID cannot have spaces"));
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Optional<AspectValidationException> qualifiedNameCheck(
|
||||||
|
MCPItem item, @Nonnull String qualifiedName) {
|
||||||
|
if (qualifiedName.contains(" ")) {
|
||||||
|
return Optional.of(
|
||||||
|
AspectValidationException.forItem(item, "Qualified names cannot have spaces"));
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,4 +397,40 @@ public class PropertyDefinitionValidatorTest {
|
|||||||
.count(),
|
.count(),
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUrnIdWithSpace()
|
||||||
|
throws URISyntaxException, CloneNotSupportedException, AspectValidationException {
|
||||||
|
Urn propertyUrn = UrnUtils.getUrn("urn:li:structuredProperty:test me out.foo.bar");
|
||||||
|
StructuredPropertyDefinition newProperty = new StructuredPropertyDefinition();
|
||||||
|
newProperty.setEntityTypes(new UrnArray(Urn.createFromString("urn:li:logicalEntity:dataset")));
|
||||||
|
newProperty.setDisplayName("oldProp");
|
||||||
|
newProperty.setQualifiedName("foo.bar");
|
||||||
|
newProperty.setCardinality(PropertyCardinality.MULTIPLE);
|
||||||
|
newProperty.setValueType(Urn.createFromString("urn:li:logicalType:STRING"));
|
||||||
|
assertEquals(
|
||||||
|
PropertyDefinitionValidator.validateDefinitionUpserts(
|
||||||
|
TestMCP.ofOneMCP(propertyUrn, null, newProperty, entityRegistry),
|
||||||
|
mockRetrieverContext)
|
||||||
|
.count(),
|
||||||
|
1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testQualifiedNameWithSpace()
|
||||||
|
throws URISyntaxException, CloneNotSupportedException, AspectValidationException {
|
||||||
|
Urn propertyUrn = UrnUtils.getUrn("urn:li:structuredProperty:foo.bar");
|
||||||
|
StructuredPropertyDefinition newProperty = new StructuredPropertyDefinition();
|
||||||
|
newProperty.setEntityTypes(new UrnArray(Urn.createFromString("urn:li:logicalEntity:dataset")));
|
||||||
|
newProperty.setDisplayName("oldProp");
|
||||||
|
newProperty.setQualifiedName("foo.bar with spaces");
|
||||||
|
newProperty.setCardinality(PropertyCardinality.MULTIPLE);
|
||||||
|
newProperty.setValueType(Urn.createFromString("urn:li:logicalType:STRING"));
|
||||||
|
assertEquals(
|
||||||
|
PropertyDefinitionValidator.validateDefinitionUpserts(
|
||||||
|
TestMCP.ofOneMCP(propertyUrn, null, newProperty, entityRegistry),
|
||||||
|
mockRetrieverContext)
|
||||||
|
.count(),
|
||||||
|
1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user