diff --git a/pom.xml b/pom.xml index f4dc7ffe..1c5cc3d3 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. @@ -225,7 +225,7 @@ Go through this file line-by-line and replace the template values with your own. jar test-jar - + 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 23e209fa..78e9f4e2 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 @@ -15,6 +15,7 @@ import gov.nasa.pds.api.registry.exceptions.UnknownGroupNameException; import gov.nasa.pds.api.registry.model.ReferencingLogicTransmuter; import gov.nasa.pds.api.registry.model.RequestAndResponseContext; +import gov.nasa.pds.api.registry.search.QuickSearch; class Member implements EndpointHandler { @@ -30,7 +31,11 @@ public ResponseEntity transmute(ControlContext control, UserContext cont throws ApplicationTypeException, IOException, LidVidNotFoundException, MembershipException, NothingFoundException, UnknownGroupNameException { - ReferencingLogic transmuter = ReferencingLogicTransmuter.getBySwaggerGroup(content.getGroup()).impl(); + ReferencingLogic transmuter; + + if (0 < content.getGroup().length()) transmuter = ReferencingLogicTransmuter.getBySwaggerGroup(content.getGroup()).impl(); + else transmuter = ReferencingLogicTransmuter.getByProductClass(QuickSearch.getValue(control.getConnection(), false, content.getLidVid(), "product_class")).impl(); + RequestAndResponseContext context = this.offspring ? transmuter.member(control, content, this.twoSteps) : transmuter.memberOf(control, content, this.twoSteps); return new ResponseEntity(context.getResponse(), HttpStatus.OK); 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 18b5952f..98aae625 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 @@ -10,6 +10,7 @@ import java.util.TreeSet; import java.util.stream.Collectors; +import gov.nasa.pds.api.registry.RequestBuildContext; import gov.nasa.pds.api.registry.model.identifiers.LidVidUtils; import gov.nasa.pds.api.registry.model.identifiers.PdsLidVid; import gov.nasa.pds.api.registry.model.identifiers.PdsProductIdentifier; @@ -161,15 +162,14 @@ static private Pagination getBundleCollectionLidVids( // Get the latest versions of LIDs List productIdentifiers = lidStrings.stream().map(PdsProductIdentifier::fromString).collect(Collectors.toList()); - 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()); + RequestBuildContext reqContext = RequestBuildContextFactory.given(true, "lid", ReferencingLogicTransmuter.Collection.impl().constraints()); + for (PdsProductIdentifier id : productIdentifiers) { + try { + PdsLidVid latestLidVid = LidVidUtils.getLatestLidVidByLid(ctlContext, reqContext, id.getLid().toString()); + lidvids.add(latestLidVid.toString()); + } catch (LidVidNotFoundException e) { + log.warn("LID is referenced but is in non-findable archive-status or 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 5716c0d6..86088b18 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 @@ -120,19 +120,20 @@ static Pagination parents (ControlContext control, ProductVersionSelecto } } sortedLidStrings = new ArrayList(lids); - Collections.sort(sortedLidStrings); // TODO: Implement comparison for PdsLids (only with other PdsLids) - List sortedLids = sortedLidStrings.stream().map(PdsLid::fromString).collect(Collectors.toList()); + Collections.sort(sortedLidStrings); // TODO: Implement comparison for PdsLids (only with other PdsLids) + List sortedLids = sortedLidStrings.stream().map(PdsLid::fromString).collect(Collectors.toList()); - if (selection == ProductVersionSelector.ALL){ + if (selection == ProductVersionSelector.ALL) { bundleLidvids.addAll(LidVidUtils.getAllLidVidsByLids(control, RequestBuildContextFactory.empty(), sortedLidStrings)); - } - else { - 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()); + } else { + RequestBuildContext reqContext = RequestBuildContextFactory.empty(); + for (PdsProductIdentifier lid : sortedLids) { + try { + PdsLidVid latestLidvid = LidVidUtils.getLatestLidVidByLid(control, reqContext, lid.getLid().toString()); + bundleLidvids.add(latestLidvid.toString()); + } catch (LidVidNotFoundException e) { + log.warn("LID is referenced but is in non-findable archive-status or 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 0c4d1a17..52e41792 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 @@ -11,6 +11,7 @@ import java.util.Set; import java.util.stream.Collectors; +import gov.nasa.pds.api.registry.RequestBuildContext; 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; @@ -77,20 +78,20 @@ static Pagination parents (ControlContext control, ProductVersionSelecto Collections.sort(sortedLidStrings); List sortedLids = sortedLidStrings.stream().map(PdsLid::fromString).collect(Collectors.toList()); - if (selection == ProductVersionSelector.ALL){ - parents.addAll (LidVidUtils.getAllLidVidsByLids(control, RequestBuildContextFactory.empty(), sortedLidStrings)); - } - else{ - 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()); + if (selection == ProductVersionSelector.ALL) { + parents.addAll(LidVidUtils.getAllLidVidsByLids(control, RequestBuildContextFactory.empty(), sortedLidStrings)); + } else { + RequestBuildContext reqContext = RequestBuildContextFactory.empty(); + for (PdsProductIdentifier id : sortedLids) { + try { + PdsLidVid latestLidvid = LidVidUtils.getLatestLidVidByLid(control, reqContext, id.getLid().toString()); + parents.add(latestLidvid.toString()); + } catch (LidVidNotFoundException e) { + log.warn("LID is referenced but is in non-findable archive-status or does not exist in db: " + e.toString()); + } } } - return parents; - } - + return parents; + } } 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 3c5d03ad..12bf792d 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 @@ -36,28 +36,6 @@ public class LidVidUtils { private static final Logger log = LoggerFactory.getLogger(LidVidUtils.class); - /** - * Get latest versions of LIDs - */ - public static List getLatestLidVidsForProductIdentifiers( - ControlContext ctlContext, - RequestBuildContext reqContext, - Collection productIdentifiers) throws IOException,LidVidNotFoundException - { - List lidVids = new ArrayList<>(); - - for (PdsProductIdentifier id : productIdentifiers) { - try { - PdsLidVid latestLidVid = LidVidUtils.getLatestLidVidByLid(ctlContext, reqContext, id.getLid().toString()); - lidVids.add(latestLidVid); - } catch (LidVidNotFoundException e) { - throw new LidVidNotFoundException("Could not find any LIDVIDs for LID " + id.getLid().toString()); - } - } - - return lidVids; - } - public static PdsLidVid getLatestLidVidByLid( ControlContext ctlContext, RequestBuildContext reqContext,