use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project synopsys-detect by blackducksoftware.
the class SyncProjectOperation method createProjectSyncModel.
public ProjectSyncModel createProjectSyncModel(NameVersion projectNameVersion, ProjectGroupFindResult projectGroupFindResult, CloneFindResult cloneFindResult, ProjectVersionLicenseFindResult projectVersionLicensesFindResult, ProjectSyncOptions projectSyncOptions) {
ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectNameVersion.getName(), projectNameVersion.getVersion());
// TODO: Handle a boolean property not being set in detect configuration - ie need to determine if this property actually exists in the ConfigurableEnvironment - just omit this one?
projectSyncModel.setProjectLevelAdjustments(projectSyncOptions.getProjectLevelAdjustments());
Optional.ofNullable(projectSyncOptions.getProjectVersionPhase()).ifPresent(projectSyncModel::setPhase);
Optional.ofNullable(projectSyncOptions.getProjectVersionDistribution()).ifPresent(projectSyncModel::setDistribution);
Integer projectTier = projectSyncOptions.getProjectTier();
if (null != projectTier && projectTier >= 1 && projectTier <= 5) {
projectSyncModel.setProjectTier(projectTier);
}
String description = projectSyncOptions.getProjectDescription();
if (StringUtils.isNotBlank(description)) {
projectSyncModel.setDescription(description);
}
String releaseComments = projectSyncOptions.getProjectVersionNotes();
if (StringUtils.isNotBlank(releaseComments)) {
projectSyncModel.setReleaseComments(releaseComments);
}
List<ProjectCloneCategoriesType> cloneCategories = projectSyncOptions.getCloneCategories();
projectSyncModel.setCloneCategories(cloneCategories);
String nickname = projectSyncOptions.getProjectVersionNickname();
if (StringUtils.isNotBlank(nickname)) {
projectSyncModel.setNickname(nickname);
}
if (cloneFindResult.getCloneUrl().isPresent()) {
logger.debug("Cloning project version from release url: {}", cloneFindResult.getCloneUrl().get());
projectSyncModel.setCloneFromReleaseUrl(cloneFindResult.getCloneUrl().get().string());
}
projectGroupFindResult.getProjectGroup().ifPresent(projectGroupUrl -> {
logger.debug("Setting project group to url: {}", projectGroupUrl);
projectSyncModel.setProjectGroup(projectGroupUrl.string());
});
projectVersionLicensesFindResult.getLicenseUrl().ifPresent(projectSyncModel::setVersionLicenseUrl);
return projectSyncModel;
}
use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project synopsys-detect by blackducksoftware.
the class SyncProjectOperation method sync.
public ProjectVersionWrapper sync(NameVersion projectNameVersion, ProjectGroupFindResult projectGroupFindResult, CloneFindResult cloneFindResult, ProjectVersionLicenseFindResult projectVersionLicensesFindResult, ProjectSyncOptions projectSyncOptions) throws DetectUserFriendlyException, IntegrationException {
ProjectSyncModel projectSyncModel = createProjectSyncModel(projectNameVersion, projectGroupFindResult, cloneFindResult, projectVersionLicensesFindResult, projectSyncOptions);
boolean forceUpdate = projectSyncOptions.isForceProjectVersionUpdate();
// TODO- remove try-catch once there is a mechanism for validating property values against BD versions
try {
return projectService.syncProjectAndVersion(projectSyncModel, forceUpdate);
} catch (BlackDuckApiException e) {
if (projectSyncOptions.getCloneCategories().contains(ProjectCloneCategoriesType.DEEP_LICENSE)) {
String message = "Attempt to create or update project failed. If you are using a Black Duck earlier than 2022.2.0, this may be because you passed DEEP_LICENSE as a project clone category, either explicitly or by passing ALL.";
throw new IntegrationException(message, e);
}
throw e;
}
}
use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project synopsys-detect by blackducksoftware.
the class RiskReportServiceTestIT method createProjectFirst.
@BeforeAll
public static void createProjectFirst() throws IntegrationException {
String testPhase = ProjectVersionPhaseType.DEVELOPMENT.name();
String testDistribution = ProjectVersionDistributionType.OPENSOURCE.name();
ProjectSyncModel projectSyncModel = new ProjectSyncModel(PROJECT_NAME, PROJECT_VERSION_NAME);
projectSyncModel.setPhase(ProjectVersionPhaseType.valueOf(testPhase));
projectSyncModel.setDistribution(ProjectVersionDistributionType.valueOf(testDistribution));
BlackDuckTestConnection blackDuckTestConnection = BlackDuckTestConnection.fromEnvironment();
blackDuckTestConnection.createProjectService().syncProjectAndVersion(projectSyncModel);
}
use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.
the class ProjectBomServiceTestIT method testGetActivePoliciesForVersion.
@Test
public void testGetActivePoliciesForVersion() throws Exception {
BlackDuckServicesFactory blackDuckServicesFactory = intHttpClientTestHelper.createBlackDuckServicesFactory();
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
ProjectService projectService = blackDuckServicesFactory.createProjectService();
ProjectBomService projectBomService = blackDuckServicesFactory.createProjectBomService();
PolicyRuleService policyRuleService = blackDuckServicesFactory.createPolicyRuleService();
IntLogger logger = blackDuckServicesFactory.getLogger();
String projectName = "get_active_policies_test";
String projectVersionName = "1.0.0";
String testPolicyName = "testPolicy";
String componentGroup = "com.synopsys.integration";
String componentName = "blackduck-common";
String componentVersion = "47.0.0";
ExternalId componentExternalId = externalIdFactory.createMavenExternalId(componentGroup, componentName, componentVersion);
// delete the project, if it exists
intHttpClientTestHelper.deleteIfProjectExists(logger, projectService, blackDuckApiClient, projectName);
// create the project
ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectName, projectVersionName);
ProjectVersionWrapper projectVersionWrapper = projectService.syncProjectAndVersion(projectSyncModel);
// check for presence of active-policy-rules link for project version (if not present then this is an older/incompatible BlackDuck, test should abort)
try {
projectVersionWrapper.getProjectVersionView().metaActivePolicyRulesLink();
} catch (NoSuchElementException e) {
// skip test if exception is thrown
Assume.assumeNoException(e);
}
// verify the bom
List<ProjectVersionComponentVersionView> bomComponents = projectBomService.getComponentsForProjectVersion(projectVersionWrapper.getProjectVersionView());
assertEquals(0, bomComponents.size());
projectBomService.addComponentToProjectVersion(componentExternalId, projectVersionWrapper.getProjectVersionView());
// get added component
ProjectVersionView projectVersionView = projectVersionWrapper.getProjectVersionView();
ProjectVersionComponentVersionView projectVersionComponentVersionView = blackDuckApiClient.getAllResponses(projectVersionView.metaComponentsLink()).stream().filter(component -> component.getComponentName().equals(componentName)).findFirst().orElse(null);
// find corresponding ComponentVersionView
HttpUrl projectVersionComponentUrl = new HttpUrl(projectVersionComponentVersionView.getComponentVersion());
ComponentVersionView componentVersionView = blackDuckApiClient.getResponse(projectVersionComponentUrl, ComponentVersionView.class);
// create policy rule that should be violated by that projectversion
PolicyRuleView policyRule = createTestPolicyRuleForProjectWithComponentVersion(projectVersionWrapper.getProjectView(), componentVersionView, testPolicyName);
Optional<PolicyRuleView> existingDuplicateRule = policyRuleService.getAllPolicyRules().stream().filter(rule -> rule.getName().equals(testPolicyName)).findFirst();
if (existingDuplicateRule.isPresent()) {
blackDuckApiClient.delete(existingDuplicateRule.get());
}
policyRuleService.createPolicyRule(policyRule);
// need this to give Black Duck enough time to check the project version against the policy rule
Thread.sleep(10000);
// query projectBomService to see if project version has violated rule
Optional<List<PolicySummaryView>> activePolicies = projectBomService.getActivePoliciesForVersion(projectVersionView);
Assertions.assertTrue(activePolicies.isPresent());
Assertions.assertFalse(activePolicies.get().isEmpty());
Assertions.assertTrue(activePolicies.get().stream().filter(rule -> ProjectVersionComponentPolicyStatusType.IN_VIOLATION.equals(rule.getStatus())).map(PolicySummaryView::getName).anyMatch(name -> name.equals(testPolicyName)));
}
use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.
the class BasicRecipe method createThrowAwayProjects.
public void createThrowAwayProjects(int numberOfProjectsToCreate) throws IntegrationException {
for (int i = 1; i <= numberOfProjectsToCreate; i++) {
String uniqueProjectName = PROJECT_NAME + System.currentTimeMillis();
ProjectSyncModel projectSyncModel = createProjectSyncModel(uniqueProjectName, PROJECT_VERSION_NAME);
ProjectRequest projectRequest = projectSyncModel.createProjectRequest();
projectService.createProject(projectRequest);
}
}
Aggregations