Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(urn): Move UrnCoercer into corresponding Urn class #1661

Merged
merged 1 commit into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions li-utils/src/main/java/com/linkedin/common/urn/CorpGroupUrn.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.linkedin.common.urn;

import com.linkedin.data.template.Custom;
import com.linkedin.data.template.DirectCoercer;
import com.linkedin.data.template.TemplateOutputCastException;
import java.net.URISyntaxException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -42,4 +45,20 @@ public static CorpGroupUrn createFromUrn(Urn urn) throws URISyntaxException {
public static CorpGroupUrn deserialize(String rawUrn) throws URISyntaxException {
return createFromString(rawUrn);
}

static {
Custom.registerCoercer(new DirectCoercer<CorpGroupUrn>() {
public Object coerceInput(CorpGroupUrn object) throws ClassCastException {
return object.toString();
}

public CorpGroupUrn coerceOutput(Object object) throws TemplateOutputCastException {
try {
return CorpGroupUrn.createFromString((String) object);
} catch (URISyntaxException e) {
throw new TemplateOutputCastException("Invalid URN syntax: " + e.getMessage(), e);
}
}
}, CorpGroupUrn.class);
}
}

This file was deleted.

20 changes: 20 additions & 0 deletions li-utils/src/main/java/com/linkedin/common/urn/CorpuserUrn.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.linkedin.common.urn;

import com.linkedin.data.template.Custom;
import com.linkedin.data.template.DirectCoercer;
import com.linkedin.data.template.TemplateOutputCastException;
import java.net.URISyntaxException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -43,4 +46,21 @@ public static CorpuserUrn createFromUrn(Urn urn) throws URISyntaxException {
public static CorpuserUrn deserialize(String rawUrn) throws URISyntaxException {
return createFromString(rawUrn);
}

static {
Custom.registerCoercer(new DirectCoercer<CorpuserUrn>() {
public Object coerceInput(CorpuserUrn object) throws ClassCastException {
return object.toString();
}

public CorpuserUrn coerceOutput(Object object) throws TemplateOutputCastException {
try {
return CorpuserUrn.createFromString((String) object);
} catch (URISyntaxException e) {
throw new TemplateOutputCastException("Invalid URN syntax: " + e.getMessage(), e);
}
}
}, CorpuserUrn.class);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.linkedin.common.urn;

import com.linkedin.data.template.Custom;
import com.linkedin.data.template.DirectCoercer;
import com.linkedin.data.template.TemplateOutputCastException;

import java.net.URISyntaxException;


Expand All @@ -26,4 +30,20 @@ public static DataPlatformUrn createFromString(String rawUrn) throws URISyntaxEx
public static DataPlatformUrn deserialize(String rawUrn) throws URISyntaxException {
return createFromString(rawUrn);
}

static {
Custom.registerCoercer(new DirectCoercer<DataPlatformUrn>() {
public Object coerceInput(DataPlatformUrn object) throws ClassCastException {
return object.toString();
}

public DataPlatformUrn coerceOutput(Object object) throws TemplateOutputCastException {
try {
return DataPlatformUrn.createFromString((String) object);
} catch (URISyntaxException e) {
throw new TemplateOutputCastException("Invalid URN syntax: " + e.getMessage(), e);
}
}
}, DataPlatformUrn.class);
}
}

This file was deleted.

19 changes: 19 additions & 0 deletions li-utils/src/main/java/com/linkedin/common/urn/DatasetUrn.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.linkedin.common.urn;

import com.linkedin.common.FabricType;
import com.linkedin.data.template.Custom;
import com.linkedin.data.template.DirectCoercer;
import com.linkedin.data.template.TemplateOutputCastException;
import java.net.URISyntaxException;

import static com.linkedin.common.urn.UrnUtils.*;
Expand Down Expand Up @@ -46,4 +49,20 @@ public static DatasetUrn createFromString(String rawUrn) throws URISyntaxExcepti
public static DatasetUrn deserialize(String rawUrn) throws URISyntaxException {
return createFromString(rawUrn);
}

static {
Custom.registerCoercer(new DirectCoercer<DatasetUrn>() {
public Object coerceInput(DatasetUrn object) throws ClassCastException {
return object.toString();
}

public DatasetUrn coerceOutput(Object object) throws TemplateOutputCastException {
try {
return DatasetUrn.createFromString((String) object);
} catch (URISyntaxException e) {
throw new TemplateOutputCastException("Invalid URN syntax: " + e.getMessage(), e);
}
}
}, DatasetUrn.class);
}
}

This file was deleted.

21 changes: 21 additions & 0 deletions li-utils/src/main/java/com/linkedin/common/urn/Urn.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.linkedin.common.urn;

import com.linkedin.data.template.Custom;
import com.linkedin.data.template.DirectCoercer;
import com.linkedin.data.template.TemplateOutputCastException;

import javax.annotation.Nonnull;
import java.net.URISyntaxException;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -86,4 +90,21 @@ public static boolean isUrn(@Nonnull String urn) {
public static Urn deserialize(String rawUrn) throws URISyntaxException {
return createFromString(rawUrn);
}

static {
Custom.registerCoercer(new DirectCoercer<Urn>() {
public Object coerceInput(Urn object) throws ClassCastException {
return object.toString();
}

public Urn coerceOutput(Object object) throws TemplateOutputCastException {
try {
return Urn.createFromString((String) object);
} catch (URISyntaxException e) {
throw new TemplateOutputCastException("Invalid URN syntax: " + e.getMessage(), e);
}
}

}, Urn.class);
}
}
27 changes: 0 additions & 27 deletions li-utils/src/main/java/com/linkedin/common/urn/UrnCoercer.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"ref" : "string",
"java" : {
"class" : "com.linkedin.common.urn.CorpGroupUrn",
"coercerClass": "com.linkedin.common.urn.CorpGroupUrnCoercer"
"class" : "com.linkedin.common.urn.CorpGroupUrn"
},
"name" : "CorpGroupUrn",
"namespace" : "com.linkedin.common",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"ref" : "string",
"java" : {
"class" : "com.linkedin.common.urn.CorpuserUrn",
"coercerClass": "com.linkedin.common.urn.CorpuserUrnCoercer"
"class" : "com.linkedin.common.urn.CorpuserUrn"
},
"name" : "CorpuserUrn",
"namespace" : "com.linkedin.common",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"ref" : "string",
"java" : {
"class" : "com.linkedin.common.urn.DataPlatformUrn",
"coercerClass": "com.linkedin.common.urn.DataPlatformUrnCoercer"
"class" : "com.linkedin.common.urn.DataPlatformUrn"
},
"name" : "DataPlatformUrn",
"namespace" : "com.linkedin.common",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"ref" : "string",
"java" : {
"class" : "com.linkedin.common.urn.DatasetUrn",
"coercerClass": "com.linkedin.common.urn.DatasetUrnCoercer"
"class" : "com.linkedin.common.urn.DatasetUrn"
},
"name" : "DatasetUrn",
"namespace" : "com.linkedin.common",
Expand Down
3 changes: 1 addition & 2 deletions li-utils/src/main/pegasus/com/linkedin/common/Urn.pdsc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"namespace": "com.linkedin.common",
"ref": "string",
"java": {
"class": "com.linkedin.common.urn.Urn",
"coercerClass": "com.linkedin.common.urn.UrnCoercer"
"class": "com.linkedin.common.urn.Urn"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private static <T> T invokeProtectedMethod(Object object, Method method, Object.
method.setAccessible(true);
return (T) method.invoke(object, args);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
throw new RuntimeException(e.getCause());
} finally {
method.setAccessible(false);
}
Expand Down