ProductBaselineManagerBean implements IProductBaselineManagerLocal { @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override public ProductBaseline createBaseline(ConfigurationItemKey ciKey, String name, ProductBaselineType pType, String description, List<PartIterationKey> partIterationKeys, List<String> substituteLinks, List<String> optionalUsageLinks, Date effectiveDate, String effectiveSerialNumber, String effectiveLotId, boolean dryRun) throws UserNotFoundException, AccessRightException, WorkspaceNotFoundException, ConfigurationItemNotFoundException, NotAllowedException, EntityConstraintException, PartMasterNotFoundException, CreationException, BaselineNotFoundException, PathToPathLinkAlreadyExistsException, WorkspaceNotEnabledException { String workspaceId = ciKey.getWorkspace(); User user = userManager.checkWorkspaceWriteAccess(workspaceId); if (null == name || name.isEmpty()) { throw new NotAllowedException("NotAllowedException61"); } ConfigurationItem configurationItem = configurationItemDAO.loadConfigurationItem(ciKey); List<String> visitedPaths = new ArrayList<>(); ProductConfigSpec filter; switch(pType){ case EFFECTIVE_DATE: filter = new DateBasedEffectivityConfigSpec(effectiveDate, configurationItem); break; case EFFECTIVE_SERIAL_NUMBER: filter = new SerialNumberBasedEffectivityConfigSpec(effectiveSerialNumber, configurationItem); break; case EFFECTIVE_LOT_ID: filter = new LotBasedEffectivityConfigSpec(effectiveLotId, configurationItem); break; case LATEST: case RELEASED: default: List<PartIteration> partIterations = partIterationKeys.stream() .map(piKey -> em.find(PartIteration.class, piKey)) .filter(Objects::nonNull) .collect(Collectors.toList()); filter = new ProductBaselineCreationConfigSpec(pType, partIterations, substituteLinks, optionalUsageLinks); break; } psFilterVisitor.visit(workspaceId, filter, configurationItem.getDesignItem(), -1, new PSFilterVisitorCallbacks() { @Override public void onIndeterminateVersion(PartMaster partMaster, List<PartIteration> partIterations) throws NotAllowedException { throw new NotAllowedException("NotAllowedException48"); } @Override public void onUnresolvedVersion(PartMaster partMaster) throws NotAllowedException { throw new NotAllowedException("NotAllowedException49", partMaster.getNumber()); } @Override public void onIndeterminatePath(List<PartLink> pCurrentPath, List<PartIteration> pCurrentPathPartIterations) throws NotAllowedException { throw new NotAllowedException("NotAllowedException50"); } @Override public void onUnresolvedPath(List<PartLink> pCurrentPath, List<PartIteration> partIterations) throws NotAllowedException { throw new NotAllowedException("NotAllowedException51"); } @Override public boolean onPathWalk(List<PartLink> path, List<PartMaster> parts) { String encodedPath = Tools.getPathAsString(path); visitedPaths.add(encodedPath); return true; } }); ProductBaseline baseline = new ProductBaseline(user, configurationItem, name, pType, description); DocumentCollection documentCollection = baseline.getDocumentCollection(); PartCollection partCollection = baseline.getPartCollection(); if(!dryRun) { partCollectionDAO.createPartCollection(partCollection); documentCollectionDAO.createDocumentCollection(documentCollection); } partCollection.setCreationDate(new Date()); partCollection.setAuthor(user); documentCollection.setCreationDate(new Date()); documentCollection.setAuthor(user); for (PartIteration partIteration : filter.getRetainedPartIterations()) { baseline.addBaselinedPart(partIteration); for (DocumentLink docLink : partIteration.getLinkedDocuments()) { DocumentIteration docI = docLink.getTargetDocument().getLastCheckedInIteration(); if (docI != null) baseline.addBaselinedDocument(docI); } } baseline.getSubstituteLinks().addAll(filter.getRetainedSubstituteLinks()); baseline.getOptionalUsageLinks().addAll(filter.getRetainedOptionalUsageLinks()); if(!dryRun) { productBaselineDAO.createBaseline(baseline); } List<PathToPathLink> links = pathToPathLinkDAO.getPathToPathLinkFromPathList(configurationItem, visitedPaths); for (PathToPathLink link : links) { PathToPathLink clone = link.clone(); if(!dryRun) { pathToPathLinkDAO.createPathToPathLink(clone); } baseline.addPathToPathLink(clone); } return baseline; }  @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override ProductBaseline createBaseline(ConfigurationItemKey ciKey, String name, ProductBaselineType pType,
                                          String description, List<PartIterationKey> partIterationKeys,
                                          List<String> substituteLinks, List<String> optionalUsageLinks,
                                          Date effectiveDate, String effectiveSerialNumber, String effectiveLotId,
                                          boolean dryRun); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override List<ProductBaseline> getAllBaselines(String workspaceId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override List<ProductBaseline> getBaselines(ConfigurationItemKey configurationItemKey); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void deleteBaseline(String pWorkspaceId, int baselineId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override ProductBaseline getBaseline(int baselineId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override ProductBaseline getBaselineById(int baselineId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override List<BaselinedPart> getBaselinedPartWithReference(int baselineId, String q, int maxResults); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override List<PathChoice> getBaselineCreationPathChoices(ConfigurationItemKey ciKey, ProductBaselineType type); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override List<PartIteration> getBaselineCreationVersionsChoices(ConfigurationItemKey ciKey); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override ProductConfiguration createProductConfiguration(ConfigurationItemKey ciKey, String name, String description, List<String> substituteLinks, List<String> optionalUsageLinks, Map<String, String> aclUserEntries, Map<String, String> aclUserGroupEntries); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override List<ProductConfiguration> getAllProductConfigurations(String workspaceId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override List<ProductConfiguration> getAllProductConfigurationsByConfigurationItemId(ConfigurationItemKey ciKey); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override ProductConfiguration getProductConfiguration(ConfigurationItemKey ciKey, int productConfigurationId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override ProductConfiguration updateProductConfiguration(ConfigurationItemKey ciKey, int productConfigurationId, String name, String description, List<String> substituteLinks, List<String> optionalUsageLinks); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void deleteProductConfiguration(ConfigurationItemKey ciKey, int productConfigurationId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void updateACLForConfiguration(ConfigurationItemKey ciKey, int productConfigurationId, Map<String, String> userEntries, Map<String, String> groupEntries); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void removeACLFromConfiguration(ConfigurationItemKey ciKey, int productConfigurationId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override List<PartRevision> getObsoletePartRevisionsInBaseline(String workspaceId, int baselineId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override List<PathToPathLink> getPathToPathLinkFromSourceAndTarget(String workspaceId, String configurationItemId, int baselineId, String sourcePath, String targetPath); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override List<String> getPathToPathLinkTypes(String workspaceId, String configurationItemId, int baselineId);  }
@Test public void createReleasedBaseline() throws UserNotFoundException, AccessRightException, WorkspaceNotFoundException, ConfigurationItemNotFoundException, NotAllowedException, UserNotActiveException, PartIterationNotFoundException, PartRevisionNotReleasedException, EntityConstraintException, PartMasterNotFoundException, CreationException, BaselineNotFoundException, PathToPathLinkAlreadyExistsException, WorkspaceNotEnabledException { baselineRuleReleased = new BaselineRule("myBaseline", ProductBaselineType.RELEASED, "description", "workspace01", "user1", "part01", "product01", true); doReturn(new User()).when(userManager).checkWorkspaceWriteAccess(Matchers.anyString()); Mockito.when(userManager.checkWorkspaceWriteAccess(Matchers.anyString())).thenReturn(baselineRuleReleased.getUser()); Mockito.when(productService.getRootPartUsageLink(Matchers.any())).thenReturn(baselineRuleReleased.getRootPartUsageLink()); Mockito.when(mockedQuery.setParameter(Matchers.anyString(), Matchers.any())).thenReturn(mockedQuery); ConfigurationItem configurationItem = new ConfigurationItem(baselineRuleReleased.getUser(), baselineRuleReleased.getWorkspace(), baselineRuleReleased.getConfigurationItemKey().getId(), "description"); configurationItem.setDesignItem(baselineRuleReleased.getPartMaster()); Mockito.when(configurationItemDAO.loadConfigurationItem(baselineRuleReleased.getConfigurationItemKey())).thenReturn(configurationItem); ProductBaseline baseline = productBaselineService.createBaseline(baselineRuleReleased.getConfigurationItemKey(), baselineRuleReleased.getName(), baselineRuleReleased.getType(), baselineRuleReleased.getDescription(), new ArrayList<>(), baselineRuleReleased.getSubstituteLinks(), baselineRuleReleased.getOptionalUsageLinks(), null, null, null, false); Assert.assertNotNull(baseline); Assert.assertEquals(baseline.getDescription(), baselineRuleReleased.getDescription()); Assert.assertEquals(baseline.getType(), baselineRuleReleased.getType()); Assert.assertEquals(baseline.getConfigurationItem().getWorkspaceId(), baselineRuleReleased.getWorkspace().getId()); }
@Test(expected = NotAllowedException.class) public void createReleasedBaselineUsingPartNotReleased() throws Exception{ baselineRuleNotReleased = new BaselineRule("myBaseline", ProductBaselineType.RELEASED, "description", "workspace01", "user1", "part01", "product01", false); doReturn(new User()).when(userManager).checkWorkspaceWriteAccess(Matchers.anyString()); Mockito.when(userManager.checkWorkspaceWriteAccess(Matchers.anyString())).thenReturn(baselineRuleNotReleased.getUser()); ConfigurationItem configurationItem = new ConfigurationItem(baselineRuleNotReleased.getUser(), baselineRuleNotReleased.getWorkspace(), baselineRuleNotReleased.getConfigurationItemKey().getId(), "description"); configurationItem.setDesignItem(baselineRuleNotReleased.getPartMaster()); Mockito.doThrow(NotAllowedException.class).when(psFilterVisitor).visit(any(), any(), any(PartMaster.class), anyInt(), any()); Mockito.when(configurationItemDAO.loadConfigurationItem(baselineRuleNotReleased.getConfigurationItemKey())).thenReturn(configurationItem); productBaselineService.createBaseline(baselineRuleNotReleased.getConfigurationItemKey(), baselineRuleNotReleased.getName(), baselineRuleNotReleased.getType(), baselineRuleNotReleased.getDescription(),new ArrayList<>(), baselineRuleNotReleased.getSubstituteLinks(), baselineRuleNotReleased.getOptionalUsageLinks(), null, null, null, false); }
@Test public void createLatestBaseline() throws UserNotFoundException, AccessRightException, WorkspaceNotFoundException, ConfigurationItemNotFoundException, EntityConstraintException, UserNotActiveException, NotAllowedException, PartIterationNotFoundException, PartRevisionNotReleasedException, PartMasterNotFoundException, CreationException, BaselineNotFoundException, PathToPathLinkAlreadyExistsException, WorkspaceNotEnabledException { baselineRuleLatest = new BaselineRule("myBaseline", ProductBaselineType.LATEST, "description", "workspace01", "user1", "part01", "product01", true); doReturn(new User()).when(userManager).checkWorkspaceWriteAccess(Matchers.anyString()); Mockito.when(userManager.checkWorkspaceWriteAccess(Matchers.anyString())).thenReturn(baselineRuleLatest.getUser()); Mockito.when(productService.getRootPartUsageLink(Matchers.any())).thenReturn(baselineRuleLatest.getRootPartUsageLink()); Mockito.when(mockedQuery.setParameter(Matchers.anyString(), Matchers.any())).thenReturn(mockedQuery); ConfigurationItem configurationItem = new ConfigurationItem(baselineRuleLatest.getUser(), baselineRuleLatest.getWorkspace(), baselineRuleLatest.getConfigurationItemKey().getId(), "description"); configurationItem.setDesignItem(baselineRuleLatest.getPartMaster()); Mockito.when(configurationItemDAO.loadConfigurationItem(baselineRuleLatest.getConfigurationItemKey())).thenReturn(configurationItem); ProductBaseline baseline = productBaselineService.createBaseline(baselineRuleLatest.getConfigurationItemKey(), baselineRuleLatest.getName(), baselineRuleLatest.getType(), baselineRuleLatest.getDescription(), new ArrayList<>(), baselineRuleLatest.getSubstituteLinks(), baselineRuleLatest.getOptionalUsageLinks(), null, null, null, false); Assert.assertNotNull(baseline); Assert.assertEquals(baseline.getDescription(), baselineRuleLatest.getDescription()); Assert.assertEquals(baseline.getType(), baselineRuleLatest.getType()); Assert.assertEquals(baseline.getConfigurationItem().getWorkspaceId(), baselineRuleLatest.getWorkspace().getId()); }
@Test public void createLatestBaselineWithCheckedPart() throws UserNotFoundException, AccessRightException, WorkspaceNotFoundException, ConfigurationItemNotFoundException, NotAllowedException, UserNotActiveException, PartIterationNotFoundException, PartRevisionNotReleasedException, EntityConstraintException, PartMasterNotFoundException, CreationException, BaselineNotFoundException, PathToPathLinkAlreadyExistsException, WorkspaceNotEnabledException { baselineRuleReleased = new BaselineRule("myBaseline", ProductBaselineType.LATEST , "description", "workspace01", "user1", "part01", "product01", true, false); doReturn(new User()).when(userManager).checkWorkspaceWriteAccess(Matchers.anyString()); Mockito.when(userManager.checkWorkspaceWriteAccess(Matchers.anyString())).thenReturn(baselineRuleReleased.getUser()); Mockito.when(partIterationDAO.loadPartI(baselineRuleReleased.getPartMaster().getLastReleasedRevision().getIteration(1).getKey())).thenReturn(baselineRuleReleased.getPartMaster().getLastReleasedRevision().getIteration(1)); Mockito.when(productService.getRootPartUsageLink(Matchers.any())).thenReturn(baselineRuleReleased.getRootPartUsageLink()); Mockito.when(mockedQuery.setParameter(Matchers.anyString(), Matchers.any())).thenReturn(mockedQuery); ConfigurationItem configurationItem = new ConfigurationItem(baselineRuleReleased.getUser(), baselineRuleReleased.getWorkspace(), baselineRuleReleased.getConfigurationItemKey().getId(), "description"); configurationItem.setDesignItem(baselineRuleReleased.getPartMaster()); Mockito.when(configurationItemDAO.loadConfigurationItem(baselineRuleReleased.getConfigurationItemKey())).thenReturn(configurationItem); ProductBaseline baseline = productBaselineService.createBaseline(baselineRuleReleased.getConfigurationItemKey(), baselineRuleReleased.getName(), baselineRuleReleased.getType(), baselineRuleReleased.getDescription(), new ArrayList<>(), baselineRuleReleased.getSubstituteLinks(), baselineRuleReleased.getOptionalUsageLinks(), null, null, null, false); Assert.assertNotNull(baseline); Assert.assertEquals(baselineRuleReleased.getDescription(), baseline.getDescription()); Assert.assertEquals(ProductBaselineType.LATEST, baseline.getType()); Assert.assertEquals(baselineRuleReleased.getWorkspace().getId(), baseline.getConfigurationItem().getWorkspaceId()); }