Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

411 Removes dependency on immature "alternate_ids" product property #414

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;

public interface LidvidsContext {
public String getLidVid();
public String getProductIdentifierStr();

public Integer getLimit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ResponseEntity<Object> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public boolean getSingletonResultExpected() {
}

@Override
public String getLidVid() {
public String getProductIdentifierStr() {
return productIdentifier != null ? productIdentifier.toString() : "";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public GroupConstraint constraints() {
* @return a list of collection LIDVIDs
* @throws IOException IO exception
*/
static private List<String> getAllBundleCollectionLidVids(ControlContext ctrlContext, PdsLidVid bundleLidvid) throws IOException {
static private List<PdsLidVid> getAllBundleCollectionLidVids(ControlContext ctrlContext, PdsLidVid bundleLidvid) throws IOException {
List<String> collectionPropertyKeys = List.of("ref_lid_collection", "ref_lid_collection_secondary");
SearchRequest collectionReferencesRequest =
new SearchRequestFactory(RequestConstructionContextFactory.given(bundleLidvid.toString()),
Expand All @@ -70,27 +70,27 @@ static private List<String> getAllBundleCollectionLidVids(ControlContext ctrlCon
ctrlContext.getConnection().getRegistryIndex());

// Retrieve member collection LIDVIDs
List<String> results = new ArrayList<>();
List<PdsLidVid> results = new ArrayList<>();
for (final Map<String, Object> kvp : new HitIterator(ctrlContext.getConnection().getRestHighLevelClient(), collectionReferencesRequest)) {
collectionPropertyKeys.forEach(
key -> {
Object referencesRawObj = kvp.get(key);
if (referencesRawObj == null) return;

List<String> refStrings = (List<String>) referencesRawObj;
Set<String> lidvidReferences = refStrings.stream().filter(PdsProductIdentifier::stringIsLidvid).collect(Collectors.toSet());
Set<String> lidReferences = refStrings.stream().filter(PdsProductIdentifier::stringIsLid).collect(Collectors.toSet());
for (String lidRef : lidReferences) {
Set<PdsLidVid> collectionRefLidVids = refStrings.stream().filter(PdsProductIdentifier::stringIsLidvid).map(PdsLidVid::fromString).collect(Collectors.toSet());
Set<String> 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);
});
}

Expand All @@ -102,15 +102,14 @@ static private List<String> getAllBundleCollectionLidVids(ControlContext ctrlCon
public RequestAndResponseContext member(ControlContext ctrlContext, UserContext searchContext,
boolean twoSteps) throws ApplicationTypeException, IOException, LidVidNotFoundException, UnknownGroupNameException {

List<String> collectionLidvids = getAllBundleCollectionLidVids(ctrlContext, PdsLidVid.fromString(searchContext.getLidVid()));
GroupConstraint collectionMemberSelector = GroupConstraintImpl.buildAny(Map.of("_id", collectionLidvids));
List<PdsLidVid> collectionLidvids = getAllBundleCollectionLidVids(ctrlContext, PdsLidVid.fromString(searchContext.getProductIdentifierStr()));
List<String> 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<String> 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<String> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> targetProductAlternateIds = QuickSearch.getValues(control.getConnection(), false, parentCollectionLidvid, "alternate_ids");

private GroupConstraint getChildProductsConstraint(ControlContext control, PdsLidVid parentCollectionLidvid) throws IOException, LidVidNotFoundException {
List<String> 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);
}

Expand All @@ -68,7 +67,7 @@ public RequestAndResponseContext memberOf(ControlContext ctrlContext, UserContex
if (twoSteps)
throw new MembershipException(searchContext.getIdentifier().toString(), "member-of/member-of", "collections");

List<String> parentIdStrings = QuickSearch.getValues(ctrlContext.getConnection(), false, searchContext.getLidVid(), "ops:Provenance/ops:parent_bundle_identifier");
List<String> 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<String> parentLidvidStrings = parentIdStrings.stream().filter(PdsProductIdentifier::stringIsLidvid).collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -61,7 +53,7 @@ public RequestAndResponseContext memberOf(

List<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Unlimited implements LidvidsContext {
}

@Override
public String getLidVid() {
public String getProductIdentifierStr() {
return this.lidvid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Loading