Search in sources :

Example 11 with ProjectSyncModel

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;
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) ProjectCloneCategoriesType(com.synopsys.integration.blackduck.api.generated.enumeration.ProjectCloneCategoriesType)

Example 12 with 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;
    }
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) BlackDuckApiException(com.synopsys.integration.blackduck.exception.BlackDuckApiException)

Example 13 with ProjectSyncModel

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);
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) BlackDuckTestConnection(com.synopsys.integration.detect.battery.docker.integration.BlackDuckTestConnection) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 14 with 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)));
}
Also used : PolicyRuleExpressionSetBuilder(com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder) PolicyRuleExpressionView(com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView) ProjectBomService(com.synopsys.integration.blackduck.service.dataservice.ProjectBomService) PolicySummaryView(com.synopsys.integration.blackduck.api.manual.temporary.response.PolicySummaryView) IntLogger(com.synopsys.integration.log.IntLogger) HttpUrl(com.synopsys.integration.rest.HttpUrl) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) Assume(org.junit.Assume) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Tag(org.junit.jupiter.api.Tag) NoSuchElementException(java.util.NoSuchElementException) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) PolicyRuleCategoryType(com.synopsys.integration.blackduck.api.generated.enumeration.PolicyRuleCategoryType) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) PolicyRuleConditionOperatorType(com.synopsys.integration.blackduck.api.enumeration.PolicyRuleConditionOperatorType) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) PolicyRuleService(com.synopsys.integration.blackduck.service.dataservice.PolicyRuleService) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) Test(org.junit.jupiter.api.Test) List(java.util.List) TimingExtension(com.synopsys.integration.blackduck.TimingExtension) Assertions(org.junit.jupiter.api.Assertions) IntHttpClientTestHelper(com.synopsys.integration.blackduck.http.client.IntHttpClientTestHelper) Optional(java.util.Optional) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProjectVersionComponentPolicyStatusType(com.synopsys.integration.blackduck.api.generated.enumeration.ProjectVersionComponentPolicyStatusType) PolicyRuleService(com.synopsys.integration.blackduck.service.dataservice.PolicyRuleService) ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) PolicySummaryView(com.synopsys.integration.blackduck.api.manual.temporary.response.PolicySummaryView) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) IntLogger(com.synopsys.integration.log.IntLogger) ProjectBomService(com.synopsys.integration.blackduck.service.dataservice.ProjectBomService) HttpUrl(com.synopsys.integration.rest.HttpUrl) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) List(java.util.List) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) NoSuchElementException(java.util.NoSuchElementException) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Test(org.junit.jupiter.api.Test)

Example 15 with ProjectSyncModel

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);
    }
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) ProjectRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest)

Aggregations

ProjectSyncModel (com.synopsys.integration.blackduck.service.model.ProjectSyncModel)23 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)15 Test (org.junit.jupiter.api.Test)13 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)6 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)6 ProjectService (com.synopsys.integration.blackduck.service.dataservice.ProjectService)6 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)5 ProjectRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectRequest)5 IntLogger (com.synopsys.integration.log.IntLogger)5 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)4 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)4 HttpUrl (com.synopsys.integration.rest.HttpUrl)4 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)3 ProjectBomService (com.synopsys.integration.blackduck.service.dataservice.ProjectBomService)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)2 CodeLocationView (com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)2 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)2 ProjectVersionRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.ProjectVersionRequest)2 BlackDuckApiException (com.synopsys.integration.blackduck.exception.BlackDuckApiException)2