ResolvedCollectionConfigSpec extends ProductConfigSpec { @Override public PartLink filterPartLink(List<PartLink> path) { PartLink nominalLink = path.get(path.size()-1); if(nominalLink.isOptional() && !optionalUsageLinks.contains(Tools.getPathAsString(path))){ return null; } for(PartSubstituteLink substituteLink:nominalLink.getSubstitutes()){ List<PartLink> substitutePath = new ArrayList<>(path); substitutePath.set(substitutePath.size()-1,substituteLink); if(substitutesUsageLinks.contains(Tools.getPathAsString(substitutePath))){ return substituteLink; } } return nominalLink; } ResolvedCollectionConfigSpec(@NotNull ResolvedCollection resolvedCollection); @Override PartIteration filterPartIteration(PartMaster part); @Override PartLink filterPartLink(List<PartLink> path);  }
@Test public void filterPartLinkTest(){ PartMaster partMaster = getPartMasterWith("PART-001"); List<PartLink> links = new ArrayList<>((partMaster.getLastRevision().getLastIteration().getComponents())); PartLink result = r2CS.filterPartLink(links); assertNull(result); productBaseline.addOptionalUsageLink("u0-u0-u0-u0-u0"); r2CS = new ResolvedCollectionConfigSpec(productBaseline); result = r2CS.filterPartLink(links); assertNotNull(result); assertEquals(links.get(links.size()-1), result); productBaseline.addSubstituteLink("u0-u0-u0-u0-s0"); r2CS = new ResolvedCollectionConfigSpec(productBaseline); result = r2CS.filterPartLink(links); assertNotNull(result); assertEquals("PART-018-Substitute", result.getReferenceDescription()); }