diff --git a/li-utils/src/main/java/com/linkedin/common/urn/AzkabanFlowUrn.java b/li-utils/src/main/java/com/linkedin/common/urn/AzkabanFlowUrn.java index 85e780104cd6a1..811b79deac6eea 100644 --- a/li-utils/src/main/java/com/linkedin/common/urn/AzkabanFlowUrn.java +++ b/li-utils/src/main/java/com/linkedin/common/urn/AzkabanFlowUrn.java @@ -38,7 +38,6 @@ public String getFlowIdEntity() { } 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]); diff --git a/li-utils/src/main/java/com/linkedin/common/urn/AzkabanJobUrn.java b/li-utils/src/main/java/com/linkedin/common/urn/AzkabanJobUrn.java index c42a1a2cf7a102..bd953707568087 100644 --- a/li-utils/src/main/java/com/linkedin/common/urn/AzkabanJobUrn.java +++ b/li-utils/src/main/java/com/linkedin/common/urn/AzkabanJobUrn.java @@ -31,7 +31,6 @@ public String getJobIdEntity() { } 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(","); diff --git a/li-utils/src/main/java/com/linkedin/common/urn/ChartUrn.java b/li-utils/src/main/java/com/linkedin/common/urn/ChartUrn.java index 93f9ada94abf8e..dc99857885e0a0 100644 --- a/li-utils/src/main/java/com/linkedin/common/urn/ChartUrn.java +++ b/li-utils/src/main/java/com/linkedin/common/urn/ChartUrn.java @@ -31,8 +31,9 @@ public String getChartIdEntity() { } public static ChartUrn createFromString(String rawUrn) throws URISyntaxException { - validateUrn(rawUrn, ENTITY_TYPE); - String[] urnParts = new Urn(rawUrn).getContent().split(","); + Urn urn = new Urn(rawUrn); + validateUrn(urn, ENTITY_TYPE); + String[] urnParts = urn.getContent().split(","); return new ChartUrn(urnParts[0], urnParts[1]); } diff --git a/li-utils/src/main/java/com/linkedin/common/urn/CorpGroupUrn.java b/li-utils/src/main/java/com/linkedin/common/urn/CorpGroupUrn.java index 7a2431f4051b69..1d61edf41849a3 100644 --- a/li-utils/src/main/java/com/linkedin/common/urn/CorpGroupUrn.java +++ b/li-utils/src/main/java/com/linkedin/common/urn/CorpGroupUrn.java @@ -25,13 +25,14 @@ public String getGroupNameEntity() { } 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 { - validateUrn(urn, ENTITY_TYPE); + if (!ENTITY_TYPE.equals(urn.getEntityType())) { + throw new URISyntaxException(urn.toString(), "Can't cast URN to CorpGroupUrn, not same ENTITY"); + } Matcher matcher = URN_PATTERN.matcher(urn.toString()); if (matcher.find()) { diff --git a/li-utils/src/main/java/com/linkedin/common/urn/CorpuserUrn.java b/li-utils/src/main/java/com/linkedin/common/urn/CorpuserUrn.java index d09c1a2cd9076e..aec3cf1162dfc9 100644 --- a/li-utils/src/main/java/com/linkedin/common/urn/CorpuserUrn.java +++ b/li-utils/src/main/java/com/linkedin/common/urn/CorpuserUrn.java @@ -26,13 +26,14 @@ public String getUsernameEntity() { } 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 { - validateUrn(urn, ENTITY_TYPE); + if (!ENTITY_TYPE.equals(urn.getEntityType())) { + throw new URISyntaxException(urn.toString(), "Can't cast URN to CorpuserUrn, not same ENTITY"); + } Matcher matcher = URN_PATTERN.matcher(urn.toString()); if (matcher.find()) { diff --git a/li-utils/src/main/java/com/linkedin/common/urn/DashboardUrn.java b/li-utils/src/main/java/com/linkedin/common/urn/DashboardUrn.java index cabcb478f86f00..c33401af504246 100644 --- a/li-utils/src/main/java/com/linkedin/common/urn/DashboardUrn.java +++ b/li-utils/src/main/java/com/linkedin/common/urn/DashboardUrn.java @@ -31,8 +31,9 @@ public String getDashboardIdEntity() { } public static DashboardUrn createFromString(String rawUrn) throws URISyntaxException { - validateUrn(rawUrn, ENTITY_TYPE); - String[] urnParts = new Urn(rawUrn).getContent().split(","); + Urn urn = new Urn(rawUrn); + validateUrn(urn, ENTITY_TYPE); + String[] urnParts = urn.getContent().split(","); return new DashboardUrn(urnParts[0], urnParts[1]); } diff --git a/li-utils/src/main/java/com/linkedin/common/urn/DataPlatformUrn.java b/li-utils/src/main/java/com/linkedin/common/urn/DataPlatformUrn.java index 6d53141700866d..72712bb44e1415 100644 --- a/li-utils/src/main/java/com/linkedin/common/urn/DataPlatformUrn.java +++ b/li-utils/src/main/java/com/linkedin/common/urn/DataPlatformUrn.java @@ -23,7 +23,6 @@ public String getPlatformNameEntity() { } public static DataPlatformUrn createFromString(String rawUrn) throws URISyntaxException { - validateUrn(rawUrn, ENTITY_TYPE); String platformName = new Urn(rawUrn).getContent(); return new DataPlatformUrn(platformName); } diff --git a/li-utils/src/main/java/com/linkedin/common/urn/DataProcessUrn.java b/li-utils/src/main/java/com/linkedin/common/urn/DataProcessUrn.java index 341ef7037c7743..f882112746697f 100644 --- a/li-utils/src/main/java/com/linkedin/common/urn/DataProcessUrn.java +++ b/li-utils/src/main/java/com/linkedin/common/urn/DataProcessUrn.java @@ -40,7 +40,6 @@ public FabricType getOriginEntity() { } 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])); diff --git a/li-utils/src/main/java/com/linkedin/common/urn/DatasetUrn.java b/li-utils/src/main/java/com/linkedin/common/urn/DatasetUrn.java index d75ad503d9bd1d..20a42ad42ae872 100644 --- a/li-utils/src/main/java/com/linkedin/common/urn/DatasetUrn.java +++ b/li-utils/src/main/java/com/linkedin/common/urn/DatasetUrn.java @@ -41,7 +41,6 @@ public FabricType getOriginEntity() { } 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])); diff --git a/li-utils/src/main/java/com/linkedin/common/urn/MLModelUrn.java b/li-utils/src/main/java/com/linkedin/common/urn/MLModelUrn.java index db5ed1a2a1f776..eb81c9a64fcd0c 100644 --- a/li-utils/src/main/java/com/linkedin/common/urn/MLModelUrn.java +++ b/li-utils/src/main/java/com/linkedin/common/urn/MLModelUrn.java @@ -39,7 +39,6 @@ public FabricType getOriginEntity() { } 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])); diff --git a/li-utils/src/main/java/com/linkedin/common/urn/Urn.java b/li-utils/src/main/java/com/linkedin/common/urn/Urn.java index 981eeb4eb59183..aa9418fe33af2c 100644 --- a/li-utils/src/main/java/com/linkedin/common/urn/Urn.java +++ b/li-utils/src/main/java/com/linkedin/common/urn/Urn.java @@ -91,12 +91,6 @@ public static Urn deserialize(String rawUrn) throws URISyntaxException { 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())) {