fix: validate entity type for an urn (#1958)

This commit is contained in:
Jyoti Wadhwani 2020-10-23 12:56:29 -07:00 committed by GitHub
parent 0a232bb658
commit 127d84e3f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 20 additions and 12 deletions

View File

@ -38,6 +38,7 @@ public final class AzkabanFlowUrn extends Urn {
}
public static AzkabanFlowUrn createFromString(String rawUrn) throws URISyntaxException {
validateUrn(rawUrn, ENTITY_TYPE);
String content = new Urn(rawUrn).getContent();
String[] parts = content.substring(1, content.length() - 1).split(",");
return new AzkabanFlowUrn(parts[0], parts[1], parts[2]);

View File

@ -31,6 +31,7 @@ public final class AzkabanJobUrn extends Urn {
}
public static AzkabanJobUrn createFromString(String rawUrn) throws URISyntaxException {
validateUrn(rawUrn, ENTITY_TYPE);
String content = new Urn(rawUrn).getContent();
String flowParts = content.substring(1, content.lastIndexOf(",") + 1);
String[] parts = content.substring(1, content.length() - 1).split(",");

View File

@ -31,9 +31,8 @@ public final class ChartUrn extends Urn {
}
public static ChartUrn createFromString(String rawUrn) throws URISyntaxException {
Urn urn = new Urn(rawUrn);
validateUrn(urn, ENTITY_TYPE);
String[] urnParts = urn.getContent().split(",");
validateUrn(rawUrn, ENTITY_TYPE);
String[] urnParts = new Urn(rawUrn).getContent().split(",");
return new ChartUrn(urnParts[0], urnParts[1]);
}

View File

@ -25,14 +25,13 @@ public final class CorpGroupUrn extends Urn {
}
public static CorpGroupUrn createFromString(String rawUrn) throws URISyntaxException {
validateUrn(rawUrn, ENTITY_TYPE);
String groupName = new Urn(rawUrn).getContent();
return new CorpGroupUrn(groupName);
}
public static CorpGroupUrn createFromUrn(Urn urn) throws URISyntaxException {
if (!ENTITY_TYPE.equals(urn.getEntityType())) {
throw new URISyntaxException(urn.toString(), "Can't cast URN to CorpGroupUrn, not same ENTITY");
}
validateUrn(urn, ENTITY_TYPE);
Matcher matcher = URN_PATTERN.matcher(urn.toString());
if (matcher.find()) {

View File

@ -26,14 +26,13 @@ public final class CorpuserUrn extends Urn {
}
public static CorpuserUrn createFromString(String rawUrn) throws URISyntaxException {
validateUrn(rawUrn, ENTITY_TYPE);
String username = new Urn(rawUrn).getContent();
return new CorpuserUrn(username);
}
public static CorpuserUrn createFromUrn(Urn urn) throws URISyntaxException {
if (!ENTITY_TYPE.equals(urn.getEntityType())) {
throw new URISyntaxException(urn.toString(), "Can't cast URN to CorpuserUrn, not same ENTITY");
}
validateUrn(urn, ENTITY_TYPE);
Matcher matcher = URN_PATTERN.matcher(urn.toString());
if (matcher.find()) {

View File

@ -31,9 +31,8 @@ public final class DashboardUrn extends Urn {
}
public static DashboardUrn createFromString(String rawUrn) throws URISyntaxException {
Urn urn = new Urn(rawUrn);
validateUrn(urn, ENTITY_TYPE);
String[] urnParts = urn.getContent().split(",");
validateUrn(rawUrn, ENTITY_TYPE);
String[] urnParts = new Urn(rawUrn).getContent().split(",");
return new DashboardUrn(urnParts[0], urnParts[1]);
}

View File

@ -23,6 +23,7 @@ public final class DataPlatformUrn extends Urn {
}
public static DataPlatformUrn createFromString(String rawUrn) throws URISyntaxException {
validateUrn(rawUrn, ENTITY_TYPE);
String platformName = new Urn(rawUrn).getContent();
return new DataPlatformUrn(platformName);
}

View File

@ -40,6 +40,7 @@ public class DataProcessUrn extends Urn {
}
public static DataProcessUrn createFromString(String rawUrn) throws URISyntaxException {
validateUrn(rawUrn, ENTITY_TYPE);
String content = new Urn(rawUrn).getContent();
String[] parts = content.substring(1, content.length() - 1).split(",");
return new DataProcessUrn(parts[0], parts[1], toFabricType(parts[2]));

View File

@ -41,6 +41,7 @@ public final class DatasetUrn extends Urn {
}
public static DatasetUrn createFromString(String rawUrn) throws URISyntaxException {
validateUrn(rawUrn, ENTITY_TYPE);
String content = new Urn(rawUrn).getContent();
String[] parts = content.substring(1, content.length() - 1).split(",");
return new DatasetUrn(DataPlatformUrn.createFromString(parts[0]), parts[1], toFabricType(parts[2]));

View File

@ -39,6 +39,7 @@ public final class MLModelUrn extends Urn {
}
public static MLModelUrn createFromString(String rawUrn) throws URISyntaxException {
validateUrn(rawUrn, ENTITY_TYPE);
String content = new Urn(rawUrn).getContent();
String[] parts = content.substring(1, content.length() - 1).split(",");
return new MLModelUrn(DataPlatformUrn.createFromString(parts[0]), parts[1], toFabricType(parts[2]));

View File

@ -91,6 +91,12 @@ public class Urn {
return createFromString(rawUrn);
}
public static void validateUrn(@Nonnull String rawUrn, @Nonnull String entityType)
throws URISyntaxException {
final Urn urn = new Urn(rawUrn);
validateUrn(urn, entityType);
}
public static void validateUrn(@Nonnull Urn urn, @Nonnull String entityType)
throws URISyntaxException {
if (!entityType.equals(urn.getEntityType())) {