From 88dff44a3e0bc386d2a41f137041b0e19d3e011a Mon Sep 17 00:00:00 2001 From: Derek Pham Date: Fri, 6 Sep 2024 17:55:10 -0700 Subject: [PATCH 1/4] Add batchGet for BaseAspectV2Resource --- .../linkedin/metadata/restli/BaseAspectV2Resource.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseAspectV2Resource.java b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseAspectV2Resource.java index b9a7ae11c..2e5a10b86 100644 --- a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseAspectV2Resource.java +++ b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseAspectV2Resource.java @@ -27,6 +27,9 @@ import com.linkedin.restli.server.annotations.ReturnEntity; import com.linkedin.restli.server.resources.CollectionResourceTaskTemplate; import java.time.Clock; +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.function.Function; import javax.annotation.Nonnull; @@ -85,6 +88,12 @@ public Task get(@Nonnull URN urn) { .orElseThrow(RestliUtils::resourceNotFoundException)); } + @RestMethod.Get + @Nonnull + public Task>> get(@Nonnull Collection urns) { + return RestliUtils.toTask(() -> getLocalDAO().get(_aspectClass, new HashSet<>(urns))); + } + @RestMethod.GetAll @Nonnull public Task> getAllWithMetadata(@Nonnull URN urn, From ae243a38f5a4e1fe627df282a373375a5b8b34eb Mon Sep 17 00:00:00 2001 From: Derek Pham Date: Fri, 6 Sep 2024 17:56:18 -0700 Subject: [PATCH 2/4] fix --- .../java/com/linkedin/metadata/restli/BaseAspectV2Resource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseAspectV2Resource.java b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseAspectV2Resource.java index 2e5a10b86..a7e1ab2da 100644 --- a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseAspectV2Resource.java +++ b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseAspectV2Resource.java @@ -88,7 +88,7 @@ public Task get(@Nonnull URN urn) { .orElseThrow(RestliUtils::resourceNotFoundException)); } - @RestMethod.Get + @RestMethod.BatchGet @Nonnull public Task>> get(@Nonnull Collection urns) { return RestliUtils.toTask(() -> getLocalDAO().get(_aspectClass, new HashSet<>(urns))); From 49010829b45fe4590aafadf8216c44ca191d354d Mon Sep 17 00:00:00 2001 From: Derek Pham Date: Mon, 9 Sep 2024 22:14:19 -0700 Subject: [PATCH 3/4] fix --- .../java/com/linkedin/metadata/restli/BaseAspectV2Resource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseAspectV2Resource.java b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseAspectV2Resource.java index a7e1ab2da..7e7f94818 100644 --- a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseAspectV2Resource.java +++ b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseAspectV2Resource.java @@ -90,7 +90,7 @@ public Task get(@Nonnull URN urn) { @RestMethod.BatchGet @Nonnull - public Task>> get(@Nonnull Collection urns) { + public Task>> batchGet(@Nonnull Collection urns) { return RestliUtils.toTask(() -> getLocalDAO().get(_aspectClass, new HashSet<>(urns))); } From 9f7b20d9b83ab3fb1e4fe61f81516ae19ba158c0 Mon Sep 17 00:00:00 2001 From: Derek Pham Date: Wed, 23 Oct 2024 14:41:55 -0700 Subject: [PATCH 4/4] Properly cast generic Urn to entity specific urn --- .../metadata/restli/BaseSearchableEntityResource.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseSearchableEntityResource.java b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseSearchableEntityResource.java index a84e027a1..6a264c669 100644 --- a/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseSearchableEntityResource.java +++ b/restli-resources/src/main/java/com/linkedin/metadata/restli/BaseSearchableEntityResource.java @@ -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; @@ -210,7 +211,7 @@ public CollectionResult 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 urnValueMap = @@ -223,4 +224,12 @@ public CollectionResult 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); + } + } }