2019-08-31 20:51:14 -07:00
|
|
|
package com.linkedin.common.urn;
|
|
|
|
|
|
|
|
import com.linkedin.common.FabricType;
|
2020-05-07 15:18:33 -07:00
|
|
|
import com.linkedin.data.template.Custom;
|
|
|
|
import com.linkedin.data.template.DirectCoercer;
|
|
|
|
import com.linkedin.data.template.TemplateOutputCastException;
|
2019-08-31 20:51:14 -07:00
|
|
|
import java.net.URISyntaxException;
|
|
|
|
|
|
|
|
import static com.linkedin.common.urn.UrnUtils.*;
|
|
|
|
|
|
|
|
|
|
|
|
public final class DatasetUrn extends Urn {
|
|
|
|
|
|
|
|
public static final String ENTITY_TYPE = "dataset";
|
|
|
|
|
|
|
|
private static final String CONTENT_FORMAT = "(%s,%s,%s)";
|
|
|
|
|
|
|
|
private final DataPlatformUrn platformEntity;
|
|
|
|
|
|
|
|
private final String datasetNameEntity;
|
|
|
|
|
|
|
|
private final FabricType originEntity;
|
|
|
|
|
|
|
|
public DatasetUrn(DataPlatformUrn platform, String name, FabricType origin) {
|
|
|
|
super(ENTITY_TYPE, String.format(CONTENT_FORMAT, platform.toString(), name, origin.name()));
|
|
|
|
this.platformEntity = platform;
|
|
|
|
this.datasetNameEntity = name;
|
|
|
|
this.originEntity = origin;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DataPlatformUrn getPlatformEntity() {
|
|
|
|
return platformEntity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDatasetNameEntity() {
|
|
|
|
return datasetNameEntity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FabricType getOriginEntity() {
|
|
|
|
return originEntity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static DatasetUrn createFromString(String rawUrn) throws URISyntaxException {
|
|
|
|
String content = new Urn(rawUrn).getContent();
|
2020-05-11 08:41:02 -07:00
|
|
|
String[] parts = content.substring(1, content.length() - 1).split(",");
|
2019-08-31 20:51:14 -07:00
|
|
|
return new DatasetUrn(DataPlatformUrn.createFromString(parts[0]), parts[1], toFabricType(parts[2]));
|
|
|
|
}
|
2019-10-01 14:54:24 -07:00
|
|
|
|
|
|
|
public static DatasetUrn deserialize(String rawUrn) throws URISyntaxException {
|
|
|
|
return createFromString(rawUrn);
|
|
|
|
}
|
2020-05-07 15:18:33 -07:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2019-08-31 20:51:14 -07:00
|
|
|
}
|