Skip to content

Commit

Permalink
Merge pull request #243 from NASA-PDS/fix-outstanding-comments
Browse files Browse the repository at this point in the history
Fix outstanding comments
  • Loading branch information
alexdunnjpl authored Feb 1, 2023
2 parents 39b37a5 + 341e31b commit 440bfea
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 26 deletions.
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

0 comments on commit 440bfea

Please sign in to comment.