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

Fix outstanding comments #243

Merged
merged 3 commits into from
Feb 1, 2023
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 @@ -122,7 +122,7 @@ public URIParameters setLimit(Integer limit)
}
public URIParameters setProductIdentifier(ControlContext control) throws IOException, LidVidNotFoundException
{
this.productIdentifier = LidVidUtils.resolve(this.getIdentifier(), ProductVersionSelector.SPECIFIC,
this.productIdentifier = LidVidUtils.resolve(this.getIdentifier(), ProductVersionSelector.TYPED,
control, RequestBuildContextFactory.empty());
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package gov.nasa.pds.api.registry.model;

/**
* Used by API calls, such as "/bundles/{lidvid}/collections",
* "/bundles/{lidvid}/collections/latest",
* "/bundles/{lidvid}/collections/all", etc.,
* Used by API calls, such as "/bundles/{lidvid}/collections",
* "/bundles/{lidvid}/collections/latest",
* "/bundles/{lidvid}/collections/all", etc.,
* to select product versions.
*
*
* @author karpenko
*/
public enum ProductVersionSelector
Expand All @@ -17,13 +17,13 @@ public enum ProductVersionSelector
/**
* All versions of a product
*/
ALL,
ALL,
/**
* Latest version of a product
*/
LATEST,
/**
* A specified version of a product
*/
SPECIFIC
TYPED
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private boolean isGrandchild (ReferencingLogicTransmuter idType)
private ReferencingLogicTransmuter resolveID (ControlContext context, UserContext input)
throws IOException, LidVidNotFoundException, UnknownGroupNameException
{
PdsProductIdentifier productIdentifier = LidVidUtils.resolve(input.getIdentifier(), ProductVersionSelector.SPECIFIC, context, RequestBuildContextFactory.empty());
PdsProductIdentifier productIdentifier = LidVidUtils.resolve(input.getIdentifier(), ProductVersionSelector.TYPED, context, RequestBuildContextFactory.empty());
return ReferencingLogicTransmuter.getByProductClass(
QuickSearch.getValue(context.getConnection(), input.getSelector() == ProductVersionSelector.LATEST,
productIdentifier != null ? productIdentifier.toString() : "", "product_class"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,17 @@ static private Pagination<String> getBundleCollectionLidVids(

// Get the latest versions of LIDs
List<PdsProductIdentifier> productIdentifiers = lidStrings.stream().map(PdsProductIdentifier::fromString).collect(Collectors.toList());
List<PdsLidVid> latestLidVids = LidVidUtils.getLatestLidVidsForProductIdentifiers(
ctlContext,
RequestBuildContextFactory.given(true, "lid", ReferencingLogicTransmuter.Collection.impl().constraints()),
productIdentifiers);
List<String> latestLidVidStrings = latestLidVids.stream().map(PdsLidVid::toString).collect(Collectors.toList());
lidvids.addAll(latestLidVidStrings);
try {
List<PdsLidVid> latestLidVids = LidVidUtils.getLatestLidVidsForProductIdentifiers(
ctlContext,
RequestBuildContextFactory.given(true, "lid", ReferencingLogicTransmuter.Collection.impl().constraints()),
productIdentifiers);
List<String> latestLidVidStrings = latestLidVids.stream().map(PdsLidVid::toString).collect(Collectors.toList());
lidvids.addAll(latestLidVidStrings);
} catch (LidVidNotFoundException e) {
log.error("Database referential integrity error - LID is referenced but does not exist in db: " + e.toString());
}

return lidvids;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,13 @@ static Pagination<String> parents (ControlContext control, ProductVersionSelecto
bundleLidvids.addAll(LidVidUtils.getAllLidVidsByLids(control, RequestBuildContextFactory.empty(), sortedLidStrings));
}
else {
List<PdsLidVid> latestLidvids = LidVidUtils.getLatestLidVidsForProductIdentifiers(control, RequestBuildContextFactory.empty(), sortedLids);
List<String> latestLidVidStrings = latestLidvids.stream().map(PdsLidVid::toString).collect(Collectors.toList());
bundleLidvids.addAll(latestLidVidStrings);
try {
List<PdsLidVid> latestLidvids = LidVidUtils.getLatestLidVidsForProductIdentifiers(control, RequestBuildContextFactory.empty(), sortedLids);
List<String> latestLidVidStrings = latestLidvids.stream().map(PdsLidVid::toString).collect(Collectors.toList());
bundleLidvids.addAll(latestLidVidStrings);
} catch (LidVidNotFoundException e) {
log.error("Database referential integrity error - LID is referenced but does not exist in db: " + e.toString());
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ static Pagination<String> parents (ControlContext control, ProductVersionSelecto
parents.addAll (LidVidUtils.getAllLidVidsByLids(control, RequestBuildContextFactory.empty(), sortedLidStrings));
}
else{
List<PdsLidVid> latestLidVids = LidVidUtils.getLatestLidVidsForProductIdentifiers(control, RequestBuildContextFactory.empty(), sortedLids);
List<String> latestLidVidStrings = latestLidVids.stream().map(PdsLidVid::toString).collect(Collectors.toList());
parents.addAll(latestLidVidStrings);
try{
List<PdsLidVid> latestLidVids = LidVidUtils.getLatestLidVidsForProductIdentifiers(control, RequestBuildContextFactory.empty(), sortedLids);
List<String> latestLidVidStrings = latestLidVids.stream().map(PdsLidVid::toString).collect(Collectors.toList());
parents.addAll(latestLidVidStrings);
} catch (LidVidNotFoundException e) {
log.error("Database referential integrity error - LID is referenced but does not exist in db: " + e.toString());
}
}

return parents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private RequestAndResponseContext(
GroupConstraint outPreset, GroupConstraint resPreset // criteria for defining last node (outPreset) and first node (resOutput) for any endpoint
) throws ApplicationTypeException,LidVidNotFoundException,IOException
{
ProductVersionSelector versionSelectionScope = outPreset.equals(resPreset) ? parameters.getSelector() : ProductVersionSelector.SPECIFIC;
ProductVersionSelector versionSelectionScope = outPreset.equals(resPreset) ? parameters.getSelector() : ProductVersionSelector.TYPED;

Map<String, ProductBusinessLogic> formatters = new HashMap<String, ProductBusinessLogic>();
formatters.put("*/*", new PdsProductBusinessObject());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import gov.nasa.pds.api.registry.model.ProductVersionSelector;
import gov.nasa.pds.api.registry.model.ReferencingLogicTransmuter;
Expand Down Expand Up @@ -52,7 +51,7 @@ public static List<PdsLidVid> getLatestLidVidsForProductIdentifiers(
PdsLidVid latestLidVid = LidVidUtils.getLatestLidVidByLid(ctlContext, reqContext, id.getLid().toString());
lidVids.add(latestLidVid);
} catch (LidVidNotFoundException e) {
log.error("Database is corrupted. Have reference to LID but cannot find it: " + id.getLid().toString());
throw new LidVidNotFoundException("Could not find any LIDVIDs for LID " + id.getLid().toString());
}
}

Expand Down Expand Up @@ -109,12 +108,12 @@ public static List<String> getAllLidVidsByLids(
}

public static PdsProductIdentifier resolve (
String _identifier,
String productIdentifierString,
ProductVersionSelector scope,
ControlContext ctlContext,
RequestBuildContext reqContext) throws IOException, LidVidNotFoundException
{
PdsProductIdentifier productIdentifier = PdsProductIdentifier.fromString(_identifier);
PdsProductIdentifier productIdentifier = PdsProductIdentifier.fromString(productIdentifierString);
PdsProductIdentifier result = null;

if (productIdentifier != null)
Expand All @@ -132,7 +131,7 @@ public static PdsProductIdentifier resolve (
// to force that kind of resolution.
result = productIdentifier instanceof PdsLidVid ? productIdentifier : LidVidUtils.getLatestLidVidByLid(ctlContext, reqContext, productIdentifier.getLid().toString());
break;
case SPECIFIC:
case TYPED:
result = productIdentifier instanceof PdsLidVid ? productIdentifier : LidVidUtils.getLatestLidVidByLid(ctlContext, reqContext, productIdentifier.getLid().toString());
break;
case ORIGINAL: throw new LidVidNotFoundException("ProductVersionSelector.ORIGINAL not supported");
Expand Down