Skip to content

Commit

Permalink
Properly cast generic urn to entity specific urn (#457)
Browse files Browse the repository at this point in the history
* Add batchGet for BaseAspectV2Resource

* fix

* fix

* Properly cast generic Urn to entity specific urn

---------

Co-authored-by: Derek Pham <[email protected]>
  • Loading branch information
derekpham and Derek Pham authored Oct 23, 2024
1 parent b762dac commit 5bbe44c
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.linkedin.restli.server.annotations.PagingContextParam;
import com.linkedin.restli.server.annotations.QueryParam;
import com.linkedin.restli.server.annotations.RestMethod;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -210,7 +211,7 @@ public CollectionResult<VALUE, SearchResultMetadata> getSearchQueryCollectionRes
.map(d -> (URN) ModelUtils.getUrnFromDocument(d))
.collect(Collectors.toList());
} else if (searchResult.getSearchResultMetadata().hasUrns()) {
matchedUrns = searchResult.getSearchResultMetadata().getUrns().stream().map(urn -> (URN) urn).collect(Collectors.toList());
matchedUrns = searchResult.getSearchResultMetadata().getUrns().stream().map(this::toEntitySpecificUrn).collect(Collectors.toList());
}

final Map<URN, VALUE> urnValueMap =
Expand All @@ -223,4 +224,12 @@ public CollectionResult<VALUE, SearchResultMetadata> getSearchQueryCollectionRes
searchResult.getSearchResultMetadata().setUrns(new UrnArray(existingUrns.stream().map(urn -> (Urn) urn).collect(Collectors.toList())))
);
}

private URN toEntitySpecificUrn(Urn urn) {
try {
return (URN) (_urnClass.getMethod("createFromUrn", Urn.class).invoke(null, urn));
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 5bbe44c

Please sign in to comment.