Skip to content

Commit

Permalink
fix: use the getEntityType() to get the URN string. (#79)
Browse files Browse the repository at this point in the history
* fix: use the getEntityType() to get the URN string.
  • Loading branch information
RealChrisL authored Feb 26, 2021
1 parent 50e4192 commit 6833bb3
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,7 @@ public static String getEntityTypeFromUrnClass(@Nonnull Class<? extends Urn> urn
@Nonnull
public static <URN extends Urn, ASPECT extends RecordTemplate> String getAspectSpecificMAETopicName(@Nonnull URN urn,
@Nonnull ASPECT newValue) {
final String urnStr = urn.getClass().getSimpleName().toUpperCase();
return String.format("%s_%s_%s", METADATA_AUDIT_EVENT_PREFIX, urnStr.substring(0, urnStr.length() - "Urn".length()),
return String.format("%s_%s_%s", METADATA_AUDIT_EVENT_PREFIX, urn.getEntityType().toUpperCase(),
newValue.getClass().getSimpleName().toUpperCase());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.linkedin.common.urn.Urn;
import com.linkedin.testing.EntityFoo;
import com.linkedin.testing.EntityUnion;
import com.linkedin.testing.urn.PizzaUrn;
import com.linkedin.testing.urn.BarUrn;
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.metadata.validator.InvalidSchemaException;
Expand Down Expand Up @@ -274,6 +275,10 @@ public void testGetMAETopicName() throws URISyntaxException {
AspectFoo foo = new AspectFoo().setValue("foo");

assertEquals(ModelUtils.getAspectSpecificMAETopicName(urn, foo), "METADATA_AUDIT_EVENT_FOO_ASPECTFOO");

PizzaUrn pizza = new PizzaUrn(1);
AspectBar bar = new AspectBar().setValue("bar");
assertEquals(ModelUtils.getAspectSpecificMAETopicName(pizza, bar), "METADATA_AUDIT_EVENT_PIZZA_ASPECTBAR");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ void testGetUrn() {
// case 1: valid urn
EbeanLocalDAO<EntityAspectUnion, FooUrn> dao =
new EbeanLocalDAO<>(EntityAspectUnion.class, _mockProducer, _server, FooUrn.class);
String urn1 = "urn:li:entityFoo:1";
String urn1 = "urn:li:foo:1";
FooUrn fooUrn = makeFooUrn(1);

assertEquals(fooUrn, dao.getUrn(urn1));
Expand Down
6 changes: 3 additions & 3 deletions dao-impl/ebean-dao/src/test/resources/immutable.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"urn:li:entityFoo:1": {
"urn:li:foo:1": {
"value": "1"
},
"urn:li:entityFoo:2": {
"urn:li:foo:2": {
"value": "2"
},
"urn:li:entityFoo:3": {
"urn:li:foo:3": {
"value": "3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void testAddRelationshipRemoveAll() throws Exception {
public void testGetNodeTypeFromUrn() {
assertEquals(_dao.getNodeType(makeBarUrn(1)), ":`com.linkedin.testing.EntityBar`");
assertEquals(_dao.getNodeType(makeFooUrn(1)), ":`com.linkedin.testing.EntityFoo`");
assertEquals(_dao.getNodeType(makeUrn(1, "entityFoo")), ":`com.linkedin.testing.EntityFoo`");
assertEquals(_dao.getNodeType(makeUrn(1, "foo")), ":`com.linkedin.testing.EntityFoo`");
assertEquals(_dao.getNodeType(makeUrn("1")), ":UNKNOWN");

// test consistency !!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public final class BarUrn extends Urn {

public static final String ENTITY_TYPE = "entityBar";
public static final String ENTITY_TYPE = "bar";
// Can be obtained via getEntityKey, but not in open source. We need to unify the internal / external URN definitions.
private final int _id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public final class BazUrn extends Urn {

public static final String ENTITY_TYPE = "entityBaz";
public static final String ENTITY_TYPE = "baz";
// Can be obtained via getEntityKey, but not in open source. We need to unify the internal / external URN definitions.
private final int _id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public final class FooUrn extends Urn {

public static final String ENTITY_TYPE = "entityFoo";
public static final String ENTITY_TYPE = "foo";
// Can be obtained via getEntityKey, but not in open source. We need to unify the internal / external URN definitions.
private final int _id;

Expand Down

0 comments on commit 6833bb3

Please sign in to comment.