mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-04 22:52:54 +00:00
fix: validate entity type for an urn (#1958)
This commit is contained in:
parent
0a232bb658
commit
127d84e3f9
@ -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]);
|
||||
|
||||
@ -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(",");
|
||||
|
||||
@ -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]);
|
||||
}
|
||||
|
||||
|
||||
@ -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()) {
|
||||
|
||||
@ -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()) {
|
||||
|
||||
@ -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]);
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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]));
|
||||
|
||||
@ -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]));
|
||||
|
||||
@ -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]));
|
||||
|
||||
@ -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())) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user