diff --git a/service/src/main/java/gov/nasa/pds/api/registry/LidvidsContext.java b/service/src/main/java/gov/nasa/pds/api/registry/LidvidsContext.java index 87637e68..ec072084 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/LidvidsContext.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/LidvidsContext.java @@ -3,7 +3,7 @@ import java.util.List; public interface LidvidsContext { - public String getLidVid(); + public String getProductIdentifierStr(); public Integer getLimit(); diff --git a/service/src/main/java/gov/nasa/pds/api/registry/controller/Member.java b/service/src/main/java/gov/nasa/pds/api/registry/controller/Member.java index 554b6648..36ce9627 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/controller/Member.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/controller/Member.java @@ -35,7 +35,7 @@ public ResponseEntity transmute(ControlContext control, UserContext cont transmuter = ReferencingLogicTransmuter.getBySwaggerGroup(content.getGroup()).impl(); else transmuter = ReferencingLogicTransmuter.getByProductClass(QuickSearch - .getValue(control.getConnection(), false, content.getLidVid(), "product_class")).impl(); + .getValue(control.getConnection(), false, content.getProductIdentifierStr(), "product_class")).impl(); RequestAndResponseContext context = this.offspring ? transmuter.member(control, content, this.twoSteps) diff --git a/service/src/main/java/gov/nasa/pds/api/registry/controller/URIParameters.java b/service/src/main/java/gov/nasa/pds/api/registry/controller/URIParameters.java index 8a8bdd44..73bf5078 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/controller/URIParameters.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/controller/URIParameters.java @@ -109,7 +109,7 @@ public boolean getSingletonResultExpected() { } @Override - public String getLidVid() { + public String getProductIdentifierStr() { return productIdentifier != null ? productIdentifier.toString() : ""; } diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicBundle.java b/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicBundle.java index 239d3e9a..55234c3d 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicBundle.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicBundle.java @@ -59,7 +59,7 @@ public GroupConstraint constraints() { * @return a list of collection LIDVIDs * @throws IOException IO exception */ - static private List getAllBundleCollectionLidVids(ControlContext ctrlContext, PdsLidVid bundleLidvid) throws IOException { + static private List getAllBundleCollectionLidVids(ControlContext ctrlContext, PdsLidVid bundleLidvid) throws IOException { List collectionPropertyKeys = List.of("ref_lid_collection", "ref_lid_collection_secondary"); SearchRequest collectionReferencesRequest = new SearchRequestFactory(RequestConstructionContextFactory.given(bundleLidvid.toString()), @@ -70,7 +70,7 @@ static private List getAllBundleCollectionLidVids(ControlContext ctrlCon ctrlContext.getConnection().getRegistryIndex()); // Retrieve member collection LIDVIDs - List results = new ArrayList<>(); + List results = new ArrayList<>(); for (final Map kvp : new HitIterator(ctrlContext.getConnection().getRestHighLevelClient(), collectionReferencesRequest)) { collectionPropertyKeys.forEach( key -> { @@ -78,19 +78,19 @@ static private List getAllBundleCollectionLidVids(ControlContext ctrlCon if (referencesRawObj == null) return; List refStrings = (List) referencesRawObj; - Set lidvidReferences = refStrings.stream().filter(PdsProductIdentifier::stringIsLidvid).collect(Collectors.toSet()); - Set lidReferences = refStrings.stream().filter(PdsProductIdentifier::stringIsLid).collect(Collectors.toSet()); - for (String lidRef : lidReferences) { + Set collectionRefLidVids = refStrings.stream().filter(PdsProductIdentifier::stringIsLidvid).map(PdsLidVid::fromString).collect(Collectors.toSet()); + Set lidRefStrs = refStrings.stream().filter(PdsProductIdentifier::stringIsLid).collect(Collectors.toSet()); + for (String lidRef : lidRefStrs) { try { PdsLid lid = PdsLid.fromString(lidRef); PdsLidVid latestLidvid = LidVidUtils.getLatestLidVidByLid(ctrlContext, RequestBuildContextFactory.given(true, "_id"), lid); - lidvidReferences.add(latestLidvid.toString()); + collectionRefLidVids.add(latestLidvid); } catch (IOException | LidVidNotFoundException e) { log.warn("Failed to find extant LIDVID for given LID: " + lidRef); } } - results.addAll(lidvidReferences); + results.addAll(collectionRefLidVids); }); } @@ -102,15 +102,14 @@ static private List getAllBundleCollectionLidVids(ControlContext ctrlCon public RequestAndResponseContext member(ControlContext ctrlContext, UserContext searchContext, boolean twoSteps) throws ApplicationTypeException, IOException, LidVidNotFoundException, UnknownGroupNameException { - List collectionLidvids = getAllBundleCollectionLidVids(ctrlContext, PdsLidVid.fromString(searchContext.getLidVid())); - GroupConstraint collectionMemberSelector = GroupConstraintImpl.buildAny(Map.of("_id", collectionLidvids)); + List collectionLidvids = getAllBundleCollectionLidVids(ctrlContext, PdsLidVid.fromString(searchContext.getProductIdentifierStr())); + List collectionLidvidStrs = collectionLidvids.stream().map(PdsLidVid::toString).collect(Collectors.toList()); + GroupConstraint collectionMemberSelector = GroupConstraintImpl.buildAny(Map.of("_id", collectionLidvidStrs)); if (twoSteps) { -// Current behaviour is to return all non-aggregate products referencing this bundle's LID or LIDVID as a parent. -// This may not be desirable as it *may* end up inconsistent with "the member products of the collections returned -// by the non-twoSteps query", but this is simple to change later once desired behaviour is ironed out. GroupConstraint nonAggregateSelector = ReferencingLogicTransmuter.getBySwaggerGroup("non-aggregate-products").impl().constraints(); - List bundleAlternateIds = QuickSearch.getValues(ctrlContext.getConnection(), false, searchContext.getLidVid(), "alternate_ids"); - GroupConstraint memberSelector = GroupConstraintImpl.buildAny(Map.of("ops:Provenance/ops:parent_bundle_identifier", bundleAlternateIds)); + PdsLidVid parentBundleLidvid = PdsLidVid.fromString(searchContext.getProductIdentifierStr()); + List parentBundleConstraintValues = List.of(parentBundleLidvid.toString()); + GroupConstraint memberSelector = GroupConstraintImpl.buildAny(Map.of("ops:Provenance/ops:parent_bundle_identifier", parentBundleConstraintValues)); GroupConstraint nonAggregateMemberSelector = nonAggregateSelector.union(memberSelector); return rrContextFromConstraint(ctrlContext, searchContext, nonAggregateMemberSelector); } else { diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicCollection.java b/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicCollection.java index ccbc1415..071e9c31 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicCollection.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicCollection.java @@ -47,17 +47,16 @@ public RequestAndResponseContext member( throws ApplicationTypeException, IOException, LidVidNotFoundException, MembershipException { if (twoSteps) throw new MembershipException(userContext.getIdentifier().toString(), "members/members", "collections"); - GroupConstraint childrenConstraint = getChildProductsConstraint(ctrlContext, userContext.getLidVid()); + PdsLidVid collectionLidvid = PdsLidVid.fromString(userContext.getProductIdentifierStr()); + GroupConstraint childrenConstraint = getChildProductsConstraint(ctrlContext, collectionLidvid); return rrContextFromConstraint(ctrlContext, userContext, childrenConstraint); } - private GroupConstraint getChildProductsConstraint(ControlContext control, String parentCollectionLidvid) throws IOException, LidVidNotFoundException { -// TODO: targetProductAlternateIds should depend on all/latest/specific behaviour - List targetProductAlternateIds = QuickSearch.getValues(control.getConnection(), false, parentCollectionLidvid, "alternate_ids"); - + private GroupConstraint getChildProductsConstraint(ControlContext control, PdsLidVid parentCollectionLidvid) throws IOException, LidVidNotFoundException { + List parentCollectionConstraintValues = List.of(parentCollectionLidvid.toString()); GroupConstraint productClassConstraints = ReferencingLogicTransmuter.NonAggregateProduct.impl().constraints(); - GroupConstraint childrenSelectorConstraint = GroupConstraintImpl.buildAny(Map.of("ops:Provenance/ops:parent_collection_identifier", targetProductAlternateIds)); + GroupConstraint childrenSelectorConstraint = GroupConstraintImpl.buildAny(Map.of("ops:Provenance/ops:parent_collection_identifier", parentCollectionConstraintValues)); return productClassConstraints.union(childrenSelectorConstraint); } @@ -68,7 +67,7 @@ public RequestAndResponseContext memberOf(ControlContext ctrlContext, UserContex if (twoSteps) throw new MembershipException(searchContext.getIdentifier().toString(), "member-of/member-of", "collections"); - List parentIdStrings = QuickSearch.getValues(ctrlContext.getConnection(), false, searchContext.getLidVid(), "ops:Provenance/ops:parent_bundle_identifier"); + List parentIdStrings = QuickSearch.getValues(ctrlContext.getConnection(), false, searchContext.getProductIdentifierStr(), "ops:Provenance/ops:parent_bundle_identifier"); // Get all the LIDVID strings, convert the LID strings to LIDVID strings, then add them all together Set parentLidvidStrings = parentIdStrings.stream().filter(PdsProductIdentifier::stringIsLidvid).collect(Collectors.toSet()); diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicNonAggregateProduct.java b/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicNonAggregateProduct.java index d4c7b868..57e1ae2e 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicNonAggregateProduct.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicNonAggregateProduct.java @@ -3,18 +3,14 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import gov.nasa.pds.api.registry.RequestBuildContext; import gov.nasa.pds.api.registry.UserContext; import gov.nasa.pds.api.registry.exceptions.ApplicationTypeException; -import gov.nasa.pds.api.registry.model.identifiers.LidVidUtils; import gov.nasa.pds.api.registry.model.identifiers.PdsLid; import gov.nasa.pds.api.registry.model.identifiers.PdsLidVid; import gov.nasa.pds.api.registry.model.identifiers.PdsProductIdentifier; @@ -26,13 +22,9 @@ import gov.nasa.pds.api.registry.ControlContext; import gov.nasa.pds.api.registry.GroupConstraint; -import gov.nasa.pds.api.registry.LidvidsContext; import gov.nasa.pds.api.registry.ReferencingLogic; import gov.nasa.pds.api.registry.exceptions.LidVidNotFoundException; -import gov.nasa.pds.api.registry.search.HitIterator; import gov.nasa.pds.api.registry.search.RequestBuildContextFactory; -import gov.nasa.pds.api.registry.search.RequestConstructionContextFactory; -import gov.nasa.pds.api.registry.search.SearchRequestFactory; import gov.nasa.pds.api.registry.util.GroupConstraintImpl; import static gov.nasa.pds.api.registry.model.identifiers.LidVidUtils.getAllLidVidsByLids; @@ -61,7 +53,7 @@ public RequestAndResponseContext memberOf( List ancestorIdentifiers = QuickSearch.getValues( - ctrlContext.getConnection(), false, searchContext.getLidVid(), ancestorMetadataKey); + ctrlContext.getConnection(), false, searchContext.getProductIdentifierStr(), ancestorMetadataKey); // Get all the LIDVID refs, resolve the LID refs to all relevant LIDVIDs, then add them all // together diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/Unlimited.java b/service/src/main/java/gov/nasa/pds/api/registry/model/Unlimited.java index 9c18c411..3136c346 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/Unlimited.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/Unlimited.java @@ -12,7 +12,7 @@ class Unlimited implements LidvidsContext { } @Override - public String getLidVid() { + public String getProductIdentifierStr() { return this.lidvid; } diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/identifiers/LidVidUtils.java b/service/src/main/java/gov/nasa/pds/api/registry/model/identifiers/LidVidUtils.java index 44871266..ea54ae27 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/identifiers/LidVidUtils.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/identifiers/LidVidUtils.java @@ -131,12 +131,12 @@ public static void verify(ControlContext control, UserContext user) throws IOExc if (expected_rlt != ReferencingLogicTransmuter.Any) { String actual_group = - QuickSearch.getValue(control.getConnection(), false, user.getLidVid(), "product_class"); + QuickSearch.getValue(control.getConnection(), false, user.getProductIdentifierStr(), "product_class"); ReferencingLogicTransmuter actual_rlt = ReferencingLogicTransmuter.getByProductClass(actual_group); if (actual_rlt != expected_rlt) - throw new LidVidMismatchException(user.getLidVid(), user.getGroup(), actual_group); + throw new LidVidMismatchException(user.getProductIdentifierStr(), user.getGroup(), actual_group); } } }