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 7c4cd9bb..6897429f 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 @@ -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; } diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/ProductVersionSelector.java b/service/src/main/java/gov/nasa/pds/api/registry/model/ProductVersionSelector.java index fed4730a..daa49ca6 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/ProductVersionSelector.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/ProductVersionSelector.java @@ -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 @@ -17,7 +17,7 @@ public enum ProductVersionSelector /** * All versions of a product */ - ALL, + ALL, /** * Latest version of a product */ @@ -25,5 +25,5 @@ public enum ProductVersionSelector /** * A specified version of a product */ - SPECIFIC + TYPED } diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicAny.java b/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicAny.java index 8e3d791a..adf518f3 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicAny.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicAny.java @@ -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")); 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 afd7ccbd..18b5952f 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 @@ -161,12 +161,17 @@ static private Pagination getBundleCollectionLidVids( // Get the latest versions of LIDs List productIdentifiers = lidStrings.stream().map(PdsProductIdentifier::fromString).collect(Collectors.toList()); - List latestLidVids = LidVidUtils.getLatestLidVidsForProductIdentifiers( - ctlContext, - RequestBuildContextFactory.given(true, "lid", ReferencingLogicTransmuter.Collection.impl().constraints()), - productIdentifiers); - List latestLidVidStrings = latestLidVids.stream().map(PdsLidVid::toString).collect(Collectors.toList()); - lidvids.addAll(latestLidVidStrings); + try { + List latestLidVids = LidVidUtils.getLatestLidVidsForProductIdentifiers( + ctlContext, + RequestBuildContextFactory.given(true, "lid", ReferencingLogicTransmuter.Collection.impl().constraints()), + productIdentifiers); + List 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; } 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 df68314b..006de780 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 @@ -114,9 +114,13 @@ static Pagination parents (ControlContext control, ProductVersionSelecto bundleLidvids.addAll(LidVidUtils.getAllLidVidsByLids(control, RequestBuildContextFactory.empty(), sortedLidStrings)); } else { - List latestLidvids = LidVidUtils.getLatestLidVidsForProductIdentifiers(control, RequestBuildContextFactory.empty(), sortedLids); - List latestLidVidStrings = latestLidvids.stream().map(PdsLidVid::toString).collect(Collectors.toList()); - bundleLidvids.addAll(latestLidVidStrings); + try { + List latestLidvids = LidVidUtils.getLatestLidVidsForProductIdentifiers(control, RequestBuildContextFactory.empty(), sortedLids); + List 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()); + } } diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicProduct.java b/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicProduct.java index 69a8eded..0c4d1a17 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicProduct.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/RefLogicProduct.java @@ -81,9 +81,13 @@ static Pagination parents (ControlContext control, ProductVersionSelecto parents.addAll (LidVidUtils.getAllLidVidsByLids(control, RequestBuildContextFactory.empty(), sortedLidStrings)); } else{ - List latestLidVids = LidVidUtils.getLatestLidVidsForProductIdentifiers(control, RequestBuildContextFactory.empty(), sortedLids); - List latestLidVidStrings = latestLidVids.stream().map(PdsLidVid::toString).collect(Collectors.toList()); - parents.addAll(latestLidVidStrings); + try{ + List latestLidVids = LidVidUtils.getLatestLidVidsForProductIdentifiers(control, RequestBuildContextFactory.empty(), sortedLids); + List 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; diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/RequestAndResponseContext.java b/service/src/main/java/gov/nasa/pds/api/registry/model/RequestAndResponseContext.java index 2f2e45d7..e6e7fb09 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/RequestAndResponseContext.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/RequestAndResponseContext.java @@ -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 formatters = new HashMap(); formatters.put("*/*", new PdsProductBusinessObject()); 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 68ad5610..3c5d03ad 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 @@ -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; @@ -52,7 +51,7 @@ public static List 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()); } } @@ -109,12 +108,12 @@ public static List 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) @@ -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");