PSFilterVisitor { public Component visit(String workspaceId, ProductStructureFilter pFilter, PartMaster pNodeFrom, Integer pStopAtDepth, PSFilterVisitorCallbacks callbacks) throws PartMasterNotFoundException, EntityConstraintException, NotAllowedException { init(workspaceId, pStopAtDepth, pFilter, callbacks); return visit(pNodeFrom, new ArrayList<PartLink>() {{ add(createVirtualRootLink(pNodeFrom)); }}, new ArrayList<PartMaster>() {{ add(pNodeFrom); }} ); }  Component visit(String workspaceId, ProductStructureFilter pFilter, PartMaster pNodeFrom, Integer pStopAtDepth, PSFilterVisitorCallbacks callbacks); Component visit(String workspaceId, ProductStructureFilter pFilter, List<PartLink> pStartingPath, Integer pStopAtDepth, PSFilterVisitorCallbacks callbacks); void stop();  }
@Test public void visitLatestCheckedInFilterTest() throws Exception { Component result = psFilterVisitor.visit(WORKSPACE_ID, new LatestCheckedInPSFilter(false), getPartMasterWith("PART-006"), -1, callbacks); assertNotNull(result); assertEquals("B",result.getRetainedIteration().getVersion()); assertEquals("PART-006",result.getPartMaster().getNumber()); assertEquals(3, result.getComponents().size()); assertEquals(1, result.getComponents().get(0).getComponents().size()); assertEquals("A",result.getComponents().get(0).getRetainedIteration().getPartVersion()); assertEquals("PART-012",result.getComponents().get(0).getPartMaster().getNumber()); assertEquals(3, result.getComponents().get(1).getComponents().size()); assertEquals("B",result.getComponents().get(1).getRetainedIteration().getPartVersion()); assertEquals("PART-002",result.getComponents().get(1).getPartMaster().getNumber()); assertEquals(0, result.getComponents().get(2).getComponents().size()); assertEquals("A",result.getComponents().get(2).getRetainedIteration().getPartVersion()); assertEquals("PART-004",result.getComponents().get(2).getPartMaster().getNumber()); assertEquals("E",getPartMasterWith("PART-001").getLastRevision().getVersion()); assertTrue(getPartMasterWith("PART-001").getLastRevision().isCheckedOut()); assertEquals(1,getPartMasterWith("PART-001").getLastRevision().getPartIterations().size()); try { psFilterVisitor.visit(WORKSPACE_ID, new LatestCheckedInPSFilter(false), getPartMasterWith("PART-001"), -1, callbacks); fail(); }catch (NotAllowedException e){ assertTrue(true); } addIterationTo("PART-001", getPartMasterWith("PART-001").getLastRevision().createNextIteration(user)); assertEquals("E",getPartMasterWith("PART-001").getLastRevision().getVersion()); assertTrue(getPartMasterWith("PART-001").getLastRevision().isCheckedOut()); assertEquals(2,getPartMasterWith("PART-001").getLastRevision().getPartIterations().size()); result = psFilterVisitor.visit(WORKSPACE_ID, new LatestCheckedInPSFilter(false), getPartMasterWith("PART-001"), -1, callbacks); assertNotNull(result); assertEquals(1, result.getRetainedIteration().getIteration()); }
@Test public void visitLatestReleasedFilterTest() throws Exception { try{ psFilterVisitor.visit(WORKSPACE_ID, new LatestReleasedPSFilter(false), getPartMasterWith(defaultPartsNumber_list[5]), -1, callbacks); Assert.fail(); }catch (NotAllowedException e){ Assert.assertTrue(true); } }
@Test public void visit_should_filter_serial_number_effectivity() throws EntityConstraintException, NotAllowedException, PartMasterNotFoundException { String workspaceId = "workspace01"; ConfigurationItem configurationItem = createConfigurationItem(workspaceId); ProductConfigSpec filter = new SerialNumberBasedEffectivityConfigSpec("2", configurationItem); PartMaster designItem = createPartMaster(configurationItem, "1", "A", true, ProductBaselineType.EFFECTIVE_SERIAL_NUMBER); visit(workspaceId, filter, designItem); Assert.assertNotNull(filter); Assert.assertNotNull(filter.getRetainedPartIterations()); Assert.assertEquals(filter.getRetainedPartIterations().size(), 2); }
@Test public void visit_should_filter_lot_effectivity() throws EntityConstraintException, NotAllowedException, PartMasterNotFoundException { String workspaceId = "workspace01"; ConfigurationItem configurationItem = createConfigurationItem(workspaceId); ProductConfigSpec filter = new LotBasedEffectivityConfigSpec("50", configurationItem); PartMaster designItem = createPartMaster(configurationItem, "1", "A", true, ProductBaselineType.EFFECTIVE_LOT_ID); visit(workspaceId, filter, designItem); Assert.assertNotNull(filter); Assert.assertNotNull(filter.getRetainedPartIterations()); Assert.assertEquals(filter.getRetainedPartIterations().size(), 2); }
@Test public void visit_should_filter_date_effectivity() throws EntityConstraintException, NotAllowedException, PartMasterNotFoundException { String workspaceId = "workspace01"; ConfigurationItem configurationItem = createConfigurationItem(workspaceId); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -2); ProductConfigSpec filter = new DateBasedEffectivityConfigSpec(calendar.getTime(), configurationItem); PartMaster designItem = createPartMaster(configurationItem, "1", "A", true, ProductBaselineType.EFFECTIVE_DATE); visit(workspaceId, filter, designItem); Assert.assertNotNull(filter); Assert.assertNotNull(filter.getRetainedPartIterations()); Assert.assertEquals(filter.getRetainedPartIterations().size(), 2); }
@Test(expected = NotAllowedException.class) public void visit_should_not_work_without_partrevision() throws EntityConstraintException, NotAllowedException, PartMasterNotFoundException { String workspaceId = "workspace01"; ConfigurationItem configurationItem = createConfigurationItem(workspaceId); ProductConfigSpec filter = new SerialNumberBasedEffectivityConfigSpec("2", configurationItem); User user = configurationItem.getAuthor(); Workspace workspace = configurationItem.getWorkspace(); PartMaster designItem = new PartMaster(workspace, "1", user); visit(workspaceId, filter, designItem); }
@Test(expected = NotAllowedException.class) public void visit_should_not_work_without_effective_partlink() throws EntityConstraintException, NotAllowedException, PartMasterNotFoundException { String workspaceId = "workspace01"; ConfigurationItem configurationItem = createConfigurationItem(workspaceId); ProductConfigSpec filter = new LotBasedEffectivityConfigSpec("50", configurationItem); PartMaster designItem = createPartMaster(configurationItem, "1", "A", false, ProductBaselineType.EFFECTIVE_LOT_ID); designItem.getPartRevisions().get(0).getPartIterations().get(0).setComponents(new ArrayList<PartUsageLink>() {{ PartUsageLink partUsageLink = createPartUsageLinkWithoutEffectivity(configurationItem); add(partUsageLink); }}); visit(workspaceId, filter, designItem); }
@Test(expected = NotAllowedException.class) public void visit_should_not_work_without_effectivity() throws EntityConstraintException, NotAllowedException, PartMasterNotFoundException { String workspaceId = "workspace01"; ConfigurationItem configurationItem = createConfigurationItem(workspaceId); ProductConfigSpec filter = new SerialNumberBasedEffectivityConfigSpec("2", configurationItem); User user = configurationItem.getAuthor(); Workspace workspace = configurationItem.getWorkspace(); PartMaster designItem = new PartMaster(workspace, "1", user); PartRevision partRevision = new PartRevision(designItem, "A", configurationItem.getAuthor()); partRevision.setStatus(RevisionStatus.RELEASED); designItem.setPartRevisions(new ArrayList<PartRevision>() {{ add(partRevision); }}); visit(workspaceId, filter, designItem); }
@Test public void visit_should_return_last_effective_part_revision() throws EntityConstraintException, NotAllowedException, PartMasterNotFoundException { String workspaceId = "workspace01"; ConfigurationItem configurationItem = createConfigurationItem(workspaceId); ProductConfigSpec filter = new LotBasedEffectivityConfigSpec("50", configurationItem); User user = configurationItem.getAuthor(); Workspace workspace = configurationItem.getWorkspace(); PartMaster designItem = new PartMaster(workspace, "1", user); designItem.setPartRevisions(new ArrayList<PartRevision>() {{ add(createPartRevision(configurationItem, designItem, "1", "A", false, ProductBaselineType.EFFECTIVE_LOT_ID)); add(createPartRevision(configurationItem, designItem, "99", "D", false, ProductBaselineType.EFFECTIVE_LOT_ID)); }}); visit(workspaceId, filter, designItem); Assert.assertNotNull(filter); Assert.assertNotNull(filter.getRetainedPartIterations()); Assert.assertEquals(filter.getRetainedPartIterations().size(), 1); Assert.assertEquals(filter.getRetainedPartIterations() .stream() .filter(partIteration -> partIteration.getPartVersion().equals("D")) .count(), 1); ProductConfigSpec filter2 = new LotBasedEffectivityConfigSpec("50", configurationItem); PartMaster designItem2 = new PartMaster(workspace, "1", user); designItem2.setPartRevisions(new ArrayList<PartRevision>() {{ add(createPartRevision(configurationItem, designItem, "99", "D", false, ProductBaselineType.EFFECTIVE_LOT_ID)); add(createPartRevision(configurationItem, designItem, "1", "A", false, ProductBaselineType.EFFECTIVE_LOT_ID)); }}); visit(workspaceId, filter2, designItem2); Assert.assertNotNull(filter2); Assert.assertNotNull(filter2.getRetainedPartIterations()); Assert.assertEquals(filter2.getRetainedPartIterations().size(), 1); Assert.assertEquals(filter2.getRetainedPartIterations() .stream() .filter(partIteration -> partIteration.getPartVersion().equals("A")) .count(), 1); }