@@ -234,8 +234,9 @@ protected Task<VALUE> get(@Nonnull KEY id, @QueryParam(PARAM_ASPECTS) @Optional
234234
235235 return RestliUtils .toTask (() -> {
236236 final URN urn = toUrn (id );
237+ BaseLocalDAO <INTERNAL_ASPECT_UNION , URN > shadowReadLocalDAO = getShadowReadLocalDAO ();
237238 if (!getLocalDAO ().exists (urn )) {
238- if (getShadowReadLocalDAO () != null && getShadowReadLocalDAO () .exists (urn )) {
239+ if (shadowReadLocalDAO != null && shadowReadLocalDAO .exists (urn )) {
239240 log .warn ("Entity {} exists in shadow DAO but not in local DAO. Ignoring shadow-only data." , urn );
240241 }
241242 throw RestliUtils .resourceNotFoundException ();
@@ -571,7 +572,8 @@ public Task<ASSET> getAsset(@ActionParam(PARAM_URN) @Nonnull String urnString,
571572 return RestliUtils .toTask (() -> {
572573 final URN urn = parseUrnParam (urnString );
573574
574- if (getShadowReadLocalDAO () == null ) {
575+ BaseLocalDAO <INTERNAL_ASPECT_UNION , URN > shadowReadLocalDAO = getShadowReadLocalDAO ();
576+ if (shadowReadLocalDAO == null ) {
575577 if (!getLocalDAO ().exists (urn )) {
576578 throw RestliUtils .resourceNotFoundException ();
577579 }
@@ -589,7 +591,7 @@ public Task<ASSET> getAsset(@ActionParam(PARAM_URN) @Nonnull String urnString,
589591
590592 return ModelUtils .newAsset (_assetClass , urn , aspects );
591593 }
592- return getAssetWithShadowComparison (urn , aspectNames );
594+ return getAssetWithShadowComparison (urn , aspectNames , shadowReadLocalDAO );
593595 });
594596 } catch (ModelValidationException e ) {
595597 throw RestliUtils .invalidArgumentsException (e .getMessage ());
@@ -610,10 +612,10 @@ public Task<ASSET> getAsset(@ActionParam(PARAM_URN) @Nonnull String urnString,
610612 * @return an asset assembled from the resolved aspects
611613 * @throws RestLiServiceException if the entity does not exist in the local DAO
612614 */
613- private ASSET getAssetWithShadowComparison (@ Nonnull URN urn , @ Nullable String [] aspectNames ) {
615+ private ASSET getAssetWithShadowComparison (@ Nonnull URN urn , @ Nullable String [] aspectNames , BaseLocalDAO < INTERNAL_ASPECT_UNION , URN > shadowReadLocalDAO ) {
614616
615617 if (!getLocalDAO ().exists (urn )) {
616- if (getShadowReadLocalDAO () .exists (urn )) {
618+ if (shadowReadLocalDAO .exists (urn )) {
617619 log .warn ("Entity {} exists in shadow DAO but not in local DAO. Ignoring shadow-only data." , urn );
618620 }
619621 throw RestliUtils .resourceNotFoundException ();
@@ -628,7 +630,7 @@ private ASSET getAssetWithShadowComparison(@Nonnull URN urn, @Nullable String[]
628630 Map <AspectKey <URN , ? extends RecordTemplate >, java .util .Optional <? extends RecordTemplate >> localResults =
629631 getLocalDAO ().get (keys );
630632 Map <AspectKey <URN , ? extends RecordTemplate >, java .util .Optional <? extends RecordTemplate >> shadowResults =
631- getShadowReadLocalDAO () .get (keys );
633+ shadowReadLocalDAO .get (keys );
632634
633635 // Collect aspects
634636 List <UnionTemplate > aspects = new ArrayList <>();
@@ -1230,7 +1232,8 @@ private Map<URN, List<UnionTemplate>> getUrnAspectMap(@Nonnull Collection<URN> u
12301232 final Map <URN , List <UnionTemplate >> urnAspectsMap =
12311233 urns .stream ().collect (Collectors .toMap (Function .identity (), urn -> new ArrayList <>()));
12321234
1233- if (getShadowReadLocalDAO () == null ) {
1235+ BaseLocalDAO <INTERNAL_ASPECT_UNION , URN > shadowReadLocalDAO = getShadowReadLocalDAO ();
1236+ if (shadowReadLocalDAO == null ) {
12341237 if (isInternalModelsEnabled ) {
12351238 getLocalDAO ().get (keys )
12361239 .forEach ((key , aspect ) -> aspect .ifPresent (metadata -> urnAspectsMap .get (key .getUrn ())
@@ -1242,22 +1245,22 @@ private Map<URN, List<UnionTemplate>> getUrnAspectMap(@Nonnull Collection<URN> u
12421245 }
12431246 return urnAspectsMap ;
12441247 } else {
1245- return getUrnAspectMapFromShadowDao (urns , keys , isInternalModelsEnabled );
1248+ return getUrnAspectMapFromShadowDao (urns , keys , isInternalModelsEnabled , shadowReadLocalDAO );
12461249 }
12471250 }
12481251
12491252 @ Nonnull
12501253 private Map <URN , List <UnionTemplate >> getUrnAspectMapFromShadowDao (
12511254 @ Nonnull Collection <URN > urns ,
12521255 @ Nonnull Set <AspectKey <URN , ? extends RecordTemplate >> keys ,
1253- boolean isInternalModelsEnabled ) {
1256+ boolean isInternalModelsEnabled ,
1257+ @ Nonnull BaseLocalDAO <INTERNAL_ASPECT_UNION , URN > shadowReadLocalDAO ) {
12541258
12551259 Map <AspectKey <URN , ? extends RecordTemplate >, java .util .Optional <? extends RecordTemplate >> localResults =
12561260 getLocalDAO ().get (keys );
12571261
1258- BaseLocalDAO <INTERNAL_ASPECT_UNION , URN > shadowDao = getShadowReadLocalDAO ();
12591262 Map <AspectKey <URN , ? extends RecordTemplate >, java .util .Optional <? extends RecordTemplate >> shadowResults =
1260- shadowDao .get (keys );
1263+ shadowReadLocalDAO .get (keys );
12611264
12621265 final Map <URN , List <UnionTemplate >> urnAspectsMap =
12631266 urns .stream ().collect (Collectors .toMap (Function .identity (), urn -> new ArrayList <>()));
0 commit comments